Search in sources :

Example 6 with Cosmotron996

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

the class CosmotronUpdate996Writer method move996ToParentRecord.

private void move996ToParentRecord(HarvestedRecordUniqueId parentUniqueId) {
    List<Cosmotron996> childRecs = cosmotronDao.findByParentId(parentUniqueId);
    HarvestedRecord parentRec = hrDao.get(parentUniqueId);
    // ignore deleted HarvestedRecord
    if (parentRec.getDeleted() != null)
        return;
    updateMarc(parentRec, childRecs);
    parentRec.setUpdated(new Date());
    hrDao.persist(parentRec);
}
Also used : Cosmotron996(cz.mzk.recordmanager.server.model.Cosmotron996) Date(java.util.Date) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord)

Example 7 with Cosmotron996

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

the class ExportRecordsJobConfig method exportCosmotron996Reader.

@Bean(name = Constants.JOB_ID_EXPORT_COSMOTRON_996 + ":exportCosmotron996Reader")
@StepScope
public ItemReader<Cosmotron996> exportCosmotron996Reader(@Value("#{jobParameters[" + Constants.JOB_PARAM_CONF_ID + "]}") Long configId) throws Exception {
    JdbcPagingItemReader<Cosmotron996> reader = new JdbcPagingItemReader<Cosmotron996>();
    SqlPagingQueryProviderFactoryBean pqpf = new SqlPagingQueryProviderFactoryBean();
    pqpf.setDataSource(dataSource);
    pqpf.setSelectClause("SELECT *");
    pqpf.setFromClause("FROM cosmotron_996");
    pqpf.setWhereClause("WHERE import_conf_id = :conf_id");
    pqpf.setSortKey("record_id");
    Map<String, Object> parameterValues = new HashMap<String, Object>();
    parameterValues.put("conf_id", configId);
    reader.setParameterValues(parameterValues);
    reader.setRowMapper(new Cosmotron996RowMapper());
    reader.setPageSize(20);
    reader.setQueryProvider(pqpf.getObject());
    reader.setDataSource(dataSource);
    reader.afterPropertiesSet();
    return reader;
}
Also used : SqlPagingQueryProviderFactoryBean(org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean) Cosmotron996(cz.mzk.recordmanager.server.model.Cosmotron996) HashMap(java.util.HashMap) Cosmotron996RowMapper(cz.mzk.recordmanager.server.jdbc.Cosmotron996RowMapper) JdbcPagingItemReader(org.springframework.batch.item.database.JdbcPagingItemReader) StepScope(org.springframework.batch.core.configuration.annotation.StepScope) SqlPagingQueryProviderFactoryBean(org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 8 with Cosmotron996

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

the class CosmotronHarvestJobTest method testDeleted996.

@Test
public void testDeleted996() 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);
    Assert.assertNotNull(recordDao.findByIdAndHarvestConfiguration("CbvkUsCat" + Constants.COSMOTRON_RECORD_ID_CHAR + "m0000002", config));
    Cosmotron996 cosmo = cosmotronDao.findByIdAndHarvestConfiguration("CbvkUsCat" + Constants.COSMOTRON_RECORD_ID_CHAR + "0000003", config);
    Assert.assertNotNull(cosmo);
    Assert.assertNotNull(cosmo.getDeleted());
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) OAIHarvestConfiguration(cz.mzk.recordmanager.server.model.OAIHarvestConfiguration) HashMap(java.util.HashMap) Cosmotron996(cz.mzk.recordmanager.server.model.Cosmotron996) ByteArrayInputStream(java.io.ByteArrayInputStream) 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 9 with Cosmotron996

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

the class CosmotronHarvestJobTest method testUpdated996.

@Test
public void testUpdated996() 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/Updated996.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);
    Assert.assertNotNull(recordDao.findByIdAndHarvestConfiguration("CbvkUsCat" + Constants.COSMOTRON_RECORD_ID_CHAR + "m0000002", config));
    Cosmotron996 cosmo = cosmotronDao.findByIdAndHarvestConfiguration("CbvkUsCat" + Constants.COSMOTRON_RECORD_ID_CHAR + "0000003", config);
    Assert.assertNotNull(cosmo);
    InputStream is = new ByteArrayInputStream(cosmo.getRawRecord());
    Record record = marcXmlParser.parseUnderlyingRecord(is);
    MarcRecord marcRecord = new MarcRecordImpl(record);
    Assert.assertNotNull(marcRecord.getDataFields("100"));
}
Also used : OAIHarvestConfiguration(cz.mzk.recordmanager.server.model.OAIHarvestConfiguration) HashMap(java.util.HashMap) Cosmotron996(cz.mzk.recordmanager.server.model.Cosmotron996) 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) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Aggregations

Cosmotron996 (cz.mzk.recordmanager.server.model.Cosmotron996)9 MarcRecord (cz.mzk.recordmanager.server.marc.MarcRecord)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)4 HashMap (java.util.HashMap)4 AbstractTest (cz.mzk.recordmanager.server.AbstractTest)3 MarcRecordImpl (cz.mzk.recordmanager.server.marc.MarcRecordImpl)3 HarvestedRecord (cz.mzk.recordmanager.server.model.HarvestedRecord)3 OAIHarvestConfiguration (cz.mzk.recordmanager.server.model.OAIHarvestConfiguration)3 Date (java.util.Date)3 Record (org.marc4j.marc.Record)3 JobExecution (org.springframework.batch.core.JobExecution)3 JobParameter (org.springframework.batch.core.JobParameter)3 JobParameters (org.springframework.batch.core.JobParameters)3 Test (org.testng.annotations.Test)3 Cosmotron996RowMapper (cz.mzk.recordmanager.server.jdbc.Cosmotron996RowMapper)1 MarcRecordInterceptor (cz.mzk.recordmanager.server.marc.intercepting.MarcRecordInterceptor)1 RecordImpl (cz.mzk.recordmanager.server.marc.marc4j.RecordImpl)1 MetadataRecord (cz.mzk.recordmanager.server.metadata.MetadataRecord)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1