Search in sources :

Example 6 with ImportConfiguration

use of cz.mzk.recordmanager.server.model.ImportConfiguration in project RecordManager2 by moravianlibrary.

the class AbstractMeshVizFields method getEnrichingValues.

@Override
protected List<String> getEnrichingValues(String key, String enrichingField) {
    if (config == null) {
        List<ImportConfiguration> configs = configDao.findByIdPrefix(Constants.PREFIX_MESH);
        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 && df.getSubfield('7') != null && df.getSubfield('7').getData().startsWith("cze")) {
                    results.add(df.getSubfield('a').getData());
                }
            }
            if (!results.isEmpty()) {
                results = Collections.unmodifiableList(results);
                cache.put(key, results);
                return new ArrayList<>(results);
            }
        }
    }
    return null;
}
Also used : DataField(org.marc4j.marc.DataField) ByteArrayInputStream(java.io.ByteArrayInputStream) TezaurusRecord(cz.mzk.recordmanager.server.model.TezaurusRecord) ArrayList(java.util.ArrayList) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) ArrayList(java.util.ArrayList) List(java.util.List) ImportConfiguration(cz.mzk.recordmanager.server.model.ImportConfiguration)

Example 7 with ImportConfiguration

use of cz.mzk.recordmanager.server.model.ImportConfiguration in project RecordManager2 by moravianlibrary.

the class ImportConfigurationDAOTest method getNLK.

@Test
public void getNLK() {
    ImportConfiguration importConf = importConfigurationDao.get(301L);
    Assert.assertNotNull(importConf);
    Assert.assertEquals(importConf.getHarvestFrequency(), null);
}
Also used : ImportConfiguration(cz.mzk.recordmanager.server.model.ImportConfiguration) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Example 8 with ImportConfiguration

use of cz.mzk.recordmanager.server.model.ImportConfiguration in project RecordManager2 by moravianlibrary.

the class ImportConfigurationDAOTest method getMZK.

@Test
public void getMZK() {
    ImportConfiguration importConf = importConfigurationDao.get(300L);
    Assert.assertNotNull(importConf);
    Assert.assertEquals(importConf.getHarvestFrequency(), HarvestFrequency.DAILY);
}
Also used : ImportConfiguration(cz.mzk.recordmanager.server.model.ImportConfiguration) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Example 9 with ImportConfiguration

use of cz.mzk.recordmanager.server.model.ImportConfiguration in project RecordManager2 by moravianlibrary.

the class ImportConfigurationDAOTest method persist.

@Test
public void persist() {
    OAIHarvestConfiguration importConf = new OAIHarvestConfiguration();
    importConf.setLibrary(libraryDao.get(100L));
    importConf.setContact(contactPersonDao.get(200L));
    importConf.setUrl("http://aleph.mzk.cz/OAI");
    importConf.setHarvestFrequency(HarvestFrequency.WEEKLY);
    importConfigurationDao.persist(importConf);
    ImportConfiguration importConfFromDB = importConfigurationDao.get(importConf.getId());
    Assert.assertNotNull(importConfFromDB);
    Assert.assertEquals(importConfFromDB.getHarvestFrequency(), HarvestFrequency.WEEKLY);
}
Also used : OAIHarvestConfiguration(cz.mzk.recordmanager.server.model.OAIHarvestConfiguration) ImportConfiguration(cz.mzk.recordmanager.server.model.ImportConfiguration) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Example 10 with ImportConfiguration

use of cz.mzk.recordmanager.server.model.ImportConfiguration in project RecordManager2 by moravianlibrary.

the class MarcXmlDedupKeyParserTest method parseCorrectRecord.

@Test
public void parseCorrectRecord() throws Exception {
    InputStream is = this.getClass().getResourceAsStream("/records/marcxml/MZK01-001439241.xml");
    ImportConfiguration ic = importConfDao.get(300L);
    HarvestedRecordUniqueId id = new HarvestedRecordUniqueId(ic, "1");
    HarvestedRecord record = new HarvestedRecord(id);
    record.setHarvestedFrom(ic);
    record.setFormat("marc21-xml");
    byte[] rawRecord = ByteStreams.toByteArray(is);
    record.setRawRecord(rawRecord);
    record.setId(1L);
    parser.parse(record);
    Assert.assertTrue(record.getIsbns().size() > 0);
    Assert.assertEquals(record.getIsbns().get(0).getIsbn(), EXPECTED_ISBN);
    Assert.assertEquals(record.getTitles().size(), 1);
    Assert.assertEquals(record.getTitles().get(0).getTitleStr(), EXPECTED_TITLE);
    Assert.assertEquals(record.getPhysicalFormats().size(), 1);
    Assert.assertEquals(record.getPhysicalFormats().get(0).getName(), HarvestedRecordFormatEnum.BOOKS.name());
    Assert.assertEquals(record.getPublicationYear(), new Long(2014));
    Assert.assertEquals(record.getAuthorAuthKey(), EXPECTED_AUTHORAUTHKEY);
    Assert.assertEquals(record.getAuthorString(), EXPECTED_AUTHORSTRING);
    Assert.assertEquals(record.getScale(), EXPECTED_SCALE);
    Assert.assertEquals(record.getUuid(), EXPECTED_UUID);
    Assert.assertEquals(record.getIssnSeries(), EXPECTED_ISSNSERIES);
    Assert.assertEquals(record.getIssnSeriesOrder(), EXPECTED_ISSNSERIESORDER);
}
Also used : HarvestedRecordUniqueId(cz.mzk.recordmanager.server.model.HarvestedRecord.HarvestedRecordUniqueId) InputStream(java.io.InputStream) ImportConfiguration(cz.mzk.recordmanager.server.model.ImportConfiguration) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Aggregations

ImportConfiguration (cz.mzk.recordmanager.server.model.ImportConfiguration)10 AbstractTest (cz.mzk.recordmanager.server.AbstractTest)4 Test (org.testng.annotations.Test)4 MarcRecord (cz.mzk.recordmanager.server.marc.MarcRecord)3 HarvestedRecord (cz.mzk.recordmanager.server.model.HarvestedRecord)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 HarvestedRecordUniqueId (cz.mzk.recordmanager.server.model.HarvestedRecord.HarvestedRecordUniqueId)2 TezaurusRecord (cz.mzk.recordmanager.server.model.TezaurusRecord)2 InputStream (java.io.InputStream)2 DataField (org.marc4j.marc.DataField)2 ImportConfigurationDto (cz.mzk.recordmanager.api.model.configurations.ImportConfigurationDto)1 DublinCoreRecord (cz.mzk.recordmanager.server.dc.DublinCoreRecord)1 Inspiration (cz.mzk.recordmanager.server.model.Inspiration)1 OAIHarvestConfiguration (cz.mzk.recordmanager.server.model.OAIHarvestConfiguration)1 Date (java.util.Date)1 Matcher (java.util.regex.Matcher)1 Transactional (org.springframework.transaction.annotation.Transactional)1