Search in sources :

Example 6 with DublinCoreRecord

use of cz.mzk.recordmanager.server.dc.DublinCoreRecord 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;
}
Also used : DublinCoreRecord(cz.mzk.recordmanager.server.dc.DublinCoreRecord) MetadataDublinCoreRecord(cz.mzk.recordmanager.server.metadata.MetadataDublinCoreRecord) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InvalidDcException(cz.mzk.recordmanager.server.dc.InvalidDcException) FulltextKramerius(cz.mzk.recordmanager.server.model.FulltextKramerius) MetadataDublinCoreRecord(cz.mzk.recordmanager.server.metadata.MetadataDublinCoreRecord) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord)

Example 7 with DublinCoreRecord

use of cz.mzk.recordmanager.server.dc.DublinCoreRecord in project RecordManager2 by moravianlibrary.

the class IdentifiersDublinCoreRecordFunctionsTest method getISBNs.

@Test
public void getISBNs() {
    DublinCoreRecord record = new DublinCoreRecordImpl();
    record.addIdentifier("ISBN:0385424728");
    DublinCoreFunctionContext dcContext = new DublinCoreFunctionContext(record);
    List<String> isbns = functions.getISBNs(dcContext);
    Assert.assertFalse(isbns.isEmpty());
    Assert.assertEquals(isbns.get(0), "0385424728");
}
Also used : DublinCoreRecord(cz.mzk.recordmanager.server.dc.DublinCoreRecord) DublinCoreFunctionContext(cz.mzk.recordmanager.server.scripting.dc.DublinCoreFunctionContext) DublinCoreRecordImpl(cz.mzk.recordmanager.server.dc.DublinCoreRecordImpl) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Example 8 with DublinCoreRecord

use of cz.mzk.recordmanager.server.dc.DublinCoreRecord in project RecordManager2 by moravianlibrary.

the class IdentifiersDublinCoreRecordFunctions method getISBNs.

public List<String> getISBNs(DublinCoreFunctionContext dcContext) {
    List<String> isbns = new ArrayList<String>();
    DublinCoreRecord record = dcContext.record();
    for (String ident : record.getIdentifiers()) {
        Matcher matcher = ISBN_PATTERN.matcher(ident);
        if (matcher.matches()) {
            isbns.add(matcher.group(1));
        }
    }
    return isbns;
}
Also used : DublinCoreRecord(cz.mzk.recordmanager.server.dc.DublinCoreRecord) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList)

Example 9 with DublinCoreRecord

use of cz.mzk.recordmanager.server.dc.DublinCoreRecord in project RecordManager2 by moravianlibrary.

the class DublinCoreScriptFactoryTest method test.

@Test
public void test() {
    InputStream is1 = getClass().getResourceAsStream("/groovy/BaseDublinCore.groovy");
    MappingScript<DublinCoreFunctionContext> script = factory.create(is1);
    DublinCoreRecord record = new DublinCoreRecordImpl();
    record.addTitle("test");
    DublinCoreFunctionContext dcContext = new DublinCoreFunctionContext(record);
    Map<String, Object> entries = script.parse(dcContext);
    Assert.assertEquals(entries.size(), 1);
    Assert.assertEquals(entries.get("title"), "test");
}
Also used : DublinCoreRecord(cz.mzk.recordmanager.server.dc.DublinCoreRecord) DublinCoreFunctionContext(cz.mzk.recordmanager.server.scripting.dc.DublinCoreFunctionContext) DublinCoreRecordImpl(cz.mzk.recordmanager.server.dc.DublinCoreRecordImpl) InputStream(java.io.InputStream) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Aggregations

DublinCoreRecord (cz.mzk.recordmanager.server.dc.DublinCoreRecord)9 InputStream (java.io.InputStream)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 DublinCoreFunctionContext (cz.mzk.recordmanager.server.scripting.dc.DublinCoreFunctionContext)4 AbstractTest (cz.mzk.recordmanager.server.AbstractTest)2 DublinCoreRecordImpl (cz.mzk.recordmanager.server.dc.DublinCoreRecordImpl)2 MarcRecord (cz.mzk.recordmanager.server.marc.MarcRecord)2 HarvestedRecord (cz.mzk.recordmanager.server.model.HarvestedRecord)2 ArrayList (java.util.ArrayList)2 Matcher (java.util.regex.Matcher)2 Test (org.testng.annotations.Test)2 InvalidDcException (cz.mzk.recordmanager.server.dc.InvalidDcException)1 MetadataDublinCoreRecord (cz.mzk.recordmanager.server.metadata.MetadataDublinCoreRecord)1 FulltextKramerius (cz.mzk.recordmanager.server.model.FulltextKramerius)1 ImportConfiguration (cz.mzk.recordmanager.server.model.ImportConfiguration)1