diff --git a/crc/api.yml b/crc/api.yml index 5e79cfc9..52014447 100644 --- a/crc/api.yml +++ b/crc/api.yml @@ -362,21 +362,15 @@ paths: schema: $ref: "#/components/schemas/File" put: - operationId: crc.api.file.update_file + operationId: crc.api.file.update_file_info summary: Update a file tags: - Files requestBody: content: - multipart/form-data: + application/json: schema: - type: object - properties: - workflow_spec_id: - type: string - file: - type: string - format: binary + $ref: "#/components/schemas/File" responses: '200': description: Metadata about the uploaded file, but not the file content. @@ -401,7 +395,7 @@ paths: schema: type: integer get: - operationId: crc.api.file.get_file + operationId: crc.api.file.get_file_data summary: Returns only the file contents tags: - Files @@ -414,6 +408,29 @@ paths: type: string format: binary example: '' + put: + operationId: crc.api.file.update_file_data + summary: Update only the file contents for a given file + tags: + - Files + requestBody: + content: + multipart/form-data: + schema: + type: object + properties: + file: + type: string + format: binary + responses: + '200': + description: Returns the actual file + content: + application/octet-stream: + schema: + type: string + format: binary + example: '' # /v1.0/workflow/0 /workflow/{workflow_id}: parameters: diff --git a/crc/api/file.py b/crc/api/file.py index 85b70f82..8f33b158 100644 --- a/crc/api/file.py +++ b/crc/api/file.py @@ -60,7 +60,7 @@ def add_file(): return FileModelSchema().dump(file_model) -def update_file(file_id): +def update_file_data(file_id): file_model = session.query(FileModel).filter_by(id=file_id).with_for_update().first() if file_model is None: return ApiErrorSchema().dump(ApiError('no_such_file', 'The file id you provided does not exist')), 404 @@ -68,7 +68,7 @@ def update_file(file_id): return FileModelSchema().dump(file_model) -def get_file(file_id): +def get_file_data(file_id): file_data = session.query(FileDataModel).filter_by(id=file_id).first() if file_data is None: return ApiErrorSchema().dump(ApiError('no_such_file', 'The file id you provided does not exist')), 404 @@ -87,6 +87,23 @@ def get_file_info(file_id): return FileModelSchema().dump(file_model) +def update_file_info(file_id, body): + if file_id is None: + error = ApiError('unknown_file', 'Please provide a valid File ID.') + return ApiErrorSchema.dump(error), 404 + + file_model = session.query(FileModel).filter_by(id=file_id).first() + + if file_model is None: + error = ApiError('unknown_file_model', 'The file_model "' + file_id + '" is not recognized.') + return ApiErrorSchema.dump(error), 404 + + file_model = FileModelSchema().load(body, session=session) + session.add(file_model) + session.commit() + return FileModelSchema().dump(file_model) + + def delete_file(file_id): session.query(FileDataModel).filter_by(file_model_id=file_id).delete() session.query(FileModel).filter_by(id=file_id).delete() diff --git a/crc/workflow_processor.py b/crc/workflow_processor.py index d1b06c69..1f277663 100644 --- a/crc/workflow_processor.py +++ b/crc/workflow_processor.py @@ -72,7 +72,7 @@ class WorkflowProcessor: dmn: ElementTree.Element = ElementTree.fromstring(file_data.data) parser.add_dmn_xml(dmn, filename=file_data.file_model.name) if process_id is None: - raise(Exception("There is no primary BPMN model defined for workflow " + workflow_spec_id)) + raise(Exception("There is no primary BPMN model defined for workflow %s" % workflow_spec_id)) return parser.get_spec(process_id) @classmethod