View Javadoc
1   /*
2    * Copyright 2009-2014 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.springframework.batch.admin.web;
17  
18  import java.util.ArrayList;
19  import java.util.Collection;
20  import java.util.TimeZone;
21  
22  import org.springframework.batch.admin.domain.JobExecutionInfo;
23  import org.springframework.batch.core.JobExecution;
24  import org.springframework.batch.core.JobInstance;
25  
26  public class JobInstanceInfo {
27  
28  	private final JobInstance jobInstance;
29  
30  	private final Long id;
31  
32  	private final Collection<JobExecutionInfo> jobExecutionInfos;
33  
34  	public JobInstanceInfo(JobInstance jobInstance, Collection<JobExecution> jobExecutions, TimeZone timeZone) {
35  		this.jobInstance = jobInstance;
36  		this.jobExecutionInfos = new ArrayList<JobExecutionInfo>();
37  
38  		if (jobExecutions != null) {
39  			for (JobExecution jobExecution : jobExecutions) {
40  				jobExecutionInfos.add(new JobExecutionInfo(jobExecution, timeZone));
41  			}
42  		}
43  
44  		this.id = jobInstance.getId();
45  	}
46  
47  	public JobInstanceInfo(JobInstance jobInstance, Collection<JobExecution> jobExecutions) {
48  		this(jobInstance, jobExecutions, TimeZone.getDefault());
49  	}
50  
51  	public JobInstance getJobInstance() {
52  		return jobInstance;
53  	}
54  
55  	public Long getId() {
56  		return id;
57  	}
58  
59  	public int getJobExecutionCount() {
60  		return jobExecutionInfos.size();
61  	}
62  
63  	public Collection<JobExecution> getJobExecutions() {
64  		Collection<JobExecution> jobExecutions = new ArrayList<JobExecution>();
65  
66  		for (JobExecutionInfo jobExecutionInfo : jobExecutionInfos) {
67  			jobExecutions.add(jobExecutionInfo.getJobExecution());
68  		}
69  
70  		return jobExecutions;
71  	}
72  
73  	public JobExecution getLastJobExecution() {
74  		return jobExecutionInfos.isEmpty() ? null : jobExecutionInfos.iterator().next().getJobExecution();
75  	}
76  
77  	public JobExecutionInfo getLastJobExecutionInfo() {
78  		return jobExecutionInfos.isEmpty() ? null : jobExecutionInfos.iterator().next();
79  	}
80  }