本文整理汇总了Java中org.springframework.batch.core.ExitStatus类的典型用法代码示例。如果您正苦于以下问题:Java ExitStatus类的具体用法?Java ExitStatus怎么用?Java ExitStatus使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ExitStatus类属于org.springframework.batch.core包,在下文中一共展示了ExitStatus类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testWriteTaxonFile
import org.springframework.batch.core.ExitStatus; //导入依赖的package包/类
/**
* @throws Exception
*/
@Test
public void testWriteTaxonFile() throws Exception {
Map<String, JobParameter> parameters = new HashMap<String, JobParameter>();
parameters.put("query", new JobParameter(""));
parameters.put("selected.facets", new JobParameter("taxon.family_ss=Araceae"));
parameters.put("download.taxon", new JobParameter(toParameter(DarwinCorePropertyMap.getConceptTerms(DwcTerm.Taxon))));
parameters.put("download.file", new JobParameter(UUID.randomUUID().toString() + ".txt"));
parameters.put("download.limit", new JobParameter(new Integer(Integer.MAX_VALUE).toString()));
parameters.put("download.fieldsTerminatedBy", new JobParameter("\t"));
parameters.put("download.fieldsEnclosedBy", new JobParameter("\""));
parameters.put("download.format", new JobParameter("taxon"));
JobParameters jobParameters = new JobParameters(parameters);
Job archiveCreatorJob = jobLocator.getJob("FlatFileCreation");
assertNotNull("flatFileCreatorJob must exist", archiveCreatorJob);
JobExecution jobExecution = jobLauncher.run(archiveCreatorJob,
jobParameters);
assertEquals("The Job should be sucessful", ExitStatus.COMPLETED, jobExecution.getExitStatus());
}
示例2: execute
import org.springframework.batch.core.ExitStatus; //导入依赖的package包/类
@Override
@Transactional
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
Query<String> query = currentSession().createQuery(queryString, String.class);
query.setMaxResults(1);
query.setFirstResult(0);
try {
String result = query.getSingleResult();
chunkContext.getStepContext().getStepExecution().getJobExecution().getExecutionContext().put("record.identifier", result);
contribution.setExitStatus(new ExitStatus("MORE_RESULTS"));
} catch (NoResultException e) {
contribution.setExitStatus(new ExitStatus("NO_MORE_RESULTS"));
}
return RepeatStatus.FINISHED;
}
示例3: execute
import org.springframework.batch.core.ExitStatus; //导入依赖的package包/类
@Override
public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) {
Object parametersObj = chunkContext.getStepContext().getJobParameters().get("JobParameters");
String jobParameters = String.valueOf(System.currentTimeMillis());
String params = "(";
if (parametersObj != null) {
jobParameters = parametersObj.toString();
String[] p = jobParameters.split(" ");
for (int i = 0; i < p.length; i++) {
if (i == 0) {
params += "'" + p[i] + "'";
} else {
params += ",'" + p[i] + "'";
}
}
}
params += ")";
try {
logger.info("program is :" + scriptFile + ", argument is:" + params);
jdbcTemplate.execute("call " + scriptFile + params);
} catch (Exception e) {
logger.error(e.getMessage());
chunkContext.getStepContext().getStepExecution().setExitStatus(ExitStatus.FAILED);
}
return RepeatStatus.FINISHED;
}
示例4: afterJob
import org.springframework.batch.core.ExitStatus; //导入依赖的package包/类
@Override
public void afterJob(final JobExecution jobExecution) {
if (ExitStatus.COMPLETED.equals(jobExecution.getExitStatus())) {
final ExecutionContext executionContext = jobExecution.getExecutionContext();
final String inputFile = executionContext.getString(LHHuntingClubBatchConfig.KEY_INPUT_FILE, null);
if (inputFile != null) {
final Path path = Paths.get(inputFile);
try {
LOG.info("Deleting temporary file: {}", inputFile);
Files.deleteIfExists(path);
} catch (IOException e) {
e.printStackTrace();
}
} else {
LOG.warn("Input file not found in context");
}
}
}
示例5: execute
import org.springframework.batch.core.ExitStatus; //导入依赖的package包/类
@Override
public RepeatStatus execute(StepContribution arg0, ChunkContext arg1) throws Exception {
Long time = Calendar.getInstance().getTimeInMillis();
String exit;
if(time % 2 == 0){
exit = ExitStatus.NOOP.getExitCode().toString();
arg0.setExitStatus(ExitStatus.NOOP);
}else{
exit = ExitStatus.COMPLETED.getExitCode().toString();
arg0.setExitStatus(ExitStatus.COMPLETED);
}
System.out.println("Executing step with name " + taskletName + " and exitCode " + exit);
return RepeatStatus.FINISHED;
}
示例6: assertCorrectMixins
import org.springframework.batch.core.ExitStatus; //导入依赖的package包/类
private void assertCorrectMixins(RestTemplate restTemplate) {
boolean containsMappingJackson2HttpMessageConverter = false;
for (HttpMessageConverter<?> converter : restTemplate.getMessageConverters()) {
if (converter instanceof MappingJackson2HttpMessageConverter) {
containsMappingJackson2HttpMessageConverter = true;
final MappingJackson2HttpMessageConverter jacksonConverter = (MappingJackson2HttpMessageConverter) converter;
final ObjectMapper objectMapper = jacksonConverter.getObjectMapper();
assertNotNull(objectMapper.findMixInClassFor(JobExecution.class));
assertNotNull(objectMapper.findMixInClassFor(JobParameters.class));
assertNotNull(objectMapper.findMixInClassFor(JobParameter.class));
assertNotNull(objectMapper.findMixInClassFor(JobInstance.class));
assertNotNull(objectMapper.findMixInClassFor(ExitStatus.class));
assertNotNull(objectMapper.findMixInClassFor(StepExecution.class));
assertNotNull(objectMapper.findMixInClassFor(ExecutionContext.class));
assertNotNull(objectMapper.findMixInClassFor(StepExecutionHistory.class));
}
}
if (!containsMappingJackson2HttpMessageConverter) {
fail("Expected that the restTemplate's list of Message Converters contained a "
+ "MappingJackson2HttpMessageConverter");
}
}
示例7: mapRow
import org.springframework.batch.core.ExitStatus; //导入依赖的package包/类
/**
* @param resultSet Set the result set
* @param rowNumber Set the row number
* @throws SQLException if there is a problem
* @return a job execution instance
*/
public final JobExecution mapRow(final ResultSet resultSet,
final int rowNumber) throws SQLException {
JobInstance jobInstance = new JobInstance(resultSet.getBigDecimal(
"JOB_INSTANCE_ID").longValue(),
new JobParameters(), resultSet.getString("JOB_NAME"));
JobExecution jobExecution = new JobExecution(jobInstance,
resultSet.getBigDecimal("JOB_EXECUTION_ID").longValue());
jobExecution.setStartTime(resultSet.getTimestamp("START_TIME"));
jobExecution.setCreateTime(resultSet.getTimestamp("CREATE_TIME"));
jobExecution.setEndTime(resultSet.getTimestamp("END_TIME"));
jobExecution.setStatus(BatchStatus.valueOf(resultSet
.getString("STATUS")));
ExitStatus exitStatus = new ExitStatus(
resultSet.getString("EXIT_CODE"),
resultSet.getString("EXIT_MESSAGE"));
jobExecution.setExitStatus(exitStatus);
return jobExecution;
}
示例8: execute
import org.springframework.batch.core.ExitStatus; //导入依赖的package包/类
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputFile.getInputStream());
char[] buffer = new char[2];
InputStreamReader inputStreamReader = new InputStreamReader(bufferedInputStream);
int numChars = -1;
if((numChars = inputStreamReader.read(buffer)) == 2) {
String string = new String(buffer);
if(string.equals("[]")) {
contribution.setExitStatus(new ExitStatus("EMPTY_RESPONSE").addExitDescription("The webservice returned an empty list of taxa"));
}
} else {
contribution.setExitStatus(ExitStatus.FAILED.addExitDescription("Unable to read the webservice response"));
}
inputStreamReader.close();
return RepeatStatus.FINISHED;
}
示例9: afterStep
import org.springframework.batch.core.ExitStatus; //导入依赖的package包/类
public ExitStatus afterStep(StepExecution stepExecution) {
logger.debug("After Step " + currentStep.getStepName());
try {
Url u = new Url();
u.setLastmod(ISODateTimeFormat.dateTime().print((ReadableInstant) null));
u.setLoc(new URL(portalBaseUrl +"/" + sitemapDir + "/" + currentFile.getFilename()));
sitemapNames.add(u);
} catch (MalformedURLException e) {
logger.error("Unable create Url for sitemap", e);
}
//reset counts to nulls to support beforeStep()
currentStep = null;
currentFile = null;
chunkOfFile = 0;
commitSize = 0;
return stepExecution.getExitStatus();
}
示例10: packArchive
import org.springframework.batch.core.ExitStatus; //导入依赖的package包/类
/**
* @param source The directory containing the DwC/A files
* @param target The absolute filepath for where to write the archive
* @return
*/
public static final ExitStatus packArchive(final String source, final String target) {
logger.info("Attempting to pack " + source + " to " + target);
try { //to wrap things we can de-reference immediately
File sourceDir = new File(source);
if(!sourceDir.exists()) {
throw new FileNotFoundException("Unable to find filesystem resource - " + source);
}
if(!sourceDir.isDirectory()) {
throw new IllegalArgumentException(source + " is not a folder");
}
zip(source, target);
return ExitStatus.COMPLETED;
} catch (Exception e) {
logger.error("Error writing " + source + " to " + target, e);
return ExitStatus.FAILED;
}
}
示例11: execute
import org.springframework.batch.core.ExitStatus; //导入依赖的package包/类
@Override
@Transactional
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
Query query = this.getSession().createQuery(queryString);
query.setMaxResults(1);
query.setFirstResult(0);
List<String> results = (List<String>)query.list();
if(results.size() == 0) {
contribution.setExitStatus(new ExitStatus("NO_MORE_RESULTS"));
} else {
chunkContext.getStepContext().getStepExecution().getJobExecution().getExecutionContext().put("record.identifier", results.get(0));
contribution.setExitStatus(new ExitStatus("MORE_RESULTS"));
}
return RepeatStatus.FINISHED;
}
示例12: testWriteChecklistPdf
import org.springframework.batch.core.ExitStatus; //导入依赖的package包/类
@Test
public void testWriteChecklistPdf() throws Exception {
Map<String, JobParameter> parameters = new HashMap<String, JobParameter>();
parameters.put("query", new JobParameter(""));
parameters.put("selected.facets", new JobParameter("taxon.family_ss=Araceae"));
parameters.put("download.taxon", new JobParameter(toParameter(DarwinCorePropertyMap.getConceptTerms(DwcTerm.Taxon))));
parameters.put("download.file", new JobParameter(UUID.randomUUID().toString() + ".pdf"));
parameters.put("download.limit", new JobParameter(new Integer(Integer.MAX_VALUE).toString()));
parameters.put("download.fieldsTerminatedBy", new JobParameter("\t"));
parameters.put("download.fieldsEnclosedBy", new JobParameter("\""));
parameters.put("download.sort", new JobParameter("searchable.label_sort_asc"));
parameters.put("download.format", new JobParameter("hierarchicalChecklist"));
parameters.put("download.template.filepath", new JobParameter("org/emonocot/job/download/reports/name_report1.jrxml"));
JobParameters jobParameters = new JobParameters(parameters);
Job archiveCreatorJob = jobLocator.getJob("FlatFileCreation");
assertNotNull("flatFileCreator Job must exist", archiveCreatorJob);
JobExecution jobExecution = jobLauncher.run(archiveCreatorJob,
jobParameters);
assertEquals("The Job should be sucessful", ExitStatus.COMPLETED, jobExecution.getExitStatus());
}
示例13: testGetResourceSuccessfully
import org.springframework.batch.core.ExitStatus; //导入依赖的package包/类
/**
*
* @throws IOException
* if a temporary file cannot be created or if there is a http
* protocol error.
* @throws SAXException
* if the content retrieved is not valid xml.
*/
@Test
public final void testGetResourceSuccessfully() throws IOException,
SAXException {
File tempFile = File.createTempFile("test", "zip");
tempFile.deleteOnExit();
EasyMock.expect(httpClient.getParams())
.andReturn(new BasicHttpParams());
EasyMock.expect(httpClient.execute(EasyMock.isA(HttpGet.class)))
.andReturn(httpResponse);
EasyMock.replay(httpClient);
ExitStatus exitStatus = getResourceClient
.getResource(testzip,
Long.toString(new Date().getTime()),
tempFile.getAbsolutePath());
EasyMock.verify(httpClient);
assertNotNull("ExitStatus should not be null", exitStatus);
assertEquals("ExitStatus should be COMPLETED", exitStatus,
ExitStatus.COMPLETED);
}
示例14: testGetResourceNotModified
import org.springframework.batch.core.ExitStatus; //导入依赖的package包/类
/**
*
* @throws IOException
* if a temporary file cannot be created or if there is a http
* protocol error.
*/
@Test
public final void testGetResourceNotModified() throws IOException {
File tempFile = File.createTempFile("test", "zip");
tempFile.deleteOnExit();
httpResponse.setStatusLine(new BasicStatusLine(HttpVersion.HTTP_1_0,
HttpStatus.SC_NOT_MODIFIED, "Not Modified"));
EasyMock.expect(httpClient.getParams())
.andReturn(new BasicHttpParams());
EasyMock.expect(httpClient.execute(EasyMock.isA(HttpGet.class)))
.andReturn(httpResponse);
EasyMock.replay(httpClient);
ExitStatus exitStatus = getResourceClient
.getResource(testzip,
Long.toString(new Date().getTime()),
tempFile.getAbsolutePath());
EasyMock.verify(httpClient);
assertNotNull("ExitStatus should not be null", exitStatus);
assertEquals("ExitStatus should be NOT_MODIFIED",
exitStatus.getExitCode(), "NOT_MODIFIED");
}
示例15: testGetDocumentAnyOtherStatus
import org.springframework.batch.core.ExitStatus; //导入依赖的package包/类
/**
*
@throws IOException
* if a temporary file cannot be created or if there is a http
* protocol error.
*/
@Test
public final void testGetDocumentAnyOtherStatus() throws IOException {
File tempFile = File.createTempFile("test", "zip");
tempFile.deleteOnExit();
httpResponse.setStatusLine(new BasicStatusLine(HttpVersion.HTTP_1_0,
HttpStatus.SC_BAD_REQUEST, "Bad Request"));
EasyMock.expect(httpClient.getParams())
.andReturn(new BasicHttpParams());
EasyMock.expect(httpClient.execute(EasyMock.isA(HttpGet.class)))
.andReturn(httpResponse).anyTimes();
EasyMock.replay(httpClient);
ExitStatus exitStatus = getResourceClient
.getResource(testzip,
Long.toString(new Date().getTime()),
tempFile.getAbsolutePath());
EasyMock.verify(httpClient);
assertNotNull("ExitStatus should not be null", exitStatus);
assertEquals("ExitStatus should be FAILED", exitStatus,
ExitStatus.FAILED);
}