diff --git a/NEWS.md b/NEWS.md index 37580813..af444cf1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -12,6 +12,7 @@ ### Bug fixes * Do not delete kafka topics if tenant collection topic feature is enabled ([MODELINKS-233](https://folio-org.atlassian.net/browse/MODELINKS-233)) * Add checking for Authority source file references for member tenant in ECS ([MODELINKS-227](https://issues.folio.org/browse/MODELINKS-227)) +* Return only ids in response when idOnly=true ([MODELINKS-237](https://issues.folio.org/browse/MODELINKS-227)) ### Tech Dept * Description ([ISSUE](https://folio-org.atlassian.net/browse/ISSUE)) diff --git a/src/main/java/org/folio/entlinks/controller/AuthorityController.java b/src/main/java/org/folio/entlinks/controller/AuthorityController.java index 3b0d9dda..6e5dfcc4 100644 --- a/src/main/java/org/folio/entlinks/controller/AuthorityController.java +++ b/src/main/java/org/folio/entlinks/controller/AuthorityController.java @@ -12,7 +12,9 @@ import org.folio.entlinks.domain.dto.AuthorityBulkRequest; import org.folio.entlinks.domain.dto.AuthorityBulkResponse; import org.folio.entlinks.domain.dto.AuthorityDto; -import org.folio.entlinks.domain.dto.AuthorityDtoCollection; +import org.folio.entlinks.domain.dto.AuthorityFullDtoCollection; +import org.folio.entlinks.domain.dto.AuthorityIdDto; +import org.folio.entlinks.domain.dto.AuthorityIdDtoCollection; import org.folio.entlinks.exception.AuthoritiesRequestNotSupportedMediaTypeException; import org.folio.entlinks.rest.resource.AuthorityStorageApi; import org.folio.tenant.domain.dto.Parameter; @@ -93,16 +95,16 @@ public ResponseEntity expireAuthorities() { return ResponseEntity.status(HttpStatus.ACCEPTED).build(); } - private ResponseEntity getAuthoritiesCollectionResponse(AuthorityDtoCollection collectionDto, + private ResponseEntity getAuthoritiesCollectionResponse(AuthorityFullDtoCollection collectionDto, List acceptingMediaTypes, Boolean idOnly) { var headers = new HttpHeaders(); if (Boolean.TRUE.equals(idOnly) && CollectionUtils.isNotEmpty(acceptingMediaTypes) - && acceptingMediaTypes.contains(TEXT_PLAIN_VALUE)) { + && acceptingMediaTypes.contains(TEXT_PLAIN_VALUE)) { headers.setContentType(MediaType.TEXT_PLAIN); return new ResponseEntity<>( - collectionDto.getAuthorities().stream() - .map(AuthorityDto::getId) + ((AuthorityIdDtoCollection) collectionDto).getAuthorities().stream() + .map(AuthorityIdDto::getId) .map(UUID::toString) .collect(Collectors.joining(System.lineSeparator())), headers, diff --git a/src/main/java/org/folio/entlinks/controller/delegate/AuthorityArchiveServiceDelegate.java b/src/main/java/org/folio/entlinks/controller/delegate/AuthorityArchiveServiceDelegate.java index 0f2a6215..a7ff250a 100644 --- a/src/main/java/org/folio/entlinks/controller/delegate/AuthorityArchiveServiceDelegate.java +++ b/src/main/java/org/folio/entlinks/controller/delegate/AuthorityArchiveServiceDelegate.java @@ -8,8 +8,9 @@ import org.folio.entlinks.client.SettingsClient; import org.folio.entlinks.config.properties.AuthorityArchiveProperties; import org.folio.entlinks.controller.converter.AuthorityMapper; -import org.folio.entlinks.domain.dto.AuthorityDto; -import org.folio.entlinks.domain.dto.AuthorityDtoCollection; +import org.folio.entlinks.domain.dto.AuthorityFullDtoCollection; +import org.folio.entlinks.domain.dto.AuthorityIdDto; +import org.folio.entlinks.domain.dto.AuthorityIdDtoCollection; import org.folio.entlinks.domain.entity.AuthorityArchive; import org.folio.entlinks.domain.entity.AuthorityBase; import org.folio.entlinks.domain.repository.AuthorityArchiveRepository; @@ -37,12 +38,12 @@ public class AuthorityArchiveServiceDelegate { private final AuthorityMapper authorityMapper; private final FolioExecutionContext context; - public AuthorityDtoCollection retrieveAuthorityArchives(Integer offset, Integer limit, String cqlQuery, - Boolean idOnly) { + public AuthorityFullDtoCollection retrieveAuthorityArchives(Integer offset, Integer limit, String cqlQuery, + Boolean idOnly) { if (Boolean.TRUE.equals(idOnly)) { var entities = authorityArchiveService.getAllIds(offset, limit, cqlQuery) - .map(id -> new AuthorityDto().id(id)).stream().toList(); - return new AuthorityDtoCollection(entities, entities.size()); + .map(id -> new AuthorityIdDto().id(id)).toList(); + return new AuthorityIdDtoCollection(entities, entities.size()); } var entitiesPage = authorityArchiveService.getAll(offset, limit, cqlQuery) @@ -81,7 +82,7 @@ private Optional fetchAuthoritiesRetentionDuration() { } if (expireSetting.isPresent() && expireSetting.get().value() != null - && Boolean.FALSE.equals(expireSetting.get().value().expirationEnabled())) { + && Boolean.FALSE.equals(expireSetting.get().value().expirationEnabled())) { log.info("Authority archives expiration is disabled for the tenant through setting"); return Optional.empty(); } diff --git a/src/main/java/org/folio/entlinks/controller/delegate/AuthorityServiceDelegate.java b/src/main/java/org/folio/entlinks/controller/delegate/AuthorityServiceDelegate.java index f649a54c..5d029663 100644 --- a/src/main/java/org/folio/entlinks/controller/delegate/AuthorityServiceDelegate.java +++ b/src/main/java/org/folio/entlinks/controller/delegate/AuthorityServiceDelegate.java @@ -15,7 +15,9 @@ import org.folio.entlinks.domain.dto.AuthorityBulkRequest; import org.folio.entlinks.domain.dto.AuthorityBulkResponse; import org.folio.entlinks.domain.dto.AuthorityDto; -import org.folio.entlinks.domain.dto.AuthorityDtoCollection; +import org.folio.entlinks.domain.dto.AuthorityFullDtoCollection; +import org.folio.entlinks.domain.dto.AuthorityIdDto; +import org.folio.entlinks.domain.dto.AuthorityIdDtoCollection; import org.folio.entlinks.domain.entity.Authority; import org.folio.entlinks.domain.entity.AuthorityBase; import org.folio.entlinks.exception.RequestBodyValidationException; @@ -61,12 +63,12 @@ public AuthorityServiceDelegate(@Qualifier("authorityService") AuthorityService this.authorityS3Service = authorityS3Service; } - public AuthorityDtoCollection retrieveAuthorityCollection(Integer offset, Integer limit, String cqlQuery, - Boolean idOnly) { + public AuthorityFullDtoCollection retrieveAuthorityCollection(Integer offset, Integer limit, String cqlQuery, + Boolean idOnly) { if (Boolean.TRUE.equals(idOnly)) { var entities = service.getAllIds(offset, limit, cqlQuery) - .map(id -> new AuthorityDto().id(id)).stream().toList(); - return new AuthorityDtoCollection(entities, entities.size()); + .map(id -> new AuthorityIdDto().id(id)).toList(); + return new AuthorityIdDtoCollection(entities, entities.size()); } var entitiesPage = service.getAll(offset, limit, cqlQuery) diff --git a/src/main/resources/swagger.api/paths/authority-storage/authorities.yaml b/src/main/resources/swagger.api/paths/authority-storage/authorities.yaml index ed74cc8a..b0e00002 100644 --- a/src/main/resources/swagger.api/paths/authority-storage/authorities.yaml +++ b/src/main/resources/swagger.api/paths/authority-storage/authorities.yaml @@ -48,7 +48,10 @@ get: application/json: example: examples/authorities.sample schema: - $ref: '../../schemas/authority-storage/authorityDtoCollection.yaml' + title: authorityFullDtoCollection + oneOf: + - $ref: '../../schemas/authority-storage/authorityDtoCollection.yaml' + - $ref: '../../schemas/authority-storage/authorityIdDtoCollection.yaml' text/plain;charset=utf-8: schema: type: string diff --git a/src/main/resources/swagger.api/schemas/authority-storage/authorityIdDto.yaml b/src/main/resources/swagger.api/schemas/authority-storage/authorityIdDto.yaml new file mode 100644 index 00000000..7a5b34a0 --- /dev/null +++ b/src/main/resources/swagger.api/schemas/authority-storage/authorityIdDto.yaml @@ -0,0 +1,7 @@ +description: An authority ID record +type: object +properties: + id: + description: Authority UUID + type: string + format: uuid \ No newline at end of file diff --git a/src/main/resources/swagger.api/schemas/authority-storage/authorityIdDtoCollection.yaml b/src/main/resources/swagger.api/schemas/authority-storage/authorityIdDtoCollection.yaml new file mode 100644 index 00000000..81957dd3 --- /dev/null +++ b/src/main/resources/swagger.api/schemas/authority-storage/authorityIdDtoCollection.yaml @@ -0,0 +1,14 @@ +description: A collection of authority ID records +type: object +properties: + authorities: + description: List of authority records + type: array + items: + $ref: './authorityIdDto.yaml' + totalRecords: + description: Total amount of records + type: integer +required: + - authorities + - totalRecords diff --git a/src/test/java/org/folio/entlinks/controller/AuthorityControllerTest.java b/src/test/java/org/folio/entlinks/controller/AuthorityControllerTest.java index 5dc76537..f5b6c8d2 100644 --- a/src/test/java/org/folio/entlinks/controller/AuthorityControllerTest.java +++ b/src/test/java/org/folio/entlinks/controller/AuthorityControllerTest.java @@ -14,6 +14,8 @@ import org.folio.entlinks.controller.delegate.AuthorityServiceDelegate; import org.folio.entlinks.domain.dto.AuthorityDto; import org.folio.entlinks.domain.dto.AuthorityDtoCollection; +import org.folio.entlinks.domain.dto.AuthorityIdDto; +import org.folio.entlinks.domain.dto.AuthorityIdDtoCollection; import org.folio.entlinks.exception.AuthoritiesRequestNotSupportedMediaTypeException; import org.folio.spring.testing.type.UnitTest; import org.junit.jupiter.api.BeforeAll; @@ -71,7 +73,9 @@ void shouldRetrieveAuthorities() { @Test void shouldRetrieveAuthoritiesIds() { - var collectionDto = new AuthorityDtoCollection(List.of(dto, dto), 1); + var collectionDto = new AuthorityIdDtoCollection(List.of( + new AuthorityIdDto().id(dto.getId()), + new AuthorityIdDto().id(dto.getId())), 2); when(authorityServiceDelegate.retrieveAuthorityCollection(anyInt(), anyInt(), anyString(), anyBoolean())) .thenReturn(collectionDto); @@ -98,7 +102,9 @@ void shouldRetrieveAuthorityArchives() { @Test void shouldRetrieveAuthorityArchivesIds() { - var collectionDto = new AuthorityDtoCollection(List.of(dto, dto), 1); + var collectionDto = new AuthorityIdDtoCollection(List.of( + new AuthorityIdDto().id(dto.getId()), + new AuthorityIdDto().id(dto.getId())), 1); when(authorityArchiveServiceDelegate.retrieveAuthorityArchives(anyInt(), anyInt(), anyString(), anyBoolean())) .thenReturn(collectionDto);