Search in sources :

Example 36 with DataField

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

the class ZakonyProLidiMetadataXmlStreamReader method addField500.

private void addField500(String text, String data) throws ParseException {
    if (data == null)
        return;
    DataField df = factory.newDataField("500", ' ', ' ');
    newSubfield(df, 'a', String.format(text, SDF_500.format(SDF_ORIGIN.parse(data))));
    record.addVariableField(df);
}
Also used : DataField(org.marc4j.marc.DataField)

Example 37 with DataField

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

the class ZakonyProLidiMetadataXmlStreamReader method addField300.

private void addField300() {
    DataField df = factory.newDataField("300", ' ', ' ');
    newSubfield(df, 'a', TEXT_300A);
    record.addVariableField(df);
}
Also used : DataField(org.marc4j.marc.DataField)

Example 38 with DataField

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

the class ZakonyProLidiMetadataXmlStreamReader method addField245.

private void addField245() {
    DataField df = factory.newDataField("245", '0', '0');
    Matcher matcher = PATERN245.matcher(getAttr(ATTR_NAME_TITLE).trim());
    if (matcher.matches()) {
        newSubfield(df, 'a', String.format(TEXT_245, matcher.group(1), getAttr(ATTR_NAME_QUOTE), matcher.group(2)));
    } else
        newSubfield(df, 'a', getAttr(ATTR_NAME_TITLE));
    record.addVariableField(df);
}
Also used : DataField(org.marc4j.marc.DataField) Matcher(java.util.regex.Matcher)

Example 39 with DataField

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

the class FilterCaslinRecordsWriter method write.

@Override
public void write(List<? extends HarvestedRecordUniqueId> items) throws Exception {
    for (HarvestedRecordUniqueId uniqueId : items) {
        try {
            HarvestedRecord hr = hrDao.get(uniqueId);
            if (hr == null || hr.getRawRecord().length == 0)
                continue;
            MarcRecord marc = marcXmlParser.parseRecord(new ByteArrayInputStream(hr.getRawRecord()));
            Record record = marcXmlParser.parseUnderlyingRecord(new ByteArrayInputStream(hr.getRawRecord()));
            Boolean updated = false;
            Record newRecord = new RecordImpl();
            MarcFactory marcFactory = new MarcFactoryImpl();
            newRecord.setLeader(record.getLeader());
            for (ControlField cf : record.getControlFields()) {
                newRecord.addVariableField(cf);
            }
            Map<String, List<DataField>> dfMap = marc.getAllFields();
            for (String tag : new TreeSet<String>(dfMap.keySet())) {
                for (DataField df : dfMap.get(tag)) {
                    // add $q0 when sigla is in db
                    if (df.getTag().equals("996")) {
                        if (caslinFilter.filter(df.getSubfield('e').getData()) && (df.getSubfield('q') == null || !df.getSubfield('q').getData().equals("0"))) {
                            df.addSubfield(marcFactory.newSubfield('q', "0"));
                            updated = true;
                        }
                    }
                    newRecord.addVariableField(df);
                }
            }
            hr.setRawRecord(new MarcRecordImpl(newRecord).export(IOFormat.XML_MARC).getBytes(StandardCharsets.UTF_8));
            if (hr.getDeleted() == null && !mrFactory.getMetadataRecord(hr).matchFilter()) {
                hr.setDeleted(new Date());
                updated = true;
            }
            if (updated) {
                hr.setUpdated(new Date());
                hrDao.persist(hr);
            }
        } catch (Exception ex) {
            logger.error(String.format("Exception thrown when filtering harvested_record with id=%s", uniqueId), ex);
        }
    }
}
Also used : HarvestedRecordUniqueId(cz.mzk.recordmanager.server.model.HarvestedRecord.HarvestedRecordUniqueId) 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) Date(java.util.Date) ControlField(org.marc4j.marc.ControlField) DataField(org.marc4j.marc.DataField) MarcRecordImpl(cz.mzk.recordmanager.server.marc.MarcRecordImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) TreeSet(java.util.TreeSet) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) Record(org.marc4j.marc.Record) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord) List(java.util.List) MarcFactoryImpl(cz.mzk.recordmanager.server.marc.marc4j.MarcFactoryImpl) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord)

Example 40 with DataField

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

the class AbstractAgrovocVizFields method getEnrichingValues.

@Override
protected List<String> getEnrichingValues(String key, String enrichingField) {
    if (config == null) {
        List<ImportConfiguration> configs = configDao.findByIdPrefix(Constants.PREFIX_AGROVOC);
        if (configs != null && !configs.isEmpty()) {
            config = configs.get(0);
        }
    }
    Map<String, List<String>> cache = cacheMap.get(enrichingField);
    if (cache.containsKey(key)) {
        return new ArrayList<>(cache.get(key));
    } else {
        TezaurusRecord tr = tezaurusDao.findByConfigAndSourceFieldAndName(config, "1" + enrichingField.substring(1), key);
        if (tr != null) {
            MarcRecord mr = marcXmlParser.parseRecord(new ByteArrayInputStream(tr.getRawRecord()));
            List<String> results = new ArrayList<>();
            for (DataField df : mr.getDataFields(enrichingField)) {
                if (df.getSubfield('a') != null) {
                    results.add(df.getSubfield('a').getData());
                }
            }
            if (!results.isEmpty()) {
                results = Collections.unmodifiableList(results);
                cache.put(key, results);
                return new ArrayList<>(results);
            }
        }
    }
    return null;
}
Also used : DataField(org.marc4j.marc.DataField) ByteArrayInputStream(java.io.ByteArrayInputStream) TezaurusRecord(cz.mzk.recordmanager.server.model.TezaurusRecord) ArrayList(java.util.ArrayList) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) ArrayList(java.util.ArrayList) List(java.util.List) ImportConfiguration(cz.mzk.recordmanager.server.model.ImportConfiguration)

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