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

📄 activitywebeventprocessor.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.activity;

import java.sql.Timestamp;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

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

import com.sourcetap.sfa.event.DataMatrix;
import com.sourcetap.sfa.event.GenericEventProcessor;
import com.sourcetap.sfa.event.GenericWebEventProcessor;
import com.sourcetap.sfa.ui.UICache;
import com.sourcetap.sfa.ui.UIWebScreenSection;
import com.sourcetap.sfa.util.UserInfo;


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

    /**
     * DOCUMENT ME!
     *
     * @param userInfo 
     * @param uiWebScreenSection 
     * @param request 
     * @param response 
     * @param delegator 
     * @param eventProcessor 
     * @param dataMatrix 
     * @param uiCache 
     *
     * @return 
     */
    protected int preInsert(UserInfo userInfo,
        UIWebScreenSection uiWebScreenSection, HttpServletRequest request,
        HttpServletResponse response, GenericDelegator delegator,
        GenericEventProcessor eventProcessor, DataMatrix dataMatrix,
        UICache uiCache) {

        // If the screen section is on the composite account create window, need to copy the account ID
        // from the account to the activity.

        if (request.getAttribute("com.sourcetap.sfa.account.accountId") != null) {

            String accountId = (String) request.getAttribute(
                    "com.sourcetap.sfa.account.accountId");
            GenericValue activityGV = dataMatrix.getCurrentBuffer()
                                                .getGenericValue(0, 0);

            activityGV.set("accountId", accountId);
        }

        return STATUS_CONTINUE;
    }

    /**
     * DOCUMENT ME!
     *
     * @param userInfo 
     * @param uiWebScreenSection 
     * @param request 
     * @param response 
     * @param delegator 
     * @param eventProcessor 
     * @param dataMatrix 
     * @param uiCache 
     *
     * @return 
     */
    protected int postInsert(UserInfo userInfo,
        UIWebScreenSection uiWebScreenSection, HttpServletRequest request,
        HttpServletResponse response, GenericDelegator delegator,
        GenericEventProcessor eventProcessor, DataMatrix dataMatrix,
        UICache uiCache) {
        // If the screen section is on the composite account or  contact create window, and a contact was created,
        // need to create an activity-contact record for the created activity and contact.

        if (request.getAttribute("com.sourcetap.sfa.contact.contactId") != null) {
            String contactId = (String) request.getAttribute(
                    "com.sourcetap.sfa.contact.contactId");
            GenericValue activityGV = dataMatrix.getCurrentBuffer()
                                                .getGenericValue(0, 0);
            String activityId = activityGV.getString("activityId");

            // Create the new ActivityContact generic value.
            GenericValue activityContactGV = new GenericValue(delegator.getModelEntity(
                        "ActivityContact"));
            activityContactGV.setDelegator(delegator);
            Timestamp currentTime = new Timestamp(Calendar.getInstance()
                                                          .getTime().getTime());
            activityContactGV.set("activityId", activityId);
            activityContactGV.set("contactId", contactId);
            activityContactGV.set("createdBy", userInfo.getPartyId());
            activityContactGV.set("createdDate", currentTime);
            activityContactGV.set("modifiedBy", userInfo.getPartyId());
            activityContactGV.set("modifiedDate", currentTime);

            // Save the ActivityContact.
            try {
                delegator.create(activityContactGV);
            } catch (GenericEntityException e) {
                Debug.logWarning("Error inserting new ActivityContact. Save continued without inserting ActivityContact.",
                    "postInsert");
            }
        }

        return STATUS_CONTINUE;
    }

    /**
     * DOCUMENT ME!
     *
     * @param userInfo 
     * @param uiWebScreenSection 
     * @param request 
     * @param response 
     * @param delegator 
     * @param eventProcessor 
     * @param dataMatrix 
     * @param entityNameList 
     *
     * @return 
     */
    protected int postCreate(UserInfo userInfo,
        UIWebScreenSection uiWebScreenSection, HttpServletRequest request,
        HttpServletResponse response, GenericDelegator delegator,
        GenericEventProcessor eventProcessor, DataMatrix dataMatrix,
        List entityNameList) {

        GenericValue activityGV = dataMatrix.getCurrentBuffer().getGenericValue(0,
                0);

        // Set the Account ID.  This is done here instead of the regular event processor because the web event processor
        // has to set the contact, lead ID, or opportunity ID first so we can use it to look up the account.
        String accountId = "";


        if (activityGV.getString("contactId") != null) {
            // The contact ID is filled in.  Set the account ID.
            String contactId = activityGV.getString("contactId");

            HashMap contactFindMap = new HashMap();
            contactFindMap.put("contactId", contactId);

            try {

                GenericValue contactGV = delegator.findByPrimaryKey("Contact",
                        contactFindMap);

                if (contactGV != null) {

                    accountId = contactGV.getString("accountId");
                    activityGV.set("accountId", accountId);
                }
            } catch (GenericEntityException e) {
                // An error occurred while looking for the contact record. Don't set the account ID.
                Debug.logWarning("Error looking for contact: " +
                        e.getLocalizedMessage(), module);
            }
        }

        if (activityGV.getString("leadId") != null) {
            // The lead ID is filled in.  Set the account ID.
            String leadId = activityGV.getString("leadId");

            HashMap leadFindMap = new HashMap();
            leadFindMap.put("leadId", leadId);

            try {

                GenericValue leadGV = delegator.findByPrimaryKey("Lead",
                        leadFindMap);

                if (leadGV != null) {

                    accountId = leadGV.getString("accountId");
                    activityGV.set("accountId", accountId);
                }
            } catch (GenericEntityException e) {
                // An error occurred while looking for the lead record. Don't set the account ID.
                Debug.logWarning("Error looking for lead: " +
                        e.getLocalizedMessage(), module);
            }
        }

        if (activityGV.getString("opportunityId") != null) {
            // The contact ID is filled in.  Set the account ID.
            String opportunityId = activityGV.getString("opportunityId");

            HashMap dealFindMap = new HashMap();
            dealFindMap.put("dealId", opportunityId);

            try {

                GenericValue dealGV = delegator.findByPrimaryKey("Deal",
                        dealFindMap);

                if (dealGV != null) {
                    accountId = dealGV.getString("accountId");
                    activityGV.set("accountId", accountId);
                }
            } catch (GenericEntityException e) {
                // An error occurred while looking for the contact record. Don't set the account ID.
                Debug.logWarning("Error looking for contact: " +
                        e.getLocalizedMessage(), module);
            }
        }

        if ((accountId == null) || (accountId.length() < 1)) {
            accountId = userInfo.getAccountId();
            activityGV.set("accountId", accountId);
        }

        return STATUS_CONTINUE;
    }

    /**
     * This function gets the application path to be used to reconstruct the URI when a
     * UI History record is logged.  Example: "/accounts"
     * @author  John Nutting
     * @param url The URL used to open the screen section
     * @return String containing the application path
     */
    protected String getUiHistoryAppPath(String url) {
        return "/activities";
    }

    /**
     * This function gets the description to store in the UI history table.  This description
     * will show up in the UI History drop list.
     * @author  John Nutting
     * @param dataMatrix DataMatrix object containing the data from the screen
     * @param delegator Generic delegator through which the data base is accessed
     * @param action The action being performed on the screen
     * @param uiWebScreenSection The UIWebScreenSection being used to construct the screen section
     * @return String containing the UI History description
     */
    protected String getUiHistoryDescription(DataMatrix dataMatrix,
        GenericDelegator delegator, String action,
        UIWebScreenSection uiWebScreenSection) {
        GenericValue primaryGV = dataMatrix.getCurrentBuffer().getGenericValue(0,
                0);

        return "Activity: " +
        ((primaryGV.getString("activityName") == null) ? ""
                                                       : primaryGV.getString(
            "activityName"));
    }
}

⌨️ 快捷键说明

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