Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MODFQMMGR-635:Add Query Parameter to retrieve all the ET #598

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ public ResponseEntity<EntityType> getEntityType(UUID entityTypeId, Boolean inclu
}

@Override
public ResponseEntity<EntityTypeSummaries> getEntityTypeSummary(List<UUID> entityTypeIds, Boolean includeInaccessible) {
public ResponseEntity<EntityTypeSummaries> getEntityTypeSummary(List<UUID> entityTypeIds, Boolean includeInaccessible, Boolean includeAll) {
Set<UUID> 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())
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/folio/fqm/service/EntityTypeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<EntityTypeSummary> getEntityTypeSummary(Set<UUID> entityTypeIds, boolean includeInaccessible) {
public List<EntityTypeSummary> getEntityTypeSummary(Set<UUID> entityTypeIds, boolean includeInaccessible, boolean includeAll) {
Set<String> 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()
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/swagger.api/mod-fqm-manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}

Expand All @@ -131,13 +131,29 @@ 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);
}

Expand All @@ -152,7 +168,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)));
}
Expand Down
40 changes: 36 additions & 4 deletions src/test/java/org/folio/fqm/service/EntityTypeServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<EntityTypeSummary> actualSummary = entityTypeService.getEntityTypeSummary(ids, false);
List<EntityTypeSummary> actualSummary = entityTypeService.getEntityTypeSummary(ids, false, false);

assertEquals(expectedSummary, actualSummary, "Expected Summary should equal Actual Summary");

Expand Down Expand Up @@ -136,7 +136,7 @@ void shouldIncludeCrossTenantEntityTypesWhenInCentralTenant() {
when(localizationService.getEntityTypeLabel("translation_label_02")).thenReturn("label_02");
when(crossTenantQueryService.isCentralTenant()).thenReturn(true);

List<EntityTypeSummary> actualSummary = entityTypeService.getEntityTypeSummary(ids, false);
List<EntityTypeSummary> actualSummary = entityTypeService.getEntityTypeSummary(ids, false, false);
assertEquals(expectedSummary, actualSummary);
}

Expand All @@ -155,7 +155,7 @@ void testEntityTypeSummaryDoesNotIncludeInaccessibleWhenNotRequested() {
.then(invocationOnMock -> new HashSet<>(invocationOnMock.<EntityType>getArgument(0).getRequiredPermissions()));
when(localizationService.getEntityTypeLabel("translation_label_02")).thenReturn("label_02");

List<EntityTypeSummary> actualSummary = entityTypeService.getEntityTypeSummary(ids, false);
List<EntityTypeSummary> actualSummary = entityTypeService.getEntityTypeSummary(ids, false, false);

assertEquals(expectedSummary, actualSummary, "Expected Summary should equal Actual Summary");

Expand All @@ -166,6 +166,38 @@ void testEntityTypeSummaryDoesNotIncludeInaccessibleWhenNotRequested() {
verifyNoMoreInteractions(repo, localizationService);
}

@Test
void testEntityTypeSummaryIncludesAllWhenRequested() {
UUID id1 = UUID.randomUUID();
UUID id2 = UUID.randomUUID();
Set<UUID> ids = Set.of(id1, id2);

List<EntityTypeSummary> expectedSummary = List.of(
new EntityTypeSummary().id(id1).label("label_01"),
new EntityTypeSummary().id(id2).label("label_02")
);

when(repo.getEntityTypeDefinitions(ids, null)).thenReturn(Stream.of(
new EntityType(id1.toString(), "translation_label_01", true, true).requiredPermissions(List.of("perm1")), // Private entity
new EntityType(id2.toString(), "translation_label_02", true, false).requiredPermissions(List.of("perm2")) // Non-private entity
));

when(permissionsService.getUserPermissions()).thenReturn(Set.of("perm2", "perm1"));
when(permissionsService.getRequiredPermissions(any(EntityType.class)))
.then(invocationOnMock -> new HashSet<>(invocationOnMock.<EntityType>getArgument(0).getRequiredPermissions()));

when(localizationService.getEntityTypeLabel("translation_label_01")).thenReturn("label_01");
when(localizationService.getEntityTypeLabel("translation_label_02")).thenReturn("label_02");

List<EntityTypeSummary> actualSummary = entityTypeService.getEntityTypeSummary(ids, false, true);

assertEquals(expectedSummary, actualSummary, "Expected Summary should equal Actual Summary");

verify(repo, times(1)).getEntityTypeDefinitions(ids, null);
verify(localizationService, times(1)).getEntityTypeLabel("translation_label_01");
verify(localizationService, times(1)).getEntityTypeLabel("translation_label_02");
verifyNoMoreInteractions(repo, localizationService);
}

@Test
void testEntityTypeSummaryIncludesInaccessible() {
Expand All @@ -185,7 +217,7 @@ void testEntityTypeSummaryIncludesInaccessible() {
when(localizationService.getEntityTypeLabel("translation_label_01")).thenReturn("label_01");
when(localizationService.getEntityTypeLabel("translation_label_02")).thenReturn("label_02");

List<EntityTypeSummary> actualSummary = entityTypeService.getEntityTypeSummary(ids, true);
List<EntityTypeSummary> actualSummary = entityTypeService.getEntityTypeSummary(ids, true, false);

assertEquals(expectedSummary, actualSummary, "Expected Summary should equal Actual Summary");

Expand Down
Loading