Esempio n. 1
0
 def add_action_log_entry(message, level='INFO'):
     json = {
         "requestType": "ADD_ACTION_LOG",
         "level": level,
         "message": message
     }
     Communicator.get_instance().send_asynchronous(json=json)
Esempio n. 2
0
    def event(self, event_data):
        try:
            if event_data.event_type == "BUTTON_CLICK":
                if event_data.event_details in self.button_click_listeners:
                    for listener in self.button_click_listeners[
                            event_data.event_details]:
                        listener(event_data)

                    return False  # don't close the window
                else:
                    self.json_window.close_with_error(
                        "No button_click_listeners defined for eventDetails '{}'"
                        .format(event_data.event_details))

            elif event_data.event_type == "VALUE CHANGE":
                if event_data.object_id in self.value_change_listeners:
                    for listener in self.value_change_listeners[
                            event_data.object_id]:
                        result = listener(event_data)

                return False  # Make sure the form doesn't close
        except Exception as e:
            traceback.print_exc()
            print('Exception while handling button click: ' + str(e),
                  flush=True)
            Communicator.get_instance().show_exception_dialog(
                exception=e, title="Exception occured")

        return True
Esempio n. 3
0
 def add_action_error(code, message):
     json = {
         "requestType": "ADD_ACTION_ERROR",
         "code": code,
         "message": message
     }
     Communicator.get_instance().send_asynchronous(json=json)
Esempio n. 4
0
    def set_data_part(self,
                      key,
                      list_items_attribute="items",
                      data_part_json=None,
                      data_part_file=None,
                      data_part_url=None,
                      cached_filename=None):

        for data_part in self.data_parts:
            if data_part['id'] == key:
                self.data_parts.remove(data_part)

        full_data_part_json = self.add_data_part(key, list_items_attribute,
                                                 data_part_json,
                                                 data_part_file, data_part_url,
                                                 cached_filename)

        json = {
            "requestType": "UI",
            "subType": "UPDATE DATA PART",
            "objectId": key,
        }

        if data_part_json:
            json.update({"data": data_part_json})
        else:
            json.update({"cachedFilename": cached_filename})

        Communicator.get_instance().send_synchronous(json=json)
Esempio n. 5
0
 def set_rest_response(message):
     json = {
         "requestType": "SET_REST_RESPONSE",
         "actionResponse": {
             "message": message
         }
     }
     Communicator.get_instance().send_asynchronous(json=json)
Esempio n. 6
0
    def close(self):
        if not self.window_is_open:
            return
        json = {"requestType": "UI", "subType": "ACTION", "action": "close"}

        Communicator.get_instance().send_synchronous(json=json)
        Communicator.get_instance().stop_listening()
        self.window_is_open = False
Esempio n. 7
0
    def set_object_enabled(self, object_id, value=True):
        json = {
            "requestType": "UI",
            "subType": "SET ENABLED",
            "objectId": object_id
        }
        json.update({"value": value})

        Communicator.get_instance().send_synchronous(json=json)
Esempio n. 8
0
 def set_form(self,
              form,
              form_loaded_listener=None,
              auto_close=False,
              status=""):
     self.active_form = form
     self.auto_close = auto_close
     self.form_loaded_listener = form_loaded_listener
     json = form.generate_json()
     if status == "":
         self.set_status(status)
     Communicator.get_instance().send_synchronous(
         json=json, callback=self.answer_received)
Esempio n. 9
0
    def set_object_value(self, object_id, value=None, base64Value=None):
        assert value or base64Value

        json = {
            "requestType": "UI",
            "subType": "UPDATE VALUE",
            "objectId": object_id
        }
        if value:
            json.update({"value": value})
        else:
            json.update({"valueBase64": base64Value})

        Communicator.get_instance().send_synchronous(json=json)
Esempio n. 10
0
 def store_selected_items(self, object_id, selected_rows_only=False):
     json = {
         "requestType": "UI",
         "subType": "STORE SELECTED ITEMS",
         "objectId": object_id,
         "selectedRowsOnly": selected_rows_only
     }
     return Communicator.get_instance().send_synchronous(json=json)
Esempio n. 11
0
    def show(self, css_file=None):
        self.css_file = css_file
        json = {
            "requestType": "UI",
            "subType": "WINDOW",
        }

        if css_file:
            file = open(css_file, 'r')
            css = file.read()
            base64_css = base64.b64encode(css.encode("utf-8"))
            json["css"] = base64_css.decode("utf-8")

        Communicator.get_instance().send_synchronous(
            json=json,
            callback=self.answer_received,
            return_on_first_answer=False)
        self.window_is_open = True
    def _execute_action(self, label, json):
        self.set_status(label)
        self.logger.audit(label)
        answer = Communicator.get_instance().send_synchronous(
            json=json, return_on_first_answer=False)
        if answer:
            print("Answer: {}.".format(answer), flush=True)

        self.set_status("Finished: {}".format(label))
        return answer
    def get_from_db_by_velocity_name(self,
                                     velocity_name,
                                     container_id=None,
                                     environment_id=None):
        assert container_id or environment_id
        json = {"requestType": "GET INSTANCE", "velocityName": velocity_name}

        if container_id:
            json.update({"containerId": container_id})
        else:
            json.update({"environmentId": environment_id})

        answer = Communicator.get_instance().send_synchronous(json=json)
        print(answer, flush=True)
        self.load_instance_from_server(answer)
 def update_instance(self,
                     compile_container=False,
                     compile_instance=False,
                     compile_environment=False):
     assert self.db_id
     json = {
         "requestType": "UPDATE INSTANCE",
         "dbId": self.db_id,
         "compileInstance": compile_instance,
         "compileContainer": compile_container,
         "compileEnvironment": compile_environment,
         "fields": self.to_json_fields()
     }
     answer = Communicator.get_instance().send_synchronous(json=json)
     return answer
    def process_ensure_or_clone_request(self, json, label):
        self.logger.audit_action_start(label=label)
        answer = Communicator.get_instance().send_synchronous(json=json, return_on_first_answer=True)
        self.logger.info("Answer: {}.".format(answer))
        action_taken = answer["actionTaken"]
        if action_taken == "none":
            self.set_status("Environment '{}' already exists!".format(self.name))
            self.is_new = False
            self.reason = answer["reason"]
        else:
            self.set_status("Finished: {}".format(label))
            self.logger.audit_action_complete(label=label)
            self.is_new = True

        self.db_id = answer["dbId"]
 def ensure_instance(self,
                     compile_container=False,
                     compile_instance=False,
                     compile_environment=False):
     json = {
         "requestType": "ENSURE INSTANCE",
         "packetGuid": self.packet_guid,
         "parentInstanceId": self.parent_instance_id,
         "compileInstance": compile_instance,
         "compileContainer": compile_container,
         "compileEnvironment": compile_environment,
         "fields": self.to_json_fields()
     }
     answer = Communicator.get_instance().send_synchronous(json=json)
     self.instance_id = answer["dbId"]
     return answer
Esempio n. 17
0
    def import_instances(self, remove_existing_children):
        json_request = {
            "requestType": "IMPORT INSTANCES",
            "parentInstanceId": self.parent_instance_id,
            "packetGuid": self.packet_guid,
            "removeExistingChildren": remove_existing_children,
            "instances": []
        }

        instances_attribute = json_request["instances"]
        for instance in self.instances:
            instances_attribute.append({"fields": instance.to_json_fields()})

        answer = Communicator.get_instance().send_synchronous(
            json=json_request)
        print("Json answer: {}.".format(answer), flush=True)
        return answer
Esempio n. 18
0
    def answer_received(self, json_object):
        try:
            if json_object == "":
                self.logger.info("Empty answer received from server.")
                Communicator.get_instance().wait_for_server(
                    callback=self.answer_received)
                return

            #print("===", flush=True)
            #print(json_object, flush=True)
            #print("===", flush=True)
            schema = ServerAnswerSchema()
            event_data = schema.load(json_object)
            if event_data.event_type == "FORM_LOADED":
                if self.form_loaded_listener:
                    self.form_loaded_listener(event_data)

                Communicator.get_instance().wait_for_server(
                    callback=self.answer_received)
                return

            elif event_data.event_type == "BUTTON_CLICK":
                if event_data.event_details == "CANCEL":
                    self.canceled = True
                    self.close()
                    return

            if self.active_form.event(event_data):
                if self.auto_close and event_data.event_details == "OK":
                    self.close()
            else:
                Communicator.get_instance().wait_for_server(
                    callback=self.answer_received)

        except Exception as e:
            print("Exception handling event", flush=True)
            traceback.print_exc()
            print(e, flush=True)
            raise e
 def set_status(self, message):
     Communicator.set_status(message)