Skip to content

Commit

Permalink
[MODFQMMGR-442] Include FQL version in entity type responses
Browse files Browse the repository at this point in the history
  • Loading branch information
ncovercash committed Aug 29, 2024
1 parent be0d6c6 commit f0e1fe0
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 23 deletions.
15 changes: 11 additions & 4 deletions src/main/java/org/folio/fqm/resource/EntityTypeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -28,10 +31,14 @@ public ResponseEntity<EntityType> getEntityType(UUID entityTypeId, Boolean inclu
}

@Override
public ResponseEntity<List<EntityTypeSummary>> getEntityTypeSummary(List<UUID> entityTypeIds, Boolean includeInaccessible) {
public ResponseEntity<EntityTypeSummaries> getEntityTypeSummary(List<UUID> entityTypeIds, Boolean includeInaccessible) {
Set<UUID> 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
Expand Down
6 changes: 1 addition & 5 deletions src/main/resources/swagger.api/mod-fqm-manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 19 additions & 0 deletions src/main/resources/swagger.api/schemas/EntityTypeSummaries.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Entity Type Summary List",
"type": "object",
"properties": {
"entityTypes": {
"type": "array",
"items": {
"$ref": "./EntityTypeSummary.json"
}
},
"_version": {
"description": "Current FQL version (same as /fqm/version returns)",
"type": "string"
}
},
"additionalProperties": false,
"required": ["entityTypes", "_version"]
}
Original file line number Diff line number Diff line change
@@ -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"
},
Expand All @@ -21,8 +21,5 @@
}
},
"additionalProperties": false,
"required": [
"id",
"label"
]
"required": ["id", "label"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -41,6 +42,9 @@ class EntityTypeControllerTest {
@MockBean
private EntityTypeService entityTypeService;

@MockBean
private MigrationService migrationService;

@MockBean
private FolioExecutionContext folioExecutionContext;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f0e1fe0

Please sign in to comment.