001/* 002 * Copyright 2013 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.springframework.batch.core.jsr; 017 018import java.util.Date; 019import java.util.Properties; 020 021import javax.batch.runtime.BatchStatus; 022 023import org.springframework.batch.core.converter.JobParametersConverter; 024import org.springframework.util.Assert; 025 026/** 027 * Wrapper class to adapt the {@link javax.batch.runtime.JobExecution} to 028 * a {@link org.springframework.batch.core.JobExecution}. 029 * 030 * @author Michael Minella 031 * @since 3.0 032 */ 033public class JsrJobExecution implements javax.batch.runtime.JobExecution { 034 035 private org.springframework.batch.core.JobExecution execution; 036 private JobParametersConverter parametersConverter; 037 038 /** 039 * @param execution for all information to be delegated from. 040 * @param parametersConverter instance of {@link JobParametersConverter}. 041 */ 042 public JsrJobExecution(org.springframework.batch.core.JobExecution execution, JobParametersConverter parametersConverter) { 043 Assert.notNull(execution, "A JobExecution is required"); 044 this.execution = execution; 045 046 this.parametersConverter = parametersConverter; 047 } 048 049 /* (non-Javadoc) 050 * @see javax.batch.runtime.JobExecution#getExecutionId() 051 */ 052 @Override 053 public long getExecutionId() { 054 return this.execution.getId(); 055 } 056 057 /* (non-Javadoc) 058 * @see javax.batch.runtime.JobExecution#getJobName() 059 */ 060 @Override 061 public String getJobName() { 062 return this.execution.getJobInstance().getJobName(); 063 } 064 065 /* (non-Javadoc) 066 * @see javax.batch.runtime.JobExecution#getBatchStatus() 067 */ 068 @Override 069 public BatchStatus getBatchStatus() { 070 return this.execution.getStatus().getBatchStatus(); 071 } 072 073 /* (non-Javadoc) 074 * @see javax.batch.runtime.JobExecution#getStartTime() 075 */ 076 @Override 077 public Date getStartTime() { 078 return this.execution.getStartTime(); 079 } 080 081 /* (non-Javadoc) 082 * @see javax.batch.runtime.JobExecution#getEndTime() 083 */ 084 @Override 085 public Date getEndTime() { 086 return this.execution.getEndTime(); 087 } 088 089 /* (non-Javadoc) 090 * @see javax.batch.runtime.JobExecution#getExitStatus() 091 */ 092 @Override 093 public String getExitStatus() { 094 return this.execution.getExitStatus().getExitCode(); 095 } 096 097 /* (non-Javadoc) 098 * @see javax.batch.runtime.JobExecution#getCreateTime() 099 */ 100 @Override 101 public Date getCreateTime() { 102 return this.execution.getCreateTime(); 103 } 104 105 /* (non-Javadoc) 106 * @see javax.batch.runtime.JobExecution#getLastUpdatedTime() 107 */ 108 @Override 109 public Date getLastUpdatedTime() { 110 return this.execution.getLastUpdated(); 111 } 112 113 /* (non-Javadoc) 114 * @see javax.batch.runtime.JobExecution#getJobParameters() 115 */ 116 @Override 117 public Properties getJobParameters() { 118 Properties properties = parametersConverter.getProperties(this.execution.getJobParameters()); 119 properties.remove(JsrJobParametersConverter.JOB_RUN_ID); 120 return properties; 121 } 122}