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();
}
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();
});
}
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();
}
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);
}
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());
}
Aggregations