Search in sources :

Example 66 with JobExecution

use of org.springframework.batch.core.JobExecution 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 67 with JobExecution

use of org.springframework.batch.core.JobExecution 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 68 with JobExecution

use of org.springframework.batch.core.JobExecution 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 69 with JobExecution

use of org.springframework.batch.core.JobExecution in project RecordManager2 by moravianlibrary.

the class OAIHarvestAuthorityJobTest method testHarvestAuthorityRecords.

@Test
public void testHarvestAuthorityRecords() throws Exception {
    reset(httpClient);
    InputStream response0 = this.getClass().getResourceAsStream("/auth/Identify.xml");
    InputStream response1 = this.getClass().getResourceAsStream("/auth/ListRecords1.xml");
    expect(httpClient.executeGet("http://aleph.nkp.cz/OAI?verb=Identify")).andReturn(response0);
    expect(httpClient.executeGet("http://aleph.nkp.cz/OAI?verb=ListRecords&metadataPrefix=marc21&set=AUTH")).andReturn(response1);
    replay(httpClient);
    final Long configId = oaiConfiguration.getId();
    Map<String, JobParameter> params = new HashMap<String, JobParameter>();
    params.put("configurationId", new JobParameter(configId));
    JobParameters jobParams = new JobParameters(params);
    JobExecution exec = jobExecutor.execute(Constants.JOB_ID_HARVEST_AUTH, jobParams);
    Assert.assertEquals(exec.getExitStatus(), ExitStatus.COMPLETED);
    AuthorityRecord authRec = authorityRecordDao.findByIdAndHarvestConfiguration("oai:aleph-nkp.cz:AUT10-000000001", oaiConfiguration);
    Assert.assertNotNull(authRec);
    Assert.assertEquals(authRec.getAuthorityCode(), "jk01010001");
    authRec = authorityRecordDao.findByIdAndHarvestConfiguration("oai:aleph-nkp.cz:AUT10-000000006", oaiConfiguration);
    Assert.assertEquals(authRec.getAuthorityCode(), "jk01010009");
    Assert.assertNotNull(authRec);
    authRec = authorityRecordDao.findByIdAndHarvestConfiguration("oai:aleph-nkp.cz:AUT10-000000007", oaiConfiguration);
    Assert.assertEquals(authRec.getAuthorityCode(), "jk01010010");
    Assert.assertNotNull(authRec);
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) HashMap(java.util.HashMap) InputStream(java.io.InputStream) AuthorityRecord(cz.mzk.recordmanager.server.model.AuthorityRecord) JobParameters(org.springframework.batch.core.JobParameters) JobParameter(org.springframework.batch.core.JobParameter) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Example 70 with JobExecution

use of org.springframework.batch.core.JobExecution in project spring-boot by spring-projects.

the class JobLauncherApplicationRunner method execute.

protected void execute(Job job, JobParameters jobParameters) throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException, JobParametersNotFoundException {
    JobParameters parameters = getNextJobParameters(job, jobParameters);
    JobExecution execution = this.jobLauncher.run(job, parameters);
    if (this.publisher != null) {
        this.publisher.publishEvent(new JobExecutionEvent(execution));
    }
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) JobParameters(org.springframework.batch.core.JobParameters)

Aggregations

JobExecution (org.springframework.batch.core.JobExecution)75 JobParameters (org.springframework.batch.core.JobParameters)52 JobParameter (org.springframework.batch.core.JobParameter)42 HashMap (java.util.HashMap)41 Test (org.testng.annotations.Test)36 AbstractTest (cz.mzk.recordmanager.server.AbstractTest)30 InputStream (java.io.InputStream)25 Job (org.springframework.batch.core.Job)16 Date (java.util.Date)15 JobInstance (org.springframework.batch.core.JobInstance)14 Test (org.junit.Test)12 ByteArrayInputStream (java.io.ByteArrayInputStream)11 JobExplorer (org.springframework.batch.core.explore.JobExplorer)11 HarvestedRecord (cz.mzk.recordmanager.server.model.HarvestedRecord)9 OAIHarvestConfiguration (cz.mzk.recordmanager.server.model.OAIHarvestConfiguration)9 JobExecutionFailure (cz.mzk.recordmanager.server.facade.exception.JobExecutionFailure)6 MarcRecord (cz.mzk.recordmanager.server.marc.MarcRecord)5 MarcRecordImpl (cz.mzk.recordmanager.server.marc.MarcRecordImpl)5 Record (org.marc4j.marc.Record)5 JobLauncher (org.springframework.batch.core.launch.JobLauncher)5