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