-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #370 from folio-org/MODFQMMGR-392-ebsco
Adding an end point /fqm/migrate
- Loading branch information
Showing
6 changed files
with
218 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/org/folio/fqm/resource/MigrationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,53 @@ | ||
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.domain.dto.FqmMigrateResponseWarningsInner; | ||
import org.folio.fqm.migration.MigratableQueryInformation; | ||
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; | ||
|
||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class MigrationController implements FqmVersionApi { | ||
private final MigrationService migrationService; | ||
|
||
private final TranslationService translationService; | ||
|
||
@Override | ||
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() | ||
); | ||
|
||
MigratableQueryInformation updatedQueryInfo = migrationService.migrate(migratableQueryInformation); | ||
|
||
FqmMigrateResponse fqmMigrateResponse = new FqmMigrateResponse() | ||
.entityTypeId(updatedQueryInfo.entityTypeId()) | ||
.fqlQuery(updatedQueryInfo.fqlQuery()) | ||
.fields(updatedQueryInfo.fields()) | ||
.warnings(updatedQueryInfo.warnings().stream() | ||
.map(warning -> new FqmMigrateResponseWarningsInner() | ||
.type(warning.getType() != null ? warning.getType().toString() : null) | ||
.description(warning.getDescription(translationService) != null ? | ||
warning.getDescription(translationService) : "No description provided" | ||
) | ||
) | ||
.toList() | ||
); | ||
|
||
return new ResponseEntity<>(fqmMigrateResponse, HttpStatus.OK); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/resources/swagger.api/schemas/FqmMigrateRequest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/resources/swagger.api/schemas/FqmMigrateResponse.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"$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": { | ||
"description": { | ||
"description": "Description of the warning", | ||
"type": "string" | ||
}, | ||
"type": { | ||
"description": "Type of warning", | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
] | ||
} | ||
} | ||
}, | ||
"required": [ | ||
"entityTypeId" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters