Search in sources :

Example 11 with OAIHarvestConfiguration

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

the class ConfigurationTest method test.

@Test
public void test() {
    OAIHarvestConfiguration oaiConf = oaiConfigDao.get(OAI_CONF_ID);
    KrameriusConfiguration kramConf = kramConfigDao.get(KRAM_CONF_ID);
    Assert.assertEquals(importConfigDao.get(OAI_CONF_ID), oaiConf);
    Assert.assertEquals(importConfigDao.get(KRAM_CONF_ID), kramConf);
    kramConfigDao.persist(kramConf);
    Assert.assertNotNull(kramConfigDao.get(KRAM_CONF_ID));
}
Also used : OAIHarvestConfiguration(cz.mzk.recordmanager.server.model.OAIHarvestConfiguration) KrameriusConfiguration(cz.mzk.recordmanager.server.model.KrameriusConfiguration) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Example 12 with OAIHarvestConfiguration

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

the class OAIHarvestJobTest method testIdentify.

@Test
public void testIdentify() throws Exception {
    reset(httpClient);
    InputStream response0 = this.getClass().getResourceAsStream("/sample/Identify.xml");
    InputStream response1 = this.getClass().getResourceAsStream("/sample/ListRecords2.xml");
    expect(httpClient.executeGet("http://aleph.mzk.cz/OAI?verb=Identify")).andReturn(response0);
    expect(httpClient.executeGet("http://aleph.mzk.cz/OAI?verb=ListRecords&metadataPrefix=marc21")).andReturn(response1);
    replay(httpClient);
    final Long configId = 300L;
    Map<String, JobParameter> params = new HashMap<>();
    params.put("configurationId", new JobParameter(configId));
    JobParameters jobParams = new JobParameters(params);
    JobExecution exec = jobExecutor.execute("oaiHarvestJob", jobParams);
    Assert.assertEquals(exec.getExitStatus(), ExitStatus.COMPLETED);
    final OAIHarvestConfiguration updatedOaiConfig = configDao.get(configId);
    // is granularity correctly read from Identify?
    Assert.assertEquals(updatedOaiConfig.getGranularity(), OAIGranularity.SECOND);
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) OAIHarvestConfiguration(cz.mzk.recordmanager.server.model.OAIHarvestConfiguration) HashMap(java.util.HashMap) InputStream(java.io.InputStream) JobParameters(org.springframework.batch.core.JobParameters) JobParameter(org.springframework.batch.core.JobParameter) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Example 13 with OAIHarvestConfiguration

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

the class OAIHarvestJobTest method testDeleteRecord.

@Test
public void testDeleteRecord() throws Exception {
    reset(httpClient);
    InputStream response0 = this.getClass().getResourceAsStream("/sample/IdentifyNonstandardGranularity.xml");
    InputStream response1 = this.getClass().getResourceAsStream("/sample/ListRecordsNLKdeleted1.xml");
    InputStream response2 = this.getClass().getResourceAsStream("/sample/ListRecordsNLKdeleted2.xml");
    expect(httpClient.executeGet("http://oai.medvik.cz/medvik2cpk/oai?verb=Identify")).andReturn(response0);
    expect(httpClient.executeGet("http://oai.medvik.cz/medvik2cpk/oai?verb=ListRecords&metadataPrefix=marc21")).andReturn(response1);
    expect(httpClient.executeGet("http://oai.medvik.cz/medvik2cpk/oai?verb=ListRecords&resumptionToken=xaiutmvy00003")).andReturn(response2);
    replay(httpClient);
    final Long confID = 301L;
    Map<String, JobParameter> params = new HashMap<>();
    params.put(Constants.JOB_PARAM_CONF_ID, new JobParameter(confID));
    JobExecution exec = jobExecutor.execute(Constants.JOB_ID_HARVEST, new JobParameters(params));
    Assert.assertEquals(exec.getExitStatus(), ExitStatus.COMPLETED);
    OAIHarvestConfiguration config = configDao.get(confID);
    HarvestedRecord record = recordDao.findByIdAndHarvestConfiguration("111111", config);
    Assert.assertNotNull(record, "Record not stored.");
    Assert.assertNotNull(record.getDeleted());
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) OAIHarvestConfiguration(cz.mzk.recordmanager.server.model.OAIHarvestConfiguration) HashMap(java.util.HashMap) InputStream(java.io.InputStream) JobParameters(org.springframework.batch.core.JobParameters) JobParameter(org.springframework.batch.core.JobParameter) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Example 14 with OAIHarvestConfiguration

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

the class ImportRecordsWriter method beforeStep.

@Override
public void beforeStep(StepExecution stepExecution) {
    try (SessionBinder session = sync.register()) {
        OAIHarvestConfiguration hc = oaiHarvestConfigurationDao.get(configurationId);
        String regex = null;
        if (hc != null) {
            regex = hc.getRegex();
            harvestConfiguration = hc;
        } else {
            DownloadImportConfiguration dic = downloadImportConfigurationDao.get(configurationId);
            if (dic != null) {
                regex = dic.getRegex();
                harvestConfiguration = dic;
            }
        }
        if (regex != null) {
            regexpExtractor = new RegexpExtractor(regex);
        }
    }
}
Also used : RegexpExtractor(cz.mzk.recordmanager.server.util.RegexpExtractor) OAIHarvestConfiguration(cz.mzk.recordmanager.server.model.OAIHarvestConfiguration) SessionBinder(cz.mzk.recordmanager.server.util.HibernateSessionSynchronizer.SessionBinder) DownloadImportConfiguration(cz.mzk.recordmanager.server.model.DownloadImportConfiguration)

Example 15 with OAIHarvestConfiguration

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

the class CosmotronHarvestJobTest method testCosmotronArticle.

@Test
public void testCosmotronArticle() throws Exception {
    reset(httpClient);
    InputStream response0 = this.getClass().getResourceAsStream("/sample/Identify.xml");
    InputStream response1 = this.getClass().getResourceAsStream("/sample/cosmotron/Article.xml");
    expect(httpClient.executeGet("http://katalog.cbvk.cz/i2/i2.ws.oai.cls?verb=Identify")).andReturn(response0);
    expect(httpClient.executeGet("http://katalog.cbvk.cz/i2/i2.ws.oai.cls?verb=ListRecords&metadataPrefix=oai_marcxml_cpk")).andReturn(response1);
    replay(httpClient);
    final Long confID = 328L;
    Map<String, JobParameter> params = new HashMap<>();
    params.put(Constants.JOB_PARAM_CONF_ID, new JobParameter(confID));
    JobExecution exec = jobExecutor.execute(Constants.JOB_ID_HARVEST_COSMOTRON, new JobParameters(params));
    Assert.assertEquals(exec.getExitStatus(), ExitStatus.COMPLETED);
    OAIHarvestConfiguration config = configDao.get(confID);
    HarvestedRecord hr = recordDao.findByIdAndHarvestConfiguration("LiUsCat_r011834", config);
    Assert.assertNotNull(hr);
    Assert.assertNull(hr.getDeleted());
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) OAIHarvestConfiguration(cz.mzk.recordmanager.server.model.OAIHarvestConfiguration) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) JobParameters(org.springframework.batch.core.JobParameters) JobParameter(org.springframework.batch.core.JobParameter) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Aggregations

OAIHarvestConfiguration (cz.mzk.recordmanager.server.model.OAIHarvestConfiguration)18 AbstractTest (cz.mzk.recordmanager.server.AbstractTest)12 Test (org.testng.annotations.Test)12 InputStream (java.io.InputStream)9 HashMap (java.util.HashMap)9 JobExecution (org.springframework.batch.core.JobExecution)9 JobParameter (org.springframework.batch.core.JobParameter)9 JobParameters (org.springframework.batch.core.JobParameters)9 ByteArrayInputStream (java.io.ByteArrayInputStream)7 HarvestedRecord (cz.mzk.recordmanager.server.model.HarvestedRecord)6 SessionBinder (cz.mzk.recordmanager.server.util.HibernateSessionSynchronizer.SessionBinder)6 MarcRecord (cz.mzk.recordmanager.server.marc.MarcRecord)4 MarcRecordImpl (cz.mzk.recordmanager.server.marc.MarcRecordImpl)4 Record (org.marc4j.marc.Record)4 Cosmotron996 (cz.mzk.recordmanager.server.model.Cosmotron996)3 DownloadImportConfiguration (cz.mzk.recordmanager.server.model.DownloadImportConfiguration)2 RegexpExtractor (cz.mzk.recordmanager.server.util.RegexpExtractor)2 ImportConfiguration (cz.mzk.recordmanager.server.model.ImportConfiguration)1 KrameriusConfiguration (cz.mzk.recordmanager.server.model.KrameriusConfiguration)1 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)1