⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 opportunityteamselectep.java

📁 国外的一套开源CRM
💻 JAVA
字号:
/*
 * 
 * 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.opportunity;

import java.sql.Timestamp;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Vector;

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

import com.sourcetap.sfa.event.DataMatrix;
import com.sourcetap.sfa.event.GenericEventProcessor;
import com.sourcetap.sfa.security.SecurityWrapper;
import com.sourcetap.sfa.util.QueryInfo;
import com.sourcetap.sfa.util.UserInfo;


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

    /**
     * DOCUMENT ME!
     *
     * @param userInfo 
     * @param mainEntityName 
     * @param method 
     * @param fields 
     * @param orderBy 
     * @param queryInfo  criteria to be used in search 
     * @param relatedSearchClauses 
     * @param delegator 
     * @param dataMatrix 
     *
     * @return 
     */
    public int retrieve(UserInfo userInfo, String mainEntityName, int method,
        Map fields, List orderBy, QueryInfo queryInfo,
        List relatedSearchClauses, GenericDelegator delegator,
        DataMatrix dataMatrix) {

        // The main entity is the TeamMember because it is the primary table we are going to update.
        List mainGVL = new LinkedList();
        GenericValue entityAccessGV = null;

        // First get the deal or account ID from the entityClauses.
        String entityName = "";
        String entityId = "";
        String fieldName = "";

		if ( 1 == 0 ) throw new IllegalArgumentException("need to fix query clauses");
/*        for (int entityClauseNbr = 0; entityClauseNbr < entityClauses.size();
                entityClauseNbr++) {
            EntityClause entityClause = (EntityClause) entityClauses.get(entityClauseNbr);
            fieldName = entityClause.getFirstField();

            if (entityClause.getSecondEntity().trim().length() == 0) {
                // This entity clause has a value, and could be a query parameter.  See if it's the dealId or accountId.
                if (fieldName.equals("dealId")) {
                    entityId = (String) entityClause.getValue();
                    entityName = "Deal";

                    break;
                } else if (fieldName.equals("accountId")) {
                    entityId = (String) entityClause.getValue();
                    entityName = "Account";

                    break;
                }
            }
        }
*/
        if (!entityId.equals("") && (entityId != null) &&
                !entityName.equals("") && (entityName != null)) {
            // Found account ID or deal ID.  Next find the entity acccess record for the team tied to the account or deal.
            HashMap entityAccessFindMap = new HashMap();
            entityAccessFindMap.put("entityId", entityId);
            entityAccessFindMap.put("entity", entityName);
            entityAccessFindMap.put("partyEntityType", "Team");

            try {
                List entityAccessGVL = delegator.findByAnd("EntityAccess",
                        entityAccessFindMap);
                Iterator entityAccessGVI = entityAccessGVL.iterator();

                if (entityAccessGVI.hasNext()) {
                    entityAccessGV = (GenericValue) entityAccessGVI.next();

                    String teamId = entityAccessGV.getString("partyId");

                    // Get the team members tied to this entity access record.
                    HashMap teamMemberFindMap = new HashMap();
                    teamMemberFindMap.put("teamId", teamId);

                    try {
                        mainGVL = delegator.findByAnd("TeamMember",
                                teamMemberFindMap);
                    } catch (GenericEntityException e) {
                        Debug.logError(
                            "[OpportunityTeamSelectEP.retrieveMainEntity] An error occurred while searching for " +
                            "the team member records for the account or deal: " +
                            e.getLocalizedMessage(), module);

                        return STATUS_ERROR;
                    }
                } else {
                    // No entity access record was found.  Assume no team member records are in the data base.
                    return STATUS_CONTINUE;
                }
            } catch (GenericEntityException e) {
                Debug.logError(
                    "[OpportunityTeamSelectEP.retrieveMainEntity] An error occurred while searching for " +
                    "the entity access record for the account or deal: " +
                    e.getLocalizedMessage(), module);

                return STATUS_ERROR;
            }
        } else {
            // Neither the Account ID nor the Deal ID were found.  Assume no team member records are in the data base.
            return STATUS_CONTINUE;
        }

        // Put all the rows into the data matrix.
        Iterator mainGVI = mainGVL.iterator();
        int rowCount = 0;

        while (mainGVI.hasNext()) {
            rowCount++;

            GenericValue mainGV = (GenericValue) mainGVI.next();

            // For each instance of the main entity, start a vector of entities, and then
            // retrieve the associated entities and add them also.
            Vector outGVV = new Vector();
            outGVV.add(mainGV);

            // Get the contact tied to this team member.
            GenericValue contactGV = null;

            try {
                contactGV = delegator.getRelatedOne("Contact", mainGV);
            } catch (GenericEntityException e) {
                Debug.logError(
                    "[OpportunityTeamSelectEP.retrieveMainEntity] An error occurred while searching for " +
                    "the contact for a team member: " +
                    e.getLocalizedMessage(), module);

                return STATUS_ERROR;
            }

            // Get the team tied to this team member.
            GenericValue teamGV = null;

            try {
                teamGV = delegator.getRelatedOne("Team", mainGV);
            } catch (GenericEntityException e) {
                Debug.logError(
                    "[OpportunityTeamSelectEP.retrieveMainEntity] An error occurred while searching for " +
                    "the team for a team member: " + e.getLocalizedMessage(), module);

                return STATUS_ERROR;
            }

            // Get the deal or account.
            GenericValue dealOrAccountGV = null;
            HashMap dealOrAccountPkMap = new HashMap();
            dealOrAccountPkMap.put(fieldName, entityId);

            try {
                dealOrAccountGV = delegator.findByPrimaryKey(entityName,
                        dealOrAccountPkMap);
            } catch (GenericEntityException e) {
                Debug.logError(
                    "[OpportunityTeamSelectEP.retrieveMainEntity] An error occurred while searching for " +
                    "the deal or account: " + e.getLocalizedMessage(), module);

                return STATUS_ERROR;
            }

            // Add the data to the data matrix.
            outGVV.add(contactGV);
            outGVV.add(entityAccessGV);
            outGVV.add(teamGV);
            outGVV.add(dealOrAccountGV);
            dataMatrix.getCurrentBuffer().addContentsRow(outGVV);
        }

        return STATUS_CONTINUE;
    }

    /**
     * DOCUMENT ME!
     *
     * @param primaryModelEntity 
     * @param removeMap 
     * @param userInfo 
     * @param delegator 
     *
     * @return 
     */
    protected int deleteOneSelect(ModelEntity primaryModelEntity,
        HashMap removeMap, UserInfo userInfo, GenericDelegator delegator) {

        String contactId = ((String) removeMap.get("contactId") == null) ? ""
                                                                         : (String) removeMap.get(
                "contactId");
        String teamId = ((String) removeMap.get("teamId") == null) ? ""
                                                                   : (String) removeMap.get(
                "teamId");

        SecurityWrapper.removeTeamMember(teamId, contactId, userInfo, delegator);

        return STATUS_CONTINUE;
    }

    /**
     * DOCUMENT ME!
     *
     * @param primaryModelEntity 
     * @param createMap 
     * @param userInfo 
     * @param delegator 
     *
     * @return 
     */
    protected int insertOneSelect(ModelEntity primaryModelEntity,
        HashMap createMap, UserInfo userInfo, GenericDelegator delegator) {

        String contactId = ((String) createMap.get("contactId") == null) ? ""
                                                                         : (String) createMap.get(
                "contactId");
        String teamId = ((String) createMap.get("teamId") == null) ? ""
                                                                   : (String) createMap.get(
                "teamId");

        SecurityWrapper.addTeamMember(teamId, contactId, userInfo, delegator);

        return STATUS_CONTINUE;
    }

    /**
     * DOCUMENT ME!
     *
     * @param userInfo 
     * @param delegator 
     * @param dataMatrix 
     *
     * @return 
     */
    protected int preUpdate(UserInfo userInfo, GenericDelegator delegator,
        DataMatrix dataMatrix) {

        Timestamp now = new Timestamp(Calendar.getInstance().getTime().getTime());

        // Process all rows.
        for (int row = 0; row < dataMatrix.getCurrentBuffer().getRowCount();
                row++) {
            if (dataMatrix.getRowChanged(row)) {
                GenericValue teamMemberGV = dataMatrix.getCurrentBuffer()
                                                      .getGenericValue(row, 0);

                //				GenericValue contactGV = dataMatrix.getCurrentBuffer().getGenericValue(row, 1);
                //				GenericValue entityAccessGV = dataMatrix.getCurrentBuffer().getGenericValue(row, 2);
                //				GenericValue teamGV = dataMatrix.getCurrentBuffer().getGenericValue(row, 3);
                //				GenericValue dealGV = dataMatrix.getCurrentBuffer().getGenericValue(row, 4);
                // Set the time stamps.
                teamMemberGV.set("modifiedDate", now);

                // Store the current user's party ID in the "modified by" field.
                teamMemberGV.set("modifiedBy", userInfo.getPartyId());
            }
        }

        return STATUS_CONTINUE;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -