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

📄 genericwebeventprocessor.java

📁 国外的一套开源CRM
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/*
 * 
 * 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.event;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.StringTokenizer;
import java.util.Vector;

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

import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilFormatOut;
import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.base.util.UtilTimer;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.condition.EntityComparisonOperator;
import org.ofbiz.entity.condition.EntityOperator;
import org.ofbiz.entity.model.ModelEntity;

import com.sourcetap.sfa.replication.GenericReplicator;
import com.sourcetap.sfa.ui.UICache;
import com.sourcetap.sfa.ui.UIDisplayObject;
import com.sourcetap.sfa.ui.UIFieldInfo;
import com.sourcetap.sfa.ui.UIHistoryManager;
import com.sourcetap.sfa.ui.UIQuery;
import com.sourcetap.sfa.ui.UIScreenSection;
import com.sourcetap.sfa.ui.UIScreenSectionEntity;
import com.sourcetap.sfa.ui.UIUtility;
import com.sourcetap.sfa.ui.UIWebScreenSection;
import com.sourcetap.sfa.ui.UIWebUtility;
import com.sourcetap.sfa.util.DelimitedValueDecoder;
import com.sourcetap.sfa.util.Preference;
import com.sourcetap.sfa.util.QueryInfo;
import com.sourcetap.sfa.util.UserInfo;


/**
 * DOCUMENT ME!
 *
 */
public class GenericWebEventProcessor {
    public static final int STATUS_ERROR = -1;
    public static final int STATUS_CANCEL = 0;
    public static final int STATUS_CONTINUE = 1;
    private static final boolean TIMER = false;
	public static final String module = GenericWebEventProcessor.class.getName();

    public GenericWebEventProcessor() {
    }

    /**
     * DOCUMENT ME!
     *
     * @param screenName 
     * @param sectionName 
     * @param userInfo 
     * @param request 
     * @param response 
     * @param delegator 
     * @param eventProcessor 
     * @param uiCache 
     *
     * @return 
     *
     * @throws GenericEntityException 
     */
    public String processEvents(String screenName, String sectionName,
        UserInfo userInfo, HttpServletRequest request,
        HttpServletResponse response, GenericDelegator delegator,
        GenericEventProcessor eventProcessor, UICache uiCache)
        throws GenericEntityException {
        return processEvents(screenName, sectionName, userInfo, request,
            response, delegator, eventProcessor, uiCache, false, 0);
    }

    /**
     * DOCUMENT ME!
     *
     * @param screenName 
     * @param sectionName 
     * @param userInfo 
     * @param request 
     * @param response 
     * @param delegator 
     * @param eventProcessor 
     * @param uiCache 
     * @param isSubsection 
     *
     * @return 
     *
     * @throws GenericEntityException 
     */
    public String processEvents(String screenName, String sectionName,
        UserInfo userInfo, HttpServletRequest request,
        HttpServletResponse response, GenericDelegator delegator,
        GenericEventProcessor eventProcessor, UICache uiCache,
        boolean isSubsection) throws GenericEntityException {
        return processEvents(screenName, sectionName, userInfo, request,
            response, delegator, eventProcessor, uiCache, isSubsection, 0);
    }

    /**
     * DOCUMENT ME!
     *
     * @param screenName 
     * @param sectionName 
     * @param userInfo 
     * @param request 
     * @param response 
     * @param delegator 
     * @param eventProcessor 
     * @param uiCache 
     * @param isSubsection 
     * @param tabOffset 
     *
     * @return 
     *
     * @throws GenericEntityException 
     */
    public String processEvents(String screenName, String sectionName,
        UserInfo userInfo, HttpServletRequest request,
        HttpServletResponse response, GenericDelegator delegator,
        GenericEventProcessor eventProcessor, UICache uiCache,
        boolean isSubsection, int tabOffset) throws GenericEntityException {
        UtilTimer timer = new UtilTimer();

        if (TIMER) {
            timer.timerString("[GenericWebEventProcessor.processEvents] Start");
        }

        if ((screenName == null) || screenName.equals("")) {
            throw new GenericEntityException("Screen name is required.");
        }

        if ((sectionName == null) || sectionName.equals("")) {
            throw new GenericEntityException("Screen section name is required.");
        }

        UIWebScreenSection uiWebScreenSection = getUiWebScreenSection(userInfo,
                screenName, sectionName, delegator, uiCache);

        if (TIMER) {
            timer.timerString(
                "[GenericWebEventProcessor.processEvents] Got web screen section");
        }

        // Get the additional parameters that are needed for this screen section.  These will be used
        // for filtering a related entity on a tab page, or in completing keys in a SELECT screen.
        evalUseQueryParameterList(uiWebScreenSection, request);

        if (TIMER) {
            timer.timerString(
                "[GenericWebEventProcessor.processEvents] Evaluated \"use\" query parameter list");
        }

        Debug.logVerbose("Returned from evalUseQueryParameterList.", module);

        // Find out what needs to be done depending on the action passed in the request object.
        String action = "";

        if (request.getParameter("action") != null) {
            // Actions for Free Form sections:
            //   ACTION_SHOW          - Display the entity in non-edit mode
            //   ACTION_SHOW_UPDATE   - Display the entity so the user can edit it
            //   ACTION_SHOW_INSERT   - Show the form with empty cells so the user can enter a new entity
            //   ACTION_SHOW_QUERY    - Show the form in Query mode, and set next action to QUERY.
            //   ACTION_SHOW_QUERY_REPORT - Show the form in Query mode, and set next action to SHOW_REPORT.
            //   ACTION_SHOW_REPORT   - Show the form in Report mode, and set next action to SHOW_REPORT.
            //   ACTION_SHOW_SELECT   - Show the form in select mode, and set next action to UPDATE_SELECT.
            //   ACTION_SHOW_COPY     - Show the form with a copy of the specified entity from which a new
            //                entity will be created.  (Same as showCreate with values prefilled.)
            //   ACTION_UPDATE        - Save the entity into the database using the form values.
            //   ACTION_INSERT        - Insert a new entity into into the database using the form values
            //   ACTION_DELETE        - Delete the entity from the database.
            //   ACTION_BUTTON        - A button in the header was pushed to get here.  Look for a parameter with
            //                each possible button name until we know which button was pushed.
            // Actions for Tabular sections:
            //   ACTION_QUERY         - Search for values based on attibute values using a custom WHERE clause.
            //   ACTION_QUERY_UPDATE  - Search for values based on attibute values using a custom WHERE clause,
            //                and go into update mode.
            //   ACTION_QUERY_ALL     - Search for all values.
            //   ACTION_UPDATE        - Save the entit(ies) into the database using the form values.
            //   ACTION_UPDATE_SELECT - Add and remove entities in a many-to-many relationship table.
            action = request.getParameter("action");
        } else {
            // No action specified.
            action = uiWebScreenSection.ACTION_NONE;
        }

        if (!action.equals(uiWebScreenSection.ACTION_BUTTON) &&
                !action.equals(uiWebScreenSection.ACTION_COPY) &&
                !action.equals(uiWebScreenSection.ACTION_DELETE) &&
                !action.equals(uiWebScreenSection.ACTION_INSERT) &&
                !action.equals(uiWebScreenSection.ACTION_NONE) &&
                !action.equals(uiWebScreenSection.ACTION_QUERY) &&
                !action.equals(uiWebScreenSection.ACTION_QUERY_UPDATE) &&
                !action.equals(uiWebScreenSection.ACTION_QUERY_ALL) &&
                !action.equals(uiWebScreenSection.ACTION_UPDATE) &&
                !action.equals(uiWebScreenSection.ACTION_UPDATE_SELECT) &&
                !action.equals(uiWebScreenSection.ACTION_SHOW) &&
                !action.equals(uiWebScreenSection.ACTION_SHOW_COPY) &&
                !action.equals(uiWebScreenSection.ACTION_SHOW_INSERT) &&
                !action.equals(uiWebScreenSection.ACTION_SHOW_QUERY) &&
                !action.equals(uiWebScreenSection.ACTION_SHOW_QUERY_REPORT) &&
                !action.equals(uiWebScreenSection.ACTION_SHOW_REPORT) &&
                !action.equals(uiWebScreenSection.ACTION_SHOW_SELECT) &&
                !action.equals(uiWebScreenSection.ACTION_SHOW_UPDATE)) {
                Debug.logWarning("\"" + action + "\" is not a valid action.", module);

            throw new GenericEntityException(
                "[GenericWebEventProcessor.processEvents] \"" + action +
                "\" is not a valid action.");
        }

        Debug.logVerbose("Starting action is \"" + action + "\".", module);
        Debug.logVerbose(
                "About to convert button action to regular action if necessary.", module);

        action = UIWebUtility.convertButtonAction(action, request);

        Debug.logVerbose("Final action is \"" + action + "\".", module);

        if (TIMER) {
            timer.timerString(
                "[GenericWebEventProcessor.processEvents] Determined action");
        }

        String queryId = "";

        if (request.getParameter("queryId") != null) {
            queryId = request.getParameter("queryId");
        } else if (request.getParameter("savedQueryName") != null) {
            // The calling link specified to use a named query if it exists.
            String savedQueryName = request.getParameter("savedQueryName");
            GenericValue queryGV = UIQuery.getUiQueryByName(delegator,
                    userInfo.getPartyId(), sectionName, screenName,
                    savedQueryName);

            if (queryGV == null) {
                // Named query was not found.  Don't use a query.
                queryId = "1";  // Query = All
                Debug.logWarning("Named query not found for query name " +
                    savedQueryName + ", partyId " + userInfo.getPartyId() +
                    ", sectionName " + sectionName + ", and screenName " +
                    screenName + ".  queryId is now \"" + queryId + "\"", module);
            } else {
                // Named query was found.
                queryId = (queryGV.getString("queryId") == null) ? "NONE"
                                                                 : queryGV.getString(
                        "queryId");

                Debug.logVerbose("Named query was found. queryId is \"" +
                        queryId + "\"", module);
            }
        }

        DataMatrix dataMatrix = new DataMatrix(delegator,
                uiWebScreenSection.getEntityParamVector());

        if (TIMER) {
            timer.timerString(
                "[GenericWebEventProcessor.processEvents] Constructed data matrix");
        }

        // ---------------------------------------------------------------------------------
        // Process all events before generating the HTML to display the data on the screen.
        // ---------------------------------------------------------------------------------
        // --------
        // INSERT
        // --------
        if (action.equals(uiWebScreenSection.ACTION_INSERT)) {
            // Insert the new record(s) into the database.
            int status = this.processInsert(userInfo, uiWebScreenSection,
                    request, response, delegator, eventProcessor, dataMatrix,
                    uiCache);

            if (TIMER) {
                timer.timerString(
                    "[GenericWebEventProcessor.processEvents] Finished insert");
            }

            switch (status) {
            case STATUS_ERROR:

⌨️ 快捷键说明

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