use of org.marc4j.MarcXmlWriter in project RecordManager2 by moravianlibrary.
the class ImportRecordsWriter method writeInner.
protected void writeInner(List<? extends List<Record>> items) throws Exception {
for (List<Record> records : items) {
for (Record currentRecord : records) {
try {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
MarcWriter marcWriter = new MarcXmlWriter(outStream, true);
marcWriter.setConverter(ISOCharConvertor.INSTANCE);
marcWriter.write(currentRecord);
marcWriter.close();
// need recordId before interception
byte[] recordContent = outStream.toByteArray();
MetadataRecord metadata = parseMetadata(recordContent);
String recordId = metadata.getUniqueId();
if (regexpExtractor != null) {
recordId = regexpExtractor.extract(recordId);
}
if (harvestConfiguration.isInterceptionEnabled()) {
MarcRecordInterceptor interceptor = marcInterceptorFactory.getInterceptor(harvestConfiguration, recordId, recordContent);
if (interceptor != null) {
byte[] recordContentNew = interceptor.intercept();
if (!Arrays.equals(recordContent, recordContentNew)) {
// if record content was changed, parse metadata again
metadata = parseMetadata(recordContentNew);
// set intercepted content
recordContent = recordContentNew;
}
}
}
HarvestedRecord hr = harvestedRecordDao.findByIdAndHarvestConfiguration(recordId, configurationId);
if (hr == null) {
HarvestedRecordUniqueId id = new HarvestedRecordUniqueId(harvestConfiguration, recordId);
hr = new HarvestedRecord(id);
// TODO detect format
hr.setFormat("marc21-xml");
hr.setHarvestedFrom(harvestConfiguration);
}
hr.setUpdated(new Date());
hr.setDeleted(null);
hr.setRawRecord(recordContent);
harvestedRecordDao.persist(hr);
dedupKeysParser.parse(hr, metadata);
if (harvestConfiguration.isFilteringEnabled() && !hr.getShouldBeProcessed()) {
logger.debug("Filtered record: " + hr.getUniqueId());
hr.setDeleted(new Date());
}
harvestedRecordDao.persist(hr);
progress.incrementAndLogProgress();
} catch (Exception e) {
logger.warn("Error occured in processing record");
throw e;
}
}
}
}
use of org.marc4j.MarcXmlWriter in project RecordManager2 by moravianlibrary.
the class MarcRecordImpl method exportToXML.
protected String exportToXML() {
OutputStream stream = new ByteArrayOutputStream();
MarcXmlWriter writer = new MarcXmlWriter(stream, "UTF-8");
writer.write(record);
writer.close();
return stream.toString();
}
Aggregations