Search in sources :

Example 71 with DataField

use of org.marc4j.marc.DataField 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 72 with DataField

use of org.marc4j.marc.DataField 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 73 with DataField

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

the class MarcLineStreamReader method parseLine.

private void parseLine(Record record, String strRecord) {
    String[] arrayRec = strRecord.split("\n");
    for (String line : arrayRec) {
        String tag = line.substring(0, 3);
        Matcher matcher = LDR_PATTERN.matcher(line);
        if (matcher.find()) {
            Leader ldr;
            ldr = factory.newLeader(matcher.group(2));
            record.setLeader(ldr);
        } else if (Constants.CF_TAG_PATTERN.matcher(tag).find()) {
            record.addVariableField(factory.newControlField(tag, line.substring(4)));
        } else {
            char ind1 = line.charAt(4);
            char ind2 = line.charAt(5);
            String data = line.substring(6);
            if (data.length() > 0 && data.charAt(0) == '$') {
                DataField df = factory.newDataField(tag, ind1, ind2);
                record.addVariableField(parseDataField(df, data));
            } else {
                record.addVariableField(factory.newControlField(tag, line.substring(4)));
            }
        }
    }
}
Also used : Leader(org.marc4j.marc.Leader) DataField(org.marc4j.marc.DataField) Matcher(java.util.regex.Matcher)

Example 74 with DataField

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

Example 75 with DataField

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

the class GenerateSkatKeysProcessor method process.

@Override
public Set<SkatKey> process(Long item) throws Exception {
    Set<SkatKey> parsedKeys = new HashSet<>();
    HarvestedRecord hr = harvestedRecordDao.get(item);
    if (hr.getRawRecord() == null) {
        return parsedKeys;
    }
    MarcRecord marc = null;
    InputStream is = new ByteArrayInputStream(hr.getRawRecord());
    try {
        marc = marcXmlParser.parseRecord(is);
    } catch (Exception e) {
        return parsedKeys;
    }
    for (DataField df : marc.getDataFields("996")) {
        if (df.getSubfield('e') == null) {
            continue;
        }
        if (df.getSubfield('w') == null) {
            continue;
        }
        String sigla = df.getSubfield('e').getData();
        String recordId = df.getSubfield('w').getData();
        if (recordId.length() > 100 || sigla.length() > 20) {
            // ignore garbage
            continue;
        }
        SkatKey key = new SkatKey(new SkatKeyCompositeId(hr.getId(), sigla, recordId));
        parsedKeys.add(key);
    }
    // ignore records having not enough information
    if (parsedKeys.size() < 2) {
        return Collections.emptySet();
    }
    // find already existing keys
    Set<SkatKey> existingKeys = new HashSet<>(skatKeyDao.getSkatKeysForRecord(item));
    Set<SkatKey> newKeys = new HashSet<>();
    for (SkatKey current : parsedKeys) {
        if (existingKeys.contains(current)) {
            continue;
        }
        newKeys.add(current);
    }
    return newKeys;
}
Also used : DataField(org.marc4j.marc.DataField) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SkatKeyCompositeId(cz.mzk.recordmanager.server.model.SkatKey.SkatKeyCompositeId) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) SkatKey(cz.mzk.recordmanager.server.model.SkatKey) HashSet(java.util.HashSet) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord)

Aggregations

DataField (org.marc4j.marc.DataField)82 ArrayList (java.util.ArrayList)18 Subfield (org.marc4j.marc.Subfield)17 MarcRecord (cz.mzk.recordmanager.server.marc.MarcRecord)15 ControlField (org.marc4j.marc.ControlField)13 Record (org.marc4j.marc.Record)13 MarcRecordImpl (cz.mzk.recordmanager.server.marc.MarcRecordImpl)12 RecordImpl (cz.mzk.recordmanager.server.marc.marc4j.RecordImpl)11 List (java.util.List)11 TreeSet (java.util.TreeSet)11 Matcher (java.util.regex.Matcher)11 MarcFactory (org.marc4j.marc.MarcFactory)8 MarcFactoryImpl (cz.mzk.recordmanager.server.marc.marc4j.MarcFactoryImpl)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 NoDataException (cz.mzk.recordmanager.server.util.identifier.NoDataException)4 HarvestedRecord (cz.mzk.recordmanager.server.model.HarvestedRecord)3 IOException (java.io.IOException)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 ImportConfiguration (cz.mzk.recordmanager.server.model.ImportConfiguration)2 ShortTitle (cz.mzk.recordmanager.server.model.ShortTitle)2