use of cz.mzk.recordmanager.server.dc.InvalidDcException in project RecordManager2 by moravianlibrary.
the class KrameriusFulltextProcessor method process.
@Override
public HarvestedRecord process(HarvestedRecord item) throws Exception {
logger.debug("Processing Harvested Record: " + item.toString() + " uniqueId: " + item.getUniqueId());
String policy;
String model;
// read complete HarvestedRecord using DAO
HarvestedRecord rec = recordDao.findByIdAndHarvestConfiguration(item.getUniqueId().getRecordId(), confId);
InputStream is = new ByteArrayInputStream(rec.getRawRecord());
// get Kramerius policy from record
try {
DublinCoreRecord dcRecord = parser.parseRecord(is);
MetadataDublinCoreRecord mdrc = new MetadataDublinCoreRecord(dcRecord);
policy = mdrc.getPolicyKramerius();
model = mdrc.getModelKramerius();
} catch (InvalidDcException e) {
logger.warn("InvalidDcException for record with id:" + item.getUniqueId());
logger.warn(e.getMessage());
// doesn't do anything, just returns rec from DAO and writes a message into log
return rec;
}
// modify read HarvestedRecord only if following condition is fulfilled
if (policy.equals("public") || downloadPrivateFulltexts) {
logger.debug("Processor: privacy condition fulfilled, reading pages");
String rootUuid = rec.getUniqueId().getRecordId();
List<FulltextKramerius> pages;
if (model.equals("periodical")) {
logger.info("Using (periodical) fultexter \"for root\" for uuid " + rootUuid + ".");
pages = fulltexter.getFulltextForRoot(rootUuid);
} else {
logger.info("Using (monograph/default) fultexter \"for parent\" for uuid " + rootUuid + ".");
pages = fulltexter.getFulltextObjects(rootUuid);
}
// if we got empty list in pages => do nothing, return original record
if (pages.isEmpty()) {
return rec;
}
// delete old FulltextKramerius from database before adding new ones
fmDao.deleteFulltext(rec.getId());
rec.setFulltextKramerius(pages);
} else {
logger.debug("Processor: privacy condition is NOT fulfilled, skipping record");
}
return rec;
}
use of cz.mzk.recordmanager.server.dc.InvalidDcException in project RecordManager2 by moravianlibrary.
the class HarvestedRecordWriter method writeRecord.
public void writeRecord(HarvestedRecord record) {
if (record == null) {
return;
}
if (!record.getShouldBeProcessed()) {
recordDao.updateTimestampOnly(record);
return;
}
if (record.getDeleted() == null) {
try {
if (record.getId() == null) {
recordDao.persist(record);
}
dedupKeysParser.parse(record);
if (record.getHarvestedFrom().isFilteringEnabled() && !record.getShouldBeProcessed()) {
logger.debug("Filtered record: " + record.getUniqueId());
record.setDeleted(new Date());
}
} catch (DedupKeyParserException dkpe) {
logger.error("Dedup keys could not be generated for {}, exception thrown.", record, dkpe);
} catch (InvalidMarcException ime) {
logger.warn("Skipping record due to invalid MARC {}", record.getUniqueId());
} catch (InvalidDcException dce) {
logger.warn("Skipping record due to invalid DublinCore {}", record.getUniqueId());
}
} else {
// deleted records by institution - drop dedup kyes, metadata
recordDao.dropDedupKeys(record);
record.setRawRecord(new byte[0]);
record.setDedupKeysHash("");
record.setNextDedupFlag(true);
}
recordDao.persist(record);
}
Aggregations