Search in sources :

Example 1 with RecordType

use of org.folio.rest.jaxrs.model.Record.RecordType in project mod-source-record-manager by folio-org.

the class ChangeEngineServiceImpl method ensureMappingMetaDataSnapshot.

private Future<Boolean> ensureMappingMetaDataSnapshot(String jobExecutionId, List<Record> recordsList, OkapiConnectionParams okapiParams) {
    if (CollectionUtils.isEmpty(recordsList)) {
        return Future.succeededFuture(false);
    }
    Promise<Boolean> promise = Promise.promise();
    mappingMetadataService.getMappingMetadataDto(jobExecutionId, okapiParams).onSuccess(v -> promise.complete(false)).onFailure(e -> {
        if (e instanceof NotFoundException) {
            RecordType recordType = recordsList.get(0).getRecordType();
            recordType = Objects.isNull(recordType) || recordType == RecordType.EDIFACT ? MARC_BIB : recordType;
            mappingMetadataService.saveMappingRulesSnapshot(jobExecutionId, recordType.toString(), okapiParams.getTenantId()).compose(arMappingRules -> mappingMetadataService.saveMappingParametersSnapshot(jobExecutionId, okapiParams)).onSuccess(ar -> promise.complete(true)).onFailure(promise::fail);
            return;
        }
        promise.fail(e);
    });
    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) RecordType(org.folio.rest.jaxrs.model.Record.RecordType) MarcRecordType(org.folio.dataimport.util.marc.MarcRecordType) NotFoundException(javax.ws.rs.NotFoundException)

Example 2 with RecordType

use of org.folio.rest.jaxrs.model.Record.RecordType in project mod-source-record-storage by folio-org.

the class SourceStorageStreamApiTest method shouldReturnAllMarcRecordsWithNotEmptyStateOnGetWhenNoQueryIsSpecified.

private void shouldReturnAllMarcRecordsWithNotEmptyStateOnGetWhenNoQueryIsSpecified(TestContext testContext, RecordType recordType, Record marc_auth_record_1) {
    postSnapshots(testContext, snapshot_1, snapshot_2, snapshot_3);
    Record record_4 = new Record().withId(FOURTH_UUID).withSnapshotId(snapshot_3.getJobExecutionId()).withRecordType(recordType).withRawRecord(rawRecord).withParsedRecord(marcRecord).withMatchedId(FOURTH_UUID).withOrder(1).withState(Record.State.OLD);
    postRecords(testContext, marc_bib_record_1, marc_bib_record_2, marc_bib_record_3, record_4, marc_auth_record_1);
    final Async async = testContext.async();
    InputStream response = RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_STREAM_RECORDS_PATH + "?recordType=" + recordType).then().statusCode(HttpStatus.SC_OK).extract().response().asInputStream();
    List<Record> actual = new ArrayList<>();
    flowableInputStreamScanner(response).map(r -> Json.decodeValue(r, Record.class)).doFinally(() -> {
        testContext.assertEquals(2, actual.size());
        async.complete();
    }).collect(() -> actual, (a, r) -> a.add(r)).subscribe();
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) Date(java.util.Date) ZonedDateTime(java.time.ZonedDateTime) RunWith(org.junit.runner.RunWith) RawRecord(org.folio.rest.jaxrs.model.RawRecord) Scanner(java.util.Scanner) HttpStatus(org.apache.http.HttpStatus) ArrayList(java.util.ArrayList) RecordType(org.folio.rest.jaxrs.model.Record.RecordType) Matchers.everyItem(org.hamcrest.Matchers.everyItem) Flowable(io.reactivex.Flowable) ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) TestUtil(org.folio.TestUtil) JsonObject(io.vertx.core.json.JsonObject) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) AdditionalInfo(org.folio.rest.jaxrs.model.AdditionalInfo) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Before(org.junit.Before) BackpressureStrategy(io.reactivex.BackpressureStrategy) Record(org.folio.rest.jaxrs.model.Record) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Test(org.junit.Test) ParsedRecordDaoUtil(org.folio.dao.util.ParsedRecordDaoUtil) UUID(java.util.UUID) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) SnapshotDaoUtil(org.folio.dao.util.SnapshotDaoUtil) ZoneId(java.time.ZoneId) Objects(java.util.Objects) ExtractableResponse(io.restassured.response.ExtractableResponse) List(java.util.List) Response(io.restassured.response.Response) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) DateTimeFormatter(java.time.format.DateTimeFormatter) PostgresClientFactory(org.folio.dao.PostgresClientFactory) MarcRecordSearchRequest(org.folio.rest.jaxrs.model.MarcRecordSearchRequest) Matchers.is(org.hamcrest.Matchers.is) RestAssured(io.restassured.RestAssured) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Snapshot(org.folio.rest.jaxrs.model.Snapshot) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) Async(io.vertx.ext.unit.Async) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) RawRecord(org.folio.rest.jaxrs.model.RawRecord) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Record(org.folio.rest.jaxrs.model.Record) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord)

Example 3 with RecordType

use of org.folio.rest.jaxrs.model.Record.RecordType in project mod-source-record-storage by folio-org.

the class SourceStorageStreamApiTest method shouldReturnMarcRecordsOnGetBySpecifiedSnapshotId.

private void shouldReturnMarcRecordsOnGetBySpecifiedSnapshotId(TestContext testContext, RecordType marcHolding, Record marc_holdings_record_1) {
    postSnapshots(testContext, snapshot_1, snapshot_2, snapshot_3);
    Record recordWithOldStatus = new Record().withId(FOURTH_UUID).withSnapshotId(snapshot_3.getJobExecutionId()).withRecordType(marcHolding).withRawRecord(rawRecord).withParsedRecord(marcRecord).withMatchedId(FOURTH_UUID).withOrder(1).withState(Record.State.OLD);
    postRecords(testContext, marc_bib_record_1, marc_bib_record_2, marc_bib_record_3, marc_holdings_record_1, recordWithOldStatus);
    final Async async = testContext.async();
    InputStream response = RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_STREAM_RECORDS_PATH + "?recordType=" + marcHolding + "&state=ACTUAL&snapshotId=" + marc_holdings_record_1.getSnapshotId()).then().statusCode(HttpStatus.SC_OK).extract().response().asInputStream();
    List<Record> actual = new ArrayList<>();
    flowableInputStreamScanner(response).map(r -> Json.decodeValue(r, Record.class)).doFinally(() -> {
        testContext.assertEquals(1, actual.size());
        testContext.assertEquals(marc_holdings_record_1.getSnapshotId(), actual.get(0).getSnapshotId());
        testContext.assertEquals(false, actual.get(0).getAdditionalInfo().getSuppressDiscovery());
        async.complete();
    }).collect(() -> actual, (a, r) -> a.add(r)).subscribe();
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) Date(java.util.Date) ZonedDateTime(java.time.ZonedDateTime) RunWith(org.junit.runner.RunWith) RawRecord(org.folio.rest.jaxrs.model.RawRecord) Scanner(java.util.Scanner) HttpStatus(org.apache.http.HttpStatus) ArrayList(java.util.ArrayList) RecordType(org.folio.rest.jaxrs.model.Record.RecordType) Matchers.everyItem(org.hamcrest.Matchers.everyItem) Flowable(io.reactivex.Flowable) ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) TestUtil(org.folio.TestUtil) JsonObject(io.vertx.core.json.JsonObject) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) AdditionalInfo(org.folio.rest.jaxrs.model.AdditionalInfo) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Before(org.junit.Before) BackpressureStrategy(io.reactivex.BackpressureStrategy) Record(org.folio.rest.jaxrs.model.Record) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Test(org.junit.Test) ParsedRecordDaoUtil(org.folio.dao.util.ParsedRecordDaoUtil) UUID(java.util.UUID) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) SnapshotDaoUtil(org.folio.dao.util.SnapshotDaoUtil) ZoneId(java.time.ZoneId) Objects(java.util.Objects) ExtractableResponse(io.restassured.response.ExtractableResponse) List(java.util.List) Response(io.restassured.response.Response) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) DateTimeFormatter(java.time.format.DateTimeFormatter) PostgresClientFactory(org.folio.dao.PostgresClientFactory) MarcRecordSearchRequest(org.folio.rest.jaxrs.model.MarcRecordSearchRequest) Matchers.is(org.hamcrest.Matchers.is) RestAssured(io.restassured.RestAssured) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Snapshot(org.folio.rest.jaxrs.model.Snapshot) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) Async(io.vertx.ext.unit.Async) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) RawRecord(org.folio.rest.jaxrs.model.RawRecord) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Record(org.folio.rest.jaxrs.model.Record) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord)

Example 4 with RecordType

use of org.folio.rest.jaxrs.model.Record.RecordType in project mod-source-record-storage by folio-org.

the class SourceStorageStreamApiTest method shouldReturnSortedSourceRecordsOnGetWhenSortByIsSpecified.

@Test
public void shouldReturnSortedSourceRecordsOnGetWhenSortByIsSpecified(TestContext testContext) {
    postSnapshots(testContext, snapshot_1, snapshot_2);
    String firstMatchedId = UUID.randomUUID().toString();
    Record record_4_tmp = new Record().withId(firstMatchedId).withSnapshotId(snapshot_1.getJobExecutionId()).withRecordType(Record.RecordType.MARC_BIB).withRawRecord(rawRecord).withParsedRecord(marcRecord).withMatchedId(firstMatchedId).withOrder(1).withState(Record.State.ACTUAL);
    String secondMathcedId = UUID.randomUUID().toString();
    Record record_2_tmp = new Record().withId(secondMathcedId).withSnapshotId(snapshot_2.getJobExecutionId()).withRecordType(Record.RecordType.MARC_BIB).withRawRecord(rawRecord).withParsedRecord(marcRecord).withMatchedId(secondMathcedId).withOrder(11).withState(Record.State.ACTUAL);
    postRecords(testContext, marc_bib_record_2, record_2_tmp, marc_bib_record_4, record_4_tmp);
    final Async async = testContext.async();
    InputStream response = RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_STREAM_SOURCE_RECORDS_PATH + "?recordType=MARC_BIB&orderBy=createdDate,DESC").then().statusCode(HttpStatus.SC_OK).extract().response().asInputStream();
    List<SourceRecord> actual = new ArrayList<>();
    flowableInputStreamScanner(response).map(r -> Json.decodeValue(r, SourceRecord.class)).doFinally(() -> {
        testContext.assertEquals(4, actual.size());
        testContext.assertTrue(Objects.nonNull(actual.get(0).getParsedRecord()));
        testContext.assertTrue(Objects.nonNull(actual.get(1).getParsedRecord()));
        testContext.assertTrue(Objects.nonNull(actual.get(2).getParsedRecord()));
        testContext.assertTrue(Objects.nonNull(actual.get(3).getParsedRecord()));
        testContext.assertEquals(false, actual.get(0).getDeleted());
        testContext.assertEquals(false, actual.get(1).getDeleted());
        testContext.assertEquals(false, actual.get(2).getDeleted());
        testContext.assertEquals(false, actual.get(3).getDeleted());
        testContext.assertTrue(actual.get(0).getMetadata().getCreatedDate().after(actual.get(1).getMetadata().getCreatedDate()));
        testContext.assertTrue(actual.get(1).getMetadata().getCreatedDate().after(actual.get(2).getMetadata().getCreatedDate()));
        testContext.assertTrue(actual.get(2).getMetadata().getCreatedDate().after(actual.get(3).getMetadata().getCreatedDate()));
        async.complete();
    }).collect(() -> actual, (a, r) -> a.add(r)).subscribe();
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) Date(java.util.Date) ZonedDateTime(java.time.ZonedDateTime) RunWith(org.junit.runner.RunWith) RawRecord(org.folio.rest.jaxrs.model.RawRecord) Scanner(java.util.Scanner) HttpStatus(org.apache.http.HttpStatus) ArrayList(java.util.ArrayList) RecordType(org.folio.rest.jaxrs.model.Record.RecordType) Matchers.everyItem(org.hamcrest.Matchers.everyItem) Flowable(io.reactivex.Flowable) ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) TestUtil(org.folio.TestUtil) JsonObject(io.vertx.core.json.JsonObject) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) AdditionalInfo(org.folio.rest.jaxrs.model.AdditionalInfo) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Before(org.junit.Before) BackpressureStrategy(io.reactivex.BackpressureStrategy) Record(org.folio.rest.jaxrs.model.Record) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Test(org.junit.Test) ParsedRecordDaoUtil(org.folio.dao.util.ParsedRecordDaoUtil) UUID(java.util.UUID) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) SnapshotDaoUtil(org.folio.dao.util.SnapshotDaoUtil) ZoneId(java.time.ZoneId) Objects(java.util.Objects) ExtractableResponse(io.restassured.response.ExtractableResponse) List(java.util.List) Response(io.restassured.response.Response) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) DateTimeFormatter(java.time.format.DateTimeFormatter) PostgresClientFactory(org.folio.dao.PostgresClientFactory) MarcRecordSearchRequest(org.folio.rest.jaxrs.model.MarcRecordSearchRequest) Matchers.is(org.hamcrest.Matchers.is) RestAssured(io.restassured.RestAssured) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Snapshot(org.folio.rest.jaxrs.model.Snapshot) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) Async(io.vertx.ext.unit.Async) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) RawRecord(org.folio.rest.jaxrs.model.RawRecord) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Record(org.folio.rest.jaxrs.model.Record) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Test(org.junit.Test)

Aggregations

Json (io.vertx.core.json.Json)4 JsonObject (io.vertx.core.json.JsonObject)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Objects (java.util.Objects)4 UUID (java.util.UUID)4 ErrorRecord (org.folio.rest.jaxrs.model.ErrorRecord)4 ExternalIdsHolder (org.folio.rest.jaxrs.model.ExternalIdsHolder)4 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)4 RawRecord (org.folio.rest.jaxrs.model.RawRecord)4 Record (org.folio.rest.jaxrs.model.Record)4 RecordType (org.folio.rest.jaxrs.model.Record.RecordType)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 BackpressureStrategy (io.reactivex.BackpressureStrategy)3 Flowable (io.reactivex.Flowable)3 RestAssured (io.restassured.RestAssured)3 ExtractableResponse (io.restassured.response.ExtractableResponse)3 Response (io.restassured.response.Response)3 Async (io.vertx.ext.unit.Async)3 TestContext (io.vertx.ext.unit.TestContext)3