use of org.marc4j.marc.DataField in project RecordManager2 by moravianlibrary.
the class ZakonyProLidiMetadataXmlStreamReader method addField500.
private void addField500(String text, String data) throws ParseException {
if (data == null)
return;
DataField df = factory.newDataField("500", ' ', ' ');
newSubfield(df, 'a', String.format(text, SDF_500.format(SDF_ORIGIN.parse(data))));
record.addVariableField(df);
}
use of org.marc4j.marc.DataField in project RecordManager2 by moravianlibrary.
the class ZakonyProLidiMetadataXmlStreamReader method addField300.
private void addField300() {
DataField df = factory.newDataField("300", ' ', ' ');
newSubfield(df, 'a', TEXT_300A);
record.addVariableField(df);
}
use of org.marc4j.marc.DataField in project RecordManager2 by moravianlibrary.
the class ZakonyProLidiMetadataXmlStreamReader method addField245.
private void addField245() {
DataField df = factory.newDataField("245", '0', '0');
Matcher matcher = PATERN245.matcher(getAttr(ATTR_NAME_TITLE).trim());
if (matcher.matches()) {
newSubfield(df, 'a', String.format(TEXT_245, matcher.group(1), getAttr(ATTR_NAME_QUOTE), matcher.group(2)));
} else
newSubfield(df, 'a', getAttr(ATTR_NAME_TITLE));
record.addVariableField(df);
}
use of org.marc4j.marc.DataField 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 org.marc4j.marc.DataField in project RecordManager2 by moravianlibrary.
the class AbstractAgrovocVizFields method getEnrichingValues.
@Override
protected List<String> getEnrichingValues(String key, String enrichingField) {
if (config == null) {
List<ImportConfiguration> configs = configDao.findByIdPrefix(Constants.PREFIX_AGROVOC);
if (configs != null && !configs.isEmpty()) {
config = configs.get(0);
}
}
Map<String, List<String>> cache = cacheMap.get(enrichingField);
if (cache.containsKey(key)) {
return new ArrayList<>(cache.get(key));
} else {
TezaurusRecord tr = tezaurusDao.findByConfigAndSourceFieldAndName(config, "1" + enrichingField.substring(1), key);
if (tr != null) {
MarcRecord mr = marcXmlParser.parseRecord(new ByteArrayInputStream(tr.getRawRecord()));
List<String> results = new ArrayList<>();
for (DataField df : mr.getDataFields(enrichingField)) {
if (df.getSubfield('a') != null) {
results.add(df.getSubfield('a').getData());
}
}
if (!results.isEmpty()) {
results = Collections.unmodifiableList(results);
cache.put(key, results);
return new ArrayList<>(results);
}
}
}
return null;
}
Aggregations