-
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.
creating an end point for migrating fqm
- Loading branch information
Showing
5 changed files
with
191 additions
and
5 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
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,49 @@ | ||
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() | ||
); | ||
|
||
migrationService.migrate(migratableQueryInformation); | ||
|
||
FqmMigrateResponse fqmMigrateResponse = new FqmMigrateResponse() | ||
.entityTypeId(migratableQueryInformation.entityTypeId()) | ||
.fqlQuery(migratableQueryInformation.fqlQuery()) | ||
.fields(migratableQueryInformation.fields()) | ||
.warnings(migratableQueryInformation.warnings().stream() | ||
.map(warning -> new FqmMigrateResponseWarningsInner() | ||
.type(warning.getType().toString()) | ||
.description(warning.getDescription(translationService)) | ||
) | ||
.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" | ||
] | ||
} |
42 changes: 42 additions & 0 deletions
42
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,42 @@ | ||
{ | ||
"$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": { | ||
"type": "string" | ||
}, | ||
"type": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"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