Skip to content

Commit

Permalink
MODSOURMAN-1106: Fixed error counter and blank title record (#847)
Browse files Browse the repository at this point in the history
* MODSOURMAN-1106: No Content label if the title of the record is absent

* MODSOURMAN-1106: ADDED test cases for checking correctness of counter in summary

* MODSOURMAN-1106: ADDED grouping by source id in actions table
---------

Co-authored-by: yaroslav-epam <[email protected]>
  • Loading branch information
Maksat-Galymzhan and yaroslav-epam authored Jan 25, 2024
1 parent 612cfba commit 7cad088
Show file tree
Hide file tree
Showing 5 changed files with 298 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import static org.apache.commons.lang3.StringUtils.isEmpty;
import static org.folio.rest.jaxrs.model.DataImportEventTypes.DI_ERROR;
import static org.folio.rest.jaxrs.model.DataImportEventTypes.DI_INVENTORY_INSTANCE_CREATED;
import static org.folio.rest.jaxrs.model.DataImportEventTypes.DI_LOG_SRS_MARC_BIB_RECORD_UPDATED;
import static org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_BIB_RECORD_UPDATED;
import static org.folio.rest.jaxrs.model.JournalRecord.EntityType.AUTHORITY;
import static org.folio.rest.jaxrs.model.JournalRecord.EntityType.HOLDINGS;
import static org.folio.rest.jaxrs.model.JournalRecord.EntityType.INSTANCE;
Expand Down Expand Up @@ -144,8 +142,7 @@ record = Json.decodeValue(recordAsString, Record.class);
}

if (!isEmpty(entityAsString)) {
if (entityType == INSTANCE || entityType == PO_LINE || entityType == AUTHORITY ||
(entityType == MARC_BIBLIOGRAPHIC && isMarcBibUpdateEventReceived(eventPayload))) {
if (entityType == INSTANCE || entityType == PO_LINE || entityType == AUTHORITY || entityType == MARC_BIBLIOGRAPHIC) {
JsonObject entityJson = new JsonObject(entityAsString);
journalRecord.setEntityId(entityJson.getString(ID_KEY));
if (entityType == INSTANCE || entityType == PO_LINE) {
Expand Down Expand Up @@ -187,16 +184,6 @@ record = Json.decodeValue(recordAsString, Record.class);
}
}

private static boolean isMarcBibUpdateEventReceived(DataImportEventPayload eventPayload) {
if (DI_LOG_SRS_MARC_BIB_RECORD_UPDATED == DataImportEventTypes.fromValue(eventPayload.getEventType())
|| DI_SRS_MARC_BIB_RECORD_UPDATED == DataImportEventTypes.fromValue(eventPayload.getEventType())) {
return true;
}
return eventPayload.getEventsChain().stream()
.reduce((first, second) -> second)
.map(mp -> DI_SRS_MARC_BIB_RECORD_UPDATED == DataImportEventTypes.fromValue(mp)).orElse(false);
}

private static JournalRecord buildJournalRecordWithMarcBibType(JournalRecord.ActionStatus actionStatus, JournalRecord.ActionType actionType, Record currentRecord,
DataImportEventPayload eventPayload, HashMap<String, String> eventPayloadContext) {
String marcBibEntityAsString = eventPayloadContext.get(MARC_BIBLIOGRAPHIC.value());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import java.util.stream.Collectors;

import static java.lang.String.format;
import static org.apache.commons.lang3.ObjectUtils.allNotNull;
import static org.folio.rest.jaxrs.model.DataImportEventTypes.DI_INCOMING_EDIFACT_RECORD_PARSED;
import static org.folio.rest.jaxrs.model.DataImportEventTypes.DI_MARC_BIB_FOR_ORDER_CREATED;
import static org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_AUTHORITY_RECORD_CREATED;
Expand All @@ -56,6 +55,7 @@
import static org.folio.rest.jaxrs.model.Record.RecordType.MARC_BIB;
import static org.folio.rest.jaxrs.model.Record.RecordType.MARC_HOLDING;
import static org.folio.verticle.consumers.util.JobExecutionUtils.isNeedToSkip;
import static org.folio.verticle.consumers.util.MarcImportEventsHandler.NO_TITLE_MESSAGE;

@Component
@Qualifier("StoredRecordChunksKafkaHandler")
Expand Down Expand Up @@ -217,6 +217,9 @@ private JsonArray buildJournalRecords(List<Record> storedRecords, Optional<JsonO
for (Record record : storedRecords) {

if (record.getErrorRecord() == null) {
String retrievedTitleFromRecord = ParsedRecordUtil.retrieveDataByField(record.getParsedRecord(), titleFieldTag, subfieldCodes);
if (retrievedTitleFromRecord.isEmpty()) retrievedTitleFromRecord = NO_TITLE_MESSAGE;

JournalRecord journalRecord = new JournalRecord()
.withJobExecutionId(record.getSnapshotId())
.withSourceRecordOrder(record.getOrder())
Expand All @@ -226,8 +229,7 @@ private JsonArray buildJournalRecords(List<Record> storedRecords, Optional<JsonO
.withActionType(CREATE)
.withActionStatus(COMPLETED)
.withActionDate(new Date())
.withTitle(allNotNull(record.getParsedRecord(), titleFieldTag)
? ParsedRecordUtil.retrieveDataByField(record.getParsedRecord(), titleFieldTag, subfieldCodes) : null);
.withTitle(retrievedTitleFromRecord);

journalRecords.add(JsonObject.mapFrom(journalRecord));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,12 @@ private Future<JournalRecord> populateRecordTitleIfNeeded(JournalRecord journalR

return titleExtractor.apply(parsedRecord, mappingRules);
})
.map(title -> Future.succeededFuture(journalRecord.withTitle(title)))
.map(title -> {
if (title.isEmpty() || title == null) {
title = NO_TITLE_MESSAGE;
}
return Future.succeededFuture(journalRecord.withTitle(title));
})
.orElseGet(() -> Future.succeededFuture(journalRecord)));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ BEGIN
COUNT(DISTINCT(source_id)) FILTER (WHERE entity_type = 'INVOICE' AND ((action_type = 'NON_MATCH' AND action_type_max = 'NON_MATCH') OR action_status = 'ERROR')) AS total_discarded_invoices,
COUNT(DISTINCT(source_id)) FILTER (WHERE entity_type = 'INVOICE' AND action_status = 'ERROR') AS total_invoices_errors
FROM journal_records
INNER JOIN (SELECT entity_id as entity_id_max, entity_type as entity_type_max, action_status as action_status_max,(array_agg(id ORDER BY array_position(array['CREATE', 'UPDATE', 'MODIFY', 'NON_MATCH'], action_type)))[1] as id
INNER JOIN (SELECT entity_id as entity_id_max, entity_type as entity_type_max, action_status as action_status_max,(array_agg(id ORDER BY array_position(array['CREATE', 'UPDATE', 'MODIFY', 'NON_MATCH'], action_type)))[1] as id,
source_id as temp_source_id
FROM journal_records
WHERE journal_records.job_execution_id = job_id
GROUP BY entity_id, entity_type, action_status) AS actions
ON actions.id = journal_records.id
GROUP BY source_id, entity_id, entity_type, action_status) AS actions
ON actions.id = journal_records.id AND actions.temp_source_id = journal_records.source_id
INNER JOIN (SELECT (array_agg(action_type ORDER BY array_position(array['CREATE', 'UPDATE', 'MODIFY', 'NON_MATCH'], action_type)))[1] as action_type_max, source_id as source_id_max, entity_type as entity_type_max
FROM journal_records
WHERE journal_records.job_execution_id = job_id
Expand Down
Loading

0 comments on commit 7cad088

Please sign in to comment.