Search in sources :

Example 1 with MarcRecordImpl

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

the class AdresarRecordsWriter method writeInner.

protected void writeInner(List<? extends List<Record>> items) throws Exception {
    for (List<Record> records : items) {
        for (Record currentRecord : records) {
            try {
                if (currentRecord == null) {
                    continue;
                }
                MarcRecord marc = new MarcRecordImpl(currentRecord);
                String recordId = marc.getControlField("SYS");
                HarvestedRecord hr = harvestedRecordDAO.findByIdAndHarvestConfiguration(recordId, configurationId);
                if (hr == null) {
                    hr = new HarvestedRecord(new HarvestedRecordUniqueId(configurationId, recordId));
                    hr.setFormat("marc21-xml");
                }
                hr.setUpdated(new Date());
                ByteArrayOutputStream outStream = new ByteArrayOutputStream();
                MarcWriter marcWriter = new MarcXmlWriter(outStream, true);
                marcWriter.setConverter(ISOCharConvertor.INSTANCE);
                marcWriter.write(currentRecord);
                marcWriter.close();
                hr.setRawRecord(outStream.toByteArray());
                harvestedRecordDAO.persist(hr);
            } catch (Exception e) {
                logger.warn("Error occured in processing record");
                throw e;
            }
        }
    }
}
Also used : HarvestedRecordUniqueId(cz.mzk.recordmanager.server.model.HarvestedRecord.HarvestedRecordUniqueId) MarcRecordImpl(cz.mzk.recordmanager.server.marc.MarcRecordImpl) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) MarcWriter(org.marc4j.MarcWriter) Record(org.marc4j.marc.Record) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Date(java.util.Date) MarcXmlWriter(org.marc4j.MarcXmlWriter) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord)

Example 2 with MarcRecordImpl

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

the class CosmotronUpdate996Writer method updateMarc.

private void updateMarc(HarvestedRecord parentRec, List<Cosmotron996> childRecs) {
    Record record = marcXmlParser.parseUnderlyingRecord(parentRec.getRawRecord());
    Record newRecord = new RecordImpl();
    newRecord.setLeader(record.getLeader());
    for (ControlField cf : record.getControlFields()) {
        newRecord.addVariableField(cf);
    }
    for (DataField df : record.getDataFields()) {
        // remove old fields 996
        if (!df.getTag().equals("996")) {
            newRecord.addVariableField(df);
        }
    }
    for (Cosmotron996 new996 : childRecs) {
        if (new996.getDeleted() != null)
            continue;
        MarcRecord marcRecord996 = parseMarcRecord(new996.getRawRecord());
        for (DataField df : get996(marcRecord996)) {
            newRecord.addVariableField(df);
        }
    }
    parentRec.setRawRecord(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) Cosmotron996(cz.mzk.recordmanager.server.model.Cosmotron996) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord) 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 3 with MarcRecordImpl

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

the class ImportCosmotron996RecordsWriter method write.

@Override
public void write(List<? extends List<Record>> items) throws Exception {
    if (harvestConfiguration == null) {
        harvestConfiguration = oaiHarvestConfigurationDao.get(configurationId);
    }
    for (List<Record> records : items) {
        for (Record currentRecord : records) {
            try {
                MarcRecord marc = new MarcRecordImpl(currentRecord);
                String parentId = CosmotronUtils.getParentId(marc);
                MetadataRecord metadata = metadataFactory.getMetadataRecord(marc, harvestConfiguration);
                String recordId = metadata.getUniqueId();
                Cosmotron996 c996 = cosmotron996Dao.findByIdAndHarvestConfiguration(recordId, configurationId);
                if (c996 == null) {
                    c996 = new Cosmotron996();
                    c996.setRecordId(recordId);
                    c996.setHarvestedFrom(configurationId);
                }
                c996.setParentRecordId(parentId);
                c996.setUpdated(new Date());
                ByteArrayOutputStream outStream = new ByteArrayOutputStream();
                MarcWriter marcWriter = new MarcXmlWriter(outStream, true);
                marcWriter.write(currentRecord);
                marcWriter.close();
                byte[] recordContent = outStream.toByteArray();
                if (harvestConfiguration.isInterceptionEnabled()) {
                    MarcRecordInterceptor interceptor = marcInterceptorFactory.getInterceptor(harvestConfiguration, recordId, recordContent);
                    if (interceptor != null) {
                        recordContent = interceptor.intercept();
                    }
                }
                c996.setDeleted(null);
                c996.setRawRecord(recordContent);
                cosmotron996Dao.persist(c996);
            } catch (Exception e) {
                logger.warn("Error occured in processing record");
                throw e;
            }
        }
    }
}
Also used : MarcRecordInterceptor(cz.mzk.recordmanager.server.marc.intercepting.MarcRecordInterceptor) Cosmotron996(cz.mzk.recordmanager.server.model.Cosmotron996) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Date(java.util.Date) MarcXmlWriter(org.marc4j.MarcXmlWriter) MarcRecordImpl(cz.mzk.recordmanager.server.marc.MarcRecordImpl) MarcWriter(org.marc4j.MarcWriter) MetadataRecord(cz.mzk.recordmanager.server.metadata.MetadataRecord) Record(org.marc4j.marc.Record) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) MetadataRecord(cz.mzk.recordmanager.server.metadata.MetadataRecord)

Example 4 with MarcRecordImpl

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

the class RecordUtils method sortFields.

public static Record sortFields(Record record) {
    Record newRecord = factory.newRecord();
    newRecord.setLeader(record.getLeader());
    for (ControlField cf : record.getControlFields()) {
        newRecord.addVariableField(cf);
    }
    MarcRecord marc = new MarcRecordImpl(record);
    Map<String, List<DataField>> dfMap = marc.getAllFields();
    for (String tag : new TreeSet<>(dfMap.keySet())) {
        // sorted tags
        for (DataField df : dfMap.get(tag)) {
            newRecord.addVariableField(df);
        }
    }
    return newRecord;
}
Also used : ControlField(org.marc4j.marc.ControlField) MarcRecordImpl(cz.mzk.recordmanager.server.marc.MarcRecordImpl) 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)

Example 5 with MarcRecordImpl

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

Aggregations

MarcRecordImpl (cz.mzk.recordmanager.server.marc.MarcRecordImpl)24 MarcRecord (cz.mzk.recordmanager.server.marc.MarcRecord)21 Record (org.marc4j.marc.Record)21 ControlField (org.marc4j.marc.ControlField)12 DataField (org.marc4j.marc.DataField)12 RecordImpl (cz.mzk.recordmanager.server.marc.marc4j.RecordImpl)11 HarvestedRecord (cz.mzk.recordmanager.server.model.HarvestedRecord)10 List (java.util.List)9 TreeSet (java.util.TreeSet)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 AbstractTest (cz.mzk.recordmanager.server.AbstractTest)7 InputStream (java.io.InputStream)7 HashMap (java.util.HashMap)7 JobParameter (org.springframework.batch.core.JobParameter)7 JobParameters (org.springframework.batch.core.JobParameters)7 Test (org.testng.annotations.Test)7 MarcFactoryImpl (cz.mzk.recordmanager.server.marc.marc4j.MarcFactoryImpl)6 MarcFactory (org.marc4j.marc.MarcFactory)6 JobExecution (org.springframework.batch.core.JobExecution)5 OAIHarvestConfiguration (cz.mzk.recordmanager.server.model.OAIHarvestConfiguration)4