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;
}
}
}
}
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();
}
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();
}
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;
}
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));
}
Aggregations