use of org.folio.rest.jaxrs.model.JournalRecord in project mod-source-record-manager by folio-org.
the class InvoiceUtil method buildInvoiceRecord.
private static Map<String, Object> buildInvoiceRecord(DataImportEventPayload eventPayload) throws JournalRecordMapperException {
try {
String edifactRecordAsString = eventPayload.getContext().get(EDIFACT_INVOICE.value());
Record edifactRecord = new ObjectMapper().readValue(edifactRecordAsString, Record.class);
String recordAsString = eventPayload.getContext().get(INVOICE.value());
JsonObject invoiceJson = new JsonObject(recordAsString);
Integer invoiceOrder = edifactRecord.getOrder() != null ? edifactRecord.getOrder() : 0;
JournalRecord journalRecord = new JournalRecord().withJobExecutionId(eventPayload.getJobExecutionId()).withSourceId(edifactRecord.getId()).withSourceRecordOrder(invoiceOrder).withEntityType(INVOICE).withEntityId(invoiceJson.getString(FIELD_ID)).withTitle(INVOICE_TITLE).withEntityHrId(invoiceJson.getString(FIELD_FOLIO_INVOICE_NO)).withActionType(ActionType.CREATE).withActionDate(new Date()).withActionStatus(isInvoiceIncorrect(eventPayload) ? ActionStatus.ERROR : ActionStatus.COMPLETED).withError(eventPayload.getEventType().equals(DI_ERROR.value()) ? eventPayload.getContext().get(ERROR_KEY) : "");
return Map.of(FIELD_INVOICE_NO, StringUtils.isNotBlank(invoiceJson.getString(FIELD_VENDOR_INVOICE_NO)) ? invoiceJson.getString(FIELD_VENDOR_INVOICE_NO) : NO_VENDOR_INVOICE_NUMBER, FIELD_SOURCE_ID, edifactRecord.getId(), FIELD_INVOICE_ORDER, invoiceOrder, JOURNAL_RECORD, journalRecord);
} catch (Exception e) {
throw new JournalRecordMapperException(INVOICE_MAPPING_EXCEPTION_MSG, e);
}
}
use of org.folio.rest.jaxrs.model.JournalRecord in project mod-source-record-manager by folio-org.
the class MetaDataProviderJobLogEntriesAPITest method shouldReturnMarcBibUpdatedWhenMarcBibWasUpdated.
@Test
public void shouldReturnMarcBibUpdatedWhenMarcBibWasUpdated(TestContext context) {
Async async = context.async();
JobExecution createdJobExecution = constructAndPostInitJobExecutionRqDto(1).getJobExecutions().get(0);
String sourceRecordId = UUID.randomUUID().toString();
String recordTitle = "test title";
Future<JournalRecord> future = Future.succeededFuture().compose(v -> createJournalRecord(createdJobExecution.getId(), sourceRecordId, null, null, recordTitle, 0, CREATE, MARC_BIBLIOGRAPHIC, COMPLETED, null)).compose(v -> createJournalRecord(createdJobExecution.getId(), sourceRecordId, null, "in00000000001", null, 0, UPDATE, MARC_BIBLIOGRAPHIC, COMPLETED, null)).onFailure(context::fail);
future.onComplete(ar -> context.verify(v -> {
RestAssured.given().spec(spec).when().get(GET_JOB_EXECUTION_JOURNAL_RECORDS_PATH + "/" + createdJobExecution.getId()).then().statusCode(HttpStatus.SC_OK).body("entries", hasSize(1)).body("totalRecords", is(1)).body("entries[0].jobExecutionId", is(createdJobExecution.getId())).body("entries[0].sourceRecordId", is(sourceRecordId)).body("entries[0].sourceRecordTitle", is(recordTitle)).body("entries[0].sourceRecordActionStatus", is(ActionStatus.UPDATED.value()));
async.complete();
}));
}
use of org.folio.rest.jaxrs.model.JournalRecord in project mod-source-record-manager by folio-org.
the class MetaDataProviderJobLogEntriesAPITest method shouldReturnInstanceDiscardedWhenInstanceCreationFailed.
@Test
public void shouldReturnInstanceDiscardedWhenInstanceCreationFailed(TestContext context) {
// test
Async async = context.async();
JobExecution createdJobExecution = constructAndPostInitJobExecutionRqDto(1).getJobExecutions().get(0);
String sourceRecordId = UUID.randomUUID().toString();
String recordTitle = "test title";
Future<JournalRecord> future = Future.succeededFuture().compose(v -> createJournalRecord(createdJobExecution.getId(), sourceRecordId, null, null, recordTitle, 0, CREATE, MARC_BIBLIOGRAPHIC, COMPLETED, null)).compose(v -> createJournalRecord(createdJobExecution.getId(), sourceRecordId, null, null, null, 0, CREATE, INSTANCE, ERROR, "error msg")).onFailure(context::fail);
future.onComplete(ar -> context.verify(v -> {
RestAssured.given().spec(spec).when().get(GET_JOB_EXECUTION_JOURNAL_RECORDS_PATH + "/" + createdJobExecution.getId()).then().statusCode(HttpStatus.SC_OK).body("entries.size()", is(1)).body("totalRecords", is(1)).body("entries[0].jobExecutionId", is(createdJobExecution.getId())).body("entries[0].sourceRecordId", is(sourceRecordId)).body("entries[0].sourceRecordTitle", is(recordTitle)).body("entries[0].instanceActionStatus", is(ActionStatus.DISCARDED.value())).body("entries[0].error", not(emptyOrNullString()));
async.complete();
}));
}
use of org.folio.rest.jaxrs.model.JournalRecord in project mod-source-record-manager by folio-org.
the class MetaDataProviderJobLogEntriesAPITest method shouldReturnInstanceDiscardedWhenInstanceWasNotMatched.
@Test
public void shouldReturnInstanceDiscardedWhenInstanceWasNotMatched(TestContext context) {
Async async = context.async();
JobExecution createdJobExecution = constructAndPostInitJobExecutionRqDto(1).getJobExecutions().get(0);
String sourceRecordId = UUID.randomUUID().toString();
String recordTitle = "test title";
Future<JournalRecord> future = Future.succeededFuture().compose(v -> createJournalRecord(createdJobExecution.getId(), sourceRecordId, null, null, recordTitle, 0, CREATE, MARC_BIBLIOGRAPHIC, COMPLETED, null)).compose(v -> createJournalRecord(createdJobExecution.getId(), sourceRecordId, null, "in00000000001", null, 0, NON_MATCH, INSTANCE, COMPLETED, null)).onSuccess(v -> async.complete()).onFailure(context::fail);
future.onComplete(ar -> context.verify(v -> {
RestAssured.given().spec(spec).when().get(GET_JOB_EXECUTION_JOURNAL_RECORDS_PATH + "/" + createdJobExecution.getId()).then().statusCode(HttpStatus.SC_OK).body("entries.size()", is(1)).body("totalRecords", is(1)).body("entries[0].jobExecutionId", is(createdJobExecution.getId())).body("entries[0].sourceRecordId", is(sourceRecordId)).body("entries[0].sourceRecordTitle", is(recordTitle)).body("entries[0].sourceRecordActionStatus", is(ActionStatus.CREATED.value())).body("entries[0].instanceActionStatus", is(ActionStatus.DISCARDED.value())).body("entries[0].error", emptyOrNullString());
async.complete();
}));
}
use of org.folio.rest.jaxrs.model.JournalRecord in project mod-source-record-manager by folio-org.
the class MetaDataProviderJobLogEntriesAPITest method shouldReturnNotEmptyMarcBibErrorWhenMarcBibFailed.
@Test
public void shouldReturnNotEmptyMarcBibErrorWhenMarcBibFailed(TestContext context) {
Async async = context.async();
JobExecution createdJobExecution = constructAndPostInitJobExecutionRqDto(1).getJobExecutions().get(0);
String sourceRecordId = UUID.randomUUID().toString();
String recordTitle = "test title";
Future<JournalRecord> future = Future.succeededFuture().compose(v -> createJournalRecord(createdJobExecution.getId(), sourceRecordId, null, null, recordTitle, 0, CREATE, MARC_BIBLIOGRAPHIC, ERROR, "MarcBib error msg")).onFailure(context::fail);
future.onComplete(ar -> context.verify(v -> {
RestAssured.given().spec(spec).when().get(GET_JOB_EXECUTION_JOURNAL_RECORDS_PATH + "/" + createdJobExecution.getId() + "/records/" + sourceRecordId).then().statusCode(HttpStatus.SC_OK).body("jobExecutionId", is(createdJobExecution.getId())).body("sourceRecordId", is(sourceRecordId)).body("sourceRecordTitle", is(recordTitle)).body("sourceRecordOrder", is(0)).body("error", is("MarcBib error msg"));
async.complete();
}));
}
Aggregations