1 23 24 package org.infoglue.cms.entities.mydesktop; 25 26 import java.util.ArrayList ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 30 import org.infoglue.cms.entities.kernel.BaseEntityVO; 31 import org.infoglue.cms.util.ConstraintExceptionBuffer; 32 import org.infoglue.cms.util.workflow.StepFilter; 33 34 39 40 public class WorkflowVO implements BaseEntityVO 41 { 42 private static final long serialVersionUID = 1L; 43 44 public static final int STATUS_OK = 0; 45 public static final int STATUS_NOT_OK = 1; 46 47 private Long workflowId; 48 private String name; private String title; private List declaredSteps = new ArrayList (); 51 private List currentSteps = new ArrayList (); 52 private List historySteps = new ArrayList (); 53 private List initialActions = new ArrayList (); 54 private List globalActions = new ArrayList (); 55 56 private int status = STATUS_OK; 57 private String statusMessage = ""; 58 59 public WorkflowVO() {} 60 61 public WorkflowVO(Long workflowId, String name) 62 { 63 setWorkflowId(workflowId); 64 setName(name); 65 } 66 67 public Integer getId() 68 { 69 return new Integer (workflowId.intValue()); 70 } 71 72 public void setId(Integer id) 73 { 74 setWorkflowId(new Long (id.longValue())); 75 } 76 77 public long getIdAsPrimitive() 78 { 79 return (workflowId == null) ? 0 : workflowId.longValue(); 80 } 81 82 public Long getWorkflowId() 83 { 84 return workflowId; 85 } 86 87 public void setWorkflowId(Long workflowId) 88 { 89 this.workflowId = workflowId; 90 } 91 92 public String getName() 93 { 94 return name; 95 } 96 97 public void setName(String name) 98 { 99 this.name = name; 100 } 101 102 public String getTitle() 103 { 104 return title; 105 } 106 107 public void setTitle(final String title) 108 { 109 this.title = title; 110 } 111 112 public List getDeclaredSteps() 113 { 114 return declaredSteps; 115 } 116 117 public void setDeclaredSteps(List steps) 118 { 119 declaredSteps = (steps == null) ? new ArrayList () : steps; 120 } 121 122 public List getCurrentSteps() 123 { 124 return currentSteps; 125 } 126 127 133 public List getCurrentSteps(StepFilter filter) 134 { 135 List filteredSteps = new ArrayList (); 136 for (Iterator steps = currentSteps.iterator(); steps.hasNext();) 137 { 138 WorkflowStepVO step = (WorkflowStepVO)steps.next(); 139 if (filter.isAllowed(step)) 140 filteredSteps.add(step); 141 } 142 143 return filteredSteps; 144 } 145 146 public void setCurrentSteps(List steps) 147 { 148 currentSteps = (steps == null) ? new ArrayList () : steps; 149 } 150 151 public List getHistorySteps() 152 { 153 return historySteps; 154 } 155 156 public void setHistorySteps(List steps) 157 { 158 historySteps = (steps == null) ? new ArrayList () : steps; 159 } 160 161 public List getInitialActions() 162 { 163 return initialActions; 164 } 165 166 public void setInitialActions(List actions) 167 { 168 initialActions = (actions == null) ? new ArrayList () : actions; 169 } 170 171 public List getGlobalActions() 172 { 173 return globalActions; 174 } 175 176 public void setGlobalActions(List actions) 177 { 178 globalActions = (actions == null) ? new ArrayList () : actions; 179 } 180 181 185 public List getSteps() 186 { 187 List steps = new ArrayList (); 188 steps.addAll(currentSteps); 189 steps.addAll(historySteps); 190 return steps; 191 } 192 193 197 public List getAvailableActions() 198 { 199 return getAvailableActions(null); 200 } 201 202 208 public List getAvailableActions(StepFilter filter) 209 { 210 List steps = (filter == null) ? currentSteps : getCurrentSteps(filter); 211 List availableActions = new ArrayList (); 212 213 for (Iterator i = steps.iterator(); i.hasNext();) 214 availableActions.addAll(((WorkflowStepVO)i.next()).getActions()); 215 216 return availableActions; 217 } 218 219 228 public WorkflowActionVO getInitialAction(Integer id) 229 { 230 for (Iterator actions = initialActions.iterator(); actions.hasNext();) 231 { 232 WorkflowActionVO action = (WorkflowActionVO)actions.next(); 233 if (id.equals(action.getId())) 234 return action; 235 } 236 237 throw new IllegalArgumentException ("Initial action " + id + " does not exist in workflow " + name); 238 } 239 240 public String toString() 241 { 242 return new StringBuffer (getClass().getName()) 243 .append(" name=").append(name) 244 .append(" workflowId=").append(workflowId) 245 .append(" declaredSteps=").append(declaredSteps.size()) 246 .append(" currentSteps=").append(currentSteps.size()) 247 .append(" historySteps=").append(historySteps.size()) 248 .append(" historySteps=").append(historySteps.size()) 249 .append(" globalActions=").append(globalActions.size()).toString(); 250 } 251 252 public ConstraintExceptionBuffer validate() 253 { 254 return new ConstraintExceptionBuffer(); 255 } 256 257 public String getStatusMessage() 258 { 259 return statusMessage; 260 } 261 262 public void setStatusMessage(String statusMessage) 263 { 264 this.statusMessage = statusMessage; 265 } 266 267 public int getStatus() 268 { 269 return status; 270 } 271 272 public void setStatus(int status) 273 { 274 this.status = status; 275 } 276 } 277 | Popular Tags |