Search in sources :

Example 56 with JobExecution

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

the class OAIHarvestJobTest method testHarvestFromDate.

@Test
public void testHarvestFromDate() 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&from=2015-01-01T01%3A00%3A00Z")).andReturn(response1);
    replay(httpClient);
    Map<String, JobParameter> params = new HashMap<>();
    params.put(Constants.JOB_PARAM_CONF_ID, new JobParameter(300L));
    params.put(Constants.JOB_PARAM_FROM_DATE, new JobParameter(new Date(1420070400000L)));
    JobExecution exec = jobExecutor.execute("oaiHarvestJob", new JobParameters(params));
    Assert.assertEquals(exec.getExitStatus(), ExitStatus.COMPLETED);
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) HashMap(java.util.HashMap) InputStream(java.io.InputStream) JobParameters(org.springframework.batch.core.JobParameters) JobParameter(org.springframework.batch.core.JobParameter) Date(java.util.Date) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Example 57 with JobExecution

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

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

the class JobExecutorImpl method restart.

@Override
public JobExecution restart(Long jobExecutionId) {
    JobExecution execution = jobExplorer.getJobExecution(jobExecutionId);
    execution.setExitStatus(ExitStatus.FAILED);
    execution.setEndTime(new Date());
    jobRepository.update(execution);
    try {
        Job job = jobRegistry.getJob(execution.getJobInstance().getJobName());
        return execute(job.getName(), execution.getJobParameters());
    } catch (NoSuchJobException nsje) {
        throw new RuntimeException(String.format("Job execution with id=%s could not be restarted.", jobExecutionId), nsje);
    }
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) NoSuchJobException(org.springframework.batch.core.launch.NoSuchJobException) Job(org.springframework.batch.core.Job) Date(java.util.Date)

Example 59 with JobExecution

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

the class ImportRecordFacadeImpl method importFile.

@Override
public void importFile(long importConfId, File file, String format) {
    Map<String, JobParameter> parameters = new HashMap<>();
    parameters.put(Constants.JOB_PARAM_IN_FILE, new JobParameter(file.getAbsolutePath()));
    parameters.put(Constants.JOB_PARAM_FORMAT, new JobParameter(format));
    parameters.put(Constants.JOB_PARAM_CONF_ID, new JobParameter(importConfId));
    JobParameters params = new JobParameters(parameters);
    JobExecution exec = jobExecutor.execute(Constants.JOB_ID_IMPORT, params);
    if (!ExitStatus.COMPLETED.equals(exec.getExitStatus())) {
        throw new JobExecutionFailure("Incremental harvest failed", exec);
    }
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) HashMap(java.util.HashMap) JobParameters(org.springframework.batch.core.JobParameters) JobParameter(org.springframework.batch.core.JobParameter) JobExecutionFailure(cz.mzk.recordmanager.server.facade.exception.JobExecutionFailure)

Example 60 with JobExecution

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

the class ImportRecordFacadeImpl method importOaiRecordsJob.

@Override
public void importOaiRecordsJob(long impotrConfId, String fileName) {
    Map<String, JobParameter> parameters = new HashMap<>();
    parameters.put(Constants.JOB_PARAM_CONF_ID, new JobParameter(impotrConfId));
    parameters.put(Constants.JOB_PARAM_IN_FILE, new JobParameter(fileName));
    parameters.put(Constants.JOB_PARAM_REPEAT, new JobParameter(Constants.JOB_PARAM_ONE_VALUE));
    JobParameters params = new JobParameters(parameters);
    JobExecution exec = jobExecutor.execute(Constants.JOB_ID_IMPORT_OAI, params);
    if (!ExitStatus.COMPLETED.equals(exec.getExitStatus())) {
        throw new JobExecutionFailure("ImportOaiRecords failed", exec);
    }
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) HashMap(java.util.HashMap) JobParameters(org.springframework.batch.core.JobParameters) JobParameter(org.springframework.batch.core.JobParameter) JobExecutionFailure(cz.mzk.recordmanager.server.facade.exception.JobExecutionFailure)

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