1 25 package org.ofbiz.workflow.impl; 26 27 import java.util.ArrayList ; 28 import java.util.Collection ; 29 import java.util.Iterator ; 30 import java.util.List ; 31 import java.util.Map ; 32 33 import org.ofbiz.base.util.UtilMisc; 34 import org.ofbiz.entity.GenericDelegator; 35 import org.ofbiz.entity.GenericEntityException; 36 import org.ofbiz.entity.GenericValue; 37 import org.ofbiz.workflow.NotAssigned; 38 import org.ofbiz.workflow.WfActivity; 39 import org.ofbiz.workflow.WfAssignment; 40 import org.ofbiz.workflow.WfException; 41 import org.ofbiz.workflow.WfFactory; 42 import org.ofbiz.workflow.WfResource; 43 44 51 public class WfResourceImpl implements WfResource { 52 53 protected GenericDelegator delegator = null; 54 protected String resourceKey = null; 55 protected String resourceName = null; 56 protected String description = null; 57 protected String partyId = null; 58 protected String roleTypeId = null; 59 protected String type = null; 60 61 69 public WfResourceImpl(GenericDelegator delegator, String resourceKey, String resourceName, String partyId, String roleTypeId) { 70 this.delegator = delegator; 71 this.resourceKey = resourceKey; 72 this.resourceName = resourceName; 73 this.description = null; 74 this.partyId = partyId; 75 this.roleTypeId = roleTypeId; 76 this.type = "HUMAN"; 77 } 78 79 83 public WfResourceImpl(GenericValue valueObject) { 84 this.delegator = valueObject.getDelegator(); 85 this.resourceKey = valueObject.getString("participantId"); 86 this.resourceName = valueObject.getString("participantName"); 87 this.description = valueObject.getString("description"); 88 this.partyId = valueObject.getString("partyId"); 89 this.roleTypeId = valueObject.getString("roleTypeId"); 90 this.type = valueObject.getString("participantTypeId"); 91 if (partyId == null) 92 partyId = "_NA_"; 93 if (roleTypeId == null) 94 roleTypeId = "_NA_"; 95 } 96 97 100 public int howManyWorkItem() throws WfException { 101 return workItems().size(); 102 } 103 104 107 public Iterator getIteratorWorkItem() throws WfException { 108 return workItems().iterator(); 109 } 110 111 114 public List getSequenceWorkItem(int maxNumber) throws WfException { 115 if (maxNumber > 0) 116 return workItems().subList(0, (maxNumber - 1)); 117 return workItems(); 118 } 119 120 123 public boolean isMemberOfWorkItems(WfAssignment member) throws WfException { 124 return workItems().contains(member); 125 } 126 127 130 public String resourceKey() throws WfException { 131 return resourceKey; 132 } 133 134 137 public String resourceName() throws WfException { 138 return resourceName; 139 } 140 141 144 public String resourceRoleId() throws WfException { 145 return roleTypeId; 146 } 147 148 151 public String resourcePartyId() throws WfException { 152 return partyId; 153 } 154 155 158 public void release(WfAssignment fromAssignment, 159 String releaseInfo) throws WfException, NotAssigned { 160 if (!workItems().contains(fromAssignment)) 161 throw new NotAssigned(); 162 } 165 166 private List workItems() throws WfException { 167 List workList = new ArrayList (); 168 Collection c = null; 169 170 try { 171 Map fields = UtilMisc.toMap("partyId", partyId, "roleTypeId", roleTypeId); 172 c = delegator.findByAnd("WorkEffortPartyAssignment", fields); 173 } catch (GenericEntityException e) { 174 throw new WfException(e.getMessage(), e); 175 } 176 177 if (c != null) { 178 Iterator i = c.iterator(); 179 while (i.hasNext()) { 180 GenericValue v = (GenericValue) i.next(); 181 WfActivity a = null; 182 183 try { 184 a = WfFactory.getWfActivity(delegator, v.getString("workEffortId")); 185 } catch (RuntimeException e) { 186 throw new WfException(e.getMessage(), e); 187 } 188 if (a != null) 189 workList.add(a); 190 } 191 } 192 return workList; 193 } 194 } 195 196 | Popular Tags |