Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MODSOURMAN-1203 Add additional validation before marc bib record saving #638

Merged
merged 23 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
88a2470
MODSOURMAN-1203 Add additional validation before marc bib record saving
dmytrokrutii Aug 8, 2024
657d145
Merge branch 'master' into MODSOURMAN-1203
dmytrokrutii Aug 8, 2024
7422ad8
MODSOURMAN-1203 Fix validation logic
dmytrokrutii Aug 8, 2024
3df8fc4
MODSOURMAN-1203 Add instanceHrId to MARC_BIB tests records
dmytrokrutii Aug 9, 2024
5fd1316
MODSOURMAN-1203 Unit tests refactoring
dmytrokrutii Aug 15, 2024
a834667
Merge branch 'master' into MODSOURMAN-1203
dmytrokrutii Aug 16, 2024
158a4f0
MODSOURMAN-1203 Unit tests refactoring
dmytrokrutii Aug 16, 2024
751ecbd
MODSOURMAN-1203 Unit tests refactoring
dmytrokrutii Aug 19, 2024
9354c48
MODSOURMAN-1203 Get 001 field from decoded parsedContent
dmytrokrutii Aug 19, 2024
4b0cf16
MODSOURMAN-1203 Disable last commit changes
dmytrokrutii Aug 20, 2024
d4474eb
MODSOURMAN-1203 Fix Snapshot delete unit test
dmytrokrutii Aug 20, 2024
ee18907
Merge branch 'master' into MODSOURMAN-1203
dmytrokrutii Aug 20, 2024
19d9f87
MODSOURMAN-1203 Disable failed test
dmytrokrutii Aug 20, 2024
f919aa2
MODSOURMAN-1203 Fix suppress from discovery test
dmytrokrutii Aug 20, 2024
914f1d4
MODSOURMAN-1203 Logger refactoring and add validation tests
dmytrokrutii Aug 21, 2024
dc42fa4
Merge branch 'master' into MODSOURMAN-1203
dmytrokrutii Aug 21, 2024
415a84e
MODSOURMAN-1203 Upd NEWS.md
dmytrokrutii Aug 21, 2024
586b6bc
MODSOURMAN-1203 Upd NEWS.md
dmytrokrutii Aug 21, 2024
eb32c66
MODSOURMAN-1203 Fix imports
dmytrokrutii Aug 21, 2024
2a20acf
MODSOURMAN-1203 Deprecate /source-storage/populate-test-marc-records …
dmytrokrutii Aug 27, 2024
9a0a116
MODSOURMAN-1203 Fix raml
dmytrokrutii Aug 27, 2024
b514854
MODSOURMAN-1203 Revert shouldNotMatchRecordBy035FieldIfRecordExternal…
dmytrokrutii Aug 28, 2024
3df1fe8
MODSOURMAN-1203 Fix sonar warnings
dmytrokrutii Aug 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 record) {
if (record.getRecordType() == Record.RecordType.MARC_BIB) {
var idsHolder = record.getExternalIdsHolder();
if (Objects.isNull(idsHolder) || StringUtils.isEmpty(getValueFromControlledField(record, TAG_001))) {
return false;
}
if (StringUtils.isEmpty(idsHolder.getInstanceId()) || StringUtils.isEmpty(idsHolder.getInstanceHrid())) {
return false;
}
}
return true;
}

}
Loading
Loading