def _create_commands_list(self, commands_json_structure):
        """Creates a list of commands recognized by multiedit engine"""

        commands_list = []

        upload_mode = '-c'
        tag_list = ["001"]
        for current_field in commands_json_structure:

            tag = current_field["tag"]
            tag_list.append(tag)
            ind1 = current_field["ind1"]
            ind2 = current_field["ind2"]
            action = current_field["action"]

            subfields = current_field["subfields"]
            subfield_commands, upload_mode_replace = self._create_subfield_commands_list(subfields)
            if upload_mode_replace:
                upload_mode = '-r'
            # create appropriate command depending on the type
            if action == self._field_action_types.add:
                command = multi_edit_engine.AddFieldCommand(tag, ind1, ind2, subfield_commands)
            elif action == self._field_action_types.delete:
                command = multi_edit_engine.DeleteFieldCommand(tag, ind1, ind2, subfield_commands)
                upload_mode = '-r'
            elif action == self._field_action_types.update:
                command = multi_edit_engine.UpdateFieldCommand(tag, ind1, ind2, subfield_commands)
            else:
                # if someone send wrong action type, we use empty command
                command = multi_edit_engine.BaseFieldCommand()

            commands_list.append(command)

        return commands_list, upload_mode, tag_list
Beispiel #2
0
    def _create_commands_list(self, commands_json_structure):
        """Creates a list of commands recognized by multiedit engine"""

        commands_list = []

        upload_mode = '-c'
        tag_list = ["001"]
        for current_field in commands_json_structure:

            tag = current_field["tag"]
            tag_list.append(tag)
            ind1 = current_field["ind1"]
            ind2 = current_field["ind2"]
            action = current_field["action"]
            conditionSubfield = current_field["conditionSubfield"]
            condition = current_field["condition"]
            condition_exact_match = False
            condition_does_not_exist = False
            if int(current_field["conditionSubfieldExactMatch"]) == 0:
                condition_exact_match = True
            if int(current_field["conditionSubfieldExactMatch"]) == 2:
                condition_does_not_exist = True

            subfields = current_field["subfields"]
            subfield_commands, upload_mode_replace = self._create_subfield_commands_list(
                subfields)
            if upload_mode_replace:
                upload_mode = '-r'
            # create appropriate command depending on the type
            if action == self._field_action_types.add:
                command = multi_edit_engine.AddFieldCommand(
                    tag, ind1, ind2, subfield_commands)
            elif action == self._field_action_types.delete:
                command = multi_edit_engine.DeleteFieldCommand(
                    tag, ind1, ind2, subfield_commands, conditionSubfield,
                    condition, condition_exact_match, condition_does_not_exist)
                upload_mode = '-r'
            elif action == self._field_action_types.update:
                command = multi_edit_engine.UpdateFieldCommand(
                    tag, ind1, ind2, subfield_commands)
            else:
                raise ValueError("Invalid action: %s" % action)

            commands_list.append(command)

        return commands_list, upload_mode, tag_list