1 package org.enhydra.shark.assignment; 2 3 import java.util.ArrayList ; 4 import java.util.List ; 5 6 import org.enhydra.shark.Shark; 7 import org.enhydra.shark.api.RootException; 8 import org.enhydra.shark.api.SharkTransaction; 9 import org.enhydra.shark.api.client.wfmodel.WfActivity; 10 import org.enhydra.shark.api.client.wfmodel.WfActivityIterator; 11 import org.enhydra.shark.api.client.wfmodel.WfProcess; 12 import org.enhydra.shark.api.client.wfservice.AdminInterface; 13 import org.enhydra.shark.api.client.wfservice.AdminMisc; 14 import org.enhydra.shark.api.client.wfservice.ExecutionAdministration; 15 import org.enhydra.shark.api.internal.assignment.AssignmentManager; 16 import org.enhydra.shark.api.internal.assignment.PerformerData; 17 import org.enhydra.shark.api.internal.working.CallbackUtilities; 18 import org.enhydra.shark.xpdl.XMLUtil; 19 20 66 public class HistoryRelatedAssignmentManager implements AssignmentManager { 67 private CallbackUtilities cus; 68 69 private String username; 70 private String password; 71 private String extAttrReassignToOriginalPerformer; 72 private String extAttrAssignToPerformerOfActivity; 73 private String extAttrDoNotAssignToPerformerOfActivity; 74 75 public void configure(CallbackUtilities cus) throws RootException { 76 this.cus = cus; 77 78 82 username = cus.getProperty("HistoryRelatedAssignmentManager.username"); 83 password = cus.getProperty("HistoryRelatedAssignmentManager.password"); 84 85 extAttrReassignToOriginalPerformer = cus.getProperty( 86 "HistoryRelatedAssignmentManager.extAttrReassignToOriginalPerformer", 87 "ReassignToOriginalPerformer"); 88 89 extAttrAssignToPerformerOfActivity = cus.getProperty( 90 "HistoryRelatedAssignmentManager.extAttrAssignToPerformerOfActivity", 91 "AssignToPerformerOfActivity"); 92 93 extAttrDoNotAssignToPerformerOfActivity = cus 94 .getProperty( 95 "HistoryRelatedAssignmentManager.extAttrDoNotAssignToPerformerOfActivity", 96 "DoNotAssignToPerformerOfActivity"); 97 } 98 99 public List getAssignments(SharkTransaction t, 100 String engineName, 101 String procId, 102 String actId, 103 List userIds, 104 List responsibleIds, 105 String processRequesterId, 106 PerformerData xpdlParticipant, 107 List xpdlResponsibleParticipants) throws RootException { 108 List result = null; 109 110 Shark shark = Shark.getInstance(); 111 AdminInterface ai = shark.getAdminInterface(); 112 AdminMisc am = ai.getAdminMisc(); 113 114 String [][] actExtAttribs = null; 115 116 try { 117 actExtAttribs = am.getActivitiesExtendedAttributeNameValuePairs(t, procId, actId); 118 } catch (Exception ex) { 119 } 120 121 if (actExtAttribs!=null) { 122 if (XMLUtil.getExtendedAttributeValue(actExtAttribs, extAttrReassignToOriginalPerformer)!=null) { 123 result = doReassignToOriginalPerformer(t, engineName, procId, 124 actId, userIds, responsibleIds, 125 processRequesterId, ai, am); 126 } 127 else if (XMLUtil.getExtendedAttributeValue(actExtAttribs,extAttrAssignToPerformerOfActivity)!=null) { 128 result = doAssignToPerformerOfActivity(t, engineName, procId, 129 actId, userIds, responsibleIds, 130 processRequesterId, ai, am, actExtAttribs); 131 } 132 else if (XMLUtil.getExtendedAttributeValue(actExtAttribs,extAttrDoNotAssignToPerformerOfActivity)!=null) { 133 result = doDoNotAssignToPerformerOfActivity(t, engineName, procId, 134 actId, userIds, responsibleIds, 135 processRequesterId, ai, am, actExtAttribs); 136 } 137 else { 138 result = getDefaultAssignments(t, engineName, procId, actId, 140 userIds, responsibleIds, processRequesterId); 141 } 142 } else { 143 result = getDefaultAssignments(t, engineName, procId, actId, 145 userIds, responsibleIds, processRequesterId); 146 } 147 148 return result; 149 } 150 151 protected List doReassignToOriginalPerformer(SharkTransaction t, 152 String engineName, String procId, String actId, List userIds, 153 List responsibleIds, String processRequesterId, 154 AdminInterface ai, AdminMisc am) throws RootException { 155 String actDefId = am.getActivityDefinitionId(t, procId, actId); 156 157 return getAssignmentsForActDefId(t, engineName, procId, actId, userIds, 158 responsibleIds, processRequesterId, ai, am, 159 actDefId, true); 160 } 161 162 protected List doAssignToPerformerOfActivity(SharkTransaction t, 163 String engineName, String procId, String actId, List userIds, 164 List responsibleIds, String processRequesterId, 165 AdminInterface ai, AdminMisc am, String [][] actExtAttribs) 166 throws RootException { 167 String actDefId = XMLUtil.getExtendedAttributeValue(actExtAttribs, 168 extAttrAssignToPerformerOfActivity); 169 170 return getAssignmentsForActDefId(t, engineName, procId, actId, userIds, 171 responsibleIds, processRequesterId, ai, am, 172 actDefId, true); 173 } 174 175 protected List doDoNotAssignToPerformerOfActivity(SharkTransaction t, 176 String engineName, String procId, String actId, List userIds, 177 List responsibleIds, String processRequesterId, 178 AdminInterface ai, AdminMisc am, String [][] actExtAttribs) 179 throws RootException { 180 String actDefId = XMLUtil.getExtendedAttributeValue(actExtAttribs, 181 extAttrDoNotAssignToPerformerOfActivity); 182 183 List doNotAssignTo = getAssignmentsForActDefId(t, engineName, procId, 184 actId, userIds, responsibleIds, processRequesterId, 185 ai, am, actDefId, false); 186 187 List allAssignments = getDefaultAssignments(t, engineName, procId, 188 actId, userIds, responsibleIds, processRequesterId); 189 190 197 if (allAssignments.size() > 1) { 198 allAssignments.removeAll(doNotAssignTo); 199 } 200 201 return allAssignments; 202 } 203 204 208 protected List getAssignmentsForActDefId(SharkTransaction t, 209 String engineName, String procId, String actId, List userIds, 210 List responsibleIds, String processRequesterId, 211 AdminInterface ai, AdminMisc am, String actDefId, 212 boolean fallbackToDefault) throws RootException { 213 List result = new ArrayList (); 214 215 String prevPerformer = getPrevPerformerOfActDefId(t, procId, ai, am, 216 actDefId); 217 218 if (prevPerformer != null) { 219 result.add(prevPerformer); 220 } 221 else if (fallbackToDefault) { 222 227 result = getDefaultAssignments(t, engineName, procId, actId, 228 userIds, responsibleIds, processRequesterId); 229 } 230 231 return result; 232 } 233 234 protected String getPrevPerformerOfActDefId(SharkTransaction t, 235 String procId, 236 AdminInterface ai, 237 AdminMisc am, 238 String actDefId) 239 throws RootException { 240 String result = null; 241 242 if (actDefId != null) { 243 ExecutionAdministration ea = null; 244 245 try { 246 ea = ai.getExecutionAdministration(); 247 ea.connect(t, username, password, "", ""); 248 WfProcess proc = ea.getProcess(t, procId); 249 250 WfActivityIterator wai = proc.get_iterator_step(t); 251 252 String query = "state.equals(\"closed.completed\") && definitionId.equals(\"" + actDefId + "\")"; 253 254 wai.set_query_expression(t, query); 255 256 WfActivity[] acts=wai.get_next_n_sequence(t,0); 257 if (acts!=null && acts.length>0) { 258 long maxTime=-1; 260 WfActivity lastAct=null; 261 for (int i=0; i<acts.length; i++) { 262 long time=acts[i].last_state_time(t).getTime(); 263 if (time>maxTime) { 264 maxTime=time; 265 lastAct=acts[i]; 266 } 267 } 268 String prevActId = lastAct.key(t); 269 270 274 result = am.getActivityResourceUsername(t, procId, prevActId); 275 } 276 } 277 finally { 278 ea.disconnect(t); 279 } 280 281 } 282 283 return result; 284 } 285 286 public List getDefaultAssignments(SharkTransaction t, String engineName, 287 String procId, String actId, List userIds, List responsibleIds, 288 String processRequesterId) throws RootException { 289 List result; 290 291 if (userIds != null && userIds.size() > 0) { 292 result = userIds; 293 } 294 else if (responsibleIds != null && responsibleIds.size() > 0) { 295 result = responsibleIds; 296 } 297 else { 298 result = new ArrayList (); 299 result.add(processRequesterId); 300 } 301 302 return result; 303 } 304 305 } 306 | Popular Tags |