Search in sources :

Example 1 with InvalidMarcException

use of cz.mzk.recordmanager.server.marc.InvalidMarcException in project RecordManager2 by moravianlibrary.

the class RegenerateDedupKeysWriter method write.

@Override
public void write(List<? extends Long> ids) {
    for (Long id : ids) {
        HarvestedRecord rec = harvestedRecordDao.get(id);
        if (rec.getDedupKeysHash() != null || !rec.getHarvestedFrom().isGenerateDedupKeys() || rec.getRawRecord() == null || rec.getRawRecord().length == 0) {
            continue;
        }
        try {
            rec = dedupKeysParser.parse(rec);
            harvestedRecordDao.persist(rec);
            ++totalCount;
            logProgress();
        } catch (InvalidMarcException ime) {
            logger.warn("Invalid Marc in record: " + rec.getId());
        } catch (Exception e) {
            logger.warn("Skipping record due to error: " + e.toString());
        }
    }
}
Also used : InvalidMarcException(cz.mzk.recordmanager.server.marc.InvalidMarcException) InvalidMarcException(cz.mzk.recordmanager.server.marc.InvalidMarcException) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord)

Example 2 with InvalidMarcException

use of cz.mzk.recordmanager.server.marc.InvalidMarcException 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);
}
Also used : InvalidMarcException(cz.mzk.recordmanager.server.marc.InvalidMarcException) InvalidDcException(cz.mzk.recordmanager.server.dc.InvalidDcException) DedupKeyParserException(cz.mzk.recordmanager.server.dedup.DedupKeyParserException) Date(java.util.Date)

Example 3 with InvalidMarcException

use of cz.mzk.recordmanager.server.marc.InvalidMarcException in project RecordManager2 by moravianlibrary.

the class MarcInterceptorFactory method getInterceptor.

public MarcRecordInterceptor getInterceptor(ImportConfiguration configuration, String recordId, byte[] rawRecord) {
    String prefix = configuration.getIdPrefix();
    try {
        Record record = parseRecord(rawRecord);
        switch(prefix) {
            case Constants.PREFIX_CASLIN:
                MarcRecordInterceptor mri = new SkatMarcInterceptor(record);
                appCtx.getAutowireCapableBeanFactory().autowireBean(mri);
                return mri;
            case Constants.PREFIX_MZKNORMS:
                return new MzkNormsMarcInterceptor(record);
            case Constants.PREFIX_NLK:
                return new NlkMarcInterceptor(record, configuration, recordId);
            case Constants.PREFIX_OPENLIB:
                return new OpenlibMarcInterceptor(record);
            case Constants.PREFIX_KKVY:
                return new KkvyMarcInterceptor(record, configuration, recordId);
            case Constants.PREFIX_CBVK:
                return new CbvkMarcInterceptor(record, configuration, recordId);
            case Constants.PREFIX_BMC:
                return new BmcMarcInterceptor(record);
            case Constants.PREFIX_TDKIV:
                return new TdkivMarcInterceptor(record);
            case Constants.PREFIX_CELITEBIB:
                return new CelitebibMarcInterceptor(record);
            default:
                return new DefaultMarcInterceptor(record, configuration, recordId);
        }
    } catch (InvalidMarcException ime) {
        return null;
    }
}
Also used : InvalidMarcException(cz.mzk.recordmanager.server.marc.InvalidMarcException) Record(org.marc4j.marc.Record)

Aggregations

InvalidMarcException (cz.mzk.recordmanager.server.marc.InvalidMarcException)3 InvalidDcException (cz.mzk.recordmanager.server.dc.InvalidDcException)1 DedupKeyParserException (cz.mzk.recordmanager.server.dedup.DedupKeyParserException)1 HarvestedRecord (cz.mzk.recordmanager.server.model.HarvestedRecord)1 Date (java.util.Date)1 Record (org.marc4j.marc.Record)1