use of org.folio.rest.jaxrs.model.ParsedRecordDto in project mod-source-record-manager by folio-org.
the class ParsedRecordServiceImpl method getRecordByExternalId.
@Override
public Future<ParsedRecordDto> getRecordByExternalId(String externalId, OkapiConnectionParams params) {
Promise<ParsedRecordDto> promise = Promise.promise();
var client = new SourceStorageSourceRecordsClient(params.getOkapiUrl(), params.getTenantId(), params.getToken());
try {
client.getSourceStorageSourceRecordsById(externalId, "EXTERNAL", response -> {
if (HTTP_OK.toInt() == response.result().statusCode()) {
Buffer bodyAsBuffer = response.result().bodyAsBuffer();
Try.itGet(() -> mapSourceRecordToParsedRecordDto(bodyAsBuffer)).compose(parsedRecordDto -> sourceRecordStateService.get(parsedRecordDto.getId(), params.getTenantId()).map(sourceRecordStateOptional -> sourceRecordStateOptional.orElse(new SourceRecordState().withRecordState(SourceRecordState.RecordState.ACTUAL))).compose(sourceRecordState -> Future.succeededFuture(parsedRecordDto.withRecordState(ParsedRecordDto.RecordState.valueOf(sourceRecordState.getRecordState().name()))))).onComplete(parsedRecordDtoAsyncResult -> {
if (parsedRecordDtoAsyncResult.succeeded()) {
promise.complete(parsedRecordDtoAsyncResult.result());
} else {
promise.fail(parsedRecordDtoAsyncResult.cause());
}
});
} else {
String message = format("Error retrieving Record by externalId: '%s', response code %s, %s", externalId, response.result().statusCode(), response.result().statusMessage());
if (HTTP_NOT_FOUND.toInt() == response.result().statusCode()) {
promise.fail(new NotFoundException(message));
} else {
promise.fail(message);
}
}
});
} catch (Exception e) {
log.error("Failed to GET Record from SRS", e);
promise.fail(e);
}
return promise.future();
}
use of org.folio.rest.jaxrs.model.ParsedRecordDto in project mod-source-record-manager by folio-org.
the class ChangeManagerParsedRecordsAPITest method shouldUpdateParsedRecordOnPut.
@Test
public void shouldUpdateParsedRecordOnPut(TestContext testContext) throws InterruptedException {
Async async = testContext.async();
ParsedRecordDto parsedRecordDto = new ParsedRecordDto().withId(UUID.randomUUID().toString()).withParsedRecord(new ParsedRecord().withId(UUID.randomUUID().toString()).withContent("{\"leader\":\"01240cas a2200397 4500\",\"fields\":[]}")).withRecordType(ParsedRecordDto.RecordType.MARC_HOLDING).withRelatedRecordVersion("1").withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString()));
RestAssured.given().spec(spec).body(parsedRecordDto).when().put(PARSED_RECORDS_URL + "/" + parsedRecordDto.getId()).then().statusCode(HttpStatus.SC_ACCEPTED);
String observeTopic = formatTopicName(kafkaConfig.getEnvId(), getDefaultNameSpace(), TENANT_ID, QMEventTypes.QM_RECORD_UPDATED.name());
kafkaCluster.observeValues(ObserveKeyValues.on(observeTopic, 1).observeFor(30, TimeUnit.SECONDS).build());
async.complete();
}
use of org.folio.rest.jaxrs.model.ParsedRecordDto in project mod-source-record-manager by folio-org.
the class ParsedRecordServiceImpl method updateRecord.
@Override
public Future<Boolean> updateRecord(ParsedRecordDto parsedRecordDto, OkapiConnectionParams params) {
String snapshotId = UUID.randomUUID().toString();
MappingRuleCacheKey cacheKey = new MappingRuleCacheKey(params.getTenantId(), parsedRecordDto.getRecordType());
return mappingParametersProvider.get(snapshotId, params).compose(mappingParameters -> mappingRuleCache.get(cacheKey).compose(rulesOptional -> {
if (rulesOptional.isPresent()) {
return updateRecord(parsedRecordDto, snapshotId, mappingParameters, rulesOptional.get(), params);
} else {
var message = format("Can not send %s event, no mapping rules found for tenant %s", QM_RECORD_UPDATED.name(), params.getTenantId());
log.error(message);
return failedFuture(message);
}
}));
}
use of org.folio.rest.jaxrs.model.ParsedRecordDto in project mod-inventory by folio-org.
the class QuickMarcKafkaHandlerTest method shouldSendErrorEventWhenFailedToFetchRecordFromStorage.
@Test
public void shouldSendErrorEventWhenFailedToFetchRecordFromStorage(TestContext context) throws InterruptedException {
// given
Async async = context.async();
Map<String, String> payload = new HashMap<>();
payload.put("RECORD_TYPE", "MARC_AUTHORITY");
payload.put("MARC_AUTHORITY", Json.encode(authorityRecord));
payload.put("MAPPING_RULES", authorityMappingRules.encode());
payload.put("MAPPING_PARAMS", new JsonObject().encode());
payload.put("PARSED_RECORD_DTO", Json.encode(new ParsedRecordDto().withRecordType(ParsedRecordDto.RecordType.MARC_AUTHORITY).withRelatedRecordVersion("1")));
Event event = new Event().withId("01").withEventPayload(Json.encode(payload));
String expectedKafkaRecordKey = "test_key";
when(kafkaRecord.key()).thenReturn(expectedKafkaRecordKey);
when(kafkaRecord.value()).thenReturn(Json.encode(event));
doAnswer(invocationOnMock -> {
Consumer<Failure> failureHandler = invocationOnMock.getArgument(2);
failureHandler.accept(new Failure("Unexpected failure", 500));
return null;
}).when(mockedAuthorityRecordCollection).findById(anyString(), any(), any());
// when
Future<String> future = handler.handle(kafkaRecord);
// then
String observeTopic = formatTopicName(kafkaConfig.getEnvId(), getDefaultNameSpace(), TENANT_ID, QM_ERROR.name());
cluster.observeValues(ObserveKeyValues.on(observeTopic, 1).observeFor(30, TimeUnit.SECONDS).build());
future.onComplete(ar -> {
context.assertTrue(ar.succeeded());
context.assertEquals(expectedKafkaRecordKey, ar.result());
async.complete();
});
}
use of org.folio.rest.jaxrs.model.ParsedRecordDto in project mod-inventory by folio-org.
the class QuickMarcKafkaHandlerTest method shouldSendErrorEventWhenRecordIsNotExistInStorage.
@Test
public void shouldSendErrorEventWhenRecordIsNotExistInStorage(TestContext context) throws InterruptedException {
// given
Async async = context.async();
Map<String, String> payload = new HashMap<>();
payload.put("RECORD_TYPE", "MARC_AUTHORITY");
payload.put("MARC_AUTHORITY", Json.encode(authorityRecord));
payload.put("MAPPING_RULES", authorityMappingRules.encode());
payload.put("MAPPING_PARAMS", new JsonObject().encode());
payload.put("PARSED_RECORD_DTO", Json.encode(new ParsedRecordDto().withRecordType(ParsedRecordDto.RecordType.MARC_AUTHORITY).withRelatedRecordVersion("1")));
Event event = new Event().withId("01").withEventPayload(Json.encode(payload));
String expectedKafkaRecordKey = "test_key";
when(kafkaRecord.key()).thenReturn(expectedKafkaRecordKey);
when(kafkaRecord.value()).thenReturn(Json.encode(event));
doAnswer(invocationOnMock -> {
Consumer<Success<Authority>> successHandler = invocationOnMock.getArgument(1);
successHandler.accept(new Success<>(null));
return null;
}).when(mockedAuthorityRecordCollection).findById(anyString(), any(), any());
// when
Future<String> future = handler.handle(kafkaRecord);
// then
String observeTopic = formatTopicName(kafkaConfig.getEnvId(), getDefaultNameSpace(), TENANT_ID, QM_ERROR.name());
cluster.observeValues(ObserveKeyValues.on(observeTopic, 1).observeFor(30, TimeUnit.SECONDS).build());
future.onComplete(ar -> {
context.assertTrue(ar.succeeded());
context.assertEquals(expectedKafkaRecordKey, ar.result());
async.complete();
});
}
Aggregations