use of org.folio.rest.jaxrs.model.JournalRecord in project mod-source-record-manager by folio-org.
the class MarcImportEventsHandler method handle.
@Override
public void handle(JournalService journalService, DataImportEventPayload eventPayload, String tenantId) throws JournalRecordMapperException {
Optional<JournalParams> journalParamsOptional = JournalParams.JournalParamsEnum.getValue(eventPayload.getEventType()).getJournalParams(eventPayload);
if (journalParamsOptional.isPresent()) {
JournalParams journalParams = journalParamsOptional.get();
JournalRecord journalRecord = JournalUtil.buildJournalRecordByEvent(eventPayload, journalParams.journalActionType, journalParams.journalEntityType, journalParams.journalActionStatus);
populateRecordTitleIfNeeded(journalRecord, eventPayload).onComplete(ar -> journalService.save(JsonObject.mapFrom(journalRecord), tenantId));
}
}
use of org.folio.rest.jaxrs.model.JournalRecord in project mod-source-record-manager by folio-org.
the class StoredRecordChunksKafkaHandlerTest method writeSavedRecordsInfoToImportJournal.
private void writeSavedRecordsInfoToImportJournal(String marcBibRecordPath, EntityType entityType) throws IOException {
// given
Record record = Json.decodeValue(TestUtil.readFileFromPath(marcBibRecordPath), Record.class);
RecordsBatchResponse savedRecordsBatch = new RecordsBatchResponse().withRecords(List.of(record)).withTotalRecords(1);
Event event = new Event().withId(UUID.randomUUID().toString()).withEventPayload(Json.encode(savedRecordsBatch));
when(kafkaRecord.value()).thenReturn(Json.encode(event));
when(kafkaRecord.headers()).thenReturn(List.of(KafkaHeader.header(OKAPI_HEADER_TENANT, TENANT_ID)));
when(eventProcessedService.collectData(STORED_RECORD_CHUNKS_KAFKA_HANDLER_UUID, event.getId(), TENANT_ID)).thenReturn(Future.succeededFuture());
when(mappingRuleCache.get(new MappingRuleCacheKey(TENANT_ID, entityType))).thenReturn(Future.succeededFuture(Optional.of(mappingRules)));
when(recordsPublishingService.sendEventsWithRecords(anyList(), isNull(), any(OkapiConnectionParams.class), anyString())).thenReturn(Future.succeededFuture(true));
// when
Future<String> future = storedRecordChunksKafkaHandler.handle(kafkaRecord);
// then
assertTrue(future.succeeded());
verify(journalService, times(1)).saveBatch(journalRecordsCaptor.capture(), eq(TENANT_ID));
assertEquals(1, journalRecordsCaptor.getValue().size());
JournalRecord journalRecord = journalRecordsCaptor.getValue().getJsonObject(0).mapTo(JournalRecord.class);
assertEquals(record.getId(), journalRecord.getSourceId());
assertEquals(entityType, journalRecord.getEntityType());
assertEquals(JournalRecord.ActionType.CREATE, journalRecord.getActionType());
assertEquals(JournalRecord.ActionStatus.COMPLETED, journalRecord.getActionStatus());
assertEquals("The Journal of ecclesiastical history.", journalRecord.getTitle());
}
Aggregations