List of usage examples for org.springframework.batch.core.scope.context ChunkContext getStepContext
public StepContext getStepContext()
From source file:com.springdeveloper.data.jdbc.batch.JdbcTasklet.java
/** * Execute the {@link #setSql(String) SQL query} provided. If the query * starts with "select" (case insensitive) the result is a list of maps, * which is logged and added to the step execution exit status. Otherwise * the query is executed and the result is an indication, also in the exit * status, of the number of rows updated. *///from w w w . j av a2 s. c om public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { StepExecution stepExecution = chunkContext.getStepContext().getStepExecution(); ExitStatus exitStatus = stepExecution.getExitStatus(); if (sql.trim().toUpperCase().startsWith("SELECT")) { logger.debug("Executing: " + sql); List<Map<String, Object>> result = jdbcTemplate.queryForList(sql, new BeanPropertySqlParameterSource(chunkContext.getStepContext())); String msg = "Result: " + result; logger.debug(msg); stepExecution.setExitStatus(exitStatus.addExitDescription(msg)); } else { logger.debug("Updating : " + sql); int updated = jdbcTemplate.update(sql, new BeanPropertySqlParameterSource(chunkContext.getStepContext())); String msg = "Updated: " + updated + " rows"; logger.debug(msg); stepExecution.setExitStatus(exitStatus.addExitDescription(msg)); } return RepeatStatus.FINISHED; }
From source file:org.cbio.portal.pipelines.foundation.MetaDataTasklet.java
@Override public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception { ExecutionContext executionContext = chunkContext.getStepContext().getStepExecution().getExecutionContext(); writeMutationsMetaFile(executionContext); writeCnaMetaFile(executionContext);/*from ww w .j a v a 2 s.co m*/ writeFusionsMetaFile(executionContext); return RepeatStatus.FINISHED; }
From source file:de.langmi.spring.batch.examples.complex.file.split.GetLineCountTasklet.java
/** * Check if resouce is a file and get the line count from the file. * Line count is // ww w.j a va 2s . co m * * @param contribution * @param chunkContext * @return * @throws Exception */ @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { checkResource(); int lineCount = getLineCount(resource.getFile()); chunkContext.getStepContext().getStepExecution().getExecutionContext().put("line.count", lineCount); return RepeatStatus.FINISHED; }
From source file:org.cbio.portal.pipelines.foundation.FoundationXmlGeneratorTasklet.java
@Override public RepeatStatus execute(StepContribution stepContext, ChunkContext chunkContext) throws Exception { // get fmi case type map from execution context Map<String, CaseType> fmiCaseTypeMap = (Map<String, CaseType>) chunkContext.getStepContext() .getJobExecutionContext().get("fmiCaseTypeMap"); // create new client case info type object to generate merged xml document ClientCaseInfoType clientCaseInfo = new ClientCaseInfoType(); CasesType cases = new CasesType(); cases.setCase(new ArrayList(fmiCaseTypeMap.values())); clientCaseInfo.setCases(cases);/* w w w .j a va 2s . c o m*/ writeFoundationXmlDocument(clientCaseInfo); return RepeatStatus.FINISHED; }
From source file:com.github.jrrdev.mantisbtsync.core.jobs.issues.tasklets.IssuesLastRunExtractorTasklet.java
/** * {@inheritDoc}//from w ww . j a v a2s.co m * @see org.springframework.batch.core.step.tasklet.Tasklet#execute(org.springframework.batch.core.StepContribution, org.springframework.batch.core.scope.context.ChunkContext) */ @Override public RepeatStatus execute(final StepContribution contribution, final ChunkContext chunkContext) throws Exception { final StepContext stepContext = chunkContext.getStepContext(); final String jobName = stepContext.getJobName(); final JobParameters jobParams = stepContext.getStepExecution().getJobParameters(); final Map<String, JobParameter> currParams = new HashMap<String, JobParameter>(jobParams.getParameters()); currParams.remove("run.id"); Date lastJobRun = null; final List<JobInstance> jobInstances = jobExplorer.getJobInstances(jobName, 0, 1000); for (final JobInstance jobInstance : jobInstances) { final List<JobExecution> jobExecutions = jobExplorer.getJobExecutions(jobInstance); for (final JobExecution jobExecution : jobExecutions) { final JobParameters oldJobParams = jobExecution.getJobParameters(); final Map<String, JobParameter> oldParams = new HashMap<String, JobParameter>( oldJobParams.getParameters()); oldParams.remove("run.id"); if (ExitStatus.COMPLETED.equals(jobExecution.getExitStatus()) && oldParams.equals(currParams)) { if (lastJobRun == null || lastJobRun.before(jobExecution.getStartTime())) { lastJobRun = jobExecution.getStartTime(); } } } } if (lastJobRun != null) { stepContext.getStepExecution().getExecutionContext().put("mantis.update.last_job_run", lastJobRun); } stepContext.getStepExecution().getExecutionContext().put("mantis.update.current_job_run", Calendar.getInstance()); return RepeatStatus.FINISHED; }
From source file:fr.acxio.tools.agia.tasks.FilesOperationTasklet.java
public RepeatStatus execute(StepContribution sContribution, ChunkContext sChunkContext) throws IOException, ResourceCreationException, FileOperationException { StepExecution aStepContext = ((sChunkContext != null) && (sChunkContext.getStepContext() != null)) ? sChunkContext.getStepContext().getStepExecution() : null;/*from w w w. j ava 2 s .c o m*/ Map<String, Object> aSourceParams = new HashMap<String, Object>(); aSourceParams.put(ResourceFactoryConstants.PARAM_STEP_EXEC, aStepContext); Resource[] aSourceResources = sourceFactory.getResources(aSourceParams); Map<String, Object> aDestinationParams = new HashMap<String, Object>(); if (LOGGER.isInfoEnabled()) { LOGGER.info("{} file(s) to {}", aSourceResources.length, operation.toString().toLowerCase()); } for (Resource aSourceResource : aSourceResources) { doOperation(aSourceResource, aDestinationParams, sContribution, aStepContext); } return RepeatStatus.FINISHED; }
From source file:com.gopivotal.spring.xd.module.jdbc.JdbcTasklet.java
/** * Execute the {@link #setSql(String) SQL query} provided. If the query starts with "select" (case insensitive) the * result is a list of maps, which is logged and added to the step execution exit status. Otherwise the query is * executed and the result is an indication, also in the exit status, of the number of rows updated. *//*from w ww . j a va2s. c o m*/ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { StepExecution stepExecution = chunkContext.getStepContext().getStepExecution(); ExitStatus exitStatus = stepExecution.getExitStatus(); String msg = ""; if (StringUtils.hasText(sql)) { msg = runCommand(chunkContext.getStepContext(), sql); } else if (!CollectionUtils.isEmpty(scripts)) { msg = runScripts(chunkContext, scripts, null); } stepExecution.setExitStatus(exitStatus.addExitDescription(msg)); return RepeatStatus.FINISHED; }
From source file:org.ohdsi.webapi.feasibility.PerformFeasibilityTasklet.java
private int[] doTask(ChunkContext chunkContext) { Map<String, Object> jobParams = chunkContext.getStepContext().getJobParameters(); Integer studyId = Integer.valueOf(jobParams.get("study_id").toString()); int[] result = null; try {/*from w ww.ja v a 2s . c om*/ String sessionId = SessionUtils.sessionId(); FeasibilityStudy study = this.feasibilityStudyRepository.findOne(studyId); FeasibilityStudyQueryBuilder.BuildExpressionQueryOptions options = new FeasibilityStudyQueryBuilder.BuildExpressionQueryOptions(); options.cdmSchema = jobParams.get("cdm_database_schema").toString(); options.ohdsiSchema = jobParams.get("target_database_schema").toString(); options.cohortTable = jobParams.get("target_database_schema").toString() + "." + jobParams.get("target_table").toString(); if (study.getResultRule() != null) { prepareTempTables(study, jobParams.get("target_dialect").toString(), sessionId); String expressionSql = studyQueryBuilder.buildSimulateQuery(study, options); String translatedSql = SqlTranslate.translateSql(expressionSql, "sql server", jobParams.get("target_dialect").toString(), sessionId, null); String[] sqlStatements = SqlSplit.splitSql(translatedSql); result = PerformFeasibilityTasklet.this.jdbcTemplate.batchUpdate(sqlStatements); cleanupTempTables(jobParams.get("target_dialect").toString(), sessionId); } else { String expressionSql = studyQueryBuilder.buildNullQuery(study, options); String translatedSql = SqlTranslate.translateSql(expressionSql, "sql server", jobParams.get("target_dialect").toString(), sessionId, null); String[] sqlStatements = SqlSplit.splitSql(translatedSql); result = PerformFeasibilityTasklet.this.jdbcTemplate.batchUpdate(sqlStatements); } } catch (Exception e) { throw new RuntimeException(e); } return result; }
From source file:fr.acxio.tools.agia.tasks.FileOperationTasklet.java
public RepeatStatus execute(StepContribution sContribution, ChunkContext sChunkContext) throws IOException, ResourceCreationException, FileOperationException { doOperation(origin, new HashMap<String, Object>(), sContribution, ((sChunkContext != null) && (sChunkContext.getStepContext() != null)) ? sChunkContext.getStepContext().getStepExecution() : null);/* w w w . ja va 2 s .com*/ return RepeatStatus.FINISHED; }