Skip to content

Commit

Permalink
re
Browse files Browse the repository at this point in the history
  • Loading branch information
kjain110 committed Aug 14, 2024
1 parent df652c7 commit 42d2e92
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/main/java/org/folio/fqm/resource/MigrationController.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
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.migration.warnings.Warning;
import org.folio.fqm.service.MigrationService;
import org.folio.spring.i18n.service.TranslationService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequiredArgsConstructor
public class MigrationController implements FqmVersionApi {
Expand All @@ -15,4 +24,23 @@ public class MigrationController implements FqmVersionApi {
public ResponseEntity<String> getFqmVersion() {
return new ResponseEntity<>(migrationService.getLatestVersion(), HttpStatus.OK);
}

@Override
public ResponseEntity<FqmMigrateResponse> fqmMigrate(FqmMigrateRequest fqmMigrateRequest) {
MigratableQueryInformation migratableQueryInformation = new MigratableQueryInformation(
fqmMigrateRequest.getEntityTypeId(),
fqmMigrateRequest.getFqlQuery(),
fqmMigrateRequest.getFields()
);

migrationService.migrate(migratableQueryInformation);

FqmMigrateResponse fqmMigrateResponse = new FqmMigrateResponse()
.entityTypeId(migratableQueryInformation.entityTypeId())
.fqlQuery(migratableQueryInformation.fqlQuery()).fields(migratableQueryInformation.fields())
.warnings(migratableQueryInformation.warnings().stream()
.map(warning -> warning.getType().toString())
.toList());
return new ResponseEntity<>(fqmMigrateResponse, HttpStatus.OK);
}
}
28 changes: 28 additions & 0 deletions src/main/resources/swagger.api/mod-fqm-manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -137,6 +161,10 @@ components:
type: array
items:
type: string
fqmMigrateRequest:
$ref: schemas/FqmMigrateRequest.json
fqmMigrateResponse:
$ref: schemas/FqmMigrateResponse.json

responses:
badRequestResponse:
Expand Down
27 changes: 27 additions & 0 deletions src/main/resources/swagger.api/schemas/FqmMigrateRequest.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
34 changes: 34 additions & 0 deletions src/main/resources/swagger.api/schemas/FqmMigrateResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"$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": "string"
}
}
},
"required": [
"entityTypeId"
]
}

0 comments on commit 42d2e92

Please sign in to comment.