Search in sources :

Example 31 with HarvestedRecord

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

the class KrameriusHarvesterTest method harvesterNoServerResponse.

// Kramerius Harvester without sorting
@Test
public void harvesterNoServerResponse() throws Exception {
    initHttpClientWithException();
    initSolrServerWithException();
    KrameriusHarvesterParams parameters = new KrameriusHarvesterParams();
    parameters.setUrl("http://k4.techlib.cz/search/api/v5.0");
    parameters.setMetadataStream("DC");
    KrameriusHarvester harvester = new KrameriusHarvester(httpClient, solrServerFactory, parameters, 1L);
    // 1st response with IOException => uuid list is empty
    List<String> uuids = harvester.getUuids(null);
    Assert.assertTrue(uuids.isEmpty());
    // 2nd response with SolrServerException => uuid list is empty
    uuids = harvester.getUuids(null);
    Assert.assertTrue(uuids.isEmpty());
    // 3rd response is => OK
    uuids = harvester.getUuids(null);
    Assert.assertFalse(uuids.isEmpty());
    // 1st DC download - server responds with IOException, download returns null;
    HarvestedRecord record = harvester.downloadRecord(uuids.get(0));
    Assert.assertNull(record);
    // 2nd DC download - OK
    record = harvester.downloadRecord(uuids.get(1));
    Assert.assertNotNull(record);
}
Also used : HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord) Test(org.testng.annotations.Test)

Example 32 with HarvestedRecord

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

the class KrameriusHarvesterTest method downloadRecord.

// Kramerius Harvester with sorting
@Test
public void downloadRecord() throws Exception {
    init();
    KrameriusHarvesterParams parameters = new KrameriusHarvesterParams();
    parameters.setUrl("http://k4.techlib.cz/search/api/v5.0");
    parameters.setMetadataStream("DC");
    KrameriusHarvester harvester = new KrameriusHarvester(httpClient, solrServerFactory, parameters, 1L);
    List<String> uuids = harvester.getUuids(null);
    for (String uuid : uuids) {
        HarvestedRecord record = harvester.downloadRecord(uuid);
        Assert.assertNotNull(record);
    }
}
Also used : HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord) Test(org.testng.annotations.Test)

Example 33 with HarvestedRecord

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

Example 34 with HarvestedRecord

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

the class ImportRecordsJobTest method testSimpleImportOsobnosti.

@Test
public void testSimpleImportOsobnosti() throws Exception {
    Job job = jobRegistry.getJob(Constants.JOB_ID_IMPORT);
    Map<String, JobParameter> params = new HashMap<>();
    params.put(Constants.JOB_PARAM_CONF_ID, new JobParameter(300L));
    params.put(Constants.JOB_PARAM_IN_FILE, new JobParameter(testFileOsobnosti1));
    params.put(Constants.JOB_PARAM_FORMAT, new JobParameter("osobnosti"));
    JobParameters jobParams = new JobParameters(params);
    jobLauncher.run(job, jobParams);
    HarvestedRecord hr = harvestedRecordDao.findByIdAndHarvestConfiguration("5", 300L);
    Assert.assertNotNull(hr);
    InputStream is = new ByteArrayInputStream(hr.getRawRecord());
    MarcRecord mr = new MarcRecordImpl(marcXmlParser.parseUnderlyingRecord(is));
    Assert.assertFalse(mr.getDataFields("100").isEmpty());
    Assert.assertFalse(mr.getDataFields("670").isEmpty());
    Assert.assertEquals(mr.getDataFields("856").size(), 1);
}
Also used : MarcRecordImpl(cz.mzk.recordmanager.server.marc.MarcRecordImpl) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) JobParameters(org.springframework.batch.core.JobParameters) Job(org.springframework.batch.core.Job) 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 35 with HarvestedRecord

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

the class ImportRecordsJobTest method testSimpleImportPatents.

@Test
public void testSimpleImportPatents() throws Exception {
    Job job = jobRegistry.getJob(Constants.JOB_ID_IMPORT);
    Map<String, JobParameter> params = new HashMap<>();
    params.put(Constants.JOB_PARAM_CONF_ID, new JobParameter(300L));
    params.put(Constants.JOB_PARAM_IN_FILE, new JobParameter(testFilePatents1));
    params.put(Constants.JOB_PARAM_FORMAT, new JobParameter("patents"));
    JobParameters jobParams = new JobParameters(params);
    jobLauncher.run(job, jobParams);
    HarvestedRecord hr = harvestedRecordDao.findByIdAndHarvestConfiguration("St36_CZ_305523_B6", 300L);
    Assert.assertNotNull(hr);
    InputStream is = new ByteArrayInputStream(hr.getRawRecord());
    MarcRecord mr = new MarcRecordImpl(marcXmlParser.parseUnderlyingRecord(is));
    Assert.assertFalse(mr.getDataFields("100").isEmpty());
    Assert.assertFalse(mr.getDataFields("520").isEmpty());
}
Also used : MarcRecordImpl(cz.mzk.recordmanager.server.marc.MarcRecordImpl) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) JobParameters(org.springframework.batch.core.JobParameters) Job(org.springframework.batch.core.Job) 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

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