Search in sources :

Example 11 with MarcRecord

use of cz.mzk.recordmanager.server.marc.MarcRecord 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 12 with MarcRecord

use of cz.mzk.recordmanager.server.marc.MarcRecord in project RecordManager2 by moravianlibrary.

the class MarcSolrRecordMapper method parseAsDedupRecord.

protected Map<String, Object> parseAsDedupRecord(HarvestedRecord record) {
    InputStream is = new ByteArrayInputStream(record.getRawRecord());
    MarcRecord rec = marcXmlParser.parseRecord(is);
    MappingScript<MarcFunctionContext> script = getDedupMappingScript(record);
    MarcFunctionContext ctx = new MarcFunctionContext(rec, record, metadataRecordFactory.getMetadataRecord(record));
    Map<String, Object> result = script.parse(ctx);
    return result;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) MarcFunctionContext(cz.mzk.recordmanager.server.scripting.marc.MarcFunctionContext)

Example 13 with MarcRecord

use of cz.mzk.recordmanager.server.marc.MarcRecord in project RecordManager2 by moravianlibrary.

the class ExportRecordsForClassifierProcessor method process.

@Override
public String process(HarvestedRecord.HarvestedRecordUniqueId recordId) throws Exception {
    HarvestedRecord record = harvestedRecordDao.get(recordId);
    if (record != null && record.getRawRecord().length != 0) {
        InputStream is = new ByteArrayInputStream(record.getRawRecord());
        MarcRecord marcRecord = marcXmlParser.parseRecord(is);
        if (marcRecord.getDataFields(OAI_FIELD).isEmpty()) {
            marcRecord.addDataField(OAI_FIELD, ' ', ' ', "a", record.getUniqueId().getRecordId());
        }
        return marcRecord.getDataFields("080").isEmpty() ? null : marcRecord.export(iOFormat);
    }
    return null;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord)

Example 14 with MarcRecord

use of cz.mzk.recordmanager.server.marc.MarcRecord in project RecordManager2 by moravianlibrary.

the class DefaultMarcInterceptor method intercept.

@Override
public byte[] intercept() {
    if (conf.getItemId() == null) {
        MarcRecord marcRecord = new MarcRecordImpl(record);
        return marcRecord.export(IOFormat.XML_MARC).getBytes(StandardCharsets.UTF_8);
    }
    Record newRecord = new RecordImpl();
    newRecord.setLeader(record.getLeader());
    for (ControlField cf : record.getControlFields()) {
        newRecord.addVariableField(cf);
    }
    for (DataField df : record.getDataFields()) {
        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) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) Record(org.marc4j.marc.Record) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) MarcRecordImpl(cz.mzk.recordmanager.server.marc.MarcRecordImpl) RecordImpl(cz.mzk.recordmanager.server.marc.marc4j.RecordImpl)

Example 15 with MarcRecord

use of cz.mzk.recordmanager.server.marc.MarcRecord in project RecordManager2 by moravianlibrary.

the class MzkNormsMarcInterceptor 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)) {
            // kill fields 996, 910 and 540
            if (df.getTag().equals("996"))
                continue;
            if (df.getTag().equals("910"))
                continue;
            if (df.getTag().equals("540")) {
                if (df.getSubfield('a').getData().contains("Normy lze objednat u pultu ve Studovně novin " + "a časopisů (2.p.) a studovat se mohou pouze ve studovně."))
                    continue;
            }
            if (df.getTag().equals("520")) {
                /*
					 * MAPPING
					 * 520 a Norma je platná = 500a
					 */
                List<Pair<Character, Character>> directMapping = new ArrayList<>();
                directMapping.add(Pair.of('a', 'a'));
                DataField newDf = marcFactory.newDataField("500", ' ', ' ');
                for (Pair<Character, Character> mapping : directMapping) {
                    Subfield sf = df.getSubfield(mapping.getLeft());
                    if (!sf.getData().contains("Norma je platná")) {
                        continue;
                    }
                    newDf.addSubfield(sf);
                }
                newRecord.addVariableField(newDf);
            } else {
                newRecord.addVariableField(df);
            }
        }
    }
    return new MarcRecordImpl(newRecord).export(IOFormat.XML_MARC).getBytes(StandardCharsets.UTF_8);
}
Also used : ArrayList(java.util.ArrayList) 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) ArrayList(java.util.ArrayList) List(java.util.List) MarcFactoryImpl(cz.mzk.recordmanager.server.marc.marc4j.MarcFactoryImpl) Subfield(org.marc4j.marc.Subfield) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

MarcRecord (cz.mzk.recordmanager.server.marc.MarcRecord)46 ByteArrayInputStream (java.io.ByteArrayInputStream)22 MarcRecordImpl (cz.mzk.recordmanager.server.marc.MarcRecordImpl)21 InputStream (java.io.InputStream)19 Record (org.marc4j.marc.Record)19 AbstractTest (cz.mzk.recordmanager.server.AbstractTest)15 HarvestedRecord (cz.mzk.recordmanager.server.model.HarvestedRecord)15 DataField (org.marc4j.marc.DataField)15 Test (org.testng.annotations.Test)15 List (java.util.List)13 ArrayList (java.util.ArrayList)11 TreeSet (java.util.TreeSet)11 ControlField (org.marc4j.marc.ControlField)11 RecordImpl (cz.mzk.recordmanager.server.marc.marc4j.RecordImpl)10 MarcFunctionContext (cz.mzk.recordmanager.server.scripting.marc.MarcFunctionContext)9 JobParameters (org.springframework.batch.core.JobParameters)8 HashMap (java.util.HashMap)7 JobParameter (org.springframework.batch.core.JobParameter)7 MarcFactoryImpl (cz.mzk.recordmanager.server.marc.marc4j.MarcFactoryImpl)5 MarcFactory (org.marc4j.marc.MarcFactory)5