예제 #1
0
def decide(order):
    decision_type = DecisionType.IGNORE
    o = order
    message = ""

    if order.order_type() == OrderType.CREATE_APPLICATION:
        kintone = kintoneInterface()
        infos = kintone.find_similar_applications(order.target)
        if len(infos) > 0:
            decision_type = DecisionType.HOLD
            Order.hold_order(o)
            names = [info.name for info in infos][:2]
            message = "{0}などの似ているアプリケーションがありますがよろしいですか?".format("、".join(names))
        else:
            decision_type = DecisionType.EXECUTE
    elif order.order_type() == OrderType.ALLOW:
        o = Order.pop_order(order.user_address)
        decision_type = DecisionType.EXECUTE
    else:
        if order.app_id:
            decision_type = DecisionType.EXECUTE
        else:
            message = "このアドレスで登録されているアプリケーションが見つかりません。"

    a = Action(decision_type, o, message)
    return a
예제 #2
0
def post(action):
    ks = kintoneInterface()
    app = ks.service.app(action.order.app_id)
    app_index = ks.get_application_index(app.app_id)
    letter = action.order.letter()
    analyzer = TextAnalyzer()

    # get form structure
    layouts = app.administration().form().get_layout(app.app_id).layouts
    fields = []
    for ly in layouts:
        fields += ly.fields
    data = analyzer.map_letter_to_field(letter, fields)

    # file field
    file_field = [f for f in fields if f.field_type == "FILE"]
    if len(file_field) > 0 and len(letter.attached_files) > 0:
        from pykintone.structure_field import File
        at = letter.attached_files[0]
        f = File.upload(at["content"], app, file_name=at["filename"])
        data[file_field[0].code] = {
            "value": [{
                "fileKey": f.file_key
            }]
        }

    result = app.create(data)
    return result, app_index
예제 #3
0
def update_application(action):
    from kanaria.core.environment import Environment

    kintone = kintoneInterface()
    order_type = action.order.order_type()
    field_name = action.order.target

    app = kintone.service.app(action.order.app_id)
    app_index = kintone.get_application_index(app.app_id)
    result = None
    with app.administration().form() as admin:
        if order_type == OrderType.ADD_ITEM:
            import pykintone.application_settings.form_field as ff
            analyzer = TextAnalyzer()
            field_type = analyzer.estimate_field_type(field_name)
            field_code = Environment.get_translator(kintone._env).translate(
                field_name, "en").replace(" ", "_")
            f = ff.BaseFormField.create(field_type, field_code, field_name)
            result = admin.add(f)
        else:
            fields = admin.get().fields
            target = [f for f in fields if f.label == field_name]
            if len(target) > 0:
                result = admin.delete(target[0])

    return result, app_index
예제 #4
0
def update_application(action):
    from kanaria.core.environment import Environment

    kintone = kintoneInterface()
    order_type = action.order.order_type()
    field_name = action.order.target

    app = kintone.service.app(action.order.app_id)
    app_index = kintone.get_application_index(app.app_id)
    result = None
    with app.administration().form() as admin:
        if order_type == OrderType.ADD_ITEM:
            import pykintone.application_settings.form_field as ff
            analyzer = TextAnalyzer()
            field_type = analyzer.estimate_field_type(field_name)
            field_code = Environment.get_translator(kintone._env).translate(field_name, "en").replace(" ", "_")
            f = ff.BaseFormField.create(field_type, field_code, field_name)
            result = admin.add(f)
        else:
            fields = admin.get().fields
            target = [f for f in fields if f.label == field_name]
            if len(target) > 0:
                result = admin.delete(target[0])

    return result, app_index
예제 #5
0
def decide(order):
    decision_type = DecisionType.IGNORE
    o = order
    message = ""

    if order.order_type() == OrderType.CREATE_APPLICATION:
        kintone = kintoneInterface()
        infos = kintone.find_similar_applications(order.target)
        if len(infos) > 0:
            decision_type = DecisionType.HOLD
            Order.hold_order(o)
            names = [info.name for info in infos][:2]
            message = "{0}などの似ているアプリケーションがありますがよろしいですか?".format(
                "、".join(names))
        else:
            decision_type = DecisionType.EXECUTE
    elif order.order_type() == OrderType.ALLOW:
        o = Order.pop_order(order.user_address)
        decision_type = DecisionType.EXECUTE
    else:
        if order.app_id:
            decision_type = DecisionType.EXECUTE
        else:
            message = "このアドレスで登録されているアプリケーションが見つかりません。"

    a = Action(decision_type, o, message)
    return a
예제 #6
0
파일: order.py 프로젝트: icoxfog417/kanaria
 def letter(self):
     lt = None
     if self._letter:
         lt = self._letter
     elif self.letter_id:
         from kanaria.core.service.kintone import kintoneInterface
         kintone = kintoneInterface()
         app = kintone.get_kanaria(create_if_not_exist=False)
         if app:
             self._letter = app.get(self.letter_id).model(Letter)
             self._letter.attached_files = self._letter.attached_files if self._letter.attached_files else []
             self._letter.to_addresses = self._letter.to_addresses if self._letter.to_addresses else []
             lt = self._letter
     return lt
예제 #7
0
파일: order.py 프로젝트: icoxfog417/kanaria
    def letter(self):
        lt = None
        if self._letter:
            lt = self._letter
        elif self.letter_id:
            from kanaria.core.service.kintone import kintoneInterface

            kintone = kintoneInterface()
            app = kintone.get_kanaria(create_if_not_exist=False)
            if app:
                self._letter = app.get(self.letter_id).model(Letter)
                self._letter.attached_files = self._letter.attached_files if self._letter.attached_files else []
                self._letter.to_addresses = self._letter.to_addresses if self._letter.to_addresses else []
                lt = self._letter
        return lt
예제 #8
0
def interpret(letter):
    kintone = kintoneInterface()
    order_type = OrderType.NONE
    app_id = ""
    target = ""
    kanaria = kintone.get_kanaria()

    if letter.to_includes(Brain.MY_USER_NAME):
        # to kanaria administrator
        if kanaria:
            app_id = kanaria.app_id

        if letter.subject:
            order_type = interpret_allow(letter.subject)
            if order_type != OrderType.ALLOW:
                order_type = OrderType.CREATE_APPLICATION
                target = extract_application_name(letter.subject)
    else:
        # to application's address
        for a in letter.to_addresses:
            app = kintone.get_application_by_code(Letter.get_user(a))
            if app:
                app_id = app.app_id

        # get order type
        if app_id:
            if letter.subject:
                target, order_type = interpret_operation(letter.subject)
            if order_type == OrderType.NONE:
                order_type = OrderType.POST_LETTER

    o = Order(order_type,
              letter.from_address,
              app_id=app_id,
              target=target,
              letter=letter)
    # post letter to kanaria
    if kanaria:
        # todo have to support attached file
        if len(letter.attached_files) == 0:
            created = kanaria.create(letter)
            o.letter_id = created.record_id

    return o
예제 #9
0
def create_application(action, enable_copy=True):
    from kanaria.core.environment import Environment

    kintone = kintoneInterface()
    name = action.order.target
    code = Environment.get_translator(kintone._env).translate(name, "en").replace(" ", "_").lower()
    app_info = kintone.find_similar_applications(name, find_template=True)

    app = None
    app_index = None
    if len(app_info) > 0 and enable_copy:
        app = kintone.copy_application(app_info[0].app_id, name, code)
    else:
        app = kintone.create_default_application(name, code)

    if app:
        app_index = kintone.get_application_index(app.app_id)

    return app, app_index
예제 #10
0
def create_application(action, enable_copy=True):
    from kanaria.core.environment import Environment

    kintone = kintoneInterface()
    name = action.order.target
    code = Environment.get_translator(kintone._env).translate(
        name, "en").replace(" ", "_").lower()
    app_info = kintone.find_similar_applications(name, find_template=True)

    app = None
    app_index = None
    if len(app_info) > 0 and enable_copy:
        app = kintone.copy_application(app_info[0].app_id, name, code)
    else:
        app = kintone.create_default_application(name, code)

    if app:
        app_index = kintone.get_application_index(app.app_id)

    return app, app_index
예제 #11
0
def interpret(letter):
    kintone = kintoneInterface()
    order_type = OrderType.NONE
    app_id = ""
    target = ""
    kanaria = kintone.get_kanaria()

    if letter.to_includes(Brain.MY_USER_NAME):
        # to kanaria administrator
        if kanaria:
            app_id =kanaria.app_id

        if letter.subject:
            order_type = interpret_allow(letter.subject)
            if order_type != OrderType.ALLOW:
                order_type = OrderType.CREATE_APPLICATION
                target = extract_application_name(letter.subject)
    else:
        # to application's address
        for a in letter.to_addresses:
            app = kintone.get_application_by_code(Letter.get_user(a))
            if app:
                app_id = app.app_id

        # get order type
        if app_id:
            if letter.subject:
                target, order_type = interpret_operation(letter.subject)
            if order_type == OrderType.NONE:
                order_type = OrderType.POST_LETTER

    o = Order(order_type, letter.from_address, app_id=app_id, target=target, letter=letter)
    # post letter to kanaria
    if kanaria:
        # todo have to support attached file
        if len(letter.attached_files) == 0:
            created = kanaria.create(letter)
            o.letter_id = created.record_id

    return o
예제 #12
0
def post(action):
    ks = kintoneInterface()
    app = ks.service.app(action.order.app_id)
    app_index = ks.get_application_index(app.app_id)
    letter = action.order.letter()
    analyzer = TextAnalyzer()

    # get form structure
    layouts = app.administration().form().get_layout(app.app_id).layouts
    fields = []
    for ly in layouts:
        fields += ly.fields
    data = analyzer.map_letter_to_field(letter, fields)

    # file field
    file_field = [f for f in fields if f.field_type == "FILE"]
    if len(file_field) > 0 and len(letter.attached_files) > 0:
        from pykintone.structure_field import File
        at = letter.attached_files[0]
        f = File.upload(at["content"], app, file_name=at["filename"])
        data[file_field[0].code] = {"value": [{"fileKey": f.file_key}]}

    result = app.create(data)
    return result, app_index
예제 #13
0
 def test_create_kanaria(self):
     kintone = kintoneInterface()
     kanaria = kintone.get_kanaria(True)
     self.assertTrue(kanaria)
예제 #14
0
 def test_get_application(self):
     kintone = kintoneInterface()
     app = kintone.get_application_by_code("xxxx")
     print(app)
예제 #15
0
파일: agent.py 프로젝트: icoxfog417/kanaria
 def __init__(self):
     kintone = kintoneInterface()
     kintone.get_kanaria(create_if_not_exist=True)
예제 #16
0
 def test_create_kanaria(self):
     kintone = kintoneInterface()
     kanaria = kintone.get_kanaria(True)
     self.assertTrue(kanaria)
예제 #17
0
파일: agent.py 프로젝트: icoxfog417/kanaria
 def __init__(self):
     kintone = kintoneInterface()
     kintone.get_kanaria(create_if_not_exist=True)
예제 #18
0
 def test_get_application(self):
     kintone = kintoneInterface()
     app = kintone.get_application_by_code("xxxx")
     print(app)