use of org.folio.rest.jaxrs.model.MappingMetadataDto in project mod-source-record-storage by folio-org.
the class DataImportConsumersVerticleTest method setUp.
@Before
public void setUp(TestContext context) throws IOException {
WireMock.stubFor(get(new UrlPathPattern(new RegexPattern(MAPPING_METADATA_URL + "/.*"), true)).willReturn(WireMock.ok().withBody(Json.encode(new MappingMetadataDto().withMappingParams(Json.encode(new MappingParameters()))))));
RawRecord rawRecord = new RawRecord().withId(recordId).withContent(new ObjectMapper().readValue(TestUtil.readFileFromPath(RAW_MARC_RECORD_CONTENT_SAMPLE_PATH), String.class));
ParsedRecord parsedRecord = new ParsedRecord().withId(recordId).withContent(PARSED_CONTENT);
Snapshot snapshot = new Snapshot().withJobExecutionId(snapshotId).withProcessingStartedDate(new Date()).withStatus(Snapshot.Status.COMMITTED);
record = new Record().withId(recordId).withSnapshotId(snapshot.getJobExecutionId()).withGeneration(0).withMatchedId(recordId).withRecordType(MARC_BIB).withRawRecord(rawRecord).withParsedRecord(parsedRecord).withExternalIdsHolder(new ExternalIdsHolder().withAuthorityId(UUID.randomUUID().toString()));
ReactiveClassicGenericQueryExecutor queryExecutor = postgresClientFactory.getQueryExecutor(TENANT_ID);
RecordDaoImpl recordDao = new RecordDaoImpl(postgresClientFactory);
SnapshotDaoUtil.save(queryExecutor, snapshot).compose(v -> recordDao.saveRecord(record, TENANT_ID)).onComplete(context.asyncAssertSuccess());
}
use of org.folio.rest.jaxrs.model.MappingMetadataDto in project mod-source-record-storage by folio-org.
the class InstancePostProcessingEventHandlerTest method shouldUpdateField005WhenThisFiledIsProtected.
@Test
public void shouldUpdateField005WhenThisFiledIsProtected(TestContext context) throws IOException {
Async async = context.async();
MappingParameters mappingParameters = new MappingParameters().withMarcFieldProtectionSettings(List.of(new MarcFieldProtectionSetting().withField(TAG_005).withData("*")));
WireMock.stubFor(get(new UrlPathPattern(new RegexPattern(MAPPING_METADATA__URL + "/.*"), true)).willReturn(WireMock.ok().withBody(Json.encode(new MappingMetadataDto().withMappingParams(Json.encode(mappingParameters))))));
String recordId = UUID.randomUUID().toString();
RawRecord rawRecord = new RawRecord().withId(recordId).withContent(new ObjectMapper().readValue(TestUtil.readFileFromPath(RAW_MARC_RECORD_CONTENT_SAMPLE_PATH), String.class));
ParsedRecord parsedRecord = new ParsedRecord().withId(recordId).withContent(new ObjectMapper().readValue(TestUtil.readFileFromPath(PARSED_MARC_RECORD_CONTENT_SAMPLE_PATH), JsonObject.class).encode());
Record defaultRecord = new Record().withId(recordId).withMatchedId(recordId).withSnapshotId(snapshotId1).withGeneration(0).withRecordType(MARC_BIB).withRawRecord(rawRecord).withParsedRecord(parsedRecord);
String expectedInstanceId = UUID.randomUUID().toString();
String expectedHrId = UUID.randomUUID().toString();
JsonObject instance = createExternalEntity(expectedInstanceId, expectedHrId);
HashMap<String, String> payloadContext = new HashMap<>();
payloadContext.put(INSTANCE.value(), instance.encode());
payloadContext.put(MARC_BIBLIOGRAPHIC.value(), Json.encode(defaultRecord));
String expectedDate = AdditionalFieldsUtil.getValueFromControlledField(record, TAG_005);
DataImportEventPayload dataImportEventPayload = createDataImportEventPayload(payloadContext, DI_INVENTORY_INSTANCE_CREATED_READY_FOR_POST_PROCESSING);
CompletableFuture<DataImportEventPayload> future = handler.handle(dataImportEventPayload);
future.whenComplete((payload, throwable) -> {
if (throwable != null) {
context.fail(throwable);
}
recordDao.getRecordByMatchedId(defaultRecord.getMatchedId(), TENANT_ID).onComplete(getAr -> {
if (getAr.failed()) {
context.fail(getAr.cause());
}
context.assertTrue(getAr.result().isPresent());
Record updatedRecord = getAr.result().get();
String actualDate = AdditionalFieldsUtil.getValueFromControlledField(updatedRecord, TAG_005);
Assert.assertEquals(expectedDate, actualDate);
async.complete();
});
});
}
use of org.folio.rest.jaxrs.model.MappingMetadataDto in project mod-source-record-storage by folio-org.
the class MarcAuthorityUpdateModifyEventHandlerTest method setUp.
@Before
public void setUp(TestContext context) {
WireMock.stubFor(get(new UrlPathPattern(new RegexPattern(MAPPING_METADATA__URL + "/.*"), true)).willReturn(WireMock.ok().withBody(Json.encode(new MappingMetadataDto().withMappingParams(Json.encode(new MappingParameters()))))));
recordDao = new RecordDaoImpl(postgresClientFactory);
recordService = new RecordServiceImpl(recordDao);
modifyRecordEventHandler = new MarcAuthorityUpdateModifyEventHandler(recordService, new MappingParametersSnapshotCache(vertx), vertx);
Snapshot snapshot = new Snapshot().withJobExecutionId(UUID.randomUUID().toString()).withProcessingStartedDate(new Date()).withStatus(Snapshot.Status.COMMITTED);
snapshotForRecordUpdate = new Snapshot().withJobExecutionId(UUID.randomUUID().toString()).withStatus(Snapshot.Status.PARSING_IN_PROGRESS);
record = new Record().withId(recordId).withSnapshotId(snapshot.getJobExecutionId()).withGeneration(0).withMatchedId(recordId).withRecordType(MARC_BIB).withRawRecord(rawRecord).withParsedRecord(parsedRecord);
ReactiveClassicGenericQueryExecutor queryExecutor = postgresClientFactory.getQueryExecutor(TENANT_ID);
SnapshotDaoUtil.save(queryExecutor, snapshot).compose(v -> recordService.saveRecord(record, TENANT_ID)).compose(v -> SnapshotDaoUtil.save(queryExecutor, snapshotForRecordUpdate)).onComplete(context.asyncAssertSuccess());
}
use of org.folio.rest.jaxrs.model.MappingMetadataDto in project mod-source-record-storage by folio-org.
the class MarcBibUpdateModifyEventHandlerTest method setUp.
@Before
public void setUp(TestContext context) {
WireMock.stubFor(get(new UrlPathPattern(new RegexPattern(MAPPING_METADATA__URL + "/.*"), true)).willReturn(WireMock.ok().withBody(Json.encode(new MappingMetadataDto().withMappingParams(Json.encode(new MappingParameters()))))));
recordDao = new RecordDaoImpl(postgresClientFactory);
recordService = new RecordServiceImpl(recordDao);
modifyRecordEventHandler = new MarcBibUpdateModifyEventHandler(recordService, new MappingParametersSnapshotCache(vertx), vertx);
Snapshot snapshot = new Snapshot().withJobExecutionId(UUID.randomUUID().toString()).withProcessingStartedDate(new Date()).withStatus(Snapshot.Status.COMMITTED);
snapshotForRecordUpdate = new Snapshot().withJobExecutionId(UUID.randomUUID().toString()).withStatus(Snapshot.Status.PARSING_IN_PROGRESS);
record = new Record().withId(recordId).withSnapshotId(snapshot.getJobExecutionId()).withGeneration(0).withMatchedId(recordId).withRecordType(MARC_BIB).withRawRecord(rawRecord).withParsedRecord(parsedRecord);
ReactiveClassicGenericQueryExecutor queryExecutor = postgresClientFactory.getQueryExecutor(TENANT_ID);
SnapshotDaoUtil.save(queryExecutor, snapshot).compose(v -> recordService.saveRecord(record, TENANT_ID)).compose(v -> SnapshotDaoUtil.save(queryExecutor, snapshotForRecordUpdate)).onComplete(context.asyncAssertSuccess());
}
use of org.folio.rest.jaxrs.model.MappingMetadataDto in project mod-source-record-storage by folio-org.
the class HoldingsPostProcessingEventHandlerTest method shouldUpdateField005WhenThisFiledIsProtected.
@Test
public void shouldUpdateField005WhenThisFiledIsProtected(TestContext context) throws IOException {
Async async = context.async();
MappingParameters mappingParameters = new MappingParameters().withMarcFieldProtectionSettings(List.of(new MarcFieldProtectionSetting().withField(TAG_005).withData("*")));
WireMock.stubFor(get(new UrlPathPattern(new RegexPattern(MAPPING_METADATA__URL + "/.*"), true)).willReturn(WireMock.ok().withBody(Json.encode(new MappingMetadataDto().withMappingParams(Json.encode(mappingParameters))))));
String recordId = UUID.randomUUID().toString();
RawRecord rawRecord = new RawRecord().withId(recordId).withContent(new ObjectMapper().readValue(TestUtil.readFileFromPath(RAW_MARC_RECORD_CONTENT_SAMPLE_PATH), String.class));
ParsedRecord parsedRecord = new ParsedRecord().withId(recordId).withContent(new ObjectMapper().readValue(TestUtil.readFileFromPath(PARSED_MARC_RECORD_CONTENT_SAMPLE_PATH), JsonObject.class).encode());
Record defaultRecord = new Record().withId(recordId).withMatchedId(recordId).withSnapshotId(snapshotId1).withGeneration(0).withRecordType(MARC_HOLDING).withRawRecord(rawRecord).withParsedRecord(parsedRecord);
String expectedHoldingsId = UUID.randomUUID().toString();
String expectedHrId = UUID.randomUUID().toString();
JsonObject holdings = createExternalEntity(expectedHoldingsId, expectedHrId);
HashMap<String, String> payloadContext = new HashMap<>();
payloadContext.put(HOLDINGS.value(), holdings.encode());
payloadContext.put(MARC_HOLDINGS.value(), Json.encode(defaultRecord));
String expectedDate = AdditionalFieldsUtil.getValueFromControlledField(record, TAG_005);
DataImportEventPayload dataImportEventPayload = createDataImportEventPayload(payloadContext, DI_INVENTORY_HOLDINGS_CREATED_READY_FOR_POST_PROCESSING);
CompletableFuture<DataImportEventPayload> future = handler.handle(dataImportEventPayload);
future.whenComplete((payload, throwable) -> {
if (throwable != null) {
context.fail(throwable);
}
recordDao.getRecordByMatchedId(defaultRecord.getMatchedId(), TENANT_ID).onComplete(getAr -> {
if (getAr.failed()) {
context.fail(getAr.cause());
}
context.assertTrue(getAr.result().isPresent());
Record updatedRecord = getAr.result().get();
String actualDate = AdditionalFieldsUtil.getValueFromControlledField(updatedRecord, TAG_005);
Assert.assertEquals(expectedDate, actualDate);
async.complete();
});
});
}
Aggregations