Search in sources :

Example 6 with StatusDto

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();
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) MutableInt(org.apache.commons.lang3.mutable.MutableInt) TAG_999(org.folio.services.afterprocessing.AdditionalFieldsUtil.TAG_999) Autowired(org.springframework.beans.factory.annotation.Autowired) RecordAnalyzer(org.folio.dataimport.util.marc.RecordAnalyzer) MARC_HOLDING(org.folio.rest.jaxrs.model.Record.RecordType.MARC_HOLDING) RecordType(org.folio.rest.jaxrs.model.Record.RecordType) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MarcRecordAnalyzer(org.folio.dataimport.util.marc.MarcRecordAnalyzer) Map(java.util.Map) JobExecutionSourceChunkDao(org.folio.dao.JobExecutionSourceChunkDao) JobExecution(org.folio.rest.jaxrs.model.JobExecution) RecordParserBuilder(org.folio.services.parsers.RecordParserBuilder) JsonObject(io.vertx.core.json.JsonObject) DI_ERROR(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_ERROR) AdditionalFieldsUtil.getValue(org.folio.services.afterprocessing.AdditionalFieldsUtil.getValue) InitialRecord(org.folio.rest.jaxrs.model.InitialRecord) StatusDto(org.folio.rest.jaxrs.model.StatusDto) MODULE_SPECIFIC_ARGS(org.folio.rest.RestVerticle.MODULE_SPECIFIC_ARGS) AdditionalFieldsUtil.getControlFieldValue(org.folio.services.afterprocessing.AdditionalFieldsUtil.getControlFieldValue) Collection(java.util.Collection) EventHandlingUtil.sendEventToKafka(org.folio.services.util.EventHandlingUtil.sendEventToKafka) UUID(java.util.UUID) JobExecutionSourceChunk(org.folio.rest.jaxrs.model.JobExecutionSourceChunk) RecordCollection(org.folio.rest.jaxrs.model.RecordCollection) Collectors(java.util.stream.Collectors) Future(io.vertx.core.Future) String.format(java.lang.String.format) NotFoundException(javax.ws.rs.NotFoundException) OkapiConnectionParams(org.folio.dataimport.util.OkapiConnectionParams) KafkaHeaderImpl(io.vertx.kafka.client.producer.impl.KafkaHeaderImpl) FolioRecord(org.folio.rest.jaxrs.model.ActionProfile.FolioRecord) Objects(java.util.Objects) List(java.util.List) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) Logger(org.apache.logging.log4j.Logger) DI_MARC_FOR_UPDATE_RECEIVED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_MARC_FOR_UPDATE_RECEIVED) KafkaHeaderUtils(org.folio.kafka.KafkaHeaderUtils) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) HrIdFieldService(org.folio.services.afterprocessing.HrIdFieldService) Json(io.vertx.core.json.Json) DI_RAW_RECORDS_CHUNK_PARSED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_RAW_RECORDS_CHUNK_PARSED) DataImportEventPayload(org.folio.rest.jaxrs.model.DataImportEventPayload) RawRecord(org.folio.rest.jaxrs.model.RawRecord) HashMap(java.util.HashMap) RecordsMetadata(org.folio.rest.jaxrs.model.RecordsMetadata) Function(java.util.function.Function) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) DI_MARC_FOR_DELETE_RECEIVED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_MARC_FOR_DELETE_RECEIVED) Value(org.springframework.beans.factory.annotation.Value) MARC_AUTHORITY(org.folio.rest.jaxrs.model.Record.RecordType.MARC_AUTHORITY) CompositeFuture(io.vertx.core.CompositeFuture) IterableUtils(org.apache.commons.collections4.IterableUtils) DataType(org.folio.rest.jaxrs.model.JobProfileInfo.DataType) Lists(com.google.common.collect.Lists) Action(org.folio.rest.jaxrs.model.ActionProfile.Action) ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) Service(org.springframework.stereotype.Service) AdditionalFieldsUtil.addFieldToMarcRecord(org.folio.services.afterprocessing.AdditionalFieldsUtil.addFieldToMarcRecord) SourceStorageBatchClient(org.folio.rest.client.SourceStorageBatchClient) ActionProfile(org.folio.rest.jaxrs.model.ActionProfile) EntityType(org.folio.rest.jaxrs.model.EntityType) Record(org.folio.rest.jaxrs.model.Record) ParsedResult(org.folio.services.parsers.ParsedResult) RecordConversionUtil(org.folio.services.util.RecordConversionUtil) Promise(io.vertx.core.Promise) AdditionalFieldsUtil.hasIndicator(org.folio.services.afterprocessing.AdditionalFieldsUtil.hasIndicator) RawRecordsDto(org.folio.rest.jaxrs.model.RawRecordsDto) MARC_BIB(org.folio.rest.jaxrs.model.Record.RecordType.MARC_BIB) SUBFIELD_S(org.folio.services.afterprocessing.AdditionalFieldsUtil.SUBFIELD_S) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) SUBFIELD_I(org.folio.services.afterprocessing.AdditionalFieldsUtil.SUBFIELD_I) MarcRecordType(org.folio.dataimport.util.marc.MarcRecordType) Collections(java.util.Collections) KafkaHeader(io.vertx.kafka.client.producer.KafkaHeader) LogManager(org.apache.logging.log4j.LogManager) KafkaConfig(org.folio.kafka.KafkaConfig) StatusDto(org.folio.rest.jaxrs.model.StatusDto) NotFoundException(javax.ws.rs.NotFoundException) List(java.util.List) ArrayList(java.util.ArrayList)

Example 7 with StatusDto

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));
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) TestContext(io.vertx.ext.unit.TestContext) EDIFACT(org.folio.rest.jaxrs.model.JournalRecord.EntityType.EDIFACT) MARC_BIBLIOGRAPHIC(org.folio.rest.jaxrs.model.JournalRecord.EntityType.MARC_BIBLIOGRAPHIC) MARC_AUTHORITY(org.folio.rest.jaxrs.model.JournalRecord.EntityType.MARC_AUTHORITY) Date(java.util.Date) ZonedDateTime(java.time.ZonedDateTime) Matchers.not(org.hamcrest.Matchers.not) HttpStatus(org.apache.http.HttpStatus) CHILD(org.folio.rest.jaxrs.model.JobExecution.SubordinationType.CHILD) MockitoAnnotations(org.mockito.MockitoAnnotations) Matchers.everyItem(org.hamcrest.Matchers.everyItem) JobExecution(org.folio.rest.jaxrs.model.JobExecution) JobProfileInfo(org.folio.rest.jaxrs.model.JobProfileInfo) After(org.junit.After) Spy(org.mockito.Spy) Matchers.nullValue(org.hamcrest.Matchers.nullValue) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) JsonObject(io.vertx.core.json.JsonObject) ERROR(org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.ERROR) ZoneOffset(java.time.ZoneOffset) HOLDINGS(org.folio.rest.jaxrs.model.JournalRecord.EntityType.HOLDINGS) JobExecutionDto(org.folio.rest.jaxrs.model.JobExecutionDto) MODIFY(org.folio.rest.jaxrs.model.JournalRecord.ActionType.MODIFY) StatusDto(org.folio.rest.jaxrs.model.StatusDto) ChangeManagerAPITest(org.folio.rest.impl.changeManager.ChangeManagerAPITest) AUTHORITY(org.folio.rest.jaxrs.model.JournalRecord.EntityType.AUTHORITY) JournalRecord(org.folio.rest.jaxrs.model.JournalRecord) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) UUID(java.util.UUID) Instant(java.time.Instant) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) List(java.util.List) JobExecutionDtoCollection(org.folio.rest.jaxrs.model.JobExecutionDtoCollection) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) RestAssured(io.restassured.RestAssured) Progress(org.folio.rest.jaxrs.model.Progress) Async(io.vertx.ext.unit.Async) RunWith(org.junit.runner.RunWith) PARENT_MULTIPLE(org.folio.rest.jaxrs.model.JobExecution.SubordinationType.PARENT_MULTIPLE) DeleteJobExecutionsResp(org.folio.rest.jaxrs.model.DeleteJobExecutionsResp) PostgresClientFactory(org.folio.dao.util.PostgresClientFactory) JournalRecordCollection(org.folio.rest.jaxrs.model.JournalRecordCollection) EntityType(org.folio.rest.jaxrs.model.EntityType) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Status(org.folio.services.Status) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) MARC(org.folio.rest.jaxrs.model.JobProfileInfo.DataType.MARC) ITEM(org.folio.rest.jaxrs.model.JournalRecord.EntityType.ITEM) Matchers.empty(org.hamcrest.Matchers.empty) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) UPDATE(org.folio.rest.jaxrs.model.JournalRecord.ActionType.UPDATE) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) COMPLETED(org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.COMPLETED) INSTANCE(org.folio.rest.jaxrs.model.JournalRecord.EntityType.INSTANCE) NON_MATCH(org.folio.rest.jaxrs.model.JournalRecord.ActionType.NON_MATCH) RunBy(org.folio.rest.jaxrs.model.RunBy) INVOICE(org.folio.rest.jaxrs.model.JournalRecord.EntityType.INVOICE) ChronoUnit(java.time.temporal.ChronoUnit) Matchers.hasItem(org.hamcrest.Matchers.hasItem) JobExecutionsCache(org.folio.services.JobExecutionsCache) DateTimeFormatter(java.time.format.DateTimeFormatter) Assert(org.junit.Assert) JournalRecordDaoImpl(org.folio.dao.JournalRecordDaoImpl) CREATE(org.folio.rest.jaxrs.model.JournalRecord.ActionType.CREATE) StatusDto(org.folio.rest.jaxrs.model.StatusDto) ChangeManagerAPITest(org.folio.rest.impl.changeManager.ChangeManagerAPITest) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Example 8 with StatusDto

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();
    });
}
Also used : TestContext(io.vertx.ext.unit.TestContext) MappingParametersProvider(org.folio.services.mappers.processor.MappingParametersProvider) Arrays(java.util.Arrays) JobMonitoringDaoImpl(org.folio.dao.JobMonitoringDaoImpl) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) MockitoAnnotations(org.mockito.MockitoAnnotations) MarcRecordAnalyzer(org.folio.dataimport.util.marc.MarcRecordAnalyzer) JobExecution(org.folio.rest.jaxrs.model.JobExecution) JobProfileInfo(org.folio.rest.jaxrs.model.JobProfileInfo) After(org.junit.After) Spy(org.mockito.Spy) JsonObject(io.vertx.core.json.JsonObject) MappingRuleDaoImpl(org.folio.dao.MappingRuleDaoImpl) WireMock.post(com.github.tomakehurst.wiremock.client.WireMock.post) InitialRecord(org.folio.rest.jaxrs.model.InitialRecord) StatusDto(org.folio.rest.jaxrs.model.StatusDto) MappingRulesSnapshotDaoImpl(org.folio.dao.MappingRulesSnapshotDaoImpl) WireMock.put(com.github.tomakehurst.wiremock.client.WireMock.put) UUID(java.util.UUID) Future(io.vertx.core.Future) OkapiConnectionParams(org.folio.dataimport.util.OkapiConnectionParams) Optional(java.util.Optional) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) JobExecutionSourceChunkDaoImpl(org.folio.dao.JobExecutionSourceChunkDaoImpl) RunTestOnContext(io.vertx.ext.unit.junit.RunTestOnContext) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Async(io.vertx.ext.unit.Async) OKAPI_TENANT_HEADER(org.folio.rest.util.OkapiConnectionParams.OKAPI_TENANT_HEADER) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Record(org.folio.Record) RunWith(org.junit.runner.RunWith) RecordsMetadata(org.folio.rest.jaxrs.model.RecordsMetadata) HashMap(java.util.HashMap) WireMock.postRequestedFor(com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor) HrIdFieldServiceImpl(org.folio.services.afterprocessing.HrIdFieldServiceImpl) JobExecutionProgressServiceImpl(org.folio.services.progress.JobExecutionProgressServiceImpl) OKAPI_URL_HEADER(org.folio.dataimport.util.RestUtil.OKAPI_URL_HEADER) WireMock.ok(com.github.tomakehurst.wiremock.client.WireMock.ok) WireMock(com.github.tomakehurst.wiremock.client.WireMock) PostgresClientFactory(org.folio.dao.util.PostgresClientFactory) DataType(org.folio.rest.jaxrs.model.JobProfileInfo.DataType) ArgumentCaptor(org.mockito.ArgumentCaptor) TestUtil(org.folio.TestUtil) InitJobExecutionsRqDto(org.folio.rest.jaxrs.model.InitJobExecutionsRqDto) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) Before(org.junit.Before) ArgumentMatchers.isA(org.mockito.ArgumentMatchers.isA) InjectMocks(org.mockito.InjectMocks) WireMock.get(com.github.tomakehurst.wiremock.client.WireMock.get) WireMock.urlPathEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) JobExecutionProgressDaoImpl(org.folio.dao.JobExecutionProgressDaoImpl) Vertx(io.vertx.core.Vertx) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Test(org.junit.Test) IOException(java.io.IOException) Mockito.times(org.mockito.Mockito.times) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) MappingParamsSnapshotDaoImpl(org.folio.dao.MappingParamsSnapshotDaoImpl) Mockito.when(org.mockito.Mockito.when) WireMock.verify(com.github.tomakehurst.wiremock.client.WireMock.verify) RawRecordsDto(org.folio.rest.jaxrs.model.RawRecordsDto) Mockito(org.mockito.Mockito) Rule(org.junit.Rule) File(org.folio.rest.jaxrs.model.File) WireMock.created(com.github.tomakehurst.wiremock.client.WireMock.created) JobExecutionDaoImpl(org.folio.dao.JobExecutionDaoImpl) PARSING_IN_PROGRESS(org.folio.rest.jaxrs.model.StatusDto.Status.PARSING_IN_PROGRESS) OKAPI_TOKEN_HEADER(org.folio.rest.util.OkapiConnectionParams.OKAPI_TOKEN_HEADER) WireMock.urlEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo) Collections(java.util.Collections) JournalRecordDaoImpl(org.folio.dao.JournalRecordDaoImpl) KafkaConfig(org.folio.kafka.KafkaConfig) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StatusDto(org.folio.rest.jaxrs.model.StatusDto) InitialRecord(org.folio.rest.jaxrs.model.InitialRecord) Async(io.vertx.ext.unit.Async) RawRecordsDto(org.folio.rest.jaxrs.model.RawRecordsDto) RecordsMetadata(org.folio.rest.jaxrs.model.RecordsMetadata) OkapiConnectionParams(org.folio.dataimport.util.OkapiConnectionParams) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Example 9 with StatusDto

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();
    });
}
Also used : TestContext(io.vertx.ext.unit.TestContext) MappingParametersProvider(org.folio.services.mappers.processor.MappingParametersProvider) Arrays(java.util.Arrays) JobMonitoringDaoImpl(org.folio.dao.JobMonitoringDaoImpl) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) MockitoAnnotations(org.mockito.MockitoAnnotations) MarcRecordAnalyzer(org.folio.dataimport.util.marc.MarcRecordAnalyzer) JobExecution(org.folio.rest.jaxrs.model.JobExecution) JobProfileInfo(org.folio.rest.jaxrs.model.JobProfileInfo) After(org.junit.After) Spy(org.mockito.Spy) JsonObject(io.vertx.core.json.JsonObject) MappingRuleDaoImpl(org.folio.dao.MappingRuleDaoImpl) WireMock.post(com.github.tomakehurst.wiremock.client.WireMock.post) InitialRecord(org.folio.rest.jaxrs.model.InitialRecord) StatusDto(org.folio.rest.jaxrs.model.StatusDto) MappingRulesSnapshotDaoImpl(org.folio.dao.MappingRulesSnapshotDaoImpl) WireMock.put(com.github.tomakehurst.wiremock.client.WireMock.put) UUID(java.util.UUID) Future(io.vertx.core.Future) OkapiConnectionParams(org.folio.dataimport.util.OkapiConnectionParams) Optional(java.util.Optional) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) JobExecutionSourceChunkDaoImpl(org.folio.dao.JobExecutionSourceChunkDaoImpl) RunTestOnContext(io.vertx.ext.unit.junit.RunTestOnContext) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Async(io.vertx.ext.unit.Async) OKAPI_TENANT_HEADER(org.folio.rest.util.OkapiConnectionParams.OKAPI_TENANT_HEADER) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Record(org.folio.Record) RunWith(org.junit.runner.RunWith) RecordsMetadata(org.folio.rest.jaxrs.model.RecordsMetadata) HashMap(java.util.HashMap) WireMock.postRequestedFor(com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor) HrIdFieldServiceImpl(org.folio.services.afterprocessing.HrIdFieldServiceImpl) JobExecutionProgressServiceImpl(org.folio.services.progress.JobExecutionProgressServiceImpl) OKAPI_URL_HEADER(org.folio.dataimport.util.RestUtil.OKAPI_URL_HEADER) WireMock.ok(com.github.tomakehurst.wiremock.client.WireMock.ok) WireMock(com.github.tomakehurst.wiremock.client.WireMock) PostgresClientFactory(org.folio.dao.util.PostgresClientFactory) DataType(org.folio.rest.jaxrs.model.JobProfileInfo.DataType) ArgumentCaptor(org.mockito.ArgumentCaptor) TestUtil(org.folio.TestUtil) InitJobExecutionsRqDto(org.folio.rest.jaxrs.model.InitJobExecutionsRqDto) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) Before(org.junit.Before) ArgumentMatchers.isA(org.mockito.ArgumentMatchers.isA) InjectMocks(org.mockito.InjectMocks) WireMock.get(com.github.tomakehurst.wiremock.client.WireMock.get) WireMock.urlPathEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) JobExecutionProgressDaoImpl(org.folio.dao.JobExecutionProgressDaoImpl) Vertx(io.vertx.core.Vertx) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Test(org.junit.Test) IOException(java.io.IOException) Mockito.times(org.mockito.Mockito.times) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) MappingParamsSnapshotDaoImpl(org.folio.dao.MappingParamsSnapshotDaoImpl) Mockito.when(org.mockito.Mockito.when) WireMock.verify(com.github.tomakehurst.wiremock.client.WireMock.verify) RawRecordsDto(org.folio.rest.jaxrs.model.RawRecordsDto) Mockito(org.mockito.Mockito) Rule(org.junit.Rule) File(org.folio.rest.jaxrs.model.File) WireMock.created(com.github.tomakehurst.wiremock.client.WireMock.created) JobExecutionDaoImpl(org.folio.dao.JobExecutionDaoImpl) PARSING_IN_PROGRESS(org.folio.rest.jaxrs.model.StatusDto.Status.PARSING_IN_PROGRESS) OKAPI_TOKEN_HEADER(org.folio.rest.util.OkapiConnectionParams.OKAPI_TOKEN_HEADER) WireMock.urlEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo) Collections(java.util.Collections) JournalRecordDaoImpl(org.folio.dao.JournalRecordDaoImpl) KafkaConfig(org.folio.kafka.KafkaConfig) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StatusDto(org.folio.rest.jaxrs.model.StatusDto) Async(io.vertx.ext.unit.Async) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) OkapiConnectionParams(org.folio.dataimport.util.OkapiConnectionParams) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Example 10 with StatusDto

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));
    }
}
Also used : 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) Promise(io.vertx.core.Promise) BadRequestException(javax.ws.rs.BadRequestException) JobDuplicateUpdateException(org.folio.services.exceptions.JobDuplicateUpdateException) BadRequestException(javax.ws.rs.BadRequestException) HttpException(io.vertx.ext.web.handler.HttpException) NotFoundException(javax.ws.rs.NotFoundException)

Aggregations

StatusDto (org.folio.rest.jaxrs.model.StatusDto)18 JobExecution (org.folio.rest.jaxrs.model.JobExecution)17 AbstractRestTest (org.folio.rest.impl.AbstractRestTest)14 Test (org.junit.Test)14 InitJobExecutionsRsDto (org.folio.rest.jaxrs.model.InitJobExecutionsRsDto)10 Future (io.vertx.core.Future)8 JsonObject (io.vertx.core.json.JsonObject)7 UUID (java.util.UUID)7 OkapiConnectionParams (org.folio.dataimport.util.OkapiConnectionParams)7 JobProfileInfo (org.folio.rest.jaxrs.model.JobProfileInfo)7 Async (io.vertx.ext.unit.Async)6 Collections (java.util.Collections)6 RegexPattern (com.github.tomakehurst.wiremock.matching.RegexPattern)5 UrlPathPattern (com.github.tomakehurst.wiremock.matching.UrlPathPattern)5 TestContext (io.vertx.ext.unit.TestContext)5 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)5 HashMap (java.util.HashMap)5 WireMock (com.github.tomakehurst.wiremock.client.WireMock)4 WireMock.created (com.github.tomakehurst.wiremock.client.WireMock.created)4 WireMock.get (com.github.tomakehurst.wiremock.client.WireMock.get)4