KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > workflow > impl > WfResourceImpl


1 /*
2  * $Id: WfResourceImpl.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */

25 package org.ofbiz.workflow.impl;
26
27 import java.util.ArrayList JavaDoc;
28 import java.util.Collection JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.List JavaDoc;
31 import java.util.Map JavaDoc;
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 /**
45  * WfResourceImpl - Workflow Resource Object implementation
46  *
47  * @author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
48  * @version $Rev: 5462 $
49  * @since 2.0
50  */

51 public class WfResourceImpl implements WfResource {
52
53     protected GenericDelegator delegator = null;
54     protected String JavaDoc resourceKey = null;
55     protected String JavaDoc resourceName = null;
56     protected String JavaDoc description = null;
57     protected String JavaDoc partyId = null;
58     protected String JavaDoc roleTypeId = null;
59     protected String JavaDoc type = null;
60
61     /**
62      * Creates a new WfResource
63      * @param resourceKey Uniquely identifies the resource
64      * @param resourceName The name of the resource
65      * @param partyId The partyID of this resource
66      * @param roleTypeId The roleTypeId of this resource
67      * @param fromDate The fromDate of this resource
68      */

69     public WfResourceImpl(GenericDelegator delegator, String JavaDoc resourceKey, String JavaDoc resourceName, String JavaDoc partyId, String JavaDoc 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     /**
80      * Creates a new WfResource
81      * @param valueObject The GenericValue object of the WorkflowParticipant
82      */

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     /**
98      * @see org.ofbiz.workflow.WfResource#howManyWorkItem()
99      */

100     public int howManyWorkItem() throws WfException {
101         return workItems().size();
102     }
103  
104     /**
105      * @see org.ofbiz.workflow.WfResource#getIteratorWorkItem()
106      */

107     public Iterator JavaDoc getIteratorWorkItem() throws WfException {
108         return workItems().iterator();
109     }
110   
111     /**
112      * @see org.ofbiz.workflow.WfResource#getSequenceWorkItem(int)
113      */

114     public List JavaDoc getSequenceWorkItem(int maxNumber) throws WfException {
115         if (maxNumber > 0)
116             return workItems().subList(0, (maxNumber - 1));
117         return workItems();
118     }
119
120     /**
121      * @see org.ofbiz.workflow.WfResource#isMemberOfWorkItems(org.ofbiz.workflow.WfAssignment)
122      */

123     public boolean isMemberOfWorkItems(WfAssignment member) throws WfException {
124         return workItems().contains(member);
125     }
126
127     /**
128      * @see org.ofbiz.workflow.WfResource#resourceKey()
129      */

130     public String JavaDoc resourceKey() throws WfException {
131         return resourceKey;
132     }
133
134     /**
135      * @see org.ofbiz.workflow.WfResource#resourceName()
136      */

137     public String JavaDoc resourceName() throws WfException {
138         return resourceName;
139     }
140
141     /**
142      * @see org.ofbiz.workflow.WfResource#resourceRoleId()
143      */

144     public String JavaDoc resourceRoleId() throws WfException {
145         return roleTypeId;
146     }
147
148     /**
149      * @see org.ofbiz.workflow.WfResource#resourcePartyId()
150      */

151     public String JavaDoc resourcePartyId() throws WfException {
152         return partyId;
153     }
154
155     /**
156      * @see org.ofbiz.workflow.WfResource#release(org.ofbiz.workflow.WfAssignment, java.lang.String)
157      */

158     public void release(WfAssignment fromAssignment,
159         String JavaDoc releaseInfo) throws WfException, NotAssigned {
160         if (!workItems().contains(fromAssignment))
161             throw new NotAssigned();
162         // workItems.remove(fromAssignment);
163
// log the transaction
164
}
165
166     private List JavaDoc workItems() throws WfException {
167         List JavaDoc workList = new ArrayList JavaDoc();
168         Collection JavaDoc c = null;
169
170         try {
171             Map JavaDoc 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 JavaDoc 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 JavaDoc 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