diff --git a/src/main/java/org/folio/fqm/resource/EntityTypeController.java b/src/main/java/org/folio/fqm/resource/EntityTypeController.java index 25a63b6f..8095ca67 100644 --- a/src/main/java/org/folio/fqm/resource/EntityTypeController.java +++ b/src/main/java/org/folio/fqm/resource/EntityTypeController.java @@ -3,9 +3,10 @@ import lombok.RequiredArgsConstructor; import org.folio.fqm.annotation.EntityTypePermissionsRequired; import org.folio.fqm.service.EntityTypeService; +import org.folio.fqm.service.MigrationService; import org.folio.querytool.domain.dto.ColumnValues; import org.folio.querytool.domain.dto.EntityType; -import org.folio.fqm.domain.dto.EntityTypeSummary; +import org.folio.fqm.domain.dto.EntityTypeSummaries; import org.folio.querytool.rest.resource.EntityTypesApi; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RestController; @@ -19,7 +20,9 @@ @RestController @RequiredArgsConstructor public class EntityTypeController implements org.folio.fqm.resource.EntityTypesApi, org.folio.querytool.rest.resource.EntityTypesApi { + private final EntityTypeService entityTypeService; + private final MigrationService migrationService; @EntityTypePermissionsRequired @Override @@ -28,10 +31,14 @@ public ResponseEntity getEntityType(UUID entityTypeId, Boolean inclu } @Override - public ResponseEntity> getEntityTypeSummary(List entityTypeIds, Boolean includeInaccessible) { + public ResponseEntity getEntityTypeSummary(List entityTypeIds, Boolean includeInaccessible) { Set idsSet = entityTypeIds == null ? Set.of() : Set.copyOf(entityTypeIds); - // Permissions are handled in the service layer - return ResponseEntity.ok(entityTypeService.getEntityTypeSummary(idsSet, Boolean.TRUE.equals(includeInaccessible))); + // Permissions are handled in the service layer// Permissions are handled in the service layer + return ResponseEntity.ok( + new EntityTypeSummaries() + .entityTypes(entityTypeService.getEntityTypeSummary(idsSet, Boolean.TRUE.equals(includeInaccessible))) + .version(migrationService.getLatestVersion()) + ); } @EntityTypePermissionsRequired diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 186b5bfa..ec10bb95 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -44,7 +44,6 @@ spring: enabled: true change-log: classpath:db/changelog/changelog-master.xml jackson: - default-property-inclusion: non_empty deserialization: fail-on-unknown-properties: false accept-single-value-as-array: true diff --git a/src/main/resources/swagger.api/mod-fqm-manager.yaml b/src/main/resources/swagger.api/mod-fqm-manager.yaml index 7c44ea66..9e236ea5 100644 --- a/src/main/resources/swagger.api/mod-fqm-manager.yaml +++ b/src/main/resources/swagger.api/mod-fqm-manager.yaml @@ -119,11 +119,7 @@ components: additionalProperties: type: object entityTypeSummaries: - type: array - items: - $ref: '#/components/schemas/entityTypeSummary' - entityTypeSummary: - $ref: schemas/EntityTypeSummaryDTO.json + $ref: schemas/EntityTypeSummaries.json purgedQueries: $ref: schemas/PurgedQueries.json dataRefreshResponse: diff --git a/src/main/resources/swagger.api/schemas/EntityTypeSummaries.json b/src/main/resources/swagger.api/schemas/EntityTypeSummaries.json new file mode 100644 index 00000000..e4b981e4 --- /dev/null +++ b/src/main/resources/swagger.api/schemas/EntityTypeSummaries.json @@ -0,0 +1,20 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "description": "Entity Type Summary List", + "type": "object", + "properties": { + "entityTypes": { + "description": "Entity type list", + "type": "array", + "items": { + "$ref": "./EntityTypeSummary.json" + } + }, + "_version": { + "description": "Current FQL version (same as /fqm/version returns)", + "type": "string" + } + }, + "additionalProperties": false, + "required": ["entityTypes", "_version"] +} diff --git a/src/main/resources/swagger.api/schemas/EntityTypeSummaryDTO.json b/src/main/resources/swagger.api/schemas/EntityTypeSummary.json similarity index 80% rename from src/main/resources/swagger.api/schemas/EntityTypeSummaryDTO.json rename to src/main/resources/swagger.api/schemas/EntityTypeSummary.json index 4dd53a34..7511fb54 100644 --- a/src/main/resources/swagger.api/schemas/EntityTypeSummaryDTO.json +++ b/src/main/resources/swagger.api/schemas/EntityTypeSummary.json @@ -1,14 +1,14 @@ { "$schema": "http://json-schema.org/draft-04/schema#", - "description": "Entity Type Summary DTO", + "description": "Entity Type Summary", "type": "object", "properties": { - "id" : { + "id": { "description": "Entity type id", "type": "string", "format": "UUID" }, - "label" : { + "label": { "description": "Entity type label", "type": "string" }, @@ -21,8 +21,5 @@ } }, "additionalProperties": false, - "required": [ - "id", - "label" - ] + "required": ["id", "label"] } diff --git a/src/test/java/org/folio/fqm/IntegrationTestBase.java b/src/test/java/org/folio/fqm/IntegrationTestBase.java index 6de17460..ca47b7ba 100644 --- a/src/test/java/org/folio/fqm/IntegrationTestBase.java +++ b/src/test/java/org/folio/fqm/IntegrationTestBase.java @@ -148,7 +148,7 @@ private static void smokeTest() { .get("/entity-types?includeInaccessible=true") .then() .statusCode(200) - .body("$.size()", greaterThan(0)); + .body("entityTypes.size()", greaterThan(0)); } protected static Map getOkapiHeaders() { diff --git a/src/test/java/org/folio/fqm/controller/EntityTypeControllerTest.java b/src/test/java/org/folio/fqm/controller/EntityTypeControllerTest.java index e077a68d..ef86fc2b 100644 --- a/src/test/java/org/folio/fqm/controller/EntityTypeControllerTest.java +++ b/src/test/java/org/folio/fqm/controller/EntityTypeControllerTest.java @@ -14,6 +14,7 @@ import org.folio.fqm.exception.FieldNotFoundException; import org.folio.fqm.resource.EntityTypeController; import org.folio.fqm.service.EntityTypeService; +import org.folio.fqm.service.MigrationService; import org.folio.querytool.domain.dto.ColumnValues; import org.folio.querytool.domain.dto.EntityType; import org.folio.querytool.domain.dto.EntityTypeColumn; @@ -41,6 +42,9 @@ class EntityTypeControllerTest { @MockBean private EntityTypeService entityTypeService; + @MockBean + private MigrationService migrationService; + @MockBean private FolioExecutionContext folioExecutionContext; @@ -101,16 +105,20 @@ void shouldGetEntityTypeSummaryForValidIds() throws Exception { .get("/entity-types") .header(XOkapiHeaders.TENANT, "tenant_01") .queryParam("ids", id1.toString(), id2.toString()); + when(entityTypeService.getEntityTypeSummary(ids, false)).thenReturn(expectedSummary); + when(migrationService.getLatestVersion()).thenReturn("newest coolest version"); + mockMvc .perform(requestBuilder) .andExpect(status().isOk()) - .andExpect(jsonPath("$.[0].id", is(expectedSummary.get(0).getId().toString()))) - .andExpect(jsonPath("$.[0].label", is(expectedSummary.get(0).getLabel()))) - .andExpect(jsonPath("$.[0].missingPermissions").doesNotExist()) - .andExpect(jsonPath("$.[1].id", is(expectedSummary.get(1).getId().toString()))) - .andExpect(jsonPath("$.[1].label", is(expectedSummary.get(1).getLabel()))) - .andExpect(jsonPath("$.[1].missingPermissions").doesNotExist()); + .andExpect(jsonPath("$.entityTypes.[0].id", is(expectedSummary.get(0).getId().toString()))) + .andExpect(jsonPath("$.entityTypes.[0].label", is(expectedSummary.get(0).getLabel()))) + .andExpect(jsonPath("$.entityTypes.[0].missingPermissions").doesNotExist()) + .andExpect(jsonPath("$.entityTypes.[1].id", is(expectedSummary.get(1).getId().toString()))) + .andExpect(jsonPath("$.entityTypes.[1].label", is(expectedSummary.get(1).getLabel()))) + .andExpect(jsonPath("$.entityTypes.[1].missingPermissions").doesNotExist()) + .andExpect(jsonPath("$._version", is("newest coolest version"))); verify(entityTypeService, times(1)).getEntityTypeSummary(ids, false); verifyNoMoreInteractions(entityTypeService); @@ -143,8 +151,10 @@ void shouldReturnEmptyListWhenEntityTypeSummaryNotFound() throws Exception { .get("/entity-types") .header(XOkapiHeaders.TENANT, "tenant_01") .queryParam("ids", id1.toString(), id2.toString()); + when(entityTypeService.getEntityTypeSummary(ids, false)).thenReturn(expectedSummary); - mockMvc.perform(requestBuilder).andExpect(status().isOk()).andExpect(jsonPath("$", is(expectedSummary))); + + mockMvc.perform(requestBuilder).andExpect(status().isOk()).andExpect(jsonPath("$.entityTypes", is(expectedSummary))); } @Test