def update_or_create_current_file(remote, workflow_spec_id, updatefile): currentfile = file_get(workflow_spec_id, updatefile['filename']) if not currentfile: currentfile = FileModel() currentfile.name = updatefile['filename'] if workflow_spec_id == 'REFERENCE_FILES': currentfile.workflow_spec_id = None currentfile.is_reference = True else: currentfile.workflow_spec_id = workflow_spec_id currentfile.date_created = updatefile['date_created'] currentfile.type = updatefile['type'] currentfile.primary = updatefile['primary'] currentfile.content_type = updatefile['content_type'] currentfile.primary_process_id = updatefile['primary_process_id'] session.add(currentfile) try: content = WorkflowSyncService.get_remote_file_by_hash( remote, updatefile['md5_hash']) FileService.update_file(currentfile, content, updatefile['type']) except ApiError: # Remote files doesn't exist, don't update it. print("Remote file " + currentfile.name + " does not exist, so not syncing.")
def update_workflow_spec_file_model(workflow_spec: WorkflowSpecModel, file_model: FileModel, binary_data, content_type): # Verify the extension file_extension = FileService.get_extension(file_model.name) if file_extension not in FileType._member_names_: raise ApiError( 'unknown_extension', 'The file you provided does not have an accepted extension:' + file_extension, status_code=404) else: file_model.type = FileType[file_extension] file_model.content_type = content_type file_model.archived = False # Unarchive the file if it is archived. # If this is a BPMN, extract the process id. if file_model.type == FileType.bpmn: try: bpmn: etree.Element = etree.fromstring(binary_data) file_model.primary_process_id = SpecFileService.get_process_id( bpmn) file_model.is_review = FileService.has_swimlane(bpmn) except etree.XMLSyntaxError as xse: raise ApiError("invalid_xml", "Failed to parse xml: " + str(xse), file_name=file_model.name) session.add(file_model) session.commit() return file_model