use of cz.mzk.recordmanager.server.marc.MarcRecord in project RecordManager2 by moravianlibrary.
the class OAIAuthItemWriter method getAuthorityCode.
protected String getAuthorityCode(byte[] rawRecord) {
if (rawRecord == null) {
return null;
}
InputStream is = new ByteArrayInputStream(rawRecord);
MarcRecord marc = marcXmlParser.parseRecord(is);
if (marc == null) {
return null;
}
return marc.getControlField("001");
}
use of cz.mzk.recordmanager.server.marc.MarcRecord in project RecordManager2 by moravianlibrary.
the class MetadataRecordFactory method getMetadataRecord.
public MetadataRecord getMetadataRecord(HarvestedRecord record) {
if (record == null) {
return null;
}
ImportConfiguration configuration = record.getHarvestedFrom();
InputStream is = new ByteArrayInputStream(record.getRawRecord());
String recordFormat = record.getFormat();
if (Constants.METADATA_FORMAT_MARC21.equals(recordFormat) || Constants.METADATA_FORMAT_XML_MARC.equals(recordFormat) || Constants.METADATA_FORMAT_MARC_CPK.equals(recordFormat) || Constants.METADATA_FORMAT_OAI_MARCXML_CPK.equals(recordFormat) || Constants.METADATA_FORMAT_MARC21E.equals(recordFormat)) {
MarcRecord marcRec = marcXmlParser.parseRecord(is);
return getMetadataRecord(marcRec, configuration);
}
if (Constants.METADATA_FORMAT_DUBLIN_CORE.equals(recordFormat) || Constants.METADATA_FORMAT_ESE.equals(recordFormat)) {
DublinCoreRecord dcRec = dcParser.parseRecord(is);
return getMetadataRecord(record, dcRec, configuration);
}
return null;
}
use of cz.mzk.recordmanager.server.marc.MarcRecord in project RecordManager2 by moravianlibrary.
the class ExportRecordsProcessor method process.
@Override
public String process(HarvestedRecordUniqueId recordId) throws Exception {
HarvestedRecord record = harvestedRecordDao.get(recordId);
try {
if (record != null && record.getRawRecord() != null && record.getRawRecord().length != 0) {
InputStream is = new ByteArrayInputStream(record.getRawRecord());
progressLogger.incrementAndLogProgress();
switch(record.getFormat()) {
case Constants.METADATA_FORMAT_MARC21:
MarcRecord marcRecord = marcXmlParser.parseRecord(is);
if (marcRecord.getDataFields(OAI_FIELD).isEmpty()) {
marcRecord.addDataField(OAI_FIELD, ' ', ' ', "a", record.getUniqueId().getRecordId());
}
return marcRecord.export(iOFormat);
case Constants.METADATA_FORMAT_DUBLIN_CORE:
case Constants.METADATA_FORMAT_ESE:
DublinCoreRecord dcRecord = dcParser.parseRecord(is);
return dcRecord.export(iOFormat);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of cz.mzk.recordmanager.server.marc.MarcRecord 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.MarcRecord 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;
}
Aggregations