Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* Implement common logic for marc record manipulation ([DIUTILS-8](https://folio-org.atlassian.net/browse/DIUTILS-8))

### Bug fixes
* Description ([ISSUE](https://folio-org.atlassian.net/browse/ISSUE))
* Fix IndexOutOfBoundsException on MARC 005 field replace in addOrReplaceControlField[DIUTILS-9](https://folio-org.atlassian.net/browse/DIUTILS-9)

### Tech Dept
* Restructured the repository into a multi-module Maven project: the root is now an aggregator/parent POM (`data-import-utils-parent`) and the production code moved to the new `data-import-support` module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,15 @@ private MarcFieldEditor() {
* @param replace if true, replaces an existing field with the same tag; if false, appends a new field
*/
public static void addOrReplaceControlField(Record marcRecord, String tag, String value, boolean replace) {
var newControlField = MarcFactory.newInstance().newControlField(tag, value);
if (replace) {
var currentField = (ControlField) marcRecord.getVariableField(tag);
var newControlField = MarcFactory.newInstance().newControlField(tag, value);
if (currentField != null) {
marcRecord.getControlFields().set(marcRecord.getControlFields().indexOf(currentField), newControlField);
} else {
marcRecord.addVariableField(newControlField);
ControlField existing = (ControlField) marcRecord.getVariableField(tag);
if (existing != null) {
marcRecord.removeVariableField(existing);
}
marcRecord.addVariableField(newControlField);
} else {
ControlField controlField = MarcFactory.newInstance().newControlField(tag, value);
marcRecord.addVariableField(controlField);
marcRecord.addVariableField(newControlField);
}
}

Expand Down
Loading