Skip to content

Commit

Permalink
Refactored after renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
RuslanLavrov committed Feb 1, 2024
1 parent 3b1d98c commit d15f8fe
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@
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;
import org.folio.rest.jaxrs.model.ParsedRecordsBatchResponse;
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;
Expand Down Expand Up @@ -540,15 +540,15 @@ private RecordsIdentifiersCollection toRecordsIdentifiersCollection(QueryResult
return new RecordsIdentifiersCollection().withTotalRecords(0);
}

List<IdentifiersPair> identifiers = result.stream()
List<RecordIdentifiersDto> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -326,7 +326,8 @@ public Future<RecordsIdentifiersCollection> 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);
Expand All @@ -341,7 +342,7 @@ private MatchField prepareMatchField(RecordMatchingDto recordMatchingDto) {
return new MatchField(filter.getField(), ind1, ind2, subfield, ListValue.of(filter.getValues()));
}

private Future<RecordsIdentifiersCollection> processDefaultMatchField(MatchField matchField, String tenantId, RecordMatchingDto.RecordType recordType) {
private Future<RecordsIdentifiersCollection> 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<String> values = ((ListValue) matchField.getValue()).getValue();
Expand All @@ -356,11 +357,11 @@ private Future<RecordsIdentifiersCollection> 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<Record> setMatchedIdForRecord(Record record, String tenantId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"))));
}

Expand Down
2 changes: 1 addition & 1 deletion ramls/source-record-storage-records.raml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit d15f8fe

Please sign in to comment.