From aa66221f4398ae904ed9aa79b78f5670e0a0ce07 Mon Sep 17 00:00:00 2001 From: Kriti Jain Date: Wed, 14 Aug 2024 13:12:44 -0500 Subject: [PATCH] re --- .../fqm/resource/MigrationController.java | 26 +++++++++++ .../swagger.api/mod-fqm-manager.yaml | 28 ++++++++++++ .../schemas/FqmMigrateRequest.json | 27 ++++++++++++ .../schemas/FqmMigrateResponse.json | 44 +++++++++++++++++++ 4 files changed, 125 insertions(+) create mode 100644 src/main/resources/swagger.api/schemas/FqmMigrateRequest.json create mode 100644 src/main/resources/swagger.api/schemas/FqmMigrateResponse.json diff --git a/src/main/java/org/folio/fqm/resource/MigrationController.java b/src/main/java/org/folio/fqm/resource/MigrationController.java index 633fd597..e52424ab 100644 --- a/src/main/java/org/folio/fqm/resource/MigrationController.java +++ b/src/main/java/org/folio/fqm/resource/MigrationController.java @@ -1,6 +1,9 @@ package org.folio.fqm.resource; import lombok.RequiredArgsConstructor; +import org.folio.fqm.domain.dto.FqmMigrateRequest; +import org.folio.fqm.domain.dto.FqmMigrateResponse; +import org.folio.fqm.migration.MigratableQueryInformation; import org.folio.fqm.service.MigrationService; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -15,4 +18,27 @@ public class MigrationController implements FqmVersionApi { public ResponseEntity getFqmVersion() { return new ResponseEntity<>(migrationService.getLatestVersion(), HttpStatus.OK); } + @Override + public ResponseEntity fqmMigrate(FqmMigrateRequest fqmMigrateRequest) { + MigratableQueryInformation migratableQueryInformation = new MigratableQueryInformation( + fqmMigrateRequest.getEntityTypeId(), + fqmMigrateRequest.getFqlQuery(), + fqmMigrateRequest.getFields() + ); + if (migratableQueryInformation.fqlQuery() == null) { + return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + } + + migrationService.migrate(migratableQueryInformation); + + // Prepare the response object + FqmMigrateResponse fqmMigrateResponse = new FqmMigrateResponse(); + fqmMigrateResponse.setEntityTypeId(migratableQueryInformation.entityTypeId()); + fqmMigrateResponse.setFqlQuery(migratableQueryInformation.fqlQuery()); + fqmMigrateResponse.setFields(migratableQueryInformation.fields()); + // fqmMigrateResponse.setWarnings(migratableQueryInformation.warnings().); + + return new ResponseEntity<>(fqmMigrateResponse, HttpStatus.OK); + } + } diff --git a/src/main/resources/swagger.api/mod-fqm-manager.yaml b/src/main/resources/swagger.api/mod-fqm-manager.yaml index 7c44ea66..cb0d08d8 100644 --- a/src/main/resources/swagger.api/mod-fqm-manager.yaml +++ b/src/main/resources/swagger.api/mod-fqm-manager.yaml @@ -79,6 +79,30 @@ paths: $ref: '#/components/responses/badRequestResponse' '500': $ref: '#/components/responses/internalServerErrorResponse' + /fqm/migrate: + post: + summary: fqm migrate request + operationId: fqmMigrate + tags: + - fqmVersion + requestBody: + description: 'Request for FQM version submitted successfully' + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/fqmMigrateRequest' + responses: + '201': + description: 'FQM version updated successfully' + content: + application/json: + schema: + $ref: '#/components/schemas/fqmMigrateResponse' + '400': + $ref: '#/components/responses/badRequestResponse' + '500': + $ref: '#/components/responses/internalServerErrorResponse' components: parameters: @@ -137,6 +161,10 @@ components: type: array items: type: string + fqmMigrateRequest: + $ref: schemas/FqmMigrateRequest.json + fqmMigrateResponse: + $ref: schemas/FqmMigrateResponse.json responses: badRequestResponse: diff --git a/src/main/resources/swagger.api/schemas/FqmMigrateRequest.json b/src/main/resources/swagger.api/schemas/FqmMigrateRequest.json new file mode 100644 index 00000000..ac532bf1 --- /dev/null +++ b/src/main/resources/swagger.api/schemas/FqmMigrateRequest.json @@ -0,0 +1,27 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "title": "Entity Upgrade Request", + "description": "Schema for a request to upgrade an entity payload, including an entity type ID, FQL query, and list of fields.", + "type": "object", + "properties": { + "entityTypeId": { + "description": "ID of the entity type to be upgraded", + "type": "string", + "format": "UUID" + }, + "fqlQuery": { + "description": "FQL query string to be used for the upgrade", + "type": "string" + }, + "fields": { + "description": "List of fields to be included in the upgrade", + "type": "array", + "items": { + "type": "string" + } + } + }, + "required": [ + "entityTypeId" + ] +} diff --git a/src/main/resources/swagger.api/schemas/FqmMigrateResponse.json b/src/main/resources/swagger.api/schemas/FqmMigrateResponse.json new file mode 100644 index 00000000..8a4e3f2a --- /dev/null +++ b/src/main/resources/swagger.api/schemas/FqmMigrateResponse.json @@ -0,0 +1,44 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "title": "Entity Upgrade Response", + "description": "Schema for a response to upgrade FQM", + "type": "object", + "properties": { + "entityTypeId": { + "description": "ID of the entity type upgraded successfully", + "type": "string", + "format": "UUID" + }, + "fqlQuery": { + "description": "FQL query string upgraded successfully", + "type": "string" + }, + "fields": { + "description": "List of fields upgraded successfully", + "type": "array", + "items": { + "type": "string" + } + }, + "warnings": { + "description": "List of warnings issued during the upgrade", + "type": "array", + "items": { + "type": "object", + "properties": { + "type": { + "description": "The type of the warning", + "type": "string" + }, + "description": { + "description": "The type of the warning", + "type": "string" + } + } + } + } + }, + "required": [ + "entityTypeId" + ] +}