use of cz.mzk.recordmanager.server.marc.MarcRecord in project RecordManager2 by moravianlibrary.
the class AdresarRecordsWriter method writeInner.
protected void writeInner(List<? extends List<Record>> items) throws Exception {
for (List<Record> records : items) {
for (Record currentRecord : records) {
try {
if (currentRecord == null) {
continue;
}
MarcRecord marc = new MarcRecordImpl(currentRecord);
String recordId = marc.getControlField("SYS");
HarvestedRecord hr = harvestedRecordDAO.findByIdAndHarvestConfiguration(recordId, configurationId);
if (hr == null) {
hr = new HarvestedRecord(new HarvestedRecordUniqueId(configurationId, recordId));
hr.setFormat("marc21-xml");
}
hr.setUpdated(new Date());
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
MarcWriter marcWriter = new MarcXmlWriter(outStream, true);
marcWriter.setConverter(ISOCharConvertor.INSTANCE);
marcWriter.write(currentRecord);
marcWriter.close();
hr.setRawRecord(outStream.toByteArray());
harvestedRecordDAO.persist(hr);
} 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 CosmotronRecordWriter method processAndSave.
private void processAndSave(HarvestedRecord hr) throws Exception {
if (hr.getId() == null) {
String recordId = hr.getUniqueId().getRecordId();
// save deleted record
if (hr.getDeleted() != null) {
Cosmotron996 deleted996;
if ((deleted996 = cosmotronDao.findByIdAndHarvestConfiguration(recordId, configurationId)) == null) {
// new deleted record
super.writeRecord(hr);
} else {
// delete existing 996 record
deleted996.setDeleted(new Date());
deleted996.setUpdated(new Date());
deleted996.setRawRecord(new byte[0]);
cosmotronDao.persist(deleted996);
}
return;
}
// process not deleted record
InputStream is = new ByteArrayInputStream(hr.getRawRecord());
MarcRecord mr = marcXmlParser.parseRecord(is);
String parentRecordId = CosmotronUtils.getParentId(mr);
if (parentRecordId == null) {
// new harvested_record
super.writeRecord(hr);
} else {
// new or updated 996 record
Cosmotron996 cr = cosmotronDao.findByIdAndHarvestConfiguration(recordId, configurationId);
if (cr == null) {
// create new record
cr = new Cosmotron996(recordId, configurationId);
cr.setHarvested(new Date());
}
cr.setParentRecordId(parentRecordId);
cr.setUpdated(new Date());
cr.setDeleted(null);
cr.setRawRecord(hr.getRawRecord());
if (!CosmotronUtils.existsFields996(mr)) {
// record with parent id and without fields 996
// save and set deleted value
cr.setDeleted(new Date());
cr.setParentRecordId(null);
}
cosmotronDao.persist(cr);
}
} else
// process existing harvested record
super.writeRecord(hr);
}
use of cz.mzk.recordmanager.server.marc.MarcRecord in project RecordManager2 by moravianlibrary.
the class PublishDateMarcFunctions method getPublishDateForSortingForArticles.
private String getPublishDateForSortingForArticles(MarcFunctionContext ctx) {
for (String year : ctx.record().getFields("773", "", '9')) {
if (year.length() > 4)
year = year.substring(0, 4);
if (SINGLE_YEAR_PATTERN.matcher(year).matches()) {
int yearInt = Integer.parseInt(year);
if (MIN_YEAR < yearInt && yearInt <= MAX_YEAR) {
return year;
}
}
}
MarcRecord mr = ctx.record();
String field008 = mr.getControlField("008");
if (field008 != null && field008.length() >= 12) {
String yearS = field008.substring(7, 11);
if (SINGLE_YEAR_PATTERN.matcher(yearS).matches()) {
int yearI = Integer.parseInt(yearS);
if ((1500 < yearI) && (yearI < (MAX_YEAR))) {
return yearS;
}
}
}
return null;
}
use of cz.mzk.recordmanager.server.marc.MarcRecord in project RecordManager2 by moravianlibrary.
the class PublishDateMarcFunctions method getPublishDate.
public Set<Integer> getPublishDate(MarcFunctionContext ctx) {
MarcRecord record = ctx.record();
Set<Integer> years = new TreeSet<Integer>();
years.addAll(parseRanges(getPublishDateFromFields(ctx)));
String field008 = record.getControlField("008");
years.addAll(parsePublishDateFrom008(field008));
return years;
}
use of cz.mzk.recordmanager.server.marc.MarcRecord in project RecordManager2 by moravianlibrary.
the class CosmotronUpdate996Writer method updateMarc.
private void updateMarc(HarvestedRecord parentRec, List<Cosmotron996> childRecs) {
Record record = marcXmlParser.parseUnderlyingRecord(parentRec.getRawRecord());
Record newRecord = new RecordImpl();
newRecord.setLeader(record.getLeader());
for (ControlField cf : record.getControlFields()) {
newRecord.addVariableField(cf);
}
for (DataField df : record.getDataFields()) {
// remove old fields 996
if (!df.getTag().equals("996")) {
newRecord.addVariableField(df);
}
}
for (Cosmotron996 new996 : childRecs) {
if (new996.getDeleted() != null)
continue;
MarcRecord marcRecord996 = parseMarcRecord(new996.getRawRecord());
for (DataField df : get996(marcRecord996)) {
newRecord.addVariableField(df);
}
}
parentRec.setRawRecord(new MarcRecordImpl(newRecord).export(IOFormat.XML_MARC).getBytes(StandardCharsets.UTF_8));
}
Aggregations