diff --git a/src/main/java/org/folio/fqm/resource/EntityTypeController.java b/src/main/java/org/folio/fqm/resource/EntityTypeController.java index 8095ca67..1dfb50bf 100644 --- a/src/main/java/org/folio/fqm/resource/EntityTypeController.java +++ b/src/main/java/org/folio/fqm/resource/EntityTypeController.java @@ -31,12 +31,12 @@ public ResponseEntity getEntityType(UUID entityTypeId, Boolean inclu } @Override - public ResponseEntity getEntityTypeSummary(List entityTypeIds, Boolean includeInaccessible) { + public ResponseEntity getEntityTypeSummary(List entityTypeIds, Boolean includeInaccessible, Boolean includeAll) { Set idsSet = entityTypeIds == null ? Set.of() : Set.copyOf(entityTypeIds); // 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))) + .entityTypes(entityTypeService.getEntityTypeSummary(idsSet, Boolean.TRUE.equals(includeInaccessible), Boolean.TRUE.equals(includeAll))) .version(migrationService.getLatestVersion()) ); } diff --git a/src/main/java/org/folio/fqm/service/EntityTypeService.java b/src/main/java/org/folio/fqm/service/EntityTypeService.java index 775cd0bd..ea62bcc2 100644 --- a/src/main/java/org/folio/fqm/service/EntityTypeService.java +++ b/src/main/java/org/folio/fqm/service/EntityTypeService.java @@ -72,11 +72,11 @@ public class EntityTypeService { * @param entityTypeIds If provided, only the entity types having the provided Ids will be included in the results */ @Transactional(readOnly = true) - public List getEntityTypeSummary(Set entityTypeIds, boolean includeInaccessible) { + public List getEntityTypeSummary(Set entityTypeIds, boolean includeInaccessible, boolean includeAll) { Set userPermissions = permissionsService.getUserPermissions(); return entityTypeRepository .getEntityTypeDefinitions(entityTypeIds, null) - .filter(entityType -> !Boolean.TRUE.equals(entityType.getPrivate())) + .filter(entityType -> includeAll || !Boolean.TRUE.equals(entityType.getPrivate())) .filter(entityType -> includeInaccessible || userPermissions.containsAll(permissionsService.getRequiredPermissions(entityType))) .map(entityType -> { EntityTypeSummary result = new EntityTypeSummary() diff --git a/src/main/resources/swagger.api/mod-fqm-manager.yaml b/src/main/resources/swagger.api/mod-fqm-manager.yaml index b6f1be11..60f9f684 100644 --- a/src/main/resources/swagger.api/mod-fqm-manager.yaml +++ b/src/main/resources/swagger.api/mod-fqm-manager.yaml @@ -17,6 +17,7 @@ paths: parameters: - $ref: '#/components/parameters/entity-type-ids' - $ref: '#/components/parameters/include-inaccessible' + - $ref: '#/components/parameters/include-All' responses: '200': description: 'Entity type summaries' @@ -135,6 +136,13 @@ components: description: Include inaccessible entity types in the result schema: type: boolean + include-All: + name: includeAll + in: query + required: false + description: Include all the entity types regardless of being private + schema: + type: boolean schemas: errorResponse: $ref: schemas/errors.json diff --git a/src/test/java/org/folio/fqm/controller/EntityTypeControllerTest.java b/src/test/java/org/folio/fqm/controller/EntityTypeControllerTest.java index ef86fc2b..55a3a6fc 100644 --- a/src/test/java/org/folio/fqm/controller/EntityTypeControllerTest.java +++ b/src/test/java/org/folio/fqm/controller/EntityTypeControllerTest.java @@ -106,7 +106,7 @@ void shouldGetEntityTypeSummaryForValidIds() throws Exception { .header(XOkapiHeaders.TENANT, "tenant_01") .queryParam("ids", id1.toString(), id2.toString()); - when(entityTypeService.getEntityTypeSummary(ids, false)).thenReturn(expectedSummary); + when(entityTypeService.getEntityTypeSummary(ids, false, false)).thenReturn(expectedSummary); when(migrationService.getLatestVersion()).thenReturn("newest coolest version"); mockMvc @@ -120,7 +120,7 @@ void shouldGetEntityTypeSummaryForValidIds() throws Exception { .andExpect(jsonPath("$.entityTypes.[1].missingPermissions").doesNotExist()) .andExpect(jsonPath("$._version", is("newest coolest version"))); - verify(entityTypeService, times(1)).getEntityTypeSummary(ids, false); + verify(entityTypeService, times(1)).getEntityTypeSummary(ids, false, false); verifyNoMoreInteractions(entityTypeService); } @@ -131,16 +131,33 @@ void testSummaryIncludesMissingPermissionsIfRequested() throws Exception { .header(XOkapiHeaders.TENANT, "tenant_01") .queryParam("includeInaccessible", "true"); - when(entityTypeService.getEntityTypeSummary(Set.of(), true)).thenReturn(List.of()); + when(entityTypeService.getEntityTypeSummary(Set.of(), true, false)).thenReturn(List.of()); // all we really want to check here is that the includeInaccessible parameter is correctly unboxed // no sense making fake data to pass through to ourself; that's redundant with shouldGetEntityTypeSummaryForValidIds mockMvc.perform(requestBuilder).andExpect(status().isOk()); - verify(entityTypeService, times(1)).getEntityTypeSummary(Set.of(), true); + verify(entityTypeService, times(1)).getEntityTypeSummary(Set.of(), true, false); verifyNoMoreInteractions(entityTypeService); } + @Test + void testSummaryIncludesAllEntityTypesIfRequested() throws Exception { + RequestBuilder requestBuilder = MockMvcRequestBuilders + .get("/entity-types") + .header(XOkapiHeaders.TENANT, "tenant_01") + .queryParam("includeAll", "true"); + + when(entityTypeService.getEntityTypeSummary(Set.of(), false, true)).thenReturn(List.of()); + + mockMvc.perform(requestBuilder) + .andExpect(status().isOk()); + + verify(entityTypeService, times(1)).getEntityTypeSummary(Set.of(), false, true); + verifyNoMoreInteractions(entityTypeService); + } + + @Test void shouldReturnEmptyListWhenEntityTypeSummaryNotFound() throws Exception { UUID id1 = UUID.randomUUID(); @@ -152,7 +169,7 @@ void shouldReturnEmptyListWhenEntityTypeSummaryNotFound() throws Exception { .header(XOkapiHeaders.TENANT, "tenant_01") .queryParam("ids", id1.toString(), id2.toString()); - when(entityTypeService.getEntityTypeSummary(ids, false)).thenReturn(expectedSummary); + when(entityTypeService.getEntityTypeSummary(ids, false, false)).thenReturn(expectedSummary); mockMvc.perform(requestBuilder).andExpect(status().isOk()).andExpect(jsonPath("$.entityTypes", is(expectedSummary))); } diff --git a/src/test/java/org/folio/fqm/service/EntityTypeServiceTest.java b/src/test/java/org/folio/fqm/service/EntityTypeServiceTest.java index e8326dcb..9ff9d1cc 100644 --- a/src/test/java/org/folio/fqm/service/EntityTypeServiceTest.java +++ b/src/test/java/org/folio/fqm/service/EntityTypeServiceTest.java @@ -108,7 +108,7 @@ void shouldGetEntityTypeSummaryForValidIds() { when(localizationService.getEntityTypeLabel("translation_label_01")).thenReturn("label_01"); when(localizationService.getEntityTypeLabel("translation_label_02")).thenReturn("label_02"); - List actualSummary = entityTypeService.getEntityTypeSummary(ids, false); + List actualSummary = entityTypeService.getEntityTypeSummary(ids, false, false); assertEquals(expectedSummary, actualSummary, "Expected Summary should equal Actual Summary"); @@ -136,7 +136,7 @@ void shouldIncludeCrossTenantEntityTypesWhenInCentralTenant() { when(localizationService.getEntityTypeLabel("translation_label_02")).thenReturn("label_02"); when(crossTenantQueryService.isCentralTenant()).thenReturn(true); - List actualSummary = entityTypeService.getEntityTypeSummary(ids, false); + List actualSummary = entityTypeService.getEntityTypeSummary(ids, false, false); assertEquals(expectedSummary, actualSummary); } @@ -155,7 +155,7 @@ void testEntityTypeSummaryDoesNotIncludeInaccessibleWhenNotRequested() { .then(invocationOnMock -> new HashSet<>(invocationOnMock.getArgument(0).getRequiredPermissions())); when(localizationService.getEntityTypeLabel("translation_label_02")).thenReturn("label_02"); - List actualSummary = entityTypeService.getEntityTypeSummary(ids, false); + List actualSummary = entityTypeService.getEntityTypeSummary(ids, false, false); assertEquals(expectedSummary, actualSummary, "Expected Summary should equal Actual Summary"); @@ -185,7 +185,7 @@ void testEntityTypeSummaryIncludesInaccessible() { when(localizationService.getEntityTypeLabel("translation_label_01")).thenReturn("label_01"); when(localizationService.getEntityTypeLabel("translation_label_02")).thenReturn("label_02"); - List actualSummary = entityTypeService.getEntityTypeSummary(ids, true); + List actualSummary = entityTypeService.getEntityTypeSummary(ids, true, false); assertEquals(expectedSummary, actualSummary, "Expected Summary should equal Actual Summary");