Search in sources :

Example 6 with ErrorRecord

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();
}
Also used : ArrayList(java.util.ArrayList) RecordsPublishingException(org.folio.services.exceptions.RecordsPublishingException) NotFoundException(javax.ws.rs.NotFoundException) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) DataImportEventPayload(org.folio.rest.jaxrs.model.DataImportEventPayload) RecordsPublishingException(org.folio.services.exceptions.RecordsPublishingException) GenericCompositeFuture(org.folio.okapi.common.GenericCompositeFuture) Future(io.vertx.core.Future) Record(org.folio.rest.jaxrs.model.Record) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord)

Example 7 with ErrorRecord

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));
}
Also used : JsonObject(io.vertx.core.json.JsonObject) KafkaHeaderImpl(io.vertx.kafka.client.producer.impl.KafkaHeaderImpl) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord)

Example 8 with ErrorRecord

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()));
    }
}
Also used : JsonObject(io.vertx.core.json.JsonObject) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord)

Example 9 with ErrorRecord

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"));
}
Also used : RecordCollection(org.folio.rest.jaxrs.model.RecordCollection) Event(org.folio.rest.jaxrs.model.Event) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Example 10 with ErrorRecord

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);
    }
}
Also used : QueryParamUtil.toRecordType(org.folio.rest.util.QueryParamUtil.toRecordType) RecordType(org.folio.dao.util.RecordType) SQLException(java.sql.SQLException) BadRequestException(javax.ws.rs.BadRequestException) DuplicateEventException(org.folio.kafka.exception.DuplicateEventException) NotFoundException(javax.ws.rs.NotFoundException) DataAccessException(org.jooq.exception.DataAccessException) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord)

Aggregations

ErrorRecord (org.folio.rest.jaxrs.model.ErrorRecord)13 Record (org.folio.rest.jaxrs.model.Record)7 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)6 RawRecord (org.folio.rest.jaxrs.model.RawRecord)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 JsonObject (io.vertx.core.json.JsonObject)4 ArrayList (java.util.ArrayList)4 Response (io.restassured.response.Response)3 Async (io.vertx.ext.unit.Async)3 IOException (java.io.IOException)3 String.format (java.lang.String.format)3 List (java.util.List)3 Objects (java.util.Objects)3 UUID (java.util.UUID)3 Collectors (java.util.stream.Collectors)3 NotFoundException (javax.ws.rs.NotFoundException)3 AdditionalInfo (org.folio.rest.jaxrs.model.AdditionalInfo)3 ExternalIdsHolder (org.folio.rest.jaxrs.model.ExternalIdsHolder)3 RecordCollection (org.folio.rest.jaxrs.model.RecordCollection)3 SourceRecord (org.folio.rest.jaxrs.model.SourceRecord)3