01: /*
02: *
03: * Copyright (c) 2004 SourceTap - www.sourcetap.com
04: *
05: * The contents of this file are subject to the SourceTap Public License
06: * ("License"); You may not use this file except in compliance with the
07: * License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
08: * Software distributed under the License is distributed on an "AS IS" basis,
09: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
10: * the specific language governing rights and limitations under the License.
11: *
12: * The above copyright notice and this permission notice shall be included
13: * in all copies or substantial portions of the Software.
14: *
15: */
16:
17: package com.sourcetap.sfa.security;
18:
19: import java.util.HashMap;
20: import java.util.LinkedList;
21: import java.util.List;
22:
23: import org.ofbiz.base.util.Debug;
24: import org.ofbiz.entity.GenericDelegator;
25: import org.ofbiz.entity.GenericEntityException;
26: import org.ofbiz.entity.GenericPK;
27: import org.ofbiz.entity.GenericValue;
28:
29: import com.sourcetap.sfa.util.UserInfo;
30:
31: /**
32: * DOCUMENT ME!
33: *
34: */
35: public class TeamHelper {
36: public static final String module = TeamHelper.class.getName();
37:
38: /**
39: * DOCUMENT ME!
40: *
41: * @param userInfo
42: * @param delegator
43: * @param entityGV
44: * @param relationTitle
45: *
46: * @return
47: */
48: public static List findRelated(UserInfo userInfo,
49: GenericDelegator delegator, GenericValue entityGV,
50: String relationTitle) {
51:
52: String mainEntityName = entityGV.getEntityName();
53: String relatedEntityName = "Team";
54:
55: // Finding related Team records. Need special processing because the relationship cannot be
56: // defined in the sfa-config.xml file.
57: GenericPK entityPK = null;
58: String entityKeyString = null;
59:
60: List relatedGVL = null;
61:
62: try {
63: Debug.logVerbose("[findRelated] Retrieving all "
64: + relatedEntityName + " records related to "
65: + entityKeyString, module);
66:
67: HashMap findMap = new HashMap();
68: String partyEntityType = (entityGV
69: .getString("partyEntityType") == null) ? ""
70: : entityGV.getString("partyEntityType");
71:
72: if (partyEntityType.equals("Team")) {
73: // This EntityAccess record is tied to a team. Need to return this team if it exists.
74: String teamId = (entityGV.getString("partyId") == null) ? ""
75: : entityGV.getString("partyId");
76:
77: findMap.put("teamId", teamId);
78: relatedGVL = delegator.findByAnd(relatedEntityName,
79: findMap);
80: } else {
81: // The party is a role. Don't need to return anything.
82: return new LinkedList();
83: }
84: } catch (GenericEntityException e) {
85: Debug.logWarning("[findRelated] Error getting the related "
86: + relatedEntityName + " records: "
87: + e.getLocalizedMessage(), module);
88:
89: return new LinkedList();
90: }
91:
92: return relatedGVL;
93: }
94: }
|