use of org.folio.rest.jaxrs.model.ErrorRecord in project mod-source-record-manager by folio-org.
the class RecordsPublishingServiceImpl method sendRecords.
private Future<Boolean> sendRecords(List<Record> createdRecords, JobExecution jobExecution, OkapiConnectionParams params, String eventType) {
Promise<Boolean> promise = Promise.promise();
List<Future<Boolean>> futures = new ArrayList<>();
List<Record> failedRecords = new ArrayList<>();
ProfileSnapshotWrapper profileSnapshotWrapper = new ObjectMapper().convertValue(jobExecution.getJobProfileSnapshotWrapper(), ProfileSnapshotWrapper.class);
for (Record record : createdRecords) {
String key = String.valueOf(indexer.incrementAndGet() % maxDistributionNum);
try {
if (isRecordReadyToSend(record)) {
DataImportEventPayload payload = prepareEventPayload(record, profileSnapshotWrapper, params, eventType);
params.getHeaders().set(RECORD_ID_HEADER, record.getId());
params.getHeaders().set(USER_ID_HEADER, jobExecution.getUserId());
futures.add(sendEventToKafka(params.getTenantId(), Json.encode(payload), eventType, KafkaHeaderUtils.kafkaHeadersFromMultiMap(params.getHeaders()), kafkaConfig, key));
}
} catch (Exception e) {
LOGGER.error("Error publishing event with record id: {}", record.getId(), e);
record.setErrorRecord(new ErrorRecord().withContent(record.getRawRecord()).withDescription(e.getMessage()));
failedRecords.add(record);
}
}
if (CollectionUtils.isNotEmpty(failedRecords)) {
futures.add(Future.failedFuture(new RecordsPublishingException(String.format("Failed to process %s records", failedRecords.size()), failedRecords)));
}
GenericCompositeFuture.join(futures).onComplete(ar -> {
if (ar.failed()) {
LOGGER.error("Error publishing events with records", ar.cause());
promise.fail(ar.cause());
return;
}
promise.complete(true);
});
return promise.future();
}
use of org.folio.rest.jaxrs.model.ErrorRecord in project mod-source-record-manager by folio-org.
the class ChangeEngineServiceImpl method populateError.
private void populateError(Record record, JobExecution jobExecution, OkapiConnectionParams okapiParams) {
var eventPayload = getDataImportPayload(record, jobExecution, okapiParams);
eventPayload.getContext().put(RECORD_ID_HEADER, record.getId());
var key = String.valueOf(indexer.incrementAndGet() % maxDistributionNum);
LOGGER.error(HOLDINGS_004_TAG_ERROR_MESSAGE);
record.setParsedRecord(null);
record.setErrorRecord(new ErrorRecord().withContent(record.getRawRecord().getContent()).withDescription(new JsonObject().put(MESSAGE_KEY, HOLDINGS_004_TAG_ERROR_MESSAGE).encode()));
var kafkaHeaders = KafkaHeaderUtils.kafkaHeadersFromMultiMap(okapiParams.getHeaders());
kafkaHeaders.add(new KafkaHeaderImpl(RECORD_ID_HEADER, record.getId()));
sendEventToKafka(okapiParams.getTenantId(), Json.encode(eventPayload), DI_ERROR.value(), kafkaHeaders, kafkaConfig, key).onFailure(th -> LOGGER.error("Error publishing DI_ERROR event for MARC Holdings record with id {}", record.getId(), th));
}
use of org.folio.rest.jaxrs.model.ErrorRecord in project mod-source-record-manager by folio-org.
the class ChangeEngineServiceImpl method postProcessMarcHoldingsRecord.
private void postProcessMarcHoldingsRecord(Record record, InitialRecord rawRecord) {
if (isBlank(getControlFieldValue(record, TAG_004))) {
LOGGER.error(HOLDINGS_004_TAG_ERROR_MESSAGE);
record.setParsedRecord(null);
record.setErrorRecord(new ErrorRecord().withContent(rawRecord).withDescription(new JsonObject().put(MESSAGE_KEY, HOLDINGS_004_TAG_ERROR_MESSAGE).encode()));
}
}
use of org.folio.rest.jaxrs.model.ErrorRecord in project mod-source-record-manager by folio-org.
the class RawMarcChunkConsumersVerticleTest method shouldCreateErrorRecordsWhenRecordNotParsed.
@Test
public void shouldCreateErrorRecordsWhenRecordNotParsed() throws InterruptedException {
// given
SendKeyValues<String, String> request = prepareWithSpecifiedRecord(JobProfileInfo.DataType.MARC, RecordsMetadata.ContentType.MARC_RAW, "errorPayload");
// when
kafkaCluster.send(request);
// then
Event obtainedEvent = checkEventWithTypeSent(DI_RAW_RECORDS_CHUNK_PARSED);
RecordCollection recordCollection = Json.decodeValue(obtainedEvent.getEventPayload(), RecordCollection.class);
assertEquals(1, recordCollection.getRecords().size());
ErrorRecord errorRecord = recordCollection.getRecords().get(0).getErrorRecord();
assertTrue(errorRecord.getDescription().contains("org.marc4j.MarcException"));
}
use of org.folio.rest.jaxrs.model.ErrorRecord in project mod-source-record-storage by folio-org.
the class RecordDaoImpl method insertOrUpdateParsedRecord.
private Future<ParsedRecord> insertOrUpdateParsedRecord(ReactiveClassicGenericQueryExecutor txQE, Record record) {
try {
// attempt to format record to validate
RecordType recordType = toRecordType(record.getRecordType().name());
recordType.formatRecord(record);
return ParsedRecordDaoUtil.save(txQE, record.getParsedRecord(), ParsedRecordDaoUtil.toRecordType(record)).map(parsedRecord -> {
record.withLeaderRecordStatus(ParsedRecordDaoUtil.getLeaderStatus(record.getParsedRecord()));
return parsedRecord;
});
} catch (Exception e) {
LOG.error("Couldn't format {} record", record.getRecordType(), e);
record.withErrorRecord(new ErrorRecord().withId(record.getId()).withDescription(e.getMessage()).withContent(record.getParsedRecord().getContent()));
record.withParsedRecord(null).withLeaderRecordStatus(null);
return Future.succeededFuture(null);
}
}
Aggregations