Skip to content

Commit

Permalink
fix(authority-storage): Return only ids in response when idOnly=true (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
psmagin authored May 17, 2024
1 parent 509da1d commit 17701a3
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 20 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -93,16 +95,16 @@ public ResponseEntity<Void> expireAuthorities() {
return ResponseEntity.status(HttpStatus.ACCEPTED).build();
}

private ResponseEntity<Object> getAuthoritiesCollectionResponse(AuthorityDtoCollection collectionDto,
private ResponseEntity<Object> getAuthoritiesCollectionResponse(AuthorityFullDtoCollection collectionDto,
List<String> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -81,7 +82,7 @@ private Optional<Integer> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
description: An authority ID record
type: object
properties:
id:
description: Authority UUID
type: string
format: uuid
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

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

Expand Down

0 comments on commit 17701a3

Please sign in to comment.