use of org.folio.rest.jaxrs.model.StatusDto in project mod-source-record-manager by folio-org.
the class ChangeEngineServiceImpl method parseRawRecordsChunkForJobExecution.
@Override
public Future<List<Record>> parseRawRecordsChunkForJobExecution(RawRecordsDto chunk, JobExecution jobExecution, String sourceChunkId, OkapiConnectionParams params) {
Promise<List<Record>> promise = Promise.promise();
Future<List<Record>> futureParsedRecords = parseRecords(chunk.getInitialRecords(), chunk.getRecordsMetadata().getContentType(), jobExecution, sourceChunkId, params.getTenantId(), params);
futureParsedRecords.compose(parsedRecords -> ensureMappingMetaDataSnapshot(jobExecution.getId(), parsedRecords, params).map(parsedRecords)).onSuccess(parsedRecords -> {
fillParsedRecordsWithAdditionalFields(parsedRecords);
if (updateMarcActionExists(jobExecution)) {
updateRecords(parsedRecords, jobExecution, params).onSuccess(ar -> promise.complete(parsedRecords)).onFailure(promise::fail);
} else if (deleteMarcActionExists(jobExecution)) {
deleteRecords(parsedRecords, jobExecution, params).onSuccess(ar -> promise.complete(parsedRecords)).onFailure(promise::fail);
} else {
saveRecords(params, jobExecution, parsedRecords).onComplete(postAr -> {
if (postAr.failed()) {
StatusDto statusDto = new StatusDto().withStatus(StatusDto.Status.ERROR).withErrorStatus(StatusDto.ErrorStatus.RECORD_UPDATE_ERROR);
jobExecutionService.updateJobExecutionStatus(jobExecution.getId(), statusDto, params).onComplete(r -> {
if (r.failed()) {
LOGGER.error("Error during update jobExecution and snapshot status", r.cause());
}
});
jobExecutionSourceChunkDao.getById(sourceChunkId, params.getTenantId()).compose(optional -> optional.map(sourceChunk -> jobExecutionSourceChunkDao.update(sourceChunk.withState(JobExecutionSourceChunk.State.ERROR), params.getTenantId())).orElseThrow(() -> new NotFoundException(String.format("Couldn't update failed jobExecutionSourceChunk status to ERROR, jobExecutionSourceChunk with id %s was not found", sourceChunkId)))).onComplete(ar -> promise.fail(postAr.cause()));
} else {
promise.complete(parsedRecords);
}
});
}
}).onFailure(th -> {
LOGGER.error("Error parsing records: {}", th.getMessage());
promise.fail(th);
});
return promise.future();
}
use of org.folio.rest.jaxrs.model.StatusDto in project mod-source-record-manager by folio-org.
the class MetadataProviderJobExecutionAPITest method shouldNotReturnDiscardedInCollection.
@Test
public void shouldNotReturnDiscardedInCollection() {
int numberOfFiles = 5;
int expectedNotDiscardedNumber = 2;
List<JobExecution> createdJobExecutions = constructAndPostInitJobExecutionRqDto(numberOfFiles).getJobExecutions();
List<JobExecution> children = createdJobExecutions.stream().filter(jobExec -> jobExec.getSubordinationType().equals(CHILD)).collect(Collectors.toList());
StatusDto discardedStatus = new StatusDto().withStatus(StatusDto.Status.DISCARDED);
for (int i = 0; i < children.size() - expectedNotDiscardedNumber; i++) {
updateJobExecutionStatus(children.get(i), discardedStatus).then().statusCode(HttpStatus.SC_OK);
}
RestAssured.given().spec(spec).when().queryParam("statusNot", Status.DISCARDED).get(GET_JOB_EXECUTIONS_PATH).then().statusCode(HttpStatus.SC_OK).body("jobExecutions.size()", is(expectedNotDiscardedNumber)).body("jobExecutions*.status", not(StatusDto.Status.DISCARDED.name())).body("totalRecords", is(expectedNotDiscardedNumber));
}
use of org.folio.rest.jaxrs.model.StatusDto in project mod-source-record-manager by folio-org.
the class EventDrivenChunkProcessingServiceImplTest method shouldProcessErrorRawRecord.
@Test
public void shouldProcessErrorRawRecord(TestContext context) {
Async async = context.async();
RawRecordsDto rawRecordsDto = new RawRecordsDto().withRecordsMetadata(new RecordsMetadata().withLast(false).withCounter(1).withContentType(RecordsMetadata.ContentType.MARC_RAW)).withInitialRecords(Collections.singletonList(new InitialRecord().withRecord(RAW_RECORD_RESULTING_IN_PARSING_ERROR)));
Future<Boolean> future = jobExecutionService.initializeJobExecutions(initJobExecutionsRqDto, params).compose(initJobExecutionsRsDto -> jobExecutionService.setJobProfileToJobExecution(initJobExecutionsRsDto.getParentJobExecutionId(), jobProfileInfo, params)).compose(jobExecution -> chunkProcessingService.processChunk(rawRecordsDto, jobExecution.getId(), params));
future.onComplete(ar -> {
context.assertTrue(ar.succeeded());
ArgumentCaptor<StatusDto> captor = ArgumentCaptor.forClass(StatusDto.class);
Mockito.verify(jobExecutionService, times(1)).updateJobExecutionStatus(anyString(), captor.capture(), isA(OkapiConnectionParams.class));
context.assertTrue(PARSING_IN_PROGRESS.equals(captor.getAllValues().get(0).getStatus()));
verify(1, postRequestedFor(urlEqualTo(SNAPSHOT_SERVICE_URL)));
async.complete();
});
}
use of org.folio.rest.jaxrs.model.StatusDto in project mod-source-record-manager by folio-org.
the class EventDrivenChunkProcessingServiceImplTest method shouldProcessChunkOfRawRecords.
@Test
public void shouldProcessChunkOfRawRecords(TestContext context) {
Async async = context.async();
Future<Boolean> future = jobExecutionService.initializeJobExecutions(initJobExecutionsRqDto, params).compose(initJobExecutionsRsDto -> jobExecutionService.setJobProfileToJobExecution(initJobExecutionsRsDto.getParentJobExecutionId(), jobProfileInfo, params)).compose(jobExecution -> chunkProcessingService.processChunk(rawRecordsDto, jobExecution.getId(), params));
future.onComplete(ar -> {
context.assertTrue(ar.succeeded());
ArgumentCaptor<StatusDto> statusCaptor = ArgumentCaptor.forClass(StatusDto.class);
ArgumentCaptor<String> jobExecutionIdCaptor = ArgumentCaptor.forClass(String.class);
Mockito.verify(jobExecutionService).updateJobExecutionStatus(jobExecutionIdCaptor.capture(), statusCaptor.capture(), isA(OkapiConnectionParams.class));
Mockito.verify(jobExecutionProgressService).initializeJobExecutionProgress(anyString(), eq(rawRecordsDto.getRecordsMetadata().getTotal()), eq(TENANT_ID));
context.assertTrue(PARSING_IN_PROGRESS.equals(statusCaptor.getValue().getStatus()));
mappingMetadataService.getMappingMetadataDto(jobExecutionIdCaptor.getValue(), params).onComplete(mappingMetadataDtoAsyncResult -> {
context.assertTrue(mappingMetadataDtoAsyncResult.succeeded());
context.assertTrue(mappingMetadataDtoAsyncResult.result().getJobExecutionId().equals(jobExecutionIdCaptor.getValue()));
});
async.complete();
});
}
use of org.folio.rest.jaxrs.model.StatusDto in project mod-source-record-manager by folio-org.
the class JobExecutionServiceImpl method updateJobExecutionStatus.
@Override
public Future<JobExecution> updateJobExecutionStatus(String jobExecutionId, StatusDto status, OkapiConnectionParams params) {
if (JobExecution.Status.PARENT.name().equals(status.getStatus().name())) {
String errorMessage = "Cannot update JobExecution status to PARENT";
LOGGER.error(errorMessage);
return Future.failedFuture(new BadRequestException(errorMessage));
} else {
return jobExecutionDao.updateBlocking(jobExecutionId, jobExecution -> {
Promise<JobExecution> promise = Promise.promise();
try {
if (JobExecution.Status.PARENT.name().equals(jobExecution.getStatus().name())) {
String message = format("JobExecution %s current status is PARENT and cannot be updated", jobExecutionId);
LOGGER.error(message);
promise.fail(new BadRequestException(message));
} else {
jobExecution.setStatus(JobExecution.Status.fromValue(status.getStatus().name()));
jobExecution.setUiStatus(JobExecution.UiStatus.fromValue(Status.valueOf(status.getStatus().name()).getUiStatus()));
updateJobExecutionIfErrorExist(status, jobExecution);
promise.complete(jobExecution);
}
} catch (Exception e) {
String errorMessage = "Error updating JobExecution with id " + jobExecutionId;
LOGGER.error(errorMessage, e);
promise.fail(errorMessage);
}
return promise.future();
}, params.getTenantId()).compose(jobExecution -> updateSnapshotStatus(jobExecution, params));
}
}
Aggregations