Package com.sourcetap.sfa.security

Source Code of com.sourcetap.sfa.security.EntityAccessHelper

/*
*
* Copyright (c) 2004 SourceTap - www.sourcetap.com
*
*  The contents of this file are subject to the SourceTap Public License
* ("License"); You may not use this file except in compliance with the
* License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
* Software distributed under the License is distributed on an  "AS IS"  basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
*/

package com.sourcetap.sfa.security;

import java.util.HashMap;
import java.util.List;

import org.ofbiz.base.util.Debug;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericPK;
import org.ofbiz.entity.GenericValue;

import com.sourcetap.sfa.util.UserInfo;


/**
* DOCUMENT ME!
*
*/
public class EntityAccessHelper {
  public static final String module = EntityAccessHelper.class.getName();

    /**
     * DOCUMENT ME!
     *
     * @param userInfo
     * @param delegator
     * @param entityGV
     * @param relationTitle
     *
     * @return
     */
    public static List findRelated(UserInfo userInfo,
        GenericDelegator delegator, GenericValue entityGV, String relationTitle) {
        // Find instances of an entity related to the current entity so the instances
        // can be deleted.

        if (userInfo == null) {
            Debug.logError("[findRelated] User info object is required.", module);

            return null;
        }

        if (delegator == null) {
            Debug.logError("[findRelated] Delegator is required.", module);

            return null;
        }

        if (entityGV == null) {
            Debug.logError("[findRelated] Entity generic value is required.", module);

            return null;
        }

        String mainEntityName = entityGV.getEntityName();
        String relatedEntityName = "EntityAccess";

        // Find related EntityAccess records. Need special processing because
        // the relationship cannot be defined in the sfa-config.xml file.
        GenericPK entityPK = null;
        String entityKeyString = null;

        String entityName = entityGV.getEntityName();
        List relatedGVL = null;

        try {

            HashMap findMap = new HashMap();
            String entityId = "";

            if (mainEntityName.equals("Account")) {
                entityId = entityGV.getString("accountId");
            } else if (mainEntityName.equals("Deal")) {
                entityId = entityGV.getString("dealId");
            } else {
                // Error.
                Debug.logError(
                    "[findRelated] Entity name must be 'Deal' or 'Account', " +
                    "but is '" + mainEntityName + "'.", module);

                return null;
            }

            String accountId = null;
            findMap.put("entityId", entityId);
            findMap.put("entity", mainEntityName);
            relatedGVL = delegator.findByAnd(relatedEntityName, findMap);
        } catch (GenericEntityException e) {
            Debug.logError("[findRelated] Error getting " + "the related " +
                relatedEntityName + " records: " + e.getLocalizedMessage(), module);

            return null;
        }

        return relatedGVL;
    }
}
TOP

Related Classes of com.sourcetap.sfa.security.EntityAccessHelper

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.