use of org.folio.rest.jaxrs.model.RawRecord 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.RawRecord in project mod-source-record-storage by folio-org.
the class QuickMarcKafkaHandlerTest method setUpClass.
@BeforeClass
public static void setUpClass() throws IOException {
rawRecord = new RawRecord().withId(recordId).withContent(new ObjectMapper().readValue(TestUtil.readFileFromPath(RAW_MARC_RECORD_CONTENT_SAMPLE_PATH), String.class));
parsedRecord = new ParsedRecord().withId(recordId).withContent(new ObjectMapper().readValue(TestUtil.readFileFromPath(PARSED_MARC_RECORD_CONTENT_SAMPLE_PATH), JsonObject.class).encode());
}
use of org.folio.rest.jaxrs.model.RawRecord in project mod-source-record-storage by folio-org.
the class HoldingsPostProcessingEventHandlerTest method shouldUpdateField005WhenThisFiledIsNotProtected.
@Test
public void shouldUpdateField005WhenThisFiledIsNotProtected(TestContext context) throws IOException {
Async async = context.async();
String expectedDate = AdditionalFieldsUtil.dateTime005Formatter.format(ZonedDateTime.ofInstant(Instant.now(), ZoneId.systemDefault()));
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));
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.substring(0, 10), actualDate.substring(0, 10));
async.complete();
});
});
}
use of org.folio.rest.jaxrs.model.RawRecord in project mod-source-record-storage by folio-org.
the class HoldingsPostProcessingEventHandlerTest method shouldSaveRecordWhenRecordDoesntExist.
@Test
public void shouldSaveRecordWhenRecordDoesntExist(TestContext context) throws IOException {
Async async = context.async();
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));
DataImportEventPayload dataImportEventPayload = createDataImportEventPayload(payloadContext, DI_INVENTORY_HOLDINGS_CREATED_READY_FOR_POST_PROCESSING);
CompletableFuture<DataImportEventPayload> future = handler.handle(dataImportEventPayload);
future.whenComplete((payload, e) -> {
if (e != null) {
context.fail(e);
}
recordDao.getRecordByMatchedId(defaultRecord.getMatchedId(), TENANT_ID).onComplete(getAr -> {
if (getAr.failed()) {
context.fail(getAr.cause());
}
context.assertTrue(getAr.result().isPresent());
Record savedRecord = getAr.result().get();
context.assertNotNull(savedRecord.getExternalIdsHolder());
context.assertEquals(expectedHoldingsId, savedRecord.getExternalIdsHolder().getHoldingsId());
context.assertNotNull(savedRecord.getParsedRecord());
context.assertNotNull(savedRecord.getParsedRecord().getContent());
JsonObject parsedContent = JsonObject.mapFrom(savedRecord.getParsedRecord().getContent());
JsonArray fields = parsedContent.getJsonArray("fields");
context.assertTrue(!fields.isEmpty());
String actualHoldingsId = getInventoryId(fields);
context.assertEquals(expectedHoldingsId, actualHoldingsId);
async.complete();
});
});
}
use of org.folio.rest.jaxrs.model.RawRecord in project mod-source-record-storage by folio-org.
the class InstancePostProcessingEventHandlerTest method shouldSaveRecordWhenRecordDoesntExist.
@Test
public void shouldSaveRecordWhenRecordDoesntExist(TestContext context) throws IOException {
Async async = context.async();
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));
DataImportEventPayload dataImportEventPayload = createDataImportEventPayload(payloadContext, DI_INVENTORY_INSTANCE_CREATED_READY_FOR_POST_PROCESSING);
CompletableFuture<DataImportEventPayload> future = handler.handle(dataImportEventPayload);
future.whenComplete((payload, e) -> {
if (e != null) {
context.fail(e);
}
recordDao.getRecordByMatchedId(defaultRecord.getMatchedId(), TENANT_ID).onComplete(getAr -> {
if (getAr.failed()) {
context.fail(getAr.cause());
}
context.assertTrue(getAr.result().isPresent());
Record savedRecord = getAr.result().get();
context.assertNotNull(savedRecord.getExternalIdsHolder());
context.assertEquals(expectedInstanceId, savedRecord.getExternalIdsHolder().getInstanceId());
context.assertNotNull(savedRecord.getParsedRecord());
context.assertNotNull(savedRecord.getParsedRecord().getContent());
JsonObject parsedContent = JsonObject.mapFrom(savedRecord.getParsedRecord().getContent());
JsonArray fields = parsedContent.getJsonArray("fields");
context.assertTrue(!fields.isEmpty());
String actualInstanceId = getInventoryId(fields);
context.assertEquals(expectedInstanceId, actualInstanceId);
async.complete();
});
});
}
Aggregations