Skip to content

Commit

Permalink
MODSOURMAN-1203 Add additional validation before marc bib record savi…
Browse files Browse the repository at this point in the history
…ng (#638)

* MODSOURMAN-1203 Add additional validation before marc bib record saving

* MODSOURMAN-1203 Fix validation logic

* MODSOURMAN-1203 Add instanceHrId to MARC_BIB tests records

* MODSOURMAN-1203 Unit tests refactoring

* MODSOURMAN-1203 Unit tests refactoring

* MODSOURMAN-1203 Unit tests refactoring

* MODSOURMAN-1203 Get 001 field from decoded parsedContent

* MODSOURMAN-1203 Disable last commit changes

* MODSOURMAN-1203 Fix Snapshot delete unit test

* MODSOURMAN-1203 Disable failed test

* MODSOURMAN-1203 Fix suppress from discovery test

* MODSOURMAN-1203 Logger refactoring and add validation tests

* MODSOURMAN-1203 Upd NEWS.md

* MODSOURMAN-1203 Upd NEWS.md

* MODSOURMAN-1203 Fix imports

* MODSOURMAN-1203 Deprecate /source-storage/populate-test-marc-records endpoint

* MODSOURMAN-1203 Fix raml

* MODSOURMAN-1203 Revert shouldNotMatchRecordBy035FieldIfRecordExternalIdIsNull test

* MODSOURMAN-1203 Fix sonar warnings
  • Loading branch information
dmytrokrutii authored Aug 29, 2024
1 parent acd5570 commit a95c3a1
Show file tree
Hide file tree
Showing 31 changed files with 509 additions and 228 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* [MODSOURMAN-783](https://folio-org.atlassian.net/browse/MODSOURCE-783) Extend MARC-MARC search query to account for qualifiers
* [MODSOURCE-752](https://folio-org.atlassian.net/browse/MODSOURCE-752) Emit Domain Events For Source Records
* [MODSOURCE-795](https://folio-org.atlassian.net/browse/MODSOURCE-795) Upgrade Spring 5 to 6 by 2024-08-31
* [MODSOURMAN-1203](https://folio-org.atlassian.net/browse/MODSOURMAN-1203) Add validation on MARC_BIB record save

## 2024-03-20 5.8.0
* [MODSOURCE-733](https://issues.folio.org/browse/MODSOURCE-733) Reduce Memory Allocation of Strings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
* @deprecated This class will no longer be used to create test data
*/
@Deprecated(forRemoval = true)
public class SourceStoragePopulateTestMarcRecordsImpl implements SourceStoragePopulateTestMarcRecords {

private static final Logger LOG = LogManager.getLogger();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.folio.services.util.AdditionalFieldsUtil.TAG_999;
import static org.folio.services.util.AdditionalFieldsUtil.addFieldToMarcRecord;
import static org.folio.services.util.AdditionalFieldsUtil.getFieldFromMarcRecord;
import static org.folio.services.util.AdditionalFieldsUtil.getValueFromControlledField;

import io.reactivex.Flowable;
import io.vertx.core.AsyncResult;
Expand Down Expand Up @@ -96,8 +97,10 @@ public class RecordServiceImpl implements RecordService {
private static final String NOT_FOUND_MESSAGE = "%s with id '%s' was not found";
private static final Character DELETED_LEADER_RECORD_STATUS = 'd';
public static final String UPDATE_RECORD_DUPLICATE_EXCEPTION = "Incoming record could be a duplicate, incoming record generation should not be the same as matched record generation and the execution of job should be started after of creating the previous record generation";
public static final String EXTERNAL_IDS_MISSING_ERROR = "MARC_BIB records must contain external instance and hr id's and 001 field into parsed record";
public static final char SUBFIELD_S = 's';
public static final char INDICATOR = 'f';
private static final String TAG_001 = "001";

private final RecordDao recordDao;

Expand Down Expand Up @@ -128,6 +131,10 @@ public Future<Record> saveRecord(Record record, Map<String, String> okapiHeaders
LOG.debug("saveRecord:: Saving record with id: {} for tenant: {}", record.getId(), tenantId);
ensureRecordHasId(record);
ensureRecordHasSuppressDiscovery(record);
if (!isRecordContainsRequiredField(record)) {
LOG.error("saveRecord:: Record '{}' has invalid externalIdHolder or missing 001 field into parsed record", record.getId());
return Future.failedFuture(new BadRequestException(EXTERNAL_IDS_MISSING_ERROR));
}
return recordDao.executeInTransaction(txQE -> SnapshotDaoUtil.findById(txQE, record.getSnapshotId())
.map(optionalSnapshot -> optionalSnapshot
.orElseThrow(() -> new NotFoundException(format(SNAPSHOT_NOT_FOUND_TEMPLATE, record.getSnapshotId()))))
Expand Down Expand Up @@ -523,4 +530,17 @@ private static void update005field(Record targetRecord) {
}
}

private boolean isRecordContainsRequiredField(Record marcRecord) {
if (marcRecord.getRecordType() == Record.RecordType.MARC_BIB) {
var idsHolder = marcRecord.getExternalIdsHolder();
if (Objects.isNull(idsHolder) || StringUtils.isEmpty(getValueFromControlledField(marcRecord, TAG_001))) {
return false;
}
if (StringUtils.isEmpty(idsHolder.getInstanceId()) || StringUtils.isEmpty(idsHolder.getInstanceHrid())) {
return false;
}
}
return true;
}

}
Loading

0 comments on commit a95c3a1

Please sign in to comment.