use of org.folio.rest.jaxrs.model.JournalRecord.ActionType.CREATE in project mod-source-record-manager by folio-org.
the class JournalRecordDaoTest method shouldReturnSortedJournalRecordListByActionType.
@Test
public void shouldReturnSortedJournalRecordListByActionType(TestContext testContext) {
InitJobExecutionsRsDto response = constructAndPostInitJobExecutionRqDto(1);
List<JobExecution> createdJobExecutions = response.getJobExecutions();
Assert.assertThat(createdJobExecutions.size(), is(1));
JobExecution jobExec = createdJobExecutions.get(0);
JournalRecord journalRecord1 = new JournalRecord().withJobExecutionId(jobExec.getId()).withSourceRecordOrder(0).withSourceId(UUID.randomUUID().toString()).withEntityType(JournalRecord.EntityType.MARC_BIBLIOGRAPHIC).withEntityId(UUID.randomUUID().toString()).withActionType(CREATE).withActionDate(new Date()).withActionStatus(COMPLETED);
JournalRecord journalRecord2 = new JournalRecord().withJobExecutionId(jobExec.getId()).withSourceRecordOrder(0).withSourceId(UUID.randomUUID().toString()).withEntityType(JournalRecord.EntityType.INSTANCE).withEntityId(UUID.randomUUID().toString()).withActionType(MODIFY).withActionDate(new Date()).withActionStatus(COMPLETED);
JournalRecord journalRecord3 = new JournalRecord().withJobExecutionId(jobExec.getId()).withSourceRecordOrder(0).withSourceId(UUID.randomUUID().toString()).withEntityType(JournalRecord.EntityType.INSTANCE).withEntityId(UUID.randomUUID().toString()).withActionType(DELETE).withActionDate(new Date()).withActionStatus(COMPLETED);
Async async = testContext.async();
Future<List<JournalRecord>> getFuture = journalRecordDao.save(journalRecord1, TENANT_ID).compose(ar -> journalRecordDao.save(journalRecord2, TENANT_ID)).compose(ar -> journalRecordDao.save(journalRecord3, TENANT_ID)).compose(ar -> journalRecordDao.getByJobExecutionId(jobExec.getId(), "action_type", "asc", TENANT_ID));
getFuture.onComplete(ar -> {
testContext.verify(v -> {
Assert.assertTrue(ar.succeeded());
List<JournalRecord> journalRecords = ar.result();
Assert.assertEquals(3, journalRecords.size());
Assert.assertThat(journalRecords.get(0).getActionType(), lessThan(journalRecords.get(1).getActionType()));
Assert.assertThat(journalRecords.get(1).getActionType(), lessThan(journalRecords.get(2).getActionType()));
});
async.complete();
});
}
use of org.folio.rest.jaxrs.model.JournalRecord.ActionType.CREATE in project mod-source-record-manager by folio-org.
the class JournalRecordDaoTest method shouldReturnSortedJournalRecordListByErrorMessage.
@Test
public void shouldReturnSortedJournalRecordListByErrorMessage(TestContext testContext) {
InitJobExecutionsRsDto response = constructAndPostInitJobExecutionRqDto(1);
List<JobExecution> createdJobExecutions = response.getJobExecutions();
Assert.assertThat(createdJobExecutions.size(), is(1));
JobExecution jobExec = createdJobExecutions.get(0);
JournalRecord journalRecord1 = new JournalRecord().withJobExecutionId(jobExec.getId()).withSourceRecordOrder(0).withSourceId(UUID.randomUUID().toString()).withEntityType(JournalRecord.EntityType.MARC_BIBLIOGRAPHIC).withEntityId(UUID.randomUUID().toString()).withActionType(CREATE).withActionDate(new Date()).withActionStatus(ERROR).withError("Record creation error");
JournalRecord journalRecord2 = new JournalRecord().withJobExecutionId(jobExec.getId()).withSourceRecordOrder(0).withSourceId(UUID.randomUUID().toString()).withEntityType(JournalRecord.EntityType.INSTANCE).withEntityId(UUID.randomUUID().toString()).withActionType(MODIFY).withActionDate(new Date()).withActionStatus(ERROR).withError("Instance was not updated");
JournalRecord journalRecord3 = new JournalRecord().withJobExecutionId(jobExec.getId()).withSourceRecordOrder(0).withSourceId(UUID.randomUUID().toString()).withEntityType(JournalRecord.EntityType.INSTANCE).withEntityId(UUID.randomUUID().toString()).withActionType(DELETE).withActionDate(new Date()).withActionStatus(ERROR).withError("No action taken");
Async async = testContext.async();
Future<List<JournalRecord>> getFuture = journalRecordDao.save(journalRecord1, TENANT_ID).compose(ar -> journalRecordDao.save(journalRecord2, TENANT_ID)).compose(ar -> journalRecordDao.save(journalRecord3, TENANT_ID)).compose(ar -> journalRecordDao.getByJobExecutionId(jobExec.getId(), "error", "desc", TENANT_ID));
getFuture.onComplete(ar -> {
testContext.verify(v -> {
Assert.assertTrue(ar.succeeded());
List<JournalRecord> journalRecords = ar.result();
Assert.assertEquals(3, journalRecords.size());
Assert.assertThat(journalRecords.get(0).getError(), greaterThan(journalRecords.get(1).getError()));
Assert.assertThat(journalRecords.get(1).getError(), greaterThan(journalRecords.get(2).getError()));
});
async.complete();
});
}
use of org.folio.rest.jaxrs.model.JournalRecord.ActionType.CREATE in project mod-source-record-manager by folio-org.
the class StoredRecordChunksKafkaHandler method buildJournalRecords.
private JsonArray buildJournalRecords(List<Record> storedRecords, Optional<JsonObject> mappingRulesOptional, String tenantId) {
EntityType entityType = getEntityType(storedRecords);
JsonArray journalRecords = new JsonArray();
String titleFieldTag = null;
List<String> subfieldCodes = null;
if (mappingRulesOptional.isPresent()) {
JsonObject mappingRules = mappingRulesOptional.get();
Optional<String> titleFieldOptional = getTitleFieldTagByInstanceFieldPath(mappingRules);
if (titleFieldOptional.isPresent()) {
titleFieldTag = titleFieldOptional.get();
subfieldCodes = mappingRules.getJsonArray(titleFieldTag).stream().map(JsonObject.class::cast).filter(fieldMappingRule -> fieldMappingRule.getString("target").equals(INSTANCE_TITLE_FIELD_PATH)).flatMap(fieldMappingRule -> fieldMappingRule.getJsonArray("subfield").stream()).map(subfieldCode -> subfieldCode.toString()).collect(Collectors.toList());
}
}
for (Record record : storedRecords) {
JournalRecord journalRecord = new JournalRecord().withJobExecutionId(record.getSnapshotId()).withSourceRecordOrder(record.getOrder()).withSourceId(record.getId()).withEntityType(entityType).withEntityId(record.getId()).withActionType(CREATE).withActionStatus(COMPLETED).withActionDate(new Date()).withTitle(allNotNull(record.getParsedRecord(), titleFieldTag) ? ParsedRecordUtil.retrieveDataByField(record.getParsedRecord(), titleFieldTag, subfieldCodes) : null);
journalRecords.add(JsonObject.mapFrom(journalRecord));
}
return journalRecords;
}
use of org.folio.rest.jaxrs.model.JournalRecord.ActionType.CREATE in project mod-source-record-manager by folio-org.
the class MetaDataProviderJobLogEntriesAPITest method shouldReturnAuthorityCreated.
@Test
public void shouldReturnAuthorityCreated(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_AUTHORITY, COMPLETED, null)).compose(v -> createJournalRecord(createdJobExecution.getId(), sourceRecordId, null, null, null, 0, CREATE, AUTHORITY, 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.size()", is(1)).body("totalRecords", is(1)).body("entries[0].sourceRecordId", is(sourceRecordId)).body("entries[0].sourceRecordTitle", is(recordTitle)).body("entries[0].sourceRecordActionStatus", is(ActionStatus.CREATED.value())).body("entries[0].authorityActionStatus", is(ActionStatus.CREATED.value()));
async.complete();
}));
}
use of org.folio.rest.jaxrs.model.JournalRecord.ActionType.CREATE in project mod-source-record-manager by folio-org.
the class MetaDataProviderJobLogEntriesAPITest method shouldReturnMarcBibUpdatedWhenMarcBibWasModified.
@Test
public void shouldReturnMarcBibUpdatedWhenMarcBibWasModified(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, null, null, 0, MODIFY, 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();
}));
}
Aggregations