001: /*
002: *
003: * Copyright (c) 2004 SourceTap - www.sourcetap.com
004: *
005: * The contents of this file are subject to the SourceTap Public License
006: * ("License"); You may not use this file except in compliance with the
007: * License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
008: * Software distributed under the License is distributed on an "AS IS" basis,
009: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
010: * the specific language governing rights and limitations under the License.
011: *
012: * The above copyright notice and this permission notice shall be included
013: * in all copies or substantial portions of the Software.
014: *
015: */
016:
017: package com.sourcetap.sfa.security;
018:
019: import java.util.HashMap;
020: import java.util.List;
021:
022: import org.ofbiz.base.util.Debug;
023: import org.ofbiz.entity.GenericDelegator;
024: import org.ofbiz.entity.GenericEntityException;
025: import org.ofbiz.entity.GenericPK;
026: import org.ofbiz.entity.GenericValue;
027:
028: import com.sourcetap.sfa.util.UserInfo;
029:
030: /**
031: * DOCUMENT ME!
032: *
033: */
034: public class EntityAccessHelper {
035: public static final String module = EntityAccessHelper.class
036: .getName();
037:
038: /**
039: * DOCUMENT ME!
040: *
041: * @param userInfo
042: * @param delegator
043: * @param entityGV
044: * @param relationTitle
045: *
046: * @return
047: */
048: public static List findRelated(UserInfo userInfo,
049: GenericDelegator delegator, GenericValue entityGV,
050: String relationTitle) {
051: // Find instances of an entity related to the current entity so the instances
052: // can be deleted.
053:
054: if (userInfo == null) {
055: Debug.logError(
056: "[findRelated] User info object is required.",
057: module);
058:
059: return null;
060: }
061:
062: if (delegator == null) {
063: Debug.logError("[findRelated] Delegator is required.",
064: module);
065:
066: return null;
067: }
068:
069: if (entityGV == null) {
070: Debug.logError(
071: "[findRelated] Entity generic value is required.",
072: module);
073:
074: return null;
075: }
076:
077: String mainEntityName = entityGV.getEntityName();
078: String relatedEntityName = "EntityAccess";
079:
080: // Find related EntityAccess records. Need special processing because
081: // the relationship cannot be defined in the sfa-config.xml file.
082: GenericPK entityPK = null;
083: String entityKeyString = null;
084:
085: String entityName = entityGV.getEntityName();
086: List relatedGVL = null;
087:
088: try {
089:
090: HashMap findMap = new HashMap();
091: String entityId = "";
092:
093: if (mainEntityName.equals("Account")) {
094: entityId = entityGV.getString("accountId");
095: } else if (mainEntityName.equals("Deal")) {
096: entityId = entityGV.getString("dealId");
097: } else {
098: // Error.
099: Debug.logError(
100: "[findRelated] Entity name must be 'Deal' or 'Account', "
101: + "but is '" + mainEntityName + "'.",
102: module);
103:
104: return null;
105: }
106:
107: String accountId = null;
108: findMap.put("entityId", entityId);
109: findMap.put("entity", mainEntityName);
110: relatedGVL = delegator
111: .findByAnd(relatedEntityName, findMap);
112: } catch (GenericEntityException e) {
113: Debug.logError("[findRelated] Error getting "
114: + "the related " + relatedEntityName + " records: "
115: + e.getLocalizedMessage(), module);
116:
117: return null;
118: }
119:
120: return relatedGVL;
121: }
122: }
|