Search in sources :

Example 11 with JobExecution

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

the class JobExecutionDaoImpl method updateBlocking.

@Override
public Future<JobExecution> updateBlocking(String jobExecutionId, JobExecutionMutator mutator, String tenantId) {
    Promise<JobExecution> promise = Promise.promise();
    String rollbackMessage = "Rollback transaction. Error during jobExecution update. jobExecutionId" + jobExecutionId;
    Promise<SQLConnection> connection = Promise.promise();
    Promise<JobExecution> jobExecutionPromise = Promise.promise();
    Future.succeededFuture().compose(v -> {
        pgClientFactory.createInstance(tenantId).startTx(connection);
        return connection.future();
    }).compose(v -> {
        String selectForUpdate = format("SELECT * FROM %s WHERE id = $1 AND is_deleted = false LIMIT 1 FOR UPDATE", formatFullTableName(tenantId, TABLE_NAME));
        Promise<RowSet<Row>> selectResult = Promise.promise();
        pgClientFactory.createInstance(tenantId).execute(connection.future(), selectForUpdate, Tuple.of(jobExecutionId), selectResult);
        return selectResult.future();
    }).compose(rowSet -> {
        if (rowSet.rowCount() != 1) {
            throw new NotFoundException(rollbackMessage);
        }
        return mutator.mutate(mapRowToJobExecution(rowSet.iterator().next())).onComplete(jobExecutionPromise);
    }).compose(jobExecution -> {
        Promise<RowSet<Row>> updateHandler = Promise.promise();
        String preparedQuery = format(UPDATE_SQL, formatFullTableName(tenantId, TABLE_NAME));
        Tuple queryParams = mapToTuple(jobExecution);
        pgClientFactory.createInstance(tenantId).execute(connection.future(), preparedQuery, queryParams, updateHandler);
        return updateHandler.future();
    }).compose(updateHandler -> {
        Promise<Void> endTxFuture = Promise.promise();
        pgClientFactory.createInstance(tenantId).endTx(connection.future(), endTxFuture);
        return endTxFuture.future();
    }).onComplete(ar -> {
        if (ar.failed()) {
            pgClientFactory.createInstance(tenantId).rollbackTx(connection.future(), rollback -> promise.fail(ar.cause()));
            return;
        }
        promise.complete(jobExecutionPromise.future().result());
    });
    return promise.future();
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) PROGRESS_TOTAL_FIELD(org.folio.dao.util.JobExecutionDBConstants.PROGRESS_TOTAL_FIELD) GET_CHILDREN_JOBS_BY_PARENT_ID_SQL(org.folio.dao.util.JobExecutionDBConstants.GET_CHILDREN_JOBS_BY_PARENT_ID_SQL) Date(java.util.Date) COMPLETED_DATE_FIELD(org.folio.dao.util.JobExecutionDBConstants.COMPLETED_DATE_FIELD) JOB_PROFILE_ID_FIELD(org.folio.dao.util.JobExecutionDBConstants.JOB_PROFILE_ID_FIELD) PostgresClient.convertToPsqlStandard(org.folio.rest.persist.PostgresClient.convertToPsqlStandard) Autowired(org.springframework.beans.factory.annotation.Autowired) TOTAL_COUNT_FIELD(org.folio.dao.util.JobExecutionDBConstants.TOTAL_COUNT_FIELD) Tuple(io.vertx.sqlclient.Tuple) SUBORDINATION_TYPE_FIELD(org.folio.dao.util.JobExecutionDBConstants.SUBORDINATION_TYPE_FIELD) TOTAL_FIELD(org.folio.dao.util.JobExecutionDBConstants.TOTAL_FIELD) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) GET_BY_ID_SQL(org.folio.dao.util.JobExecutionDBConstants.GET_BY_ID_SQL) LAST_NAME_FIELD(org.folio.dao.util.JobExecutionDBConstants.LAST_NAME_FIELD) JobExecution(org.folio.rest.jaxrs.model.JobExecution) JobProfileInfo(org.folio.rest.jaxrs.model.JobProfileInfo) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) ZoneOffset(java.time.ZoneOffset) Repository(org.springframework.stereotype.Repository) JobExecutionDto(org.folio.rest.jaxrs.model.JobExecutionDto) DbUtil(org.folio.dao.util.DbUtil) PROFILE_SNAPSHOT_WRAPPER_FIELD(org.folio.dao.util.JobExecutionDBConstants.PROFILE_SNAPSHOT_WRAPPER_FIELD) GET_UNIQUE_USERS(org.folio.dao.util.JobExecutionDBConstants.GET_UNIQUE_USERS) UUID(java.util.UUID) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) STARTED_DATE_FIELD(org.folio.dao.util.JobExecutionDBConstants.STARTED_DATE_FIELD) PostgresClient(org.folio.rest.persist.PostgresClient) NotFoundException(javax.ws.rs.NotFoundException) String.format(java.lang.String.format) Objects(java.util.Objects) List(java.util.List) Logger(org.apache.logging.log4j.Logger) HRID_FIELD(org.folio.dao.util.JobExecutionDBConstants.HRID_FIELD) StrSubstitutor(org.apache.commons.lang.text.StrSubstitutor) JobExecutionDtoCollection(org.folio.rest.jaxrs.model.JobExecutionDtoCollection) INSERT_SQL(org.folio.dao.util.JobExecutionDBConstants.INSERT_SQL) Optional(java.util.Optional) GET_RELATED_JOB_PROFILES_SQL(org.folio.dao.util.JobExecutionDBConstants.GET_RELATED_JOB_PROFILES_SQL) PARENT_ID_FIELD(org.folio.dao.util.JobExecutionDBConstants.PARENT_ID_FIELD) Objects.nonNull(java.util.Objects.nonNull) Progress(org.folio.rest.jaxrs.model.Progress) GET_JOBS_NOT_PARENT_SQL(org.folio.dao.util.JobExecutionDBConstants.GET_JOBS_NOT_PARENT_SQL) UI_STATUS_FIELD(org.folio.dao.util.JobExecutionDBConstants.UI_STATUS_FIELD) STATUS_FIELD(org.folio.dao.util.JobExecutionDBConstants.STATUS_FIELD) ID_FIELD(org.folio.dao.util.JobExecutionDBConstants.ID_FIELD) LocalDateTime(java.time.LocalDateTime) ERROR_STATUS_FIELD(org.folio.dao.util.JobExecutionDBConstants.ERROR_STATUS_FIELD) HashMap(java.util.HashMap) JOB_PROFILE_NAME_FIELD(org.folio.dao.util.JobExecutionDBConstants.JOB_PROFILE_NAME_FIELD) DeleteJobExecutionsResp(org.folio.rest.jaxrs.model.DeleteJobExecutionsResp) JobExecutionUserInfo(org.folio.rest.jaxrs.model.JobExecutionUserInfo) CollectionUtils(org.apache.commons.collections4.CollectionUtils) PostgresClientFactory(org.folio.dao.util.PostgresClientFactory) ArrayList(java.util.ArrayList) CompositeFuture(io.vertx.core.CompositeFuture) JOB_USER_LAST_NAME_FIELD(org.folio.dao.util.JobExecutionDBConstants.JOB_USER_LAST_NAME_FIELD) JobExecutionMutator(org.folio.dao.util.JobExecutionMutator) FIRST_NAME_FIELD(org.folio.dao.util.JobExecutionDBConstants.FIRST_NAME_FIELD) JOB_PROFILE_DATA_TYPE_FIELD(org.folio.dao.util.JobExecutionDBConstants.JOB_PROFILE_DATA_TYPE_FIELD) JOB_PROFILE_HIDDEN_FIELD(org.folio.dao.util.JobExecutionDBConstants.JOB_PROFILE_HIDDEN_FIELD) USER_ID_FIELD(org.folio.dao.util.JobExecutionDBConstants.USER_ID_FIELD) EMPTY(org.apache.commons.lang3.StringUtils.EMPTY) CURRENTLY_PROCESSED_FIELD(org.folio.dao.util.JobExecutionDBConstants.CURRENTLY_PROCESSED_FIELD) RowSet(io.vertx.sqlclient.RowSet) AsyncResult(io.vertx.core.AsyncResult) SOURCE_PATH_FIELD(org.folio.dao.util.JobExecutionDBConstants.SOURCE_PATH_FIELD) JOB_USER_FIRST_NAME_FIELD(org.folio.dao.util.JobExecutionDBConstants.JOB_USER_FIRST_NAME_FIELD) Promise(io.vertx.core.Promise) SQLConnection(org.folio.rest.persist.SQLConnection) UPDATE_SQL(org.folio.dao.util.JobExecutionDBConstants.UPDATE_SQL) RunBy(org.folio.rest.jaxrs.model.RunBy) ChronoUnit(java.time.temporal.ChronoUnit) SortField(org.folio.dao.util.SortField) JobExecutionUserInfoCollection(org.folio.rest.jaxrs.model.JobExecutionUserInfoCollection) JobProfileInfoCollection(org.folio.rest.jaxrs.model.JobProfileInfoCollection) Row(io.vertx.sqlclient.Row) JobExecutionDetail(org.folio.rest.jaxrs.model.JobExecutionDetail) UPDATE_BY_IDS_SQL(org.folio.dao.util.JobExecutionDBConstants.UPDATE_BY_IDS_SQL) PROGRESS_CURRENT_FIELD(org.folio.dao.util.JobExecutionDBConstants.PROGRESS_CURRENT_FIELD) LogManager(org.apache.logging.log4j.LogManager) FILE_NAME_FIELD(org.folio.dao.util.JobExecutionDBConstants.FILE_NAME_FIELD) Promise(io.vertx.core.Promise) SQLConnection(org.folio.rest.persist.SQLConnection) RowSet(io.vertx.sqlclient.RowSet) NotFoundException(javax.ws.rs.NotFoundException) Tuple(io.vertx.sqlclient.Tuple)

Example 12 with JobExecution

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

the class MappingRulesSnapshotDaoImplTest method shouldReturnSucceededFutureOnSnapshotSaveWhenMappingRulesSnapshotWithSameJobIdExists.

@Test
public void shouldReturnSucceededFutureOnSnapshotSaveWhenMappingRulesSnapshotWithSameJobIdExists(TestContext context) {
    InitJobExecutionsRsDto response = constructAndPostInitJobExecutionRqDto(1);
    List<JobExecution> createdJobExecutions = response.getJobExecutions();
    assertThat(createdJobExecutions.size(), is(1));
    JobExecution jobExecution = createdJobExecutions.get(0);
    Async async = context.async();
    Future<String> future = mappingRulesSnapshotDao.save(mappingRules, jobExecution.getId(), TENANT_ID).compose(v -> mappingRulesSnapshotDao.save(mappingRules, jobExecution.getId(), TENANT_ID));
    future.onComplete(ar -> {
        context.assertTrue(ar.succeeded());
        context.assertEquals(jobExecution.getId(), ar.result());
        async.complete();
    });
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) Async(io.vertx.ext.unit.Async) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) Test(org.junit.Test) AbstractRestTest(org.folio.rest.impl.AbstractRestTest)

Example 13 with JobExecution

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

the class ChangeManagerAPITest method shouldReturn204OkEventIfRemoveJobExecutionWithCommittedStatus.

@Test
public void shouldReturn204OkEventIfRemoveJobExecutionWithCommittedStatus(TestContext testContext) {
    InitJobExecutionsRsDto response = constructAndPostInitJobExecutionRqDto(1);
    List<JobExecution> createdJobExecutions = response.getJobExecutions();
    assertThat(createdJobExecutions.size(), is(1));
    JobExecution jobExec = createdJobExecutions.get(0);
    WireMock.stubFor(post(RECORDS_SERVICE_URL).willReturn(created().withTransformers(RequestToResponseTransformer.NAME)));
    WireMock.stubFor(WireMock.delete(new UrlPathPattern(new RegexPattern(SNAPSHOT_SERVICE_URL + "/.*"), true)).willReturn(WireMock.noContent()));
    Async async = testContext.async();
    RestAssured.given().spec(spec).body(new JobProfileInfo().withName("MARC records").withId(DEFAULT_JOB_PROFILE_ID).withDataType(JobProfileInfo.DataType.MARC)).when().put(JOB_EXECUTION_PATH + jobExec.getId() + JOB_PROFILE_PATH).then().statusCode(HttpStatus.SC_OK);
    async.complete();
    async = testContext.async();
    RestAssured.given().spec(spec).body(rawRecordsDto.withId(UUID.randomUUID().toString())).when().post(JOB_EXECUTION_PATH + jobExec.getId() + RECORDS_PATH).then().statusCode(HttpStatus.SC_NO_CONTENT);
    async.complete();
    StatusDto status = new StatusDto().withStatus(COMMITTED);
    RestAssured.given().spec(spec).body(JsonObject.mapFrom(status).toString()).when().put(JOB_EXECUTION_PATH + jobExec.getId() + STATUS_PATH).then().statusCode(HttpStatus.SC_OK);
    async = testContext.async();
    RestAssured.given().spec(spec).when().delete(JOB_EXECUTION_PATH + jobExec.getId() + RECORDS_PATH).then().statusCode(HttpStatus.SC_NO_CONTENT);
    async.complete();
    async = testContext.async();
    RestAssured.given().spec(spec).when().get(JOB_EXECUTION_PATH + jobExec.getId()).then().statusCode(HttpStatus.SC_OK).body("status", is(COMMITTED.value()));
    async.complete();
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) StatusDto(org.folio.rest.jaxrs.model.StatusDto) JobProfileInfo(org.folio.rest.jaxrs.model.JobProfileInfo) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Async(io.vertx.ext.unit.Async) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Example 14 with JobExecution

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

the class ChangeManagerAPITest method testInitJobExecutionsWith1File.

@Test
public void testInitJobExecutionsWith1File() {
    // given
    int expectedJobExecutionsNumber = 1;
    // when
    InitJobExecutionsRsDto response = constructAndPostInitJobExecutionRqDto(expectedJobExecutionsNumber);
    // then
    String actualParentJobExecutionId = response.getParentJobExecutionId();
    List<JobExecution> actualJobExecutions = response.getJobExecutions();
    Assert.assertNotNull(actualParentJobExecutionId);
    assertEquals(expectedJobExecutionsNumber, actualJobExecutions.size());
    JobExecution parentSingle = actualJobExecutions.get(0);
    assertEquals(JobExecution.SubordinationType.PARENT_SINGLE, parentSingle.getSubordinationType());
    assertParent(parentSingle);
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) Matchers.containsString(org.hamcrest.Matchers.containsString) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Example 15 with JobExecution

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

the class ChangeManagerAPITest method testInitJobExecutionsWithoutJobProfileAndOnline.

@Test
public void testInitJobExecutionsWithoutJobProfileAndOnline() {
    // given
    int expectedJobExecutionsNumber = 1;
    // when
    InitJobExecutionsRqDto requestDto = new InitJobExecutionsRqDto();
    requestDto.setUserId(okapiUserIdHeader);
    requestDto.setSourceType(InitJobExecutionsRqDto.SourceType.ONLINE);
    InitJobExecutionsRsDto response = RestAssured.given().spec(spec).body(JsonObject.mapFrom(requestDto).toString()).when().log().all().post(JOB_EXECUTION_PATH).body().as(InitJobExecutionsRsDto.class);
    // then
    String actualParentJobExecutionId = response.getParentJobExecutionId();
    List<JobExecution> actualJobExecutions = response.getJobExecutions();
    Assert.assertNotNull(actualParentJobExecutionId);
    assertEquals(expectedJobExecutionsNumber, actualJobExecutions.size());
    JobExecution parentSingle = actualJobExecutions.get(0);
    Assert.assertNotNull(parentSingle);
    assertEquals(JobExecution.SubordinationType.PARENT_SINGLE, parentSingle.getSubordinationType());
    Assert.assertNotNull(parentSingle.getId());
    Assert.assertNotNull(parentSingle.getParentJobId());
    Assert.assertTrue(parentTypes.contains(parentSingle.getSubordinationType()));
    assertEquals(parentSingle.getId(), parentSingle.getParentJobId());
    assertEquals(JobExecution.Status.NEW, parentSingle.getStatus());
    Assert.assertNotNull(parentSingle.getRunBy().getFirstName());
    Assert.assertNotNull(parentSingle.getRunBy().getLastName());
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) InitJobExecutionsRqDto(org.folio.rest.jaxrs.model.InitJobExecutionsRqDto) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) Matchers.containsString(org.hamcrest.Matchers.containsString) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Aggregations

JobExecution (org.folio.rest.jaxrs.model.JobExecution)128 Test (org.junit.Test)111 AbstractRestTest (org.folio.rest.impl.AbstractRestTest)99 InitJobExecutionsRsDto (org.folio.rest.jaxrs.model.InitJobExecutionsRsDto)73 Async (io.vertx.ext.unit.Async)68 Future (io.vertx.core.Future)55 JobProfileInfo (org.folio.rest.jaxrs.model.JobProfileInfo)55 List (java.util.List)54 Date (java.util.Date)53 UUID (java.util.UUID)52 Before (org.junit.Before)48 PostgresClientFactory (org.folio.dao.util.PostgresClientFactory)47 RunWith (org.junit.runner.RunWith)47 InjectMocks (org.mockito.InjectMocks)47 TestContext (io.vertx.ext.unit.TestContext)46 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)46 MockitoAnnotations (org.mockito.MockitoAnnotations)46 Spy (org.mockito.Spy)46 JournalRecordDaoImpl (org.folio.dao.JournalRecordDaoImpl)41 JournalRecord (org.folio.rest.jaxrs.model.JournalRecord)38