use of cz.mzk.recordmanager.server.marc.marc4j.MarcFactoryImpl 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 cz.mzk.recordmanager.server.marc.marc4j.MarcFactoryImpl 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);
}
use of cz.mzk.recordmanager.server.marc.marc4j.MarcFactoryImpl in project RecordManager2 by moravianlibrary.
the class FilterCaslinRecordsWriter method write.
@Override
public void write(List<? extends HarvestedRecordUniqueId> items) throws Exception {
for (HarvestedRecordUniqueId uniqueId : items) {
try {
HarvestedRecord hr = hrDao.get(uniqueId);
if (hr == null || hr.getRawRecord().length == 0)
continue;
MarcRecord marc = marcXmlParser.parseRecord(new ByteArrayInputStream(hr.getRawRecord()));
Record record = marcXmlParser.parseUnderlyingRecord(new ByteArrayInputStream(hr.getRawRecord()));
Boolean updated = false;
Record newRecord = new RecordImpl();
MarcFactory marcFactory = new MarcFactoryImpl();
newRecord.setLeader(record.getLeader());
for (ControlField cf : record.getControlFields()) {
newRecord.addVariableField(cf);
}
Map<String, List<DataField>> dfMap = marc.getAllFields();
for (String tag : new TreeSet<String>(dfMap.keySet())) {
for (DataField df : dfMap.get(tag)) {
// add $q0 when sigla is in db
if (df.getTag().equals("996")) {
if (caslinFilter.filter(df.getSubfield('e').getData()) && (df.getSubfield('q') == null || !df.getSubfield('q').getData().equals("0"))) {
df.addSubfield(marcFactory.newSubfield('q', "0"));
updated = true;
}
}
newRecord.addVariableField(df);
}
}
hr.setRawRecord(new MarcRecordImpl(newRecord).export(IOFormat.XML_MARC).getBytes(StandardCharsets.UTF_8));
if (hr.getDeleted() == null && !mrFactory.getMetadataRecord(hr).matchFilter()) {
hr.setDeleted(new Date());
updated = true;
}
if (updated) {
hr.setUpdated(new Date());
hrDao.persist(hr);
}
} catch (Exception ex) {
logger.error(String.format("Exception thrown when filtering harvested_record with id=%s", uniqueId), ex);
}
}
}
use of cz.mzk.recordmanager.server.marc.marc4j.MarcFactoryImpl in project RecordManager2 by moravianlibrary.
the class NlkMarcInterceptor 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("996")) {
/*
* MAPPING
* if exists 996 $d, $y, $v or $i => 996 $d = "$d / $y / $v / $i / $p"
*/
DataField newDf = marcFactory.newDataField();
newDf.setTag(tag);
newDf.setIndicator1(df.getIndicator1());
newDf.setIndicator2(df.getIndicator2());
StringJoiner sj = new StringJoiner(" / ");
for (Subfield sf : df.getSubfields()) {
if (Chars.contains(new char[] { 'd', 'y', 'v', 'i' }, sf.getCode())) {
if (!sf.getData().isEmpty()) {
sj.add(sf.getData());
}
}
}
if (sj.length() > 0) {
Subfield sfp = df.getSubfield('p');
if (!sfp.getData().isEmpty()) {
sj.add(sfp.getData());
}
for (Subfield sf : df.getSubfields()) {
if (sf.getCode() == 'd') {
Subfield newSf = marcFactory.newSubfield('d');
newSf.setData(sj.toString());
newDf.addSubfield(newSf);
} else
newDf.addSubfield(sf);
}
} else
newDf = df;
processField996(newDf);
newRecord.addVariableField(newDf);
} else if (df.getTag().equals("990") || df.getTag().equals("991")) {
continue;
} else {
newRecord.addVariableField(df);
}
}
}
return new MarcRecordImpl(newRecord).export(IOFormat.XML_MARC).getBytes(StandardCharsets.UTF_8);
}
use of cz.mzk.recordmanager.server.marc.marc4j.MarcFactoryImpl in project RecordManager2 by moravianlibrary.
the class SkatMarcInterceptor 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())) {
for (DataField df : dfMap.get(tag)) {
if (df.getTag().equals("910")) {
/*
* MAPPING
* 910 a = 996e
* 910 b = 996c
* 910 r + s = 996 d
* 910x = 996w
* 910p = 996p
*/
List<Pair<Character, Character>> directMapping = new ArrayList<>();
directMapping.add(Pair.of('a', 'e'));
directMapping.add(Pair.of('b', 'c'));
directMapping.add(Pair.of('x', 'w'));
directMapping.add(Pair.of('p', 'p'));
DataField newDf = marcFactory.newDataField("996", ' ', ' ');
for (Pair<Character, Character> mapping : directMapping) {
if (df.getSubfields(mapping.getLeft()).isEmpty()) {
continue;
}
newDf.addSubfield(marcFactory.newSubfield(mapping.getRight(), df.getSubfields(mapping.getLeft()).stream().map(Subfield::getData).collect(Collectors.joining(","))));
}
String joinedContent = "";
if (df.getSubfield('r') != null) {
joinedContent += df.getSubfield('r').getData();
}
if (df.getSubfield('s') != null) {
if (!joinedContent.isEmpty())
joinedContent += ", ";
joinedContent += df.getSubfield('s').getData();
}
if (!joinedContent.isEmpty()) {
newDf.addSubfield(marcFactory.newSubfield('d', joinedContent));
}
if (df.getSubfield('a') != null && cf.filter(df.getSubfield('a').getData())) {
newDf.addSubfield(marcFactory.newSubfield('q', "0"));
}
newDf.addSubfield(marcFactory.newSubfield('s', "NZ"));
newRecord.addVariableField(newDf);
} else if (df.getTag().equals("996")) {
if ((df.getSubfield('e') != null) && (cf.filter(df.getSubfield('e').getData())) && (df.getSubfield('q') == null || !df.getSubfield('q').getData().equals("0"))) {
df.addSubfield(marcFactory.newSubfield('q', "0"));
}
newRecord.addVariableField(df);
} else {
newRecord.addVariableField(df);
}
}
}
return new MarcRecordImpl(newRecord).export(IOFormat.XML_MARC).getBytes(StandardCharsets.UTF_8);
}
Aggregations