use of org.marc4j.marc.Record 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 org.marc4j.marc.Record 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;
}
}
}
}
use of org.marc4j.marc.Record in project RecordManager2 by moravianlibrary.
the class DefaultMarcInterceptor method intercept.
@Override
public byte[] intercept() {
if (conf.getItemId() == null) {
MarcRecord marcRecord = new MarcRecordImpl(record);
return marcRecord.export(IOFormat.XML_MARC).getBytes(StandardCharsets.UTF_8);
}
Record newRecord = new RecordImpl();
newRecord.setLeader(record.getLeader());
for (ControlField cf : record.getControlFields()) {
newRecord.addVariableField(cf);
}
for (DataField df : record.getDataFields()) {
processField996(df);
newRecord.addVariableField(df);
}
return new MarcRecordImpl(newRecord).export(IOFormat.XML_MARC).getBytes(StandardCharsets.UTF_8);
}
use of org.marc4j.marc.Record in project RecordManager2 by moravianlibrary.
the class MzkNormsMarcInterceptor method intercept.
@Override
public byte[] intercept() {
if (super.getRecord() == null) {
return new byte[0];
}
MarcRecord marc = new MarcRecordImpl(super.getRecord());
Record newRecord = new RecordImpl();
MarcFactory marcFactory = new MarcFactoryImpl();
newRecord.setLeader(getRecord().getLeader());
for (ControlField cf : super.getRecord().getControlFields()) {
newRecord.addVariableField(cf);
}
Map<String, List<DataField>> dfMap = marc.getAllFields();
for (String tag : new TreeSet<String>(dfMap.keySet())) {
// sorted tags
for (DataField df : dfMap.get(tag)) {
// kill fields 996, 910 and 540
if (df.getTag().equals("996"))
continue;
if (df.getTag().equals("910"))
continue;
if (df.getTag().equals("540")) {
if (df.getSubfield('a').getData().contains("Normy lze objednat u pultu ve Studovně novin " + "a časopisů (2.p.) a studovat se mohou pouze ve studovně."))
continue;
}
if (df.getTag().equals("520")) {
/*
* MAPPING
* 520 a Norma je platná = 500a
*/
List<Pair<Character, Character>> directMapping = new ArrayList<>();
directMapping.add(Pair.of('a', 'a'));
DataField newDf = marcFactory.newDataField("500", ' ', ' ');
for (Pair<Character, Character> mapping : directMapping) {
Subfield sf = df.getSubfield(mapping.getLeft());
if (!sf.getData().contains("Norma je platná")) {
continue;
}
newDf.addSubfield(sf);
}
newRecord.addVariableField(newDf);
} else {
newRecord.addVariableField(df);
}
}
}
return new MarcRecordImpl(newRecord).export(IOFormat.XML_MARC).getBytes(StandardCharsets.UTF_8);
}
use of org.marc4j.marc.Record in project RecordManager2 by moravianlibrary.
the class OpenlibMarcInterceptor method intercept.
@Override
public byte[] intercept() {
if (super.getRecord() == null) {
return new byte[0];
}
MarcRecord marc = new MarcRecordImpl(super.getRecord());
Record newRecord = new RecordImpl();
MarcFactory marcFactory = new MarcFactoryImpl();
newRecord.setLeader(getRecord().getLeader());
for (ControlField cf : super.getRecord().getControlFields()) {
newRecord.addVariableField(cf);
}
Map<String, List<DataField>> dfMap = marc.getAllFields();
for (String tag : new TreeSet<String>(dfMap.keySet())) {
// sorted tags
for (DataField df : dfMap.get(tag)) {
if (df.getTag().equals("856")) {
// kill field 85641
if (df.getIndicator1() == '4' && df.getIndicator2() == '1')
continue;
if (df.getIndicator1() == '4' && df.getIndicator2() == '2') {
Subfield sf = df.getSubfield('u');
if (sf != null) {
Matcher matcher = OPENLIBRARY_URL.matcher(sf.getData());
if (matcher.matches()) {
DataField newDf = marcFactory.newDataField("856", '4', '2');
newDf.addSubfield(df.getSubfield('u'));
newDf.addSubfield(marcFactory.newSubfield('y', TEXT_856y));
newRecord.addVariableField(newDf);
} else
newRecord.addVariableField(df);
}
}
} else
newRecord.addVariableField(df);
}
}
return new MarcRecordImpl(newRecord).export(IOFormat.XML_MARC).getBytes(StandardCharsets.UTF_8);
}
Aggregations