use of org.folio.rest.jaxrs.model.Snapshot in project mod-source-record-storage by folio-org.
the class SnapshotDaoUtil method toSnapshot.
/**
* Convert database query result {@link Row} to {@link Snapshot}
*
* @param row query result row
* @return Snapshot
*/
public static Snapshot toSnapshot(Row row) {
SnapshotsLb pojo = RowMappers.getSnapshotsLbMapper().apply(row);
Snapshot snapshot = new Snapshot().withJobExecutionId(pojo.getId().toString()).withStatus(Status.fromValue(pojo.getStatus().toString()));
if (Objects.nonNull(pojo.getProcessingStartedDate())) {
snapshot.withProcessingStartedDate(Date.from(pojo.getProcessingStartedDate().toInstant()));
}
Metadata metadata = new Metadata();
if (Objects.nonNull(pojo.getCreatedByUserId())) {
metadata.withCreatedByUserId(pojo.getCreatedByUserId().toString());
}
if (Objects.nonNull(pojo.getCreatedDate())) {
metadata.withCreatedDate(Date.from(pojo.getCreatedDate().toInstant()));
}
if (Objects.nonNull(pojo.getUpdatedByUserId())) {
metadata.withUpdatedByUserId(pojo.getUpdatedByUserId().toString());
}
if (Objects.nonNull(pojo.getUpdatedDate())) {
metadata.withUpdatedDate(Date.from(pojo.getUpdatedDate().toInstant()));
}
return snapshot.withMetadata(metadata);
}
use of org.folio.rest.jaxrs.model.Snapshot in project mod-source-record-manager by folio-org.
the class JobExecutionServiceImpl method updateSnapshotStatus.
private Future<JobExecution> updateSnapshotStatus(JobExecution jobExecution, OkapiConnectionParams params) {
Promise<JobExecution> promise = Promise.promise();
Snapshot snapshot = new Snapshot().withJobExecutionId(jobExecution.getId()).withStatus(Snapshot.Status.fromValue(jobExecution.getStatus().name()));
SourceStorageSnapshotsClient client = new SourceStorageSnapshotsClient(params.getOkapiUrl(), params.getTenantId(), params.getToken());
try {
client.putSourceStorageSnapshotsByJobExecutionId(jobExecution.getId(), null, snapshot, response -> {
if (response.result().statusCode() == HttpStatus.HTTP_OK.toInt()) {
promise.complete(jobExecution);
} else {
jobExecutionDao.updateBlocking(jobExecution.getId(), jobExec -> {
Promise<JobExecution> jobExecutionPromise = Promise.promise();
jobExec.setErrorStatus(JobExecution.ErrorStatus.SNAPSHOT_UPDATE_ERROR);
jobExec.setStatus(JobExecution.Status.ERROR);
jobExec.setUiStatus(JobExecution.UiStatus.ERROR);
jobExec.setCompletedDate(new Date());
jobExecutionPromise.complete(jobExec);
return jobExecutionPromise.future();
}, params.getTenantId()).onComplete(jobExecutionUpdate -> {
String message = "Couldn't update snapshot status for jobExecution with id " + jobExecution.getId();
LOGGER.error(message);
promise.fail(message);
});
}
});
} catch (Exception e) {
LOGGER.error("Error during update for Snapshot with id {}", jobExecution.getId(), e);
promise.fail(e);
}
return promise.future();
}
use of org.folio.rest.jaxrs.model.Snapshot in project mod-source-record-manager by folio-org.
the class JobExecutionServiceImpl method saveSnapshots.
/**
* Performs save for received Snapshot entities.
* For each Snapshot posts the request to mod-source-record-manager.
*
* @param snapshots list of Snapshot entities
* @param params object-wrapper with params necessary to connect to OKAPI
* @return future
*/
private Future<List<String>> saveSnapshots(List<Snapshot> snapshots, OkapiConnectionParams params) {
List<Future<String>> postedSnapshotFutures = new ArrayList<>();
for (Snapshot snapshot : snapshots) {
Future<String> postedSnapshotFuture = postSnapshot(snapshot, params);
postedSnapshotFutures.add(postedSnapshotFuture);
}
return GenericCompositeFuture.all(postedSnapshotFutures).map(genericCompositeFuture -> genericCompositeFuture.result().list());
}
use of org.folio.rest.jaxrs.model.Snapshot in project mod-source-record-manager by folio-org.
the class JobExecutionServiceImpl method initializeJobExecutions.
@Override
public Future<InitJobExecutionsRsDto> initializeJobExecutions(InitJobExecutionsRqDto jobExecutionsRqDto, OkapiConnectionParams params) {
if (jobExecutionsRqDto.getSourceType().equals(InitJobExecutionsRqDto.SourceType.FILES) && jobExecutionsRqDto.getFiles().isEmpty()) {
String errorMessage = "Received files must not be empty";
LOGGER.error(errorMessage);
return Future.failedFuture(new BadRequestException(errorMessage));
} else {
String parentJobExecutionId = UUID.randomUUID().toString();
return lookupUser(jobExecutionsRqDto.getUserId(), params).compose(userInfo -> {
List<JobExecution> jobExecutions = prepareJobExecutionList(parentJobExecutionId, jobExecutionsRqDto.getFiles(), userInfo, jobExecutionsRqDto);
List<Snapshot> snapshots = prepareSnapshotList(jobExecutions);
Future<List<String>> savedJsonExecutionsFuture = saveJobExecutions(jobExecutions, params.getTenantId());
Future<List<String>> savedSnapshotsFuture = saveSnapshots(snapshots, params);
return GenericCompositeFuture.all(Arrays.asList(savedJsonExecutionsFuture, savedSnapshotsFuture)).map(new InitJobExecutionsRsDto().withParentJobExecutionId(parentJobExecutionId).withJobExecutions(jobExecutions));
});
}
}
use of org.folio.rest.jaxrs.model.Snapshot in project mod-source-record-storage by folio-org.
the class MarcAuthorityDeleteEventHandlerTest method before.
@Before
public void before(TestContext testContext) throws IOException {
Snapshot snapshot = new Snapshot().withJobExecutionId(UUID.randomUUID().toString()).withProcessingStartedDate(new Date()).withStatus(Snapshot.Status.COMMITTED);
String recordId = UUID.randomUUID().toString();
RawRecord rawRecord = new RawRecord().withId(recordId).withContent("");
ParsedRecord parsedRecord = new ParsedRecord().withId(recordId).withContent(new JsonObject().encodePrettily());
record = new Record().withId(recordId).withSnapshotId(snapshot.getJobExecutionId()).withGeneration(0).withMatchedId(recordId).withRecordType(MARC_AUTHORITY).withRawRecord(rawRecord).withParsedRecord(parsedRecord).withExternalIdsHolder(new ExternalIdsHolder().withAuthorityId(UUID.randomUUID().toString()));
SnapshotDaoUtil.save(postgresClientFactory.getQueryExecutor(TENANT_ID), snapshot).onComplete(testContext.asyncAssertSuccess());
}
Aggregations