use of org.marc4j.marc.Subfield in project RecordManager2 by moravianlibrary.
the class NlkMarcInterceptor method intercept.
@Override
public byte[] intercept() {
if (super.getRecord() == null) {
return new byte[0];
}
MarcRecord marc = new MarcRecordImpl(super.getRecord());
Record newRecord = new RecordImpl();
MarcFactory marcFactory = new MarcFactoryImpl();
newRecord.setLeader(getRecord().getLeader());
for (ControlField cf : super.getRecord().getControlFields()) {
newRecord.addVariableField(cf);
}
Map<String, List<DataField>> dfMap = marc.getAllFields();
for (String tag : new TreeSet<String>(dfMap.keySet())) {
// sorted tags
for (DataField df : dfMap.get(tag)) {
if (df.getTag().equals("996")) {
/*
* MAPPING
* if exists 996 $d, $y, $v or $i => 996 $d = "$d / $y / $v / $i / $p"
*/
DataField newDf = marcFactory.newDataField();
newDf.setTag(tag);
newDf.setIndicator1(df.getIndicator1());
newDf.setIndicator2(df.getIndicator2());
StringJoiner sj = new StringJoiner(" / ");
for (Subfield sf : df.getSubfields()) {
if (Chars.contains(new char[] { 'd', 'y', 'v', 'i' }, sf.getCode())) {
if (!sf.getData().isEmpty()) {
sj.add(sf.getData());
}
}
}
if (sj.length() > 0) {
Subfield sfp = df.getSubfield('p');
if (!sfp.getData().isEmpty()) {
sj.add(sfp.getData());
}
for (Subfield sf : df.getSubfields()) {
if (sf.getCode() == 'd') {
Subfield newSf = marcFactory.newSubfield('d');
newSf.setData(sj.toString());
newDf.addSubfield(newSf);
} else
newDf.addSubfield(sf);
}
} else
newDf = df;
processField996(newDf);
newRecord.addVariableField(newDf);
} else if (df.getTag().equals("990") || df.getTag().equals("991")) {
continue;
} else {
newRecord.addVariableField(df);
}
}
}
return new MarcRecordImpl(newRecord).export(IOFormat.XML_MARC).getBytes(StandardCharsets.UTF_8);
}
use of org.marc4j.marc.Subfield in project RecordManager2 by moravianlibrary.
the class MetadataMarcRecord method getOclcs.
@Override
public List<Oclc> getOclcs() {
List<Oclc> result = new ArrayList<>();
if (getLanguages().contains("cze"))
return result;
for (DataField df : underlayingMarc.getDataFields("035")) {
Subfield subA = df.getSubfield('a');
if (subA == null) {
continue;
}
Matcher matcher = OCLC_PATTERN.matcher(subA.getData());
if (matcher.matches() && matcher.groupCount() >= 2) {
Oclc oclc = new Oclc();
oclc.setOclcStr(matcher.group(2));
result.add(oclc);
}
}
return result;
}
use of org.marc4j.marc.Subfield in project RecordManager2 by moravianlibrary.
the class MarcRecordImpl method getSubfield.
/**
* get first code subfield from first field having given tag
* @param tag
* @param code
* @return {@link Subfield} or null
*/
protected Subfield getSubfield(String tag, char code) {
DataField field = getDataField(tag);
if (field == null) {
return null;
}
List<Subfield> subfields = getSubfields(field, new char[] { code });
return subfields.isEmpty() ? null : subfields.get(0);
}
use of org.marc4j.marc.Subfield in project RecordManager2 by moravianlibrary.
the class MarcRecordImpl method exportToAlephMarc.
protected String exportToAlephMarc() {
StringBuilder out = new StringBuilder();
out.append(record.getControlNumber());
out.append(" LDR L ");
out.append(record.getLeader().toString());
out.append('\n');
for (ControlField field : record.getControlFields()) {
out.append(record.getControlNumber());
out.append(" ");
out.append(field.getTag());
out.append(" L ");
out.append(field.getData());
out.append("\n");
}
for (DataField field : record.getDataFields()) {
out.append(record.getControlNumber());
out.append(" ");
out.append(field.getTag());
out.append(field.getIndicator1());
out.append(field.getIndicator2());
out.append(" L ");
for (Subfield sfield : field.getSubfields()) {
out.append("$$");
out.append(sfield.getCode());
out.append(sfield.getData());
}
out.append("\n");
}
return out.toString();
}
Aggregations