Search in sources :

Example 1 with TezaurusRecord

use of cz.mzk.recordmanager.server.model.TezaurusRecord in project RecordManager2 by moravianlibrary.

the class ImportTezaurusRecordsWriter method write.

@Override
public void write(List<? extends List<Record>> items) throws Exception {
    if (config == null) {
        config = oaiHarvestConfDao.get(confId);
    }
    for (List<Record> records : items) {
        for (Record currentRecord : records) {
            try {
                MarcRecord marc = new MarcRecordImpl(currentRecord);
                MetadataRecord metadata = metadataFactory.getMetadataRecord(marc, config);
                String recordId = metadata.getUniqueId();
                TezaurusRecord tr = tezaurusDao.findByIdAndHarvestConfiguration(recordId, config);
                if (tr == null) {
                    tr = new TezaurusRecord();
                    tr.setRecordId(recordId);
                    tr.setHarvestedFrom(config);
                }
                tr.setTezaurusKey(metadata.getTezaurusKey());
                ByteArrayOutputStream outStream = new ByteArrayOutputStream();
                MarcWriter marcWriter = new MarcXmlWriter(outStream, true);
                marcWriter.write(currentRecord);
                marcWriter.close();
                byte[] recordContent = outStream.toByteArray();
                tr.setRawRecord(recordContent);
                tezaurusDao.persist(tr);
            } catch (Exception e) {
                logger.warn("Error occured in processing record");
                throw e;
            }
        }
    }
}
Also used : MarcRecordImpl(cz.mzk.recordmanager.server.marc.MarcRecordImpl) TezaurusRecord(cz.mzk.recordmanager.server.model.TezaurusRecord) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) MarcWriter(org.marc4j.MarcWriter) MetadataRecord(cz.mzk.recordmanager.server.metadata.MetadataRecord) Record(org.marc4j.marc.Record) TezaurusRecord(cz.mzk.recordmanager.server.model.TezaurusRecord) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MetadataRecord(cz.mzk.recordmanager.server.metadata.MetadataRecord) MarcXmlWriter(org.marc4j.MarcXmlWriter)

Example 2 with TezaurusRecord

use of cz.mzk.recordmanager.server.model.TezaurusRecord 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)

Example 3 with TezaurusRecord

use of cz.mzk.recordmanager.server.model.TezaurusRecord in project RecordManager2 by moravianlibrary.

the class AbstractMeshVizFields method getEnrichingValues.

@Override
protected List<String> getEnrichingValues(String key, String enrichingField) {
    if (config == null) {
        List<ImportConfiguration> configs = configDao.findByIdPrefix(Constants.PREFIX_MESH);
        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 && df.getSubfield('7') != null && df.getSubfield('7').getData().startsWith("cze")) {
                    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

MarcRecord (cz.mzk.recordmanager.server.marc.MarcRecord)3 TezaurusRecord (cz.mzk.recordmanager.server.model.TezaurusRecord)3 ImportConfiguration (cz.mzk.recordmanager.server.model.ImportConfiguration)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 DataField (org.marc4j.marc.DataField)2 MarcRecordImpl (cz.mzk.recordmanager.server.marc.MarcRecordImpl)1 MetadataRecord (cz.mzk.recordmanager.server.metadata.MetadataRecord)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 MarcWriter (org.marc4j.MarcWriter)1 MarcXmlWriter (org.marc4j.MarcXmlWriter)1 Record (org.marc4j.marc.Record)1