Search in sources :

Example 21 with ExternalIdsHolder

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

the class SourceRecordApiTest method shouldReturnSourceRecordsByListOfId.

@Test
public void shouldReturnSourceRecordsByListOfId(TestContext testContext) {
    postSnapshots(testContext, snapshot_1, snapshot_2);
    String firstSrsId = UUID.randomUUID().toString();
    String firstInstanceId = UUID.randomUUID().toString();
    ParsedRecord parsedRecord = new ParsedRecord().withId(firstSrsId).withContent(new JsonObject().put("leader", "01542dcm a2200361   4500").put("fields", new JsonArray().add(new JsonObject().put("999", new JsonObject().put("subfields", new JsonArray().add(new JsonObject().put("s", firstSrsId)).add(new JsonObject().put("i", firstInstanceId)))))));
    Record deleted_record_1 = new Record().withId(firstSrsId).withSnapshotId(snapshot_1.getJobExecutionId()).withRecordType(Record.RecordType.MARC_BIB).withRawRecord(rawRecord).withParsedRecord(parsedRecord).withMatchedId(firstSrsId).withLeaderRecordStatus("d").withOrder(11).withState(Record.State.ACTUAL).withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(firstInstanceId));
    String secondSrsId = UUID.randomUUID().toString();
    String secondInstanceId = UUID.randomUUID().toString();
    Record deleted_record_2 = new Record().withId(secondSrsId).withSnapshotId(snapshot_2.getJobExecutionId()).withRecordType(Record.RecordType.MARC_BIB).withRawRecord(rawRecord).withParsedRecord(marcRecord).withMatchedId(secondSrsId).withOrder(1).withState(Record.State.DELETED).withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(secondInstanceId));
    Record[] records = new Record[] { record_1, record_2, record_3, record_4, record_6, deleted_record_1, deleted_record_2 };
    postRecords(testContext, records);
    List<String> ids = Arrays.stream(records).filter(record -> Objects.nonNull(record.getParsedRecord())).map(Record::getId).collect(Collectors.toList());
    Async async = testContext.async();
    RestAssured.given().spec(spec).body(ids).when().post(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?idType=RECORD&deleted=false").then().statusCode(HttpStatus.SC_OK).body("sourceRecords.size()", is(3)).body("totalRecords", is(4)).body("sourceRecords*.deleted", everyItem(is(false)));
    async.complete();
    async = testContext.async();
    RestAssured.given().spec(spec).body(ids).when().post(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?idType=RECORD&deleted=true").then().statusCode(HttpStatus.SC_OK).body("sourceRecords.size()", is(4)).body("totalRecords", is(5));
    async.complete();
    List<String> externalIds = Arrays.stream(records).filter(record -> Objects.nonNull(record.getParsedRecord())).map(record -> record.getExternalIdsHolder().getInstanceId()).collect(Collectors.toList());
    async = testContext.async();
    RestAssured.given().spec(spec).body(externalIds).when().post(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?idType=INSTANCE&deleted=false").then().statusCode(HttpStatus.SC_OK).body("sourceRecords.size()", is(3)).body("totalRecords", is(4)).body("sourceRecords*.deleted", everyItem(is(false)));
    async.complete();
    async = testContext.async();
    RestAssured.given().spec(spec).body(externalIds).when().post(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?idType=INSTANCE&deleted=true").then().statusCode(HttpStatus.SC_OK).body("sourceRecords.size()", is(4)).body("totalRecords", is(5));
    async.complete();
    async = testContext.async();
    RestAssured.given().spec(spec).body(ids).when().post(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?idType=RECORD").then().statusCode(HttpStatus.SC_OK).body("sourceRecords.size()", is(3)).body("totalRecords", is(4));
    async.complete();
}
Also used : JsonArray(io.vertx.core.json.JsonArray) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Arrays(java.util.Arrays) Date(java.util.Date) ZonedDateTime(java.time.ZonedDateTime) RunWith(org.junit.runner.RunWith) RawRecord(org.folio.rest.jaxrs.model.RawRecord) HttpStatus(org.apache.http.HttpStatus) RecordType(org.folio.rest.jaxrs.model.Record.RecordType) Matchers.everyItem(org.hamcrest.Matchers.everyItem) ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) Matchers.nullValue(org.hamcrest.Matchers.nullValue) 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) Matchers.empty(org.hamcrest.Matchers.empty) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) 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) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) Objects(java.util.Objects) JsonArray(io.vertx.core.json.JsonArray) 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) Matchers.is(org.hamcrest.Matchers.is) RestAssured(io.restassured.RestAssured) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Snapshot(org.folio.rest.jaxrs.model.Snapshot) SourceRecordCollection(org.folio.rest.jaxrs.model.SourceRecordCollection) ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) Async(io.vertx.ext.unit.Async) JsonObject(io.vertx.core.json.JsonObject) 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) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Test(org.junit.Test)

Example 22 with ExternalIdsHolder

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

the class SourceStorageBatchApiTest method searchMarcBibIdsByMatcher.

public void searchMarcBibIdsByMatcher(TestContext testContext, List<String> ids, Matcher matcher) {
    postSnapshots(testContext, snapshot_1, snapshot_2);
    Record recordWithOldStatus = new Record().withId(FOURTH_UUID).withSnapshotId(snapshot_2.getJobExecutionId()).withRecordType(Record.RecordType.MARC_BIB).withRawRecord(rawRecord).withParsedRecord(marcRecord).withMatchedId(FOURTH_UUID).withOrder(1).withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString()).withInstanceHrid(VALID_HRID)).withState(Record.State.OLD);
    postRecords(testContext, record_1, record_2, record_3, recordWithOldStatus);
    Async async = testContext.async();
    RestAssured.given().spec(spec).body(ids).when().post(SOURCE_STORAGE_BATCH_VERIFIED_RECORDS).then().statusCode(HttpStatus.SC_OK).body("invalidMarcBibIds", matcher);
    async.complete();
}
Also used : ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) Async(io.vertx.ext.unit.Async) RawRecord(org.folio.rest.jaxrs.model.RawRecord) Record(org.folio.rest.jaxrs.model.Record) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord)

Example 23 with ExternalIdsHolder

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

the class RecordsGenerationTest method shouldReturnRecordOnGetByInstanceId.

@Test
public void shouldReturnRecordOnGetByInstanceId(TestContext testContext) {
    Async async = testContext.async();
    RestAssured.given().spec(spec).body(snapshot_1.withStatus(Snapshot.Status.PARSING_IN_PROGRESS)).when().post(SOURCE_STORAGE_SNAPSHOTS_PATH).then().statusCode(HttpStatus.SC_CREATED);
    async.complete();
    async = testContext.async();
    String srsId = UUID.randomUUID().toString();
    String instanceId = UUID.randomUUID().toString();
    ParsedRecord parsedRecord = new ParsedRecord().withId(srsId).withContent(new JsonObject().put("leader", "01542ccm a2200361   4500").put("fields", new JsonArray().add(new JsonObject().put("999", new JsonObject().put("subfields", new JsonArray().add(new JsonObject().put("s", srsId)).add(new JsonObject().put("i", instanceId)))))));
    Record newRecord = new Record().withId(srsId).withSnapshotId(snapshot_1.getJobExecutionId()).withRecordType(Record.RecordType.MARC_BIB).withRawRecord(rawRecord).withParsedRecord(parsedRecord).withMatchedId(matchedId).withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(instanceId));
    RestAssured.given().spec(spec).body(JsonObject.mapFrom(newRecord).toString()).when().post(SOURCE_STORAGE_RECORDS_PATH).then().statusCode(HttpStatus.SC_CREATED).body("id", is(srsId));
    async.complete();
    async = testContext.async();
    RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_RECORDS_PATH + "/" + instanceId + "/formatted?idType=INSTANCE").then().statusCode(HttpStatus.SC_OK).body("parsedRecord.content", notNullValue());
    async.complete();
}
Also used : JsonArray(io.vertx.core.json.JsonArray) ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) Async(io.vertx.ext.unit.Async) 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) Matchers.containsString(org.hamcrest.Matchers.containsString) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Test(org.junit.Test)

Example 24 with ExternalIdsHolder

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

the class SnapshotApiTest method shouldDeleteExistingSnapshotOnDelete.

@Test
public void shouldDeleteExistingSnapshotOnDelete(TestContext testContext) {
    Async async = testContext.async();
    RestAssured.given().spec(spec).body(snapshot_3).when().post(SOURCE_STORAGE_SNAPSHOTS_PATH).then().statusCode(HttpStatus.SC_CREATED).body("jobExecutionId", is(snapshot_3.getJobExecutionId())).body("status", is(snapshot_3.getStatus().name()));
    async.complete();
    String instanceId = UUID.randomUUID().toString();
    String recordId = UUID.randomUUID().toString();
    Record record = new Record().withRecordType(Record.RecordType.MARC_BIB).withRawRecord(rawRecord).withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(instanceId)).withSnapshotId(snapshot_3.getJobExecutionId());
    List<String> recordIds = Arrays.asList(recordId, UUID.randomUUID().toString());
    for (String id : recordIds) {
        RestAssured.given().spec(spec).body(record.withId(id).withMatchedId(id)).when().post(SOURCE_STORAGE_RECORDS_PATH).then().statusCode(HttpStatus.SC_CREATED);
    }
    async = testContext.async();
    RestAssured.given().spec(spec).when().delete(SOURCE_STORAGE_SNAPSHOTS_PATH + "/" + snapshot_3.getJobExecutionId()).then().statusCode(HttpStatus.SC_NO_CONTENT);
    async.complete();
    for (String id : recordIds) {
        RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_RECORDS_PATH + "/" + id).then().statusCode(HttpStatus.SC_NOT_FOUND);
    }
    verify(recordIds.size(), deleteRequestedFor(new UrlPathPattern(new RegexPattern(INVENTORY_INSTANCES_PATH + "/.*"), true)));
}
Also used : ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Async(io.vertx.ext.unit.Async) RawRecord(org.folio.rest.jaxrs.model.RawRecord) Record(org.folio.rest.jaxrs.model.Record) Test(org.junit.Test)

Example 25 with ExternalIdsHolder

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

the class InstancePostProcessingEventHandlerTest method shouldSetInstanceIdToParsedRecordWhenContentHasField999.

@Test
public void shouldSetInstanceIdToParsedRecordWhenContentHasField999(TestContext context) {
    Async async = context.async();
    String expectedInstanceId = UUID.randomUUID().toString();
    var expectedHrid = "in0002";
    record.withParsedRecord(new ParsedRecord().withId(recordId).withContent(PARSED_CONTENT_WITH_999_FIELD)).withExternalIdsHolder(new ExternalIdsHolder().withInstanceHrid("in0001").withInstanceId(expectedInstanceId));
    HashMap<String, String> payloadContext = new HashMap<>();
    payloadContext.put(INSTANCE.value(), new JsonObject().put("id", expectedInstanceId).put("hrid", expectedHrid).encode());
    payloadContext.put(MARC_BIBLIOGRAPHIC.value(), Json.encode(record));
    DataImportEventPayload dataImportEventPayload = createDataImportEventPayload(payloadContext, DI_INVENTORY_INSTANCE_CREATED_READY_FOR_POST_PROCESSING);
    CompletableFuture<DataImportEventPayload> future = new CompletableFuture<>();
    recordDao.saveRecord(record, TENANT_ID).onFailure(future::completeExceptionally).onSuccess(rec -> handler.handle(dataImportEventPayload).thenApply(future::complete).exceptionally(future::completeExceptionally));
    future.whenComplete((payload, throwable) -> {
        if (throwable != null) {
            context.fail(throwable);
        }
        recordDao.getRecordById(record.getId(), TENANT_ID).onComplete(getAr -> {
            if (getAr.failed()) {
                context.fail(getAr.cause());
            }
            context.assertTrue(getAr.result().isPresent());
            Record updatedRecord = getAr.result().get();
            context.assertNotNull(updatedRecord.getExternalIdsHolder());
            context.assertTrue(expectedInstanceId.equals(updatedRecord.getExternalIdsHolder().getInstanceId()));
            context.assertNotNull(updatedRecord.getParsedRecord().getContent());
            JsonObject parsedContent = JsonObject.mapFrom(updatedRecord.getParsedRecord().getContent());
            JsonArray fields = parsedContent.getJsonArray("fields");
            context.assertTrue(!fields.isEmpty());
            String actualInstanceId = getInventoryId(fields);
            context.assertEquals(expectedInstanceId, actualInstanceId);
            var actualInventoryHrid = getInventoryHrid(fields);
            context.assertEquals(expectedHrid, actualInventoryHrid);
            async.complete();
        });
    });
}
Also used : ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) HashMap(java.util.HashMap) JsonObject(io.vertx.core.json.JsonObject) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) DataImportEventPayload(org.folio.DataImportEventPayload) JsonArray(io.vertx.core.json.JsonArray) CompletableFuture(java.util.concurrent.CompletableFuture) Async(io.vertx.ext.unit.Async) RawRecord(org.folio.rest.jaxrs.model.RawRecord) Record(org.folio.rest.jaxrs.model.Record) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Test(org.junit.Test)

Aggregations

ExternalIdsHolder (org.folio.rest.jaxrs.model.ExternalIdsHolder)25 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)22 Record (org.folio.rest.jaxrs.model.Record)22 Test (org.junit.Test)18 RawRecord (org.folio.rest.jaxrs.model.RawRecord)16 Async (io.vertx.ext.unit.Async)15 JsonObject (io.vertx.core.json.JsonObject)11 ErrorRecord (org.folio.rest.jaxrs.model.ErrorRecord)8 Date (java.util.Date)6 HashMap (java.util.HashMap)6 Snapshot (org.folio.rest.jaxrs.model.Snapshot)6 SourceRecord (org.folio.rest.jaxrs.model.SourceRecord)6 Before (org.junit.Before)6 JsonArray (io.vertx.core.json.JsonArray)5 UUID (java.util.UUID)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 DataImportEventPayload (org.folio.DataImportEventPayload)4 SnapshotDaoUtil (org.folio.dao.util.SnapshotDaoUtil)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3