/** * Method should be called when finalizing the command. The execution step is being ended with * success and the finalization step is started. * * @param executionContext The context of the job * @return A created instance of the Finalizing step */ public static Step startFinalizingStep(ExecutionContext executionContext) { if (executionContext == null) { return null; } Step step = null; try { if (executionContext.getExecutionMethod() == ExecutionMethod.AsJob) { Job job = executionContext.getJob(); if (job != null) { Step executingStep = job.getStep(StepEnum.EXECUTING); Step finalizingStep = job.addStep( StepEnum.FINALIZING, ExecutionMessageDirector.getInstance().getStepMessage(StepEnum.FINALIZING)); if (executingStep != null) { executingStep.markStepEnded(true); JobRepositoryFactory.getJobRepository() .updateExistingStepAndSaveNewStep(executingStep, finalizingStep); } else { JobRepositoryFactory.getJobRepository().saveStep(finalizingStep); } } } else if (executionContext.getExecutionMethod() == ExecutionMethod.AsStep) { Step parentStep = executionContext.getStep(); if (parentStep != null) { Step executingStep = parentStep.getStep(StepEnum.EXECUTING); Step finalizingStep = parentStep.addStep( StepEnum.FINALIZING, ExecutionMessageDirector.getInstance().getStepMessage(StepEnum.FINALIZING)); if (executingStep != null) { executingStep.markStepEnded(true); JobRepositoryFactory.getJobRepository() .updateExistingStepAndSaveNewStep(executingStep, finalizingStep); } else { JobRepositoryFactory.getJobRepository().saveStep(finalizingStep); } } } } catch (Exception e) { log.error(e); } return step; }