Search in sources :

Example 51 with HarvestedRecord

use of cz.mzk.recordmanager.server.model.HarvestedRecord 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)

Example 52 with HarvestedRecord

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

the class CosmotronHarvestJobTest method testCopy996ToParentRecord.

@Test
public void testCopy996ToParentRecord() throws Exception {
    reset(httpClient);
    InputStream response0 = this.getClass().getResourceAsStream("/sample/Identify.xml");
    InputStream response1 = this.getClass().getResourceAsStream("/sample/cosmotron/RecordAnd996.xml");
    InputStream response2 = this.getClass().getResourceAsStream("/sample/cosmotron/Deleted996.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);
    expect(httpClient.executeGet("http://katalog.cbvk.cz/i2/i2.ws.oai.cls?verb=ListRecords&resumptionToken=123456")).andReturn(response2);
    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("CbvkUsCat" + Constants.COSMOTRON_RECORD_ID_CHAR + "m0000002", config);
    Assert.assertNotNull(hr);
    InputStream is = new ByteArrayInputStream(hr.getRawRecord());
    Record record = marcXmlParser.parseUnderlyingRecord(is);
    MarcRecord marcRecord = new MarcRecordImpl(record);
    Assert.assertEquals(marcRecord.getDataFields("996").size(), 2);
}
Also used : OAIHarvestConfiguration(cz.mzk.recordmanager.server.model.OAIHarvestConfiguration) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) JobExecution(org.springframework.batch.core.JobExecution) MarcRecordImpl(cz.mzk.recordmanager.server.marc.MarcRecordImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) Record(org.marc4j.marc.Record) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord) 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 53 with HarvestedRecord

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

the class CosmotronHarvestJobTest method testHarvestRecords.

@Test
public void testHarvestRecords() 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 confID = 300L;
    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);
    HarvestedRecord hr = recordDao.findByIdAndHarvestConfiguration("MZK01-000213478", confID);
    Assert.assertNotNull(hr);
    InputStream is = new ByteArrayInputStream(hr.getRawRecord());
    Record record = marcXmlParser.parseUnderlyingRecord(is);
    MarcRecord marcRecord = new MarcRecordImpl(record);
    Assert.assertEquals(marcRecord.getDataFields("996").size(), 5);
}
Also used : HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) JobExecution(org.springframework.batch.core.JobExecution) MarcRecordImpl(cz.mzk.recordmanager.server.marc.MarcRecordImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) Record(org.marc4j.marc.Record) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord) 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 54 with HarvestedRecord

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

the class CosmotronHarvestJobTest method testDeletedExistsRecord.

@Test
public void testDeletedExistsRecord() 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_COSMOTRON, new JobParameters(params));
    Assert.assertEquals(exec.getExitStatus(), ExitStatus.COMPLETED);
    HarvestedRecord record = recordDao.findByIdAndHarvestConfiguration("111111", confID);
    Assert.assertNotNull(record, "Record not stored.");
    Assert.assertNotNull(record.getDeleted());
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) 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)

Example 55 with HarvestedRecord

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

the class KrameriusHarvesterNoSorting method downloadRecord.

public HarvestedRecord downloadRecord(String uuid) {
    String recordId;
    HarvestedRecordUniqueId id;
    HarvestedRecord unparsedHr;
    recordId = uuid;
    id = new HarvestedRecordUniqueId(harvestedFrom, recordId);
    unparsedHr = new HarvestedRecord(id);
    String url = createUrl(uuid);
    logger.info("Harvesting record from: " + url);
    try (InputStream is = httpClient.executeGet(url)) {
        if (is.markSupported()) {
            is.mark(Integer.MAX_VALUE);
            is.reset();
        }
        unparsedHr.setRawRecord(IOUtils.toByteArray(is));
    } catch (IOException ioe) {
        logger.error("Harvesting record from: " + url + " caused IOException!");
        logger.error(ioe.getMessage());
        return null;
    }
    // yet)
    return unparsedHr;
}
Also used : HarvestedRecordUniqueId(cz.mzk.recordmanager.server.model.HarvestedRecord.HarvestedRecordUniqueId) InputStream(java.io.InputStream) IOException(java.io.IOException) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord)

Aggregations

HarvestedRecord (cz.mzk.recordmanager.server.model.HarvestedRecord)60 Test (org.testng.annotations.Test)20 InputStream (java.io.InputStream)19 ByteArrayInputStream (java.io.ByteArrayInputStream)18 AbstractTest (cz.mzk.recordmanager.server.AbstractTest)16 HashMap (java.util.HashMap)16 MarcRecord (cz.mzk.recordmanager.server.marc.MarcRecord)15 Date (java.util.Date)14 JobParameters (org.springframework.batch.core.JobParameters)14 HarvestedRecordUniqueId (cz.mzk.recordmanager.server.model.HarvestedRecord.HarvestedRecordUniqueId)12 JobParameter (org.springframework.batch.core.JobParameter)12 MarcRecordImpl (cz.mzk.recordmanager.server.marc.MarcRecordImpl)9 Record (org.marc4j.marc.Record)9 JobExecution (org.springframework.batch.core.JobExecution)8 Job (org.springframework.batch.core.Job)6 OAIHarvestConfiguration (cz.mzk.recordmanager.server.model.OAIHarvestConfiguration)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 DedupRecord (cz.mzk.recordmanager.server.model.DedupRecord)4 FulltextKramerius (cz.mzk.recordmanager.server.model.FulltextKramerius)3