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);
}
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());
}
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);
}
}
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);
}
}
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);
}
}
Aggregations