def _create_subfield_commands_list(self, subfields): """Creates the list of commands for the given subfields. @param subfields: json structure containing information about the subfileds. This data is used for creating the commands. @return: list of subfield commands. """ commands_list = [] for current_subfield in subfields: action = current_subfield["action"] subfield_code = current_subfield["subfieldCode"] value = current_subfield["value"] new_value = current_subfield["newValue"] condition = current_subfield["condition"] condition_subfield = current_subfield["conditionSubfield"] if action == self._subfield_action_types.add: subfield_command = multi_edit_engine.AddSubfieldCommand(subfield_code, value, condition=condition, condition_subfield=condition_subfield) elif action == self._subfield_action_types.delete: subfield_command = multi_edit_engine.DeleteSubfieldCommand(subfield_code, condition=condition, condition_subfield=condition_subfield) elif action == self._subfield_action_types.replace_content: subfield_command = multi_edit_engine.ReplaceSubfieldContentCommand(subfield_code, value, condition=condition, condition_subfield=condition_subfield) elif action == self._subfield_action_types.replace_text: subfield_command = multi_edit_engine.ReplaceTextInSubfieldCommand(subfield_code, value, new_value, condition=condition, condition_subfield=condition_subfield) else: subfield_command = multi_edit_engine.BaseFieldCommand(subfield_code, value, new_value) commands_list.append(subfield_command) return commands_list
def _create_subfield_commands_list(self, subfields): """Creates the list of commands for the given subfields. @param subfields: json structure containing information about the subfileds. This data is used for creating the commands. @return: list of subfield commands. """ commands_list = [] upload_mode_replace = False for current_subfield in subfields: action = current_subfield["action"] subfield_code = current_subfield["subfieldCode"] value = current_subfield["value"] if "additionalValues" in current_subfield: additional_values = current_subfield["additionalValues"] else: additional_values = [] new_value = current_subfield["newValue"] condition = current_subfield["condition"] condition_exact_match = False condition_does_not_exist = False if int(current_subfield["conditionSubfieldExactMatch"]) == 0: condition_exact_match = True if int(current_subfield["conditionSubfieldExactMatch"]) == 2: condition_does_not_exist = True condition_subfield = current_subfield["conditionSubfield"] if action == self._subfield_action_types.add: subfield_command = multi_edit_engine.AddSubfieldCommand(subfield_code, value, condition=condition, condition_exact_match=condition_exact_match, condition_does_not_exist=condition_does_not_exist, condition_subfield=condition_subfield) elif action == self._subfield_action_types.delete: subfield_command = multi_edit_engine.DeleteSubfieldCommand(subfield_code, condition=condition, condition_exact_match=condition_exact_match, condition_does_not_exist=condition_does_not_exist, condition_subfield=condition_subfield) upload_mode_replace = True elif action == self._subfield_action_types.replace_content: subfield_command = multi_edit_engine.ReplaceSubfieldContentCommand(subfield_code, value, condition=condition, condition_exact_match=condition_exact_match, condition_does_not_exist=condition_does_not_exist, condition_subfield=condition_subfield) elif action == self._subfield_action_types.replace_text: subfield_command = multi_edit_engine.ReplaceTextInSubfieldCommand(subfield_code, value, new_value, condition=condition, condition_exact_match=condition_exact_match, condition_does_not_exist=condition_does_not_exist, condition_subfield=condition_subfield, additional_values=additional_values) else: subfield_command = multi_edit_engine.BaseFieldCommand(subfield_code, value, new_value) commands_list.append(subfield_command) return commands_list, upload_mode_replace