Search in sources :

Example 11 with ControlField

use of org.marc4j.marc.ControlField 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)

Example 12 with ControlField

use of org.marc4j.marc.ControlField in project RecordManager2 by moravianlibrary.

the class BmcMarcInterceptor method intercept.

@Override
public byte[] intercept() {
    if (super.getRecord() == null) {
        return new byte[0];
    }
    MarcRecord marc = new MarcRecordImpl(super.getRecord());
    Record newRecord = new RecordImpl();
    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)) {
            // remove field 990, 991
            if (!df.getTag().equals("990") && !df.getTag().equals("991"))
                newRecord.addVariableField(df);
        }
    }
    return new MarcRecordImpl(newRecord).export(IOFormat.XML_MARC).getBytes(StandardCharsets.UTF_8);
}
Also used : MarcRecordImpl(cz.mzk.recordmanager.server.marc.MarcRecordImpl) ControlField(org.marc4j.marc.ControlField) DataField(org.marc4j.marc.DataField) TreeSet(java.util.TreeSet) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) Record(org.marc4j.marc.Record) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) List(java.util.List) MarcRecordImpl(cz.mzk.recordmanager.server.marc.MarcRecordImpl) RecordImpl(cz.mzk.recordmanager.server.marc.marc4j.RecordImpl)

Example 13 with ControlField

use of org.marc4j.marc.ControlField in project RecordManager2 by moravianlibrary.

the class TdkivMarcInterceptor method intercept.

@Override
public byte[] intercept() {
    if (super.getRecord() == null) {
        return new byte[0];
    }
    Record newRecord = new RecordImpl();
    MarcFactory marcFactory = new MarcFactoryImpl();
    newRecord.addVariableField(marcFactory.newControlField("FMT", "VA"));
    newRecord.addVariableField(marcFactory.newControlField("003", "CZ-PrNK"));
    newRecord.addVariableField(marcFactory.newControlField("005", new SimpleDateFormat(DATE_STRING_005).format(new Date())));
    newRecord.addVariableField(marcFactory.newControlField("008", "000804|n|anznnbabn-----------n-a|a------"));
    newRecord.addVariableField(marcFactory.newDataField("040", ' ', ' ', "a", "ABA001", "b", "cze", "d", "ABA001"));
    newRecord.setLeader(getRecord().getLeader());
    for (ControlField cf : super.getRecord().getControlFields()) {
        newRecord.addVariableField(cf);
    }
    for (DataField df : super.getRecord().getDataFields()) {
        if (df.getTag().equals("DRL") && df.getSubfield('a') != null && newRecord.getControlNumberField() == null) {
            Matcher matcher = RECORD_ID.matcher(df.getSubfield('a').getData());
            if (matcher.find()) {
                newRecord.addVariableField(marcFactory.newControlField("001", matcher.group(1)));
            }
        }
        if (TAGS.containsKey(df.getTag())) {
            df.setTag(TAGS.get(df.getTag()));
        } else if (df.getTag().equals("ANG")) {
            df.setTag("750");
            df.setIndicator1('0');
            df.setIndicator2('7');
        } else if (df.getTag().equals("DRL")) {
            df = marcFactory.newDataField("856", '4', '1', "u", df.getSubfield('a').getData(), "y", TEXT_856y);
        } else
            continue;
        newRecord.addVariableField(df);
    }
    return new MarcRecordImpl(newRecord).export(IOFormat.XML_MARC).getBytes(StandardCharsets.UTF_8);
}
Also used : ControlField(org.marc4j.marc.ControlField) DataField(org.marc4j.marc.DataField) MarcRecordImpl(cz.mzk.recordmanager.server.marc.MarcRecordImpl) Matcher(java.util.regex.Matcher) Record(org.marc4j.marc.Record) MarcFactory(org.marc4j.marc.MarcFactory) MarcRecordImpl(cz.mzk.recordmanager.server.marc.MarcRecordImpl) RecordImpl(cz.mzk.recordmanager.server.marc.marc4j.RecordImpl) MarcFactoryImpl(cz.mzk.recordmanager.server.marc.marc4j.MarcFactoryImpl) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 14 with ControlField

use of org.marc4j.marc.ControlField in project RecordManager2 by moravianlibrary.

the class CbvkMarcInterceptor method intercept.

@Override
public byte[] intercept() {
    if (super.getRecord() == null) {
        return new byte[0];
    }
    MarcRecord marc = new MarcRecordImpl(super.getRecord());
    Record newRecord = new RecordImpl();
    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)) {
            // remove field 520
            if (df.getTag().equals("520"))
                continue;
            processField996(df);
            newRecord.addVariableField(df);
        }
    }
    return new MarcRecordImpl(newRecord).export(IOFormat.XML_MARC).getBytes(StandardCharsets.UTF_8);
}
Also used : MarcRecordImpl(cz.mzk.recordmanager.server.marc.MarcRecordImpl) ControlField(org.marc4j.marc.ControlField) DataField(org.marc4j.marc.DataField) TreeSet(java.util.TreeSet) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) Record(org.marc4j.marc.Record) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) List(java.util.List) MarcRecordImpl(cz.mzk.recordmanager.server.marc.MarcRecordImpl) RecordImpl(cz.mzk.recordmanager.server.marc.marc4j.RecordImpl)

Aggregations

ControlField (org.marc4j.marc.ControlField)14 DataField (org.marc4j.marc.DataField)13 MarcRecordImpl (cz.mzk.recordmanager.server.marc.MarcRecordImpl)12 Record (org.marc4j.marc.Record)12 MarcRecord (cz.mzk.recordmanager.server.marc.MarcRecord)11 RecordImpl (cz.mzk.recordmanager.server.marc.marc4j.RecordImpl)11 List (java.util.List)9 TreeSet (java.util.TreeSet)9 MarcFactoryImpl (cz.mzk.recordmanager.server.marc.marc4j.MarcFactoryImpl)6 MarcFactory (org.marc4j.marc.MarcFactory)6 Subfield (org.marc4j.marc.Subfield)4 HarvestedRecord (cz.mzk.recordmanager.server.model.HarvestedRecord)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Matcher (java.util.regex.Matcher)2 Pair (org.apache.commons.lang3.tuple.Pair)2 Cosmotron996 (cz.mzk.recordmanager.server.model.Cosmotron996)1 HarvestedRecordUniqueId (cz.mzk.recordmanager.server.model.HarvestedRecord.HarvestedRecordUniqueId)1 DataInputStream (java.io.DataInputStream)1