Search in sources :

Example 16 with Snapshot

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);
}
Also used : Snapshot(org.folio.rest.jaxrs.model.Snapshot) SnapshotsLb(org.folio.rest.jooq.tables.pojos.SnapshotsLb) Metadata(org.folio.rest.jaxrs.model.Metadata)

Example 17 with Snapshot

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();
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) DataImportProfilesClient(org.folio.rest.client.DataImportProfilesClient) Arrays(java.util.Arrays) Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) UserInfo(org.folio.rest.jaxrs.model.UserInfo) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) JobDuplicateUpdateException(org.folio.services.exceptions.JobDuplicateUpdateException) JobExecutionSourceChunkDao(org.folio.dao.JobExecutionSourceChunkDao) JobExecution(org.folio.rest.jaxrs.model.JobExecution) JobProfileInfo(org.folio.rest.jaxrs.model.JobProfileInfo) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) ERROR(org.folio.rest.jaxrs.model.StatusDto.Status.ERROR) JsonObject(io.vertx.core.json.JsonObject) BadRequestException(javax.ws.rs.BadRequestException) HttpException(io.vertx.ext.web.handler.HttpException) GenericCompositeFuture(org.folio.okapi.common.GenericCompositeFuture) StatusDto(org.folio.rest.jaxrs.model.StatusDto) UUID(java.util.UUID) Future(io.vertx.core.Future) Try(org.folio.dataimport.util.Try) OkapiConnectionParams(org.folio.dataimport.util.OkapiConnectionParams) NotFoundException(javax.ws.rs.NotFoundException) String.format(java.lang.String.format) Objects(java.util.Objects) List(java.util.List) HTTP_OK(org.folio.HttpStatus.HTTP_OK) Logger(org.apache.logging.log4j.Logger) JobExecutionFilter(org.folio.dao.JobExecutionFilter) JobExecutionDtoCollection(org.folio.rest.jaxrs.model.JobExecutionDtoCollection) HTTP_CREATED(org.folio.HttpStatus.HTTP_CREATED) Optional(java.util.Optional) RestUtil(org.folio.dataimport.util.RestUtil) JobProfile(org.folio.rest.jaxrs.model.JobProfile) FilenameUtils(org.apache.commons.io.FilenameUtils) Progress(org.folio.rest.jaxrs.model.Progress) JobExecutionDao(org.folio.dao.JobExecutionDao) CANCELLED(org.folio.rest.jaxrs.model.StatusDto.Status.CANCELLED) DeleteJobExecutionsResp(org.folio.rest.jaxrs.model.DeleteJobExecutionsResp) ArrayList(java.util.ArrayList) SourceStorageSnapshotsClient(org.folio.rest.client.SourceStorageSnapshotsClient) Service(org.springframework.stereotype.Service) InitJobExecutionsRqDto(org.folio.rest.jaxrs.model.InitJobExecutionsRqDto) Promise(io.vertx.core.Promise) COMMITTED(org.folio.rest.jaxrs.model.JobExecution.Status.COMMITTED) RunBy(org.folio.rest.jaxrs.model.RunBy) File(org.folio.rest.jaxrs.model.File) SortField(org.folio.dao.util.SortField) HttpMethod(io.vertx.core.http.HttpMethod) JobExecutionUserInfoCollection(org.folio.rest.jaxrs.model.JobExecutionUserInfoCollection) JobProfileInfoCollection(org.folio.rest.jaxrs.model.JobProfileInfoCollection) HttpStatus(org.folio.HttpStatus) PROFILE_SNAPSHOT_CREATING_ERROR(org.folio.rest.jaxrs.model.StatusDto.ErrorStatus.PROFILE_SNAPSHOT_CREATING_ERROR) LogManager(org.apache.logging.log4j.LogManager) Snapshot(org.folio.rest.jaxrs.model.Snapshot) Collections(java.util.Collections) Snapshot(org.folio.rest.jaxrs.model.Snapshot) Promise(io.vertx.core.Promise) SourceStorageSnapshotsClient(org.folio.rest.client.SourceStorageSnapshotsClient) Date(java.util.Date) JobDuplicateUpdateException(org.folio.services.exceptions.JobDuplicateUpdateException) BadRequestException(javax.ws.rs.BadRequestException) HttpException(io.vertx.ext.web.handler.HttpException) NotFoundException(javax.ws.rs.NotFoundException)

Example 18 with Snapshot

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());
}
Also used : Snapshot(org.folio.rest.jaxrs.model.Snapshot) ArrayList(java.util.ArrayList) GenericCompositeFuture(org.folio.okapi.common.GenericCompositeFuture) Future(io.vertx.core.Future)

Example 19 with Snapshot

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));
        });
    }
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) Snapshot(org.folio.rest.jaxrs.model.Snapshot) BadRequestException(javax.ws.rs.BadRequestException) List(java.util.List) ArrayList(java.util.ArrayList) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto)

Example 20 with Snapshot

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());
}
Also used : Snapshot(org.folio.rest.jaxrs.model.Snapshot) ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) RawRecord(org.folio.rest.jaxrs.model.RawRecord) JsonObject(io.vertx.core.json.JsonObject) RawRecord(org.folio.rest.jaxrs.model.RawRecord) Record(org.folio.rest.jaxrs.model.Record) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Date(java.util.Date) Before(org.junit.Before)

Aggregations

Snapshot (org.folio.rest.jaxrs.model.Snapshot)31 Async (io.vertx.ext.unit.Async)25 Test (org.junit.Test)21 Record (org.folio.rest.jaxrs.model.Record)15 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)14 RawRecord (org.folio.rest.jaxrs.model.RawRecord)14 Before (org.junit.Before)13 ArrayList (java.util.ArrayList)10 Date (java.util.Date)10 JsonObject (io.vertx.core.json.JsonObject)9 UUID (java.util.UUID)9 TestContext (io.vertx.ext.unit.TestContext)8 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)8 RecordDaoImpl (org.folio.dao.RecordDaoImpl)8 SnapshotDaoUtil (org.folio.dao.util.SnapshotDaoUtil)8 ExternalIdsHolder (org.folio.rest.jaxrs.model.ExternalIdsHolder)8 RunWith (org.junit.runner.RunWith)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 IOException (java.io.IOException)7 Collections (java.util.Collections)7