View Javadoc

1   package net.sf.appstatus.batch.jdbc;
2   
3   import java.util.ArrayList;
4   import java.util.Arrays;
5   import java.util.Date;
6   import java.util.List;
7   
8   import net.sf.appstatus.core.batch.IBatch;
9   import net.sf.appstatus.core.batch.IBatchProgressMonitor;
10  
11  import org.apache.commons.lang3.BooleanUtils;
12  import org.apache.commons.lang3.StringUtils;
13  
14  public class Batch implements IBatch {
15      private Integer zombieInterval = 1000 * 60 * 10;
16  
17      public void setZombieInterval(int zombieInterval) {
18          this.zombieInterval = zombieInterval;
19      }
20  
21      BdBatch dbBatch = null;
22      JdbcBatchProgressMonitor monitor;
23  
24      public Batch(BdBatch bdBatch) {
25          this.dbBatch = bdBatch;
26      }
27  
28      public BdBatch getBdBatch() {
29          return dbBatch;
30      }
31  
32      public String getCurrentItem() {
33          return dbBatch.getCurrentItem();
34      }
35  
36      public String getCurrentTask() {
37          return dbBatch.getCurrentTask();
38      }
39  
40      public Date getEndDate() {
41          return dbBatch.getEndDate();
42      }
43  
44      public String getGroup() {
45          return dbBatch.getGroup();
46      }
47  
48      public long getItemCount() {
49          return dbBatch.getItemCount();
50      }
51  
52      public String getLastMessage() {
53          return dbBatch.getLastMessage();
54      }
55  
56      public Date getLastUpdate() {
57          return dbBatch.getLastUpdate();
58      }
59  
60      public String getName() {
61          return dbBatch.getName();
62      }
63  
64      public IBatchProgressMonitor getProgressMonitor() {
65          return (IBatchProgressMonitor) monitor;
66      }
67  
68      public float getProgressStatus() {
69          return dbBatch.getProgress();
70      }
71  
72      public List<String> getRejectedItemsId() {
73          if (dbBatch.getReject() == null) {
74              return new ArrayList<String>();
75          }
76          return Arrays.asList(StringUtils.split(dbBatch.getReject(), "|"));
77      }
78  
79      public Date getStartDate() {
80          return dbBatch.getStartDate();
81      }
82  
83      public String getStatus() {
84          String status = dbBatch.getStatus();
85  
86          if (IBatch.STATUS_RUNNING.equals(status)) {
87              Date lastUpdate = getLastUpdate();
88              if (lastUpdate == null)
89                  lastUpdate = getStartDate();
90  
91              if (new Date().getTime() - lastUpdate.getTime() > zombieInterval) {
92                  return STATUS_ZOMBIE;
93              }
94          }
95          return status;
96      }
97  
98      public String getUuid() {
99          return dbBatch.getUuid();
100     }
101 
102     public boolean isSuccess() {
103         return BooleanUtils.isTrue(dbBatch.getSuccess());
104     }
105 
106     public void setProgressMonitor(IBatchProgressMonitor monitor) {
107         this.monitor = (JdbcBatchProgressMonitor) monitor;
108     }
109 
110     /*
111      * (non-Javadoc)
112      * 
113      * @see java.lang.Object#hashCode()
114      */
115     @Override
116     public int hashCode() {
117         final int prime = 31;
118         int result = 1;
119         result = prime * result + ((dbBatch == null) ? 0 : dbBatch.hashCode());
120         return result;
121     }
122 
123     /*
124      * (non-Javadoc)
125      * 
126      * @see java.lang.Object#equals(java.lang.Object)
127      */
128     @Override
129     public boolean equals(Object obj) {
130         if (this == obj) {
131             return true;
132         }
133         if (obj == null) {
134             return false;
135         }
136         if (getClass() != obj.getClass()) {
137             return false;
138         }
139         Batch other = (Batch) obj;
140         if (dbBatch == null) {
141             if (other.dbBatch != null) {
142                 return false;
143             }
144         } else if (!dbBatch.equals(other.dbBatch)) {
145             return false;
146         }
147         return true;
148     }
149 }