Search in sources :

Example 21 with Subfield

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);
}
Also used : MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) MarcFactory(org.marc4j.marc.MarcFactory) MarcRecordImpl(cz.mzk.recordmanager.server.marc.MarcRecordImpl) RecordImpl(cz.mzk.recordmanager.server.marc.marc4j.RecordImpl) MarcRecordImpl(cz.mzk.recordmanager.server.marc.MarcRecordImpl) ControlField(org.marc4j.marc.ControlField) DataField(org.marc4j.marc.DataField) TreeSet(java.util.TreeSet) Record(org.marc4j.marc.Record) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) List(java.util.List) MarcFactoryImpl(cz.mzk.recordmanager.server.marc.marc4j.MarcFactoryImpl) StringJoiner(java.util.StringJoiner) Subfield(org.marc4j.marc.Subfield)

Example 22 with Subfield

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;
}
Also used : DataField(org.marc4j.marc.DataField) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) Oclc(cz.mzk.recordmanager.server.model.Oclc) Subfield(org.marc4j.marc.Subfield)

Example 23 with Subfield

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);
}
Also used : DataField(org.marc4j.marc.DataField) Subfield(org.marc4j.marc.Subfield)

Example 24 with Subfield

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();
}
Also used : ControlField(org.marc4j.marc.ControlField) DataField(org.marc4j.marc.DataField) Subfield(org.marc4j.marc.Subfield)

Aggregations

Subfield (org.marc4j.marc.Subfield)24 DataField (org.marc4j.marc.DataField)17 ArrayList (java.util.ArrayList)8 Matcher (java.util.regex.Matcher)6 ControlField (org.marc4j.marc.ControlField)4 MarcRecord (cz.mzk.recordmanager.server.marc.MarcRecord)3 MarcRecordImpl (cz.mzk.recordmanager.server.marc.MarcRecordImpl)3 MarcFactoryImpl (cz.mzk.recordmanager.server.marc.marc4j.MarcFactoryImpl)3 RecordImpl (cz.mzk.recordmanager.server.marc.marc4j.RecordImpl)3 List (java.util.List)3 TreeSet (java.util.TreeSet)3 MarcFactory (org.marc4j.marc.MarcFactory)3 Record (org.marc4j.marc.Record)3 IOException (java.io.IOException)2 Oclc (cz.mzk.recordmanager.server.model.Oclc)1 Sigla (cz.mzk.recordmanager.server.model.Sigla)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 HashSet (java.util.HashSet)1 StringJoiner (java.util.StringJoiner)1 Pair (org.apache.commons.lang3.tuple.Pair)1