Search in sources :

Example 1 with JobLogEntryDto

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

the class JournalRecordDaoImpl method mapJobLogEntryRow.

private JobLogEntryDto mapJobLogEntryRow(Row row) {
    final var entityType = mapToEntityType(row.getString(SOURCE_RECORD_ENTITY_TYPE));
    final var entityHrid = row.getArrayOfStrings(HOLDINGS_ENTITY_HRID);
    final var holdingsActionStatus = mapNameToEntityActionStatus(row.getString(HOLDINGS_ACTION_STATUS));
    return new JobLogEntryDto().withJobExecutionId(row.getValue(JOB_EXECUTION_ID).toString()).withSourceRecordId(row.getValue(SOURCE_ID).toString()).withSourceRecordOrder(isEmpty(row.getString(INVOICE_ACTION_STATUS)) ? row.getInteger(SOURCE_RECORD_ORDER).toString() : row.getString(INVOICE_LINE_NUMBER)).withSourceRecordTitle(getJobLogEntryTitle(row.getString(TITLE), entityType, entityHrid, holdingsActionStatus)).withSourceRecordType(entityType).withHoldingsRecordHridList(ArrayUtils.isEmpty(entityHrid) ? Collections.emptyList() : Arrays.asList(entityHrid)).withSourceRecordActionStatus(mapNameToEntityActionStatus(row.getString(SOURCE_RECORD_ACTION_STATUS))).withInstanceActionStatus(mapNameToEntityActionStatus(row.getString(INSTANCE_ACTION_STATUS))).withHoldingsActionStatus(holdingsActionStatus).withItemActionStatus(mapNameToEntityActionStatus(row.getString(ITEM_ACTION_STATUS))).withAuthorityActionStatus(mapNameToEntityActionStatus(row.getString(AUTHORITY_ACTION_STATUS))).withOrderActionStatus(mapNameToEntityActionStatus(row.getString(ORDER_ACTION_STATUS))).withInvoiceActionStatus(mapNameToEntityActionStatus(row.getString(INVOICE_ACTION_STATUS))).withInvoiceLineJournalRecordId(Objects.isNull(row.getValue(INVOICE_LINE_JOURNAL_RECORD_ID)) ? null : row.getValue(INVOICE_LINE_JOURNAL_RECORD_ID).toString()).withError(row.getString(ERROR));
}
Also used : JobLogEntryDto(org.folio.rest.jaxrs.model.JobLogEntryDto)

Example 2 with JobLogEntryDto

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

the class MetaDataProviderJobLogEntriesAPITest method shouldReturnSortedEntriesWhenSortByParameterSpecified.

@Test
public void shouldReturnSortedEntriesWhenSortByParameterSpecified(TestContext context) {
    Async async = context.async();
    JobExecution createdJobExecution = constructAndPostInitJobExecutionRqDto(1).getJobExecutions().get(0);
    String sourceRecordId1 = UUID.randomUUID().toString();
    String sourceRecordId2 = UUID.randomUUID().toString();
    String sourceRecordId3 = UUID.randomUUID().toString();
    Future<JournalRecord> future = Future.succeededFuture().compose(v -> createJournalRecord(createdJobExecution.getId(), sourceRecordId1, null, null, null, 1, CREATE, MARC_BIBLIOGRAPHIC, COMPLETED, null)).compose(v -> createJournalRecord(createdJobExecution.getId(), sourceRecordId1, null, "in00000000002", null, 1, CREATE, INSTANCE, COMPLETED, null)).compose(v -> createJournalRecord(createdJobExecution.getId(), sourceRecordId2, null, null, null, 0, CREATE, MARC_BIBLIOGRAPHIC, COMPLETED, null)).compose(v -> createJournalRecord(createdJobExecution.getId(), sourceRecordId2, null, "in00000000001", null, 0, CREATE, INSTANCE, COMPLETED, null)).compose(v -> createJournalRecord(createdJobExecution.getId(), sourceRecordId3, null, null, null, 3, CREATE, MARC_BIBLIOGRAPHIC, COMPLETED, null)).compose(v -> createJournalRecord(createdJobExecution.getId(), sourceRecordId3, null, "in00000000003", null, 3, CREATE, INSTANCE, COMPLETED, null)).onFailure(context::fail);
    future.onComplete(ar -> context.verify(v -> {
        List<JobLogEntryDto> jobLogEntries = RestAssured.given().spec(spec).queryParam("sortBy", "source_record_order").queryParam("order", "desc").when().get(GET_JOB_EXECUTION_JOURNAL_RECORDS_PATH + "/" + createdJobExecution.getId()).then().statusCode(HttpStatus.SC_OK).body("entries", hasSize(3)).body("totalRecords", is(3)).extract().body().as(JobLogEntryDtoCollection.class).getEntries();
        context.assertTrue(Integer.parseInt(jobLogEntries.get(0).getSourceRecordOrder()) > Integer.parseInt(jobLogEntries.get(1).getSourceRecordOrder()));
        context.assertTrue(Integer.parseInt(jobLogEntries.get(1).getSourceRecordOrder()) > Integer.parseInt(jobLogEntries.get(2).getSourceRecordOrder()));
        async.complete();
    }));
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) EDIFACT(org.folio.rest.jaxrs.model.JournalRecord.EntityType.EDIFACT) MARC_BIBLIOGRAPHIC(org.folio.rest.jaxrs.model.JournalRecord.EntityType.MARC_BIBLIOGRAPHIC) TestContext(io.vertx.ext.unit.TestContext) MARC_AUTHORITY(org.folio.rest.jaxrs.model.JournalRecord.EntityType.MARC_AUTHORITY) Date(java.util.Date) Matchers.not(org.hamcrest.Matchers.not) HttpStatus(org.apache.http.HttpStatus) MockitoAnnotations(org.mockito.MockitoAnnotations) Matchers.everyItem(org.hamcrest.Matchers.everyItem) Matchers.nullValue(org.hamcrest.Matchers.nullValue) JobExecution(org.folio.rest.jaxrs.model.JobExecution) Spy(org.mockito.Spy) ActionStatus(org.folio.rest.jaxrs.model.ActionStatus) ERROR(org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.ERROR) HOLDINGS(org.folio.rest.jaxrs.model.JournalRecord.EntityType.HOLDINGS) MODIFY(org.folio.rest.jaxrs.model.JournalRecord.ActionType.MODIFY) GenericCompositeFuture(org.folio.okapi.common.GenericCompositeFuture) AUTHORITY(org.folio.rest.jaxrs.model.JournalRecord.EntityType.AUTHORITY) JournalRecord(org.folio.rest.jaxrs.model.JournalRecord) UUID(java.util.UUID) Future(io.vertx.core.Future) List(java.util.List) Matchers.is(org.hamcrest.Matchers.is) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) RestAssured(io.restassured.RestAssured) Async(io.vertx.ext.unit.Async) JobLogEntryDtoCollection(org.folio.rest.jaxrs.model.JobLogEntryDtoCollection) RunWith(org.junit.runner.RunWith) JobLogEntryDto(org.folio.rest.jaxrs.model.JobLogEntryDto) PostgresClientFactory(org.folio.dao.util.PostgresClientFactory) CompositeFuture(io.vertx.core.CompositeFuture) Matchers.emptyOrNullString(org.hamcrest.Matchers.emptyOrNullString) MARC_HOLDINGS(org.folio.rest.jaxrs.model.JournalRecord.EntityType.MARC_HOLDINGS) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) ITEM(org.folio.rest.jaxrs.model.JournalRecord.EntityType.ITEM) Matchers.empty(org.hamcrest.Matchers.empty) UPDATE(org.folio.rest.jaxrs.model.JournalRecord.ActionType.UPDATE) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) Test(org.junit.Test) COMPLETED(org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.COMPLETED) INSTANCE(org.folio.rest.jaxrs.model.JournalRecord.EntityType.INSTANCE) ORDER(org.folio.rest.jaxrs.model.JournalRecord.EntityType.ORDER) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) NON_MATCH(org.folio.rest.jaxrs.model.JournalRecord.ActionType.NON_MATCH) INVOICE(org.folio.rest.jaxrs.model.JournalRecord.EntityType.INVOICE) Assert(org.junit.Assert) CREATE(org.folio.rest.jaxrs.model.JournalRecord.ActionType.CREATE) JournalRecordDaoImpl(org.folio.dao.JournalRecordDaoImpl) Async(io.vertx.ext.unit.Async) List(java.util.List) Matchers.emptyOrNullString(org.hamcrest.Matchers.emptyOrNullString) JournalRecord(org.folio.rest.jaxrs.model.JournalRecord) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Example 3 with JobLogEntryDto

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

the class MetaDataProviderJobLogEntriesAPITest method shouldReturnNotEmptyListWithInvoicesLinesThatContainsError.

@Test
public void shouldReturnNotEmptyListWithInvoicesLinesThatContainsError(TestContext context) {
    Async async = context.async();
    JobExecution createdJobExecution = constructAndPostInitJobExecutionRqDto(1).getJobExecutions().get(0);
    String sourceRecordId = UUID.randomUUID().toString();
    String invoiceLineDescription = "Some description";
    String invoiceLineId = "0704159";
    Future<JournalRecord> future = Future.succeededFuture().compose(v -> createJournalRecord(createdJobExecution.getId(), sourceRecordId, null, "228D126", "INVOICE", 0, CREATE, INVOICE, COMPLETED, null)).compose(v -> createJournalRecord(createdJobExecution.getId(), sourceRecordId, null, invoiceLineId + "-1", invoiceLineDescription + "1", 1, CREATE, INVOICE, COMPLETED, null)).compose(v -> createJournalRecord(createdJobExecution.getId(), sourceRecordId, null, invoiceLineId + "-2", invoiceLineDescription + "2", 2, CREATE, INVOICE, COMPLETED, null)).compose(v -> createJournalRecord(createdJobExecution.getId(), sourceRecordId, null, invoiceLineId + "-3", invoiceLineDescription + "3", 3, CREATE, INVOICE, ERROR, "Exception")).onFailure(context::fail);
    future.onComplete(ar -> context.verify(v -> {
        List<JobLogEntryDto> jobLogEntries = RestAssured.given().spec(spec).when().get(GET_JOB_EXECUTION_JOURNAL_RECORDS_PATH + "/" + createdJobExecution.getId()).then().statusCode(HttpStatus.SC_OK).body("entries.size()", is(3)).body("totalRecords", is(3)).body("entries[0].jobExecutionId", is(createdJobExecution.getId())).body("entries[0].sourceRecordId", is(sourceRecordId)).body("entries[0].sourceRecordTitle", is(invoiceLineDescription + "1")).body("entries[0].sourceRecordOrder", is(invoiceLineId + "-1")).body("entries[2].sourceRecordTitle", is(invoiceLineDescription + "3")).body("entries[2].sourceRecordOrder", is(invoiceLineId + "-3")).extract().body().as(JobLogEntryDtoCollection.class).getEntries();
        Assert.assertEquals("Exception", jobLogEntries.get(2).getError());
        Assert.assertEquals(ActionStatus.DISCARDED, jobLogEntries.get(2).getInvoiceActionStatus());
        async.complete();
    }));
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) EDIFACT(org.folio.rest.jaxrs.model.JournalRecord.EntityType.EDIFACT) MARC_BIBLIOGRAPHIC(org.folio.rest.jaxrs.model.JournalRecord.EntityType.MARC_BIBLIOGRAPHIC) TestContext(io.vertx.ext.unit.TestContext) MARC_AUTHORITY(org.folio.rest.jaxrs.model.JournalRecord.EntityType.MARC_AUTHORITY) Date(java.util.Date) Matchers.not(org.hamcrest.Matchers.not) HttpStatus(org.apache.http.HttpStatus) MockitoAnnotations(org.mockito.MockitoAnnotations) Matchers.everyItem(org.hamcrest.Matchers.everyItem) Matchers.nullValue(org.hamcrest.Matchers.nullValue) JobExecution(org.folio.rest.jaxrs.model.JobExecution) Spy(org.mockito.Spy) ActionStatus(org.folio.rest.jaxrs.model.ActionStatus) ERROR(org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.ERROR) HOLDINGS(org.folio.rest.jaxrs.model.JournalRecord.EntityType.HOLDINGS) MODIFY(org.folio.rest.jaxrs.model.JournalRecord.ActionType.MODIFY) GenericCompositeFuture(org.folio.okapi.common.GenericCompositeFuture) AUTHORITY(org.folio.rest.jaxrs.model.JournalRecord.EntityType.AUTHORITY) JournalRecord(org.folio.rest.jaxrs.model.JournalRecord) UUID(java.util.UUID) Future(io.vertx.core.Future) List(java.util.List) Matchers.is(org.hamcrest.Matchers.is) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) RestAssured(io.restassured.RestAssured) Async(io.vertx.ext.unit.Async) JobLogEntryDtoCollection(org.folio.rest.jaxrs.model.JobLogEntryDtoCollection) RunWith(org.junit.runner.RunWith) JobLogEntryDto(org.folio.rest.jaxrs.model.JobLogEntryDto) PostgresClientFactory(org.folio.dao.util.PostgresClientFactory) CompositeFuture(io.vertx.core.CompositeFuture) Matchers.emptyOrNullString(org.hamcrest.Matchers.emptyOrNullString) MARC_HOLDINGS(org.folio.rest.jaxrs.model.JournalRecord.EntityType.MARC_HOLDINGS) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) ITEM(org.folio.rest.jaxrs.model.JournalRecord.EntityType.ITEM) Matchers.empty(org.hamcrest.Matchers.empty) UPDATE(org.folio.rest.jaxrs.model.JournalRecord.ActionType.UPDATE) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) Test(org.junit.Test) COMPLETED(org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.COMPLETED) INSTANCE(org.folio.rest.jaxrs.model.JournalRecord.EntityType.INSTANCE) ORDER(org.folio.rest.jaxrs.model.JournalRecord.EntityType.ORDER) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) NON_MATCH(org.folio.rest.jaxrs.model.JournalRecord.ActionType.NON_MATCH) INVOICE(org.folio.rest.jaxrs.model.JournalRecord.EntityType.INVOICE) Assert(org.junit.Assert) CREATE(org.folio.rest.jaxrs.model.JournalRecord.ActionType.CREATE) JournalRecordDaoImpl(org.folio.dao.JournalRecordDaoImpl) Async(io.vertx.ext.unit.Async) List(java.util.List) Matchers.emptyOrNullString(org.hamcrest.Matchers.emptyOrNullString) JournalRecord(org.folio.rest.jaxrs.model.JournalRecord) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Example 4 with JobLogEntryDto

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

the class MetaDataProviderJobLogEntriesAPITest method shouldReturnOnlyInvoiceLinesWithErrorWhenRetrieveWithErrorsOnlyParam.

@Test
public void shouldReturnOnlyInvoiceLinesWithErrorWhenRetrieveWithErrorsOnlyParam(TestContext context) {
    Async async = context.async();
    JobExecution createdJobExecution = constructAndPostInitJobExecutionRqDto(1).getJobExecutions().get(0);
    String sourceRecordId = UUID.randomUUID().toString();
    String invoiceLineDescription = "Some description";
    String invoiceLineId = "246816";
    Future<JournalRecord> future = Future.succeededFuture().compose(v -> createJournalRecord(createdJobExecution.getId(), sourceRecordId, null, "10001", "INVOICE", 0, CREATE, INVOICE, COMPLETED, null)).compose(v -> createJournalRecord(createdJobExecution.getId(), sourceRecordId, null, invoiceLineId + "-1", invoiceLineDescription + "1", 1, CREATE, INVOICE, COMPLETED, null)).compose(v -> createJournalRecord(createdJobExecution.getId(), sourceRecordId, null, invoiceLineId + "-2", invoiceLineDescription + "2", 2, CREATE, INVOICE, COMPLETED, null)).compose(v -> createJournalRecord(createdJobExecution.getId(), sourceRecordId, null, invoiceLineId + "-3", invoiceLineDescription + "3", 3, CREATE, INVOICE, ERROR, "Exception")).onFailure(context::fail);
    future.onComplete(ar -> context.verify(v -> {
        List<JobLogEntryDto> jobLogEntries = RestAssured.given().spec(spec).when().param("errorsOnly", true).get(GET_JOB_EXECUTION_JOURNAL_RECORDS_PATH + "/" + createdJobExecution.getId()).then().statusCode(HttpStatus.SC_OK).body("entries.size()", is(1)).body("totalRecords", is(3)).body("entries[0].jobExecutionId", is(createdJobExecution.getId())).body("entries[0].sourceRecordId", is(sourceRecordId)).extract().body().as(JobLogEntryDtoCollection.class).getEntries();
        Assert.assertEquals("Exception", jobLogEntries.get(0).getError());
        Assert.assertEquals(ActionStatus.DISCARDED, jobLogEntries.get(0).getInvoiceActionStatus());
        async.complete();
    }));
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) EDIFACT(org.folio.rest.jaxrs.model.JournalRecord.EntityType.EDIFACT) MARC_BIBLIOGRAPHIC(org.folio.rest.jaxrs.model.JournalRecord.EntityType.MARC_BIBLIOGRAPHIC) TestContext(io.vertx.ext.unit.TestContext) MARC_AUTHORITY(org.folio.rest.jaxrs.model.JournalRecord.EntityType.MARC_AUTHORITY) Date(java.util.Date) Matchers.not(org.hamcrest.Matchers.not) HttpStatus(org.apache.http.HttpStatus) MockitoAnnotations(org.mockito.MockitoAnnotations) Matchers.everyItem(org.hamcrest.Matchers.everyItem) Matchers.nullValue(org.hamcrest.Matchers.nullValue) JobExecution(org.folio.rest.jaxrs.model.JobExecution) Spy(org.mockito.Spy) ActionStatus(org.folio.rest.jaxrs.model.ActionStatus) ERROR(org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.ERROR) HOLDINGS(org.folio.rest.jaxrs.model.JournalRecord.EntityType.HOLDINGS) MODIFY(org.folio.rest.jaxrs.model.JournalRecord.ActionType.MODIFY) GenericCompositeFuture(org.folio.okapi.common.GenericCompositeFuture) AUTHORITY(org.folio.rest.jaxrs.model.JournalRecord.EntityType.AUTHORITY) JournalRecord(org.folio.rest.jaxrs.model.JournalRecord) UUID(java.util.UUID) Future(io.vertx.core.Future) List(java.util.List) Matchers.is(org.hamcrest.Matchers.is) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) RestAssured(io.restassured.RestAssured) Async(io.vertx.ext.unit.Async) JobLogEntryDtoCollection(org.folio.rest.jaxrs.model.JobLogEntryDtoCollection) RunWith(org.junit.runner.RunWith) JobLogEntryDto(org.folio.rest.jaxrs.model.JobLogEntryDto) PostgresClientFactory(org.folio.dao.util.PostgresClientFactory) CompositeFuture(io.vertx.core.CompositeFuture) Matchers.emptyOrNullString(org.hamcrest.Matchers.emptyOrNullString) MARC_HOLDINGS(org.folio.rest.jaxrs.model.JournalRecord.EntityType.MARC_HOLDINGS) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) ITEM(org.folio.rest.jaxrs.model.JournalRecord.EntityType.ITEM) Matchers.empty(org.hamcrest.Matchers.empty) UPDATE(org.folio.rest.jaxrs.model.JournalRecord.ActionType.UPDATE) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) Test(org.junit.Test) COMPLETED(org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.COMPLETED) INSTANCE(org.folio.rest.jaxrs.model.JournalRecord.EntityType.INSTANCE) ORDER(org.folio.rest.jaxrs.model.JournalRecord.EntityType.ORDER) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) NON_MATCH(org.folio.rest.jaxrs.model.JournalRecord.ActionType.NON_MATCH) INVOICE(org.folio.rest.jaxrs.model.JournalRecord.EntityType.INVOICE) Assert(org.junit.Assert) CREATE(org.folio.rest.jaxrs.model.JournalRecord.ActionType.CREATE) JournalRecordDaoImpl(org.folio.dao.JournalRecordDaoImpl) Async(io.vertx.ext.unit.Async) List(java.util.List) Matchers.emptyOrNullString(org.hamcrest.Matchers.emptyOrNullString) JournalRecord(org.folio.rest.jaxrs.model.JournalRecord) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Aggregations

JobLogEntryDto (org.folio.rest.jaxrs.model.JobLogEntryDto)4 RestAssured (io.restassured.RestAssured)3 CompositeFuture (io.vertx.core.CompositeFuture)3 Future (io.vertx.core.Future)3 Promise (io.vertx.core.Promise)3 Vertx (io.vertx.core.Vertx)3 Async (io.vertx.ext.unit.Async)3 TestContext (io.vertx.ext.unit.TestContext)3 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)3 Date (java.util.Date)3 List (java.util.List)3 UUID (java.util.UUID)3 HttpStatus (org.apache.http.HttpStatus)3 JournalRecordDaoImpl (org.folio.dao.JournalRecordDaoImpl)3 PostgresClientFactory (org.folio.dao.util.PostgresClientFactory)3 GenericCompositeFuture (org.folio.okapi.common.GenericCompositeFuture)3 AbstractRestTest (org.folio.rest.impl.AbstractRestTest)3 ActionStatus (org.folio.rest.jaxrs.model.ActionStatus)3 JobExecution (org.folio.rest.jaxrs.model.JobExecution)3 JobLogEntryDtoCollection (org.folio.rest.jaxrs.model.JobLogEntryDtoCollection)3