Search in sources :

Example 1 with JournalRecord

use of org.folio.rest.jaxrs.model.JournalRecord in project mod-source-record-manager by folio-org.

the class JournalServiceImpl method save.

@Override
public void save(JsonObject journalRecord, String tenantId) {
    JournalRecord record = journalRecord.mapTo(JournalRecord.class);
    journalRecordDao.save(record, tenantId);
}
Also used : JournalRecord(org.folio.rest.jaxrs.model.JournalRecord)

Example 2 with JournalRecord

use of org.folio.rest.jaxrs.model.JournalRecord in project mod-source-record-manager by folio-org.

the class JournalUtil method buildJournalRecord.

public static JournalRecord buildJournalRecord(DataImportEventPayload eventPayload, JournalRecord.ActionType actionType, JournalRecord.EntityType entityType, JournalRecord.ActionStatus actionStatus) throws JournalRecordMapperException {
    try {
        HashMap<String, String> eventPayloadContext = eventPayload.getContext();
        String recordAsString = extractRecord(eventPayloadContext);
        Record record;
        if (StringUtils.isBlank(recordAsString)) {
            // create stub record since none was introduced
            record = new Record().withId(UUID.randomUUID().toString()).withSnapshotId(eventPayload.getJobExecutionId()).withOrder(0);
        } else {
            record = new ObjectMapper().readValue(recordAsString, Record.class);
        }
        String entityAsString = eventPayloadContext.get(entityType.value());
        JournalRecord journalRecord = new JournalRecord().withJobExecutionId(record.getSnapshotId()).withSourceId(record.getId()).withSourceRecordOrder(record.getOrder()).withEntityType(entityType).withActionType(actionType).withActionDate(new Date()).withActionStatus(actionStatus);
        if (!isEmpty(entityAsString)) {
            JsonObject entityJson = new JsonObject(entityAsString);
            journalRecord.setEntityId(entityJson.getString("id"));
            if (entityType == INSTANCE || entityType == HOLDINGS || entityType == ITEM) {
                if (entityType == HOLDINGS) {
                    journalRecord.setInstanceId(entityJson.getString("instanceId"));
                }
                if (entityType == ITEM) {
                    if (eventPayloadContext.containsKey(INSTANCE.value())) {
                        JsonObject instanceJson = new JsonObject(eventPayloadContext.get(INSTANCE.value()));
                        journalRecord.setInstanceId(instanceJson.getString("id"));
                    } else if (eventPayloadContext.containsKey(HOLDINGS.value())) {
                        JsonObject holdingsJson = new JsonObject(eventPayloadContext.get(HOLDINGS.value()));
                        journalRecord.setInstanceId(holdingsJson.getString("instanceId"));
                    }
                    journalRecord.setHoldingsId(entityJson.getString("holdingsRecordId"));
                }
                journalRecord.setEntityHrId(entityJson.getString("hrid"));
            }
        }
        if (DI_ERROR == DataImportEventTypes.fromValue(eventPayload.getEventType())) {
            journalRecord.setError(eventPayloadContext.get(ERROR_KEY));
        }
        return journalRecord;
    } catch (Exception e) {
        throw new JournalRecordMapperException(String.format(ENTITY_OR_RECORD_MAPPING_EXCEPTION_MSG, entityType.value()), e);
    }
}
Also used : JsonObject(io.vertx.core.json.JsonObject) JournalRecord(org.folio.rest.jaxrs.model.JournalRecord) Record(org.folio.rest.jaxrs.model.Record) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JournalRecord(org.folio.rest.jaxrs.model.JournalRecord) Date(java.util.Date)

Example 3 with JournalRecord

use of org.folio.rest.jaxrs.model.JournalRecord in project mod-source-record-manager by folio-org.

the class JobExecutionDaoImplTest method prepareDataForDeletion.

private Future<JobExecution> prepareDataForDeletion(Instant completedDate) {
    InitJobExecutionsRsDto response = constructAndPostInitJobExecutionRqDto(1);
    List<JobExecution> createdJobExecutions = response.getJobExecutions();
    assertThat(createdJobExecutions.size(), Matchers.is(1));
    JobExecution jobExec = createdJobExecutions.get(0);
    jobExec.withCompletedDate(Date.from(completedDate));
    JobExecutionProgress jobExecutionProgress = new JobExecutionProgress().withJobExecutionId(jobExec.getId()).withTotal(1).withCurrentlySucceeded(1).withCurrentlyFailed(0);
    JobMonitoring jobMonitoring = new JobMonitoring().withId(UUID.randomUUID().toString()).withJobExecutionId(jobExec.getId()).withNotificationSent(true).withLastEventTimestamp(new Date());
    JournalRecord journalRecord = 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);
    JobExecutionSourceChunk jobExecutionSourceChunk = new JobExecutionSourceChunk().withId("67dfac11-1caf-4470-9ad1-d533f6360bdd").withJobExecutionId(jobExec.getId()).withLast(false).withState(JobExecutionSourceChunk.State.COMPLETED).withChunkSize(10).withProcessedAmount(42);
    return jobExecutionDao.updateJobExecution(jobExec, TENANT_ID).compose(jobExecution -> {
        Future<RowSet<Row>> saveProgressFuture = jobExecutionProgressDao.save(jobExecutionProgress, TENANT_ID);
        Future<String> saveMonitoringFuture = jobMonitoringDao.save(jobMonitoring, TENANT_ID);
        Future<String> saveJournalFuture = journalRecordDao.save(journalRecord, TENANT_ID);
        Future<String> saveSourceChunkFuture = jobExecutionSourceChunkDao.save(jobExecutionSourceChunk, TENANT_ID);
        return CompositeFuture.all(saveProgressFuture, saveMonitoringFuture, saveJournalFuture, saveSourceChunkFuture).compose(ar -> Future.succeededFuture(jobExecution));
    });
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) JobExecutionProgress(org.folio.rest.jaxrs.model.JobExecutionProgress) RowSet(io.vertx.sqlclient.RowSet) JobExecutionSourceChunk(org.folio.rest.jaxrs.model.JobExecutionSourceChunk) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) JobMonitoring(org.folio.rest.jaxrs.model.JobMonitoring) Date(java.util.Date) JournalRecord(org.folio.rest.jaxrs.model.JournalRecord)

Example 4 with JournalRecord

use of org.folio.rest.jaxrs.model.JournalRecord 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();
    });
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Date(java.util.Date) RunWith(org.junit.runner.RunWith) PostgresClientFactory(org.folio.dao.util.PostgresClientFactory) MockitoAnnotations(org.mockito.MockitoAnnotations) JobExecution(org.folio.rest.jaxrs.model.JobExecution) Spy(org.mockito.Spy) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) Matchers.lessThan(org.hamcrest.Matchers.lessThan) ERROR(org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.ERROR) MODIFY(org.folio.rest.jaxrs.model.JournalRecord.ActionType.MODIFY) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) DELETE(org.folio.rest.jaxrs.model.JournalRecord.ActionType.DELETE) JournalRecord(org.folio.rest.jaxrs.model.JournalRecord) Vertx(io.vertx.core.Vertx) Test(org.junit.Test) IOException(java.io.IOException) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) UUID(java.util.UUID) COMPLETED(org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.COMPLETED) Future(io.vertx.core.Future) List(java.util.List) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Assert(org.junit.Assert) CREATE(org.folio.rest.jaxrs.model.JournalRecord.ActionType.CREATE) Async(io.vertx.ext.unit.Async) List(java.util.List) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) JournalRecord(org.folio.rest.jaxrs.model.JournalRecord) Date(java.util.Date) Test(org.junit.Test) AbstractRestTest(org.folio.rest.impl.AbstractRestTest)

Example 5 with JournalRecord

use of org.folio.rest.jaxrs.model.JournalRecord 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();
    });
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Date(java.util.Date) RunWith(org.junit.runner.RunWith) PostgresClientFactory(org.folio.dao.util.PostgresClientFactory) MockitoAnnotations(org.mockito.MockitoAnnotations) JobExecution(org.folio.rest.jaxrs.model.JobExecution) Spy(org.mockito.Spy) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) Matchers.lessThan(org.hamcrest.Matchers.lessThan) ERROR(org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.ERROR) MODIFY(org.folio.rest.jaxrs.model.JournalRecord.ActionType.MODIFY) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) DELETE(org.folio.rest.jaxrs.model.JournalRecord.ActionType.DELETE) JournalRecord(org.folio.rest.jaxrs.model.JournalRecord) Vertx(io.vertx.core.Vertx) Test(org.junit.Test) IOException(java.io.IOException) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) UUID(java.util.UUID) COMPLETED(org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.COMPLETED) Future(io.vertx.core.Future) List(java.util.List) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Assert(org.junit.Assert) CREATE(org.folio.rest.jaxrs.model.JournalRecord.ActionType.CREATE) Async(io.vertx.ext.unit.Async) List(java.util.List) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) JournalRecord(org.folio.rest.jaxrs.model.JournalRecord) Date(java.util.Date) Test(org.junit.Test) AbstractRestTest(org.folio.rest.impl.AbstractRestTest)

Aggregations

JournalRecord (org.folio.rest.jaxrs.model.JournalRecord)52 Test (org.junit.Test)42 Date (java.util.Date)40 Future (io.vertx.core.Future)34 List (java.util.List)34 AbstractRestTest (org.folio.rest.impl.AbstractRestTest)34 JobExecution (org.folio.rest.jaxrs.model.JobExecution)34 COMPLETED (org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.COMPLETED)34 CREATE (org.folio.rest.jaxrs.model.JournalRecord.ActionType.CREATE)34 Async (io.vertx.ext.unit.Async)33 TestContext (io.vertx.ext.unit.TestContext)33 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)33 UUID (java.util.UUID)33 PostgresClientFactory (org.folio.dao.util.PostgresClientFactory)33 ERROR (org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.ERROR)33 MODIFY (org.folio.rest.jaxrs.model.JournalRecord.ActionType.MODIFY)33 Matchers.is (org.hamcrest.Matchers.is)33 Assert (org.junit.Assert)33 Before (org.junit.Before)33 RunWith (org.junit.runner.RunWith)33