001: /*
002: * $Id: WfResourceImpl.java,v 1.2 2003/08/19 17:45:18 jonesde Exp $
003: *
004: * Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
005: *
006: * Permission is hereby granted, free of charge, to any person obtaining a
007: * copy of this software and associated documentation files (the "Software"),
008: * to deal in the Software without restriction, including without limitation
009: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
010: * and/or sell copies of the Software, and to permit persons to whom the
011: * Software is furnished to do so, subject to the following conditions:
012: *
013: * The above copyright notice and this permission notice shall be included
014: * in all copies or substantial portions of the Software.
015: *
016: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
017: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
018: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
019: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
020: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
021: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
022: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023: *
024: */
025: package org.ofbiz.workflow.impl;
026:
027: import java.util.ArrayList;
028: import java.util.Collection;
029: import java.util.Iterator;
030: import java.util.List;
031: import java.util.Map;
032:
033: import org.ofbiz.base.util.UtilMisc;
034: import org.ofbiz.entity.GenericDelegator;
035: import org.ofbiz.entity.GenericEntityException;
036: import org.ofbiz.entity.GenericValue;
037: import org.ofbiz.workflow.NotAssigned;
038: import org.ofbiz.workflow.WfActivity;
039: import org.ofbiz.workflow.WfAssignment;
040: import org.ofbiz.workflow.WfException;
041: import org.ofbiz.workflow.WfFactory;
042: import org.ofbiz.workflow.WfResource;
043:
044: /**
045: * WfResourceImpl - Workflow Resource Object implementation
046: *
047: * @author <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a>
048: * @version $Revision: 1.2 $
049: * @since 2.0
050: */
051: public class WfResourceImpl implements WfResource {
052:
053: protected GenericDelegator delegator = null;
054: protected String resourceKey = null;
055: protected String resourceName = null;
056: protected String description = null;
057: protected String partyId = null;
058: protected String roleTypeId = null;
059: protected String type = null;
060:
061: /**
062: * Creates a new WfResource
063: * @param resourceKey Uniquely identifies the resource
064: * @param resourceName The name of the resource
065: * @param partyId The partyID of this resource
066: * @param roleTypeId The roleTypeId of this resource
067: * @param fromDate The fromDate of this resource
068: */
069: public WfResourceImpl(GenericDelegator delegator,
070: String resourceKey, String resourceName, String partyId,
071: String roleTypeId) {
072: this .delegator = delegator;
073: this .resourceKey = resourceKey;
074: this .resourceName = resourceName;
075: this .description = null;
076: this .partyId = partyId;
077: this .roleTypeId = roleTypeId;
078: this .type = "HUMAN";
079: }
080:
081: /**
082: * Creates a new WfResource
083: * @param valueObject The GenericValue object of the WorkflowParticipant
084: */
085: public WfResourceImpl(GenericValue valueObject) {
086: this .delegator = valueObject.getDelegator();
087: this .resourceKey = valueObject.getString("participantId");
088: this .resourceName = valueObject.getString("participantName");
089: this .description = valueObject.getString("description");
090: this .partyId = valueObject.getString("partyId");
091: this .roleTypeId = valueObject.getString("roleTypeId");
092: this .type = valueObject.getString("participantTypeId");
093: if (partyId == null)
094: partyId = "_NA_";
095: if (roleTypeId == null)
096: roleTypeId = "_NA_";
097: }
098:
099: /**
100: * @see org.ofbiz.workflow.WfResource#howManyWorkItem()
101: */
102: public int howManyWorkItem() throws WfException {
103: return workItems().size();
104: }
105:
106: /**
107: * @see org.ofbiz.workflow.WfResource#getIteratorWorkItem()
108: */
109: public Iterator getIteratorWorkItem() throws WfException {
110: return workItems().iterator();
111: }
112:
113: /**
114: * @see org.ofbiz.workflow.WfResource#getSequenceWorkItem(int)
115: */
116: public List getSequenceWorkItem(int maxNumber) throws WfException {
117: if (maxNumber > 0)
118: return workItems().subList(0, (maxNumber - 1));
119: return workItems();
120: }
121:
122: /**
123: * @see org.ofbiz.workflow.WfResource#isMemberOfWorkItems(org.ofbiz.workflow.WfAssignment)
124: */
125: public boolean isMemberOfWorkItems(WfAssignment member)
126: throws WfException {
127: return workItems().contains(member);
128: }
129:
130: /**
131: * @see org.ofbiz.workflow.WfResource#resourceKey()
132: */
133: public String resourceKey() throws WfException {
134: return resourceKey;
135: }
136:
137: /**
138: * @see org.ofbiz.workflow.WfResource#resourceName()
139: */
140: public String resourceName() throws WfException {
141: return resourceName;
142: }
143:
144: /**
145: * @see org.ofbiz.workflow.WfResource#resourceRoleId()
146: */
147: public String resourceRoleId() throws WfException {
148: return roleTypeId;
149: }
150:
151: /**
152: * @see org.ofbiz.workflow.WfResource#resourcePartyId()
153: */
154: public String resourcePartyId() throws WfException {
155: return partyId;
156: }
157:
158: /**
159: * @see org.ofbiz.workflow.WfResource#release(org.ofbiz.workflow.WfAssignment, java.lang.String)
160: */
161: public void release(WfAssignment fromAssignment, String releaseInfo)
162: throws WfException, NotAssigned {
163: if (!workItems().contains(fromAssignment))
164: throw new NotAssigned();
165: // workItems.remove(fromAssignment);
166: // log the transaction
167: }
168:
169: private List workItems() throws WfException {
170: List workList = new ArrayList();
171: Collection c = null;
172:
173: try {
174: Map fields = UtilMisc.toMap("partyId", partyId,
175: "roleTypeId", roleTypeId);
176: c = delegator
177: .findByAnd("WorkEffortPartyAssignment", fields);
178: } catch (GenericEntityException e) {
179: throw new WfException(e.getMessage(), e);
180: }
181:
182: if (c != null) {
183: Iterator i = c.iterator();
184: while (i.hasNext()) {
185: GenericValue v = (GenericValue) i.next();
186: WfActivity a = null;
187:
188: try {
189: a = WfFactory.getWfActivity(delegator, v
190: .getString("workEffortId"));
191: } catch (RuntimeException e) {
192: throw new WfException(e.getMessage(), e);
193: }
194: if (a != null)
195: workList.add(a);
196: }
197: }
198: return workList;
199: }
200: }
|