Search in sources :

Example 1 with HarvestedRecord

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

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

the class DedupSimpleKeysStepWriter method write.

@Override
public void write(List<? extends List<HarvestedRecord>> arg0) throws Exception {
    for (List<HarvestedRecord> hrList : arg0) {
        for (HarvestedRecord hr : hrList) {
            // check whether is need to store current record
            if (checkIfUpdateIsNeeded(hr)) {
                String query = "UPDATE harvested_record SET dedup_record_id = ? WHERE id = ? ";
                sessionFactory.getCurrentSession().createSQLQuery(query).setLong(0, hr.getDedupRecord().getId()).setLong(1, hr.getId()).executeUpdate();
            }
            totalCount++;
            logProgress(false);
        }
    }
    sessionFactory.getCurrentSession().flush();
    sessionFactory.getCurrentSession().clear();
}
Also used : HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord)

Example 3 with HarvestedRecord

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

the class HarvestedRecordWriter method write.

@Override
public void write(List<? extends List<HarvestedRecord>> records) throws Exception {
    for (List<HarvestedRecord> list : records) {
        for (HarvestedRecord record : list) {
            writeRecord(record);
        }
    }
    sessionFactory.getCurrentSession().flush();
    sessionFactory.getCurrentSession().clear();
}
Also used : HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord)

Example 4 with HarvestedRecord

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

the class OAIItemProcessor method createHarvestedRecord.

protected HarvestedRecord createHarvestedRecord(OAIRecord record) throws TransformerException {
    String recordId = idExtractor.extract(record.getHeader().getIdentifier());
    HarvestedRecord rec = recordDao.findByIdAndHarvestConfiguration(recordId, configuration);
    boolean deleted = record.getHeader().isDeleted() || record.getMetadata().getElement().getTagName().equals(METADATA_ERROR);
    byte[] recordContent = (deleted) ? null : asByteArray(record.getMetadata().getElement());
    if (recordContent != null && configuration.isInterceptionEnabled()) {
        MarcRecordInterceptor interceptor = marcInterceptorFactory.getInterceptor(configuration, recordId, recordContent);
        if (interceptor != null) {
            // in case of invalid MARC is error processed later
            recordContent = interceptor.intercept();
        }
    }
    if (rec == null) {
        // create new record
        HarvestedRecordUniqueId id = new HarvestedRecordUniqueId(configuration, recordId);
        rec = new HarvestedRecord(id);
        rec.setHarvestedFrom(configuration);
        rec.setFormat(format);
    } else if ((deleted && rec.getDeleted() != null && (rec.getRawRecord() == null || rec.getRawRecord().length == 0)) || Arrays.equals(recordContent, rec.getRawRecord())) {
        rec.setUpdated(new Date());
        rec.setShouldBeProcessed(false);
        // no change in record
        return rec;
    }
    rec.setShouldBeProcessed(true);
    rec.setUpdated(new Date());
    if (record.getHeader().getDatestamp() != null) {
        rec.setHarvested(record.getHeader().getDatestamp());
    }
    if (record.getHeader().getDatestamp() != null) {
        rec.setTemporalOldOaiTimestamp(rec.getOaiTimestamp());
        rec.setOaiTimestamp(record.getHeader().getDatestamp());
    }
    if (deleted) {
        rec.setDeleted(new Date());
        rec.setRawRecord(new byte[0]);
        return rec;
    } else {
        rec.setDeleted(null);
        rec.setRawRecord(recordContent);
    }
    return rec;
}
Also used : MarcRecordInterceptor(cz.mzk.recordmanager.server.marc.intercepting.MarcRecordInterceptor) HarvestedRecordUniqueId(cz.mzk.recordmanager.server.model.HarvestedRecord.HarvestedRecordUniqueId) Date(java.util.Date) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord)

Example 5 with HarvestedRecord

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

Aggregations

HarvestedRecord (cz.mzk.recordmanager.server.model.HarvestedRecord)60 Test (org.testng.annotations.Test)20 InputStream (java.io.InputStream)19 ByteArrayInputStream (java.io.ByteArrayInputStream)18 AbstractTest (cz.mzk.recordmanager.server.AbstractTest)16 HashMap (java.util.HashMap)16 MarcRecord (cz.mzk.recordmanager.server.marc.MarcRecord)15 Date (java.util.Date)14 JobParameters (org.springframework.batch.core.JobParameters)14 HarvestedRecordUniqueId (cz.mzk.recordmanager.server.model.HarvestedRecord.HarvestedRecordUniqueId)12 JobParameter (org.springframework.batch.core.JobParameter)12 MarcRecordImpl (cz.mzk.recordmanager.server.marc.MarcRecordImpl)9 Record (org.marc4j.marc.Record)9 JobExecution (org.springframework.batch.core.JobExecution)8 Job (org.springframework.batch.core.Job)6 OAIHarvestConfiguration (cz.mzk.recordmanager.server.model.OAIHarvestConfiguration)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 DedupRecord (cz.mzk.recordmanager.server.model.DedupRecord)4 FulltextKramerius (cz.mzk.recordmanager.server.model.FulltextKramerius)3