KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > shark > mapping > EntityParticipantMappingMgr


1 /*
2  * $Id: EntityParticipantMappingMgr.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2004 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.shark.mapping;
26
27 import java.util.List JavaDoc;
28 import java.util.ArrayList JavaDoc;
29 import java.util.Iterator JavaDoc;
30
31 import org.ofbiz.entity.GenericDelegator;
32 import org.ofbiz.entity.GenericEntityException;
33 import org.ofbiz.entity.GenericValue;
34 import org.ofbiz.shark.container.SharkContainer;
35 import org.ofbiz.shark.transaction.JtaTransaction;
36 import org.ofbiz.base.util.UtilMisc;
37
38 import org.enhydra.shark.api.internal.working.CallbackUtilities;
39 import org.enhydra.shark.api.internal.partmappersistence.ParticipantMap;
40 import org.enhydra.shark.api.internal.partmappersistence.ParticipantMappingManager;
41 import org.enhydra.shark.api.RootException;
42 import org.enhydra.shark.api.ParticipantMappingTransaction;
43 import org.enhydra.shark.api.TransactionException;
44
45 /**
46  * Shark Participant Mappings Implementation
47  *
48  * @author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
49  * @version $Rev: 5462 $
50  * @since 3.1
51  */

52 public class EntityParticipantMappingMgr implements ParticipantMappingManager {
53
54     public static final String JavaDoc module = EntityParticipantMappingMgr.class.getName();
55
56     protected CallbackUtilities callBack = null;
57
58     public void configure(CallbackUtilities callbackUtilities) throws RootException {
59         this.callBack = callbackUtilities;
60     }
61
62     public boolean saveParticipantMapping(ParticipantMappingTransaction mappingTransaction, ParticipantMap participantMap) throws RootException {
63         ((EntityParticipantMap) participantMap).store();
64         return true;
65     }
66
67     public boolean deleteParticipantMapping(ParticipantMappingTransaction mappingTransaction, ParticipantMap participantMap) throws RootException {
68         ((EntityParticipantMap) participantMap).remove();
69         return true;
70     }
71
72     public List JavaDoc getAllParticipantMappings(ParticipantMappingTransaction mappingTransaction) throws RootException {
73         GenericDelegator delegator = SharkContainer.getDelegator();
74         List JavaDoc lookupList = null;
75         try {
76             lookupList = delegator.findAll("WfParticipantMap");
77         } catch (GenericEntityException e) {
78             throw new RootException(e);
79         }
80         if (lookupList != null) {
81             List JavaDoc compiledList = new ArrayList JavaDoc();
82             Iterator JavaDoc i = lookupList.iterator();
83             while (i.hasNext()) {
84                 GenericValue v = (GenericValue) i.next();
85                 compiledList.add(EntityParticipantMap.getInstance(v));
86             }
87             return compiledList;
88         } else {
89             return new ArrayList JavaDoc();
90         }
91     }
92
93     public boolean doesParticipantMappingExist(ParticipantMappingTransaction mappingTransaction, ParticipantMap participantMap) throws RootException {
94         List JavaDoc mappings = getParticipantMappings(mappingTransaction, participantMap.getPackageId(), participantMap.getProcessDefinitionId(), participantMap.getParticipantId());
95         if (mappings != null && mappings.size() > 0) {
96             return true;
97         }
98         return false;
99     }
100
101     public ParticipantMap createParticipantMap() {
102         return new EntityParticipantMap(SharkContainer.getDelegator());
103     }
104
105     public List JavaDoc getParticipantMappings(ParticipantMappingTransaction mappingTransaction, String JavaDoc packageId, String JavaDoc processDefId, String JavaDoc participantId) throws RootException {
106         GenericDelegator delegator = SharkContainer.getDelegator();
107         List JavaDoc lookupList = null;
108         try {
109             lookupList = delegator.findByAnd("WfParticipantMap", UtilMisc.toMap("packageId", packageId, "processDefId", processDefId, "participantId", participantId));
110         } catch (GenericEntityException e) {
111             throw new RootException(e);
112         }
113         if (lookupList != null) {
114             List JavaDoc compiledList = new ArrayList JavaDoc();
115             Iterator JavaDoc i = lookupList.iterator();
116             while (i.hasNext()) {
117                 GenericValue v = (GenericValue) i.next();
118                 compiledList.add(EntityParticipantMap.getInstance(v));
119             }
120             return compiledList;
121         } else {
122             return new ArrayList JavaDoc();
123         }
124     }
125
126     public List JavaDoc getParticipantMappings(ParticipantMappingTransaction mappingTransaction, String JavaDoc userName) throws RootException {
127         GenericDelegator delegator = SharkContainer.getDelegator();
128         List JavaDoc lookupList = null;
129         try {
130             lookupList = delegator.findByAnd("WfParticipantMap", UtilMisc.toMap("userName", userName));
131         } catch (GenericEntityException e) {
132             throw new RootException(e);
133         }
134         if (lookupList != null) {
135             List JavaDoc compiledList = new ArrayList JavaDoc();
136             Iterator JavaDoc i = lookupList.iterator();
137             while (i.hasNext()) {
138                 GenericValue v = (GenericValue) i.next();
139                 compiledList.add(EntityParticipantMap.getInstance(v));
140             }
141             return compiledList;
142         } else {
143             return new ArrayList JavaDoc();
144         }
145     }
146
147     public boolean deleteParticipantMappings(ParticipantMappingTransaction mappingTransaction, String JavaDoc packageId, String JavaDoc processDefId, String JavaDoc participantId) throws RootException {
148         List JavaDoc participants = this.getParticipantMappings(mappingTransaction, packageId, processDefId, participantId);
149         if (participants != null) {
150             Iterator JavaDoc i = participants.iterator();
151             while (i.hasNext()) {
152                 EntityParticipantMap map = (EntityParticipantMap) i.next();
153                 map.remove();
154             }
155             return true;
156         } else {
157             return false;
158         }
159     }
160
161     public boolean deleteParticipantMappings(ParticipantMappingTransaction mappingTransaction, String JavaDoc userName) throws RootException {
162         List JavaDoc participants = this.getParticipantMappings(mappingTransaction, userName);
163         if (participants != null) {
164             Iterator JavaDoc i = participants.iterator();
165             while (i.hasNext()) {
166                 EntityParticipantMap map = (EntityParticipantMap) i.next();
167                 map.remove();
168             }
169             return true;
170         } else {
171             return false;
172         }
173     }
174
175     public List JavaDoc getUsernames(ParticipantMappingTransaction mappingTransaction, String JavaDoc packageId, String JavaDoc processDefId, String JavaDoc participantId) throws RootException {
176         List JavaDoc participants = this.getParticipantMappings(mappingTransaction, packageId, processDefId, participantId);
177         List JavaDoc compiledList = new ArrayList JavaDoc();
178         if (participants != null) {
179             Iterator JavaDoc i = participants.iterator();
180             while (i.hasNext()) {
181                 EntityParticipantMap map = (EntityParticipantMap) i.next();
182                 compiledList.add(map.getUsername());
183             }
184         }
185         return compiledList;
186     }
187
188     public ParticipantMappingTransaction getParticipantMappingTransaction() throws TransactionException {
189         return new JtaTransaction();
190     }
191 }
192
Popular Tags