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();
}
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();
}
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();
}
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)));
}
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();
});
});
}
Aggregations