From d15f8feabca2981c84e7d436c6905305df14e491 Mon Sep 17 00:00:00 2001 From: Ruslan Lavrov Date: Thu, 1 Feb 2024 14:54:11 +0200 Subject: [PATCH] Refactored after renaming --- .../java/org/folio/dao/RecordDaoImpl.java | 8 ++-- .../org/folio/services/RecordServiceImpl.java | 11 ++--- .../folio/rest/impl/RecordsMatchingApi.java | 44 +++++++++---------- ramls/source-record-storage-records.raml | 2 +- 4 files changed, 33 insertions(+), 32 deletions(-) diff --git a/mod-source-record-storage-server/src/main/java/org/folio/dao/RecordDaoImpl.java b/mod-source-record-storage-server/src/main/java/org/folio/dao/RecordDaoImpl.java index 92295ba71..51b1cbb6d 100644 --- a/mod-source-record-storage-server/src/main/java/org/folio/dao/RecordDaoImpl.java +++ b/mod-source-record-storage-server/src/main/java/org/folio/dao/RecordDaoImpl.java @@ -83,7 +83,6 @@ import org.folio.rest.jaxrs.model.AdditionalInfo; import org.folio.rest.jaxrs.model.ErrorRecord; import org.folio.rest.jaxrs.model.ExternalIdsHolder; -import org.folio.rest.jaxrs.model.IdentifiersPair; import org.folio.rest.jaxrs.model.MarcBibCollection; import org.folio.rest.jaxrs.model.Metadata; import org.folio.rest.jaxrs.model.ParsedRecord; @@ -91,6 +90,7 @@ import org.folio.rest.jaxrs.model.RawRecord; import org.folio.rest.jaxrs.model.Record; import org.folio.rest.jaxrs.model.RecordCollection; +import org.folio.rest.jaxrs.model.RecordIdentifiersDto; import org.folio.rest.jaxrs.model.RecordsBatchResponse; import org.folio.rest.jaxrs.model.RecordsIdentifiersCollection; import org.folio.rest.jaxrs.model.SourceRecord; @@ -540,15 +540,15 @@ private RecordsIdentifiersCollection toRecordsIdentifiersCollection(QueryResult return new RecordsIdentifiersCollection().withTotalRecords(0); } - List identifiers = result.stream() + List identifiers = result.stream() .map(res -> asRow(res.unwrap())) - .map(row -> new IdentifiersPair() + .map(row -> new RecordIdentifiersDto() .withRecordId(row.getUUID(ID).toString()) .withExternalId(row.getUUID(RECORDS_LB.EXTERNAL_ID.getName()).toString())) .collect(Collectors.toList()); return new RecordsIdentifiersCollection() - .withIdentifiersPairs(identifiers) + .withIdentifiers(identifiers) .withTotalRecords(countResult); } diff --git a/mod-source-record-storage-server/src/main/java/org/folio/services/RecordServiceImpl.java b/mod-source-record-storage-server/src/main/java/org/folio/services/RecordServiceImpl.java index fa83b65ef..a8062be0a 100644 --- a/mod-source-record-storage-server/src/main/java/org/folio/services/RecordServiceImpl.java +++ b/mod-source-record-storage-server/src/main/java/org/folio/services/RecordServiceImpl.java @@ -47,7 +47,7 @@ import org.folio.okapi.common.GenericCompositeFuture; import org.folio.processing.value.ListValue; import org.folio.rest.jaxrs.model.Filter; -import org.folio.rest.jaxrs.model.IdentifiersPair; +import org.folio.rest.jaxrs.model.RecordIdentifiersDto; import org.folio.rest.jaxrs.model.RecordMatchingDto; import org.folio.rest.jaxrs.model.RecordsIdentifiersCollection; import org.folio.services.exceptions.DuplicateRecordException; @@ -326,7 +326,8 @@ public Future getMatchedRecordsIdentifiers(RecordM TypeConnection typeConnection = TypeConnection.valueOf(recordMatchingDto.getRecordType().name()); if (matchField.isDefaultField()) { - return processDefaultMatchField(matchField, tenantId, recordMatchingDto.getRecordType()); + return processDefaultMatchField(matchField, tenantId, recordMatchingDto.getRecordType(), + recordMatchingDto.getLimit(), recordMatchingDto.getOffset()); } return recordDao.getMatchedRecordsIdentifiers(matchField, typeConnection, true, recordMatchingDto.getOffset(), recordMatchingDto.getLimit(), tenantId); @@ -341,7 +342,7 @@ private MatchField prepareMatchField(RecordMatchingDto recordMatchingDto) { return new MatchField(filter.getField(), ind1, ind2, subfield, ListValue.of(filter.getValues())); } - private Future processDefaultMatchField(MatchField matchField, String tenantId, RecordMatchingDto.RecordType recordType) { + private Future processDefaultMatchField(MatchField matchField, String tenantId, RecordMatchingDto.RecordType recordType, Integer limit, Integer offset) { TypeConnection typeConnection = TypeConnection.valueOf(recordType.name()); Condition condition = filterRecordByState(Record.State.ACTUAL.value()); List values = ((ListValue) matchField.getValue()).getValue(); @@ -356,11 +357,11 @@ private Future processDefaultMatchField(MatchField return recordDao.getRecords(condition, typeConnection.getDbType(), Collections.emptyList(), 0, 2, tenantId) .map(recordCollection -> recordCollection.getRecords().stream() - .map(sourceRecord -> new IdentifiersPair() + .map(sourceRecord -> new RecordIdentifiersDto() .withRecordId(sourceRecord.getId()) .withExternalId(EXTERNAL_ID_EXTRACTORS_MAP.get(sourceRecord.getRecordType()).apply(sourceRecord))) .collect(Collectors.collectingAndThen(toList(), identifiersPairs -> new RecordsIdentifiersCollection() - .withIdentifiersPairs(identifiersPairs).withTotalRecords(identifiersPairs.size())))); + .withIdentifiers(identifiersPairs).withTotalRecords(identifiersPairs.size())))); } private Future setMatchedIdForRecord(Record record, String tenantId) { diff --git a/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/RecordsMatchingApi.java b/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/RecordsMatchingApi.java index bb10629ad..092989134 100644 --- a/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/RecordsMatchingApi.java +++ b/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/RecordsMatchingApi.java @@ -96,7 +96,7 @@ public void shouldReturnEmptyCollectionIfRecordsDoNotMatch() { .then() .statusCode(HttpStatus.SC_OK) .body("totalRecords", is(0)) - .body("identifiersPairs.size()", is(0)); + .body("identifiers.size()", is(0)); } @Test @@ -116,9 +116,9 @@ public void shouldMatchRecordByMatchedIdField() { .then() .statusCode(HttpStatus.SC_OK) .body("totalRecords", is(1)) - .body("identifiersPairs.size()", is(1)) - .body("identifiersPairs[0].recordId", is(existingRecord.getId())) - .body("identifiersPairs[0].externalId", is(existingRecord.getExternalIdsHolder().getInstanceId())); + .body("identifiers.size()", is(1)) + .body("identifiers[0].recordId", is(existingRecord.getId())) + .body("identifiers[0].externalId", is(existingRecord.getExternalIdsHolder().getInstanceId())); } @Test @@ -138,9 +138,9 @@ public void shouldMatchRecordByInstanceIdField() { .then() .statusCode(HttpStatus.SC_OK) .body("totalRecords", is(1)) - .body("identifiersPairs.size()", is(1)) - .body("identifiersPairs[0].recordId", is(existingRecord.getId())) - .body("identifiersPairs[0].externalId", is(existingRecord.getExternalIdsHolder().getInstanceId())); + .body("identifiers.size()", is(1)) + .body("identifiers[0].recordId", is(existingRecord.getId())) + .body("identifiers[0].externalId", is(existingRecord.getExternalIdsHolder().getInstanceId())); } @Test @@ -157,9 +157,9 @@ public void shouldMatchRecordByInstanceHridField() { .then() .statusCode(HttpStatus.SC_OK) .body("totalRecords", is(1)) - .body("identifiersPairs.size()", is(1)) - .body("identifiersPairs[0].recordId", is(existingRecord.getId())) - .body("identifiersPairs[0].externalId", is(existingRecord.getExternalIdsHolder().getInstanceId())); + .body("identifiers.size()", is(1)) + .body("identifiers[0].recordId", is(existingRecord.getId())) + .body("identifiers[0].externalId", is(existingRecord.getExternalIdsHolder().getInstanceId())); } @Test @@ -179,9 +179,9 @@ public void shouldMatchRecordByMultipleDataFields() { .then() .statusCode(HttpStatus.SC_OK) .body("totalRecords", is(1)) - .body("identifiersPairs.size()", is(1)) - .body("identifiersPairs[0].recordId", is(existingRecord.getId())) - .body("identifiersPairs[0].externalId", is(existingRecord.getExternalIdsHolder().getInstanceId())); + .body("identifiers.size()", is(1)) + .body("identifiers[0].recordId", is(existingRecord.getId())) + .body("identifiers[0].externalId", is(existingRecord.getExternalIdsHolder().getInstanceId())); } @Test @@ -198,9 +198,9 @@ public void shouldMatchRecordByMultipleControlledFields() { .then() .statusCode(HttpStatus.SC_OK) .body("totalRecords", is(1)) - .body("identifiersPairs.size()", is(1)) - .body("identifiersPairs[0].recordId", is(existingRecord.getId())) - .body("identifiersPairs[0].externalId", is(existingRecord.getExternalIdsHolder().getInstanceId())); + .body("identifiers.size()", is(1)) + .body("identifiers[0].recordId", is(existingRecord.getId())) + .body("identifiers[0].externalId", is(existingRecord.getExternalIdsHolder().getInstanceId())); } @Test @@ -220,9 +220,9 @@ public void shouldMatchRecordByMultiple024FieldsWithWildcardsInd() { .then() .statusCode(HttpStatus.SC_OK) .body("totalRecords", is(1)) - .body("identifiersPairs.size()", is(1)) - .body("identifiersPairs[0].recordId", is(existingRecord.getId())) - .body("identifiersPairs[0].externalId", is(existingRecord.getExternalIdsHolder().getInstanceId())); + .body("identifiers.size()", is(1)) + .body("identifiers[0].recordId", is(existingRecord.getId())) + .body("identifiers[0].externalId", is(existingRecord.getExternalIdsHolder().getInstanceId())); } @Test @@ -254,7 +254,7 @@ public void shouldNotMatchRecordBy035FieldIfRecordExternalIdIsNull(TestContext c .then() .statusCode(HttpStatus.SC_OK) .body("totalRecords", is(0)) - .body("identifiersPairs.size()", is(0)); + .body("identifiers.size()", is(0)); } @Test @@ -293,8 +293,8 @@ public void shouldReturnLimitedRecordsIdentifiersCollectionWithLimitAndOffset(Te .then() .statusCode(HttpStatus.SC_OK) .body("totalRecords", is(4)) - .body("identifiersPairs.size()", is(2)) - .body("identifiersPairs.recordId", + .body("identifiers.size()", is(2)) + .body("identifiers.recordId", everyItem(is(oneOf("00000000-0000-1000-8000-000000000003", "00000000-0000-1000-8000-000000000004")))); } diff --git a/ramls/source-record-storage-records.raml b/ramls/source-record-storage-records.raml index 8e46f0793..271c28889 100644 --- a/ramls/source-record-storage-records.raml +++ b/ramls/source-record-storage-records.raml @@ -27,7 +27,7 @@ types: bibAuthorityLinksUpdate: !include raml-storage/schemas/mod-entities-links/bibAuthorityLinksUpdate.json marcBibUpdate: !include raml-storage/schemas/mod-source-record-storage/marcBibUpdate.json linkUpdateReport: !include raml-storage/schemas/mod-source-record-storage/linkUpdateReport.json - recordMatchingDto: !include raml-storage/schemas/dto/recordMatchingDto.json + recordMatchingDto: !include raml-storage/schemas/dto/recordMatchingRqDto.json recordsIdentifiersCollection: !include raml-storage/schemas/dto/recordsIdentifiersCollection.json traits: