Package com.sourcetap.sfa.event

Source Code of com.sourcetap.sfa.event.GenericWebEventProcessor

/*
*
* 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:
                return "An error occurred while inserting the new information into the data base.";

            case STATUS_CANCEL:
                return "Insert canceled.";
            }

            // --------
            // UPDATE
            // --------
        } else if (action.equals(uiWebScreenSection.ACTION_UPDATE)) {
            // Update the existing record(s) in the database.
            int status = this.processUpdate(userInfo, uiWebScreenSection,
                    request, response, delegator, eventProcessor, dataMatrix,
                    uiCache);

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

            switch (status) {
            case STATUS_ERROR:
                return "An error occurred while updating the information in the data base.";

            case STATUS_CANCEL:
                return "Update canceled.";
            }

            // --------
            // UPDATE_SELECT
            // --------
        } else if (action.equals(uiWebScreenSection.ACTION_UPDATE_SELECT)) {
            // Add and/or remove records in a many-to-many table.
            int status = this.processUpdateSelect(userInfo, uiWebScreenSection,
                    request, response, delegator, eventProcessor);

            if (TIMER) {
                timer.timerString(
                    "[GenericWebEventProcessor.processEventsSelect] Finished update");
            }

            switch (status) {
            case STATUS_ERROR:
                return "An error occurred while updating the information in the data base.";

            case STATUS_CANCEL:
                return "Update canceled.";
            }

            // --------
            // DELETE
            // --------
        } else if (action.equals(uiWebScreenSection.ACTION_DELETE)) {
            // Delete the current record.
            int status = this.processDelete(userInfo, uiWebScreenSection,
                    request, response, delegator, eventProcessor, uiCache);

            switch (status) {
            case STATUS_ERROR:
                return "An error occurred while deleting the information.";

            case STATUS_CANCEL:
                return "Delete canceled.";
            }

            // Create an empty entity so the user can insert a new one.
            status = this.processCreate(userInfo, uiWebScreenSection, request,
                    response, delegator, eventProcessor, dataMatrix);

            switch (status) {
            case STATUS_ERROR:
                return "An error occurred while creating an empty data form.";

            case STATUS_CANCEL:
                return "Create canceled.";
            }

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

            // --------
            // SHOW_INSERT
            // --------
        } else if (action.equals(uiWebScreenSection.ACTION_SHOW_INSERT)) {
            // Create an empty entity so the user can insert a new one.
            int status = this.processCreate(userInfo, uiWebScreenSection,
                    request, response, delegator, eventProcessor, dataMatrix);

            switch (status) {
            case STATUS_ERROR:
                return "An error occurred while creating an empty data form.";

            case STATUS_CANCEL:
                return "Create canceled.";
            }

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

            // --------
            // SHOW_QUERY or SHOW_QUERY_REPORT
            // --------
        } else if (action.equals(uiWebScreenSection.ACTION_SHOW_QUERY) ||
                action.equals(uiWebScreenSection.ACTION_SHOW_QUERY_REPORT)) {
            // Create an empty entity to be displayed for query mode.
            int status = this.processShowQuery(userInfo, uiWebScreenSection,
                    request, response, delegator, eventProcessor, dataMatrix);

            switch (status) {
            case STATUS_ERROR:
                return "An error occurred while creating an empty query form.";

            case STATUS_CANCEL:
                return "Create canceled.";
            }

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

            // --------
            // SHOW_REPORT
            // --------
        } else if (action.equals(uiWebScreenSection.ACTION_SHOW_REPORT)) {
            // Load in the entered query criteria, and re-display them in query mode.
            int status = this.processShowReport(userInfo, uiWebScreenSection,
                    request, response, delegator, eventProcessor, dataMatrix);

            switch (status) {
            case STATUS_ERROR:
                return "An error occurred while displaying the report.";

            case STATUS_CANCEL:
                return "Report canceled.";
            }

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

            // --------
            // NO ACTION
            // --------
        } else if (action.equals(uiWebScreenSection.ACTION_NONE)) {
            // No action was specified.  Allow a blank screen section to be displayed.
            if (TIMER) {
                timer.timerString(
                    "[GenericWebEventProcessor.processEvents] Finished no_action");
            }
        }

        // --------
        // RETRIEVE
        // --------
        if (action.equals(uiWebScreenSection.ACTION_SHOW) ||
        action.equals(uiWebScreenSection.ACTION_SHOW_UPDATE) ||
                action.equals(uiWebScreenSection.ACTION_SHOW_COPY) ||
                action.equals(uiWebScreenSection.ACTION_QUERY) ||
                action.equals(uiWebScreenSection.ACTION_QUERY_UPDATE) ||
                action.equals(uiWebScreenSection.ACTION_QUERY_ALL) ||
                action.equals(uiWebScreenSection.ACTION_SHOW_SELECT) ||
                action.equals(uiWebScreenSection.ACTION_UPDATE_SELECT)) {
            // Need to retrieve data from the data base.
            // Note:  ACTION_SHOW_SELECT and ACTION_UPDATE_SELECT are the only two actions that have something happen
            // in the previous IF statement, and then get retrieved.  In all other actions, the data matrix is either
            // filled from the HTML, or does not need to be filled.
            // Determine the retreive method.
            int retrieveMethod = eventProcessor.RETRIEVE_METHOD_ALL;

            switch (uiWebScreenSection.getLayoutTypeId()) {
            case UIWebScreenSection.LAYOUT_TYPE_FREEFORM:

                // Free form section should be retrieved using the primary key.
                retrieveMethod = eventProcessor.RETRIEVE_METHOD_PK;

                break;

            case UIWebScreenSection.LAYOUT_TYPE_TABULAR:

                // Tabular section can be retrieved multiple ways depending on the action
                // requested by the button or link that triggered it.
                if (action.equals(uiWebScreenSection.ACTION_QUERY) ||
                        action.equals(uiWebScreenSection.ACTION_QUERY_UPDATE)) {
                    retrieveMethod = eventProcessor.RETRIEVE_METHOD_CLAUSE;
                } else if (action.equals(uiWebScreenSection.ACTION_QUERY_ALL)) {
                    retrieveMethod = eventProcessor.RETRIEVE_METHOD_ALL;
                } else {
                    throw new GenericEntityException("Action \"" + action +
                        "\" is not valid for tabular layout type.");
                }

                break;

            case UIWebScreenSection.LAYOUT_TYPE_SELECT:

                // A select screen section is always retrieved as a query because it is always subordinate
                // to some other entity.
                retrieveMethod = eventProcessor.RETRIEVE_METHOD_CLAUSE;

                break;

            case UIWebScreenSection.LAYOUT_TYPE_CROSSTAB:
                throw new GenericEntityException(
                    "Crosstab layout type not implemented yet.");

            default:
                throw new GenericEntityException("Invalid layout type.");
            }

            // handle paging of result sets.
            int startRow = 0;
            int rowsPerPage = uiWebScreenSection.getRowsPerPage();

            if (request.getParameter("startRow") != null) {
                startRow = Integer.parseInt(request.getParameter("startRow"));
            }

            uiWebScreenSection.setFirstVisibleRow(startRow);
            eventProcessor.setRowOffset(startRow);

            eventProcessor.setFetchSize(rowsPerPage);

            // Retrieve the data for the screen section.
            Debug.logVerbose(
                    "About to call GenericWebEventProcessor.processRetrieve.", module);

            StringBuffer queryIdBuffer = new StringBuffer(queryId);
            int status = this.processRetrieve(userInfo, uiWebScreenSection,
                    retrieveMethod, request, response, delegator,
                    eventProcessor, dataMatrix, queryIdBuffer, action);
            queryId = queryIdBuffer.toString();

      if ( eventProcessor.getHasMoreData() )
        uiWebScreenSection.setTotalRows(eventProcessor.getTotalRows() + 1);
      else
            uiWebScreenSection.setTotalRows(eventProcessor.getTotalRows());

            Debug.logVerbose("queryId after call to processRetrieve: " +
                    queryId, module);

            switch (status) {
            case STATUS_ERROR:
                return "An error occurred while retrieving the data from the data base.";

            case STATUS_CANCEL:
                return "Retrieve canceled.";
            }

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

        // --------
        // SHOW_COPY
        // --------
        if (action.equals(uiWebScreenSection.ACTION_SHOW_COPY)) {
            // Displaying a copy of the retrieved record on the screen.
            int status = this.processShowCopy(userInfo, uiWebScreenSection,
                    request, response, delegator, eventProcessor, dataMatrix);

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

            switch (status) {
            case STATUS_ERROR:
                return "An error occurred while updating the copied record before displaying it.";

            case STATUS_CANCEL:
                return "Copy canceled.";
            }
        }

        // Get values of extra parameters to send to other screen sections when buttons on this screen
        // section are clicked.
        evalSendQueryParameterList(uiWebScreenSection, request, dataMatrix);

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

        // ---------------------------------------------------------------------------------
        // Generate the HTML to display the data on the screen, and return it to the calling method.
        // ---------------------------------------------------------------------------------
        Debug.logVerbose("Data matrix before display: " +
                dataMatrix.getCurrentBuffer().getContents().toString(), module);


        String displayHtml = uiWebScreenSection.display(dataMatrix, action,
                queryId, isSubsection, tabOffset);

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

        logUiHistory(action, request, dataMatrix, delegator, userInfo,
            uiWebScreenSection);

        return displayHtml;
    }

    //-------------------------------------------------------------------------
    // RETRIEVE - Retrieves an entity and associated entities from the data base.
    //-------------------------------------------------------------------------
    protected int processRetrieve(UserInfo userInfo,
        UIWebScreenSection uiWebScreenSection, int retrieveMethod,
        HttpServletRequest request, HttpServletResponse response,
        GenericDelegator delegator, GenericEventProcessor eventProcessor,
        DataMatrix dataMatrix, StringBuffer queryIdBuffer, String action)
        throws GenericEntityException {
        UtilTimer timer = new UtilTimer();

        if (TIMER) {
            timer.timerString(1,
                "[GenericWebEventProcessor.processRetrieve] Start");
        }

        int status = STATUS_CONTINUE;

        String queryId = queryIdBuffer.toString();

        // Get info about the screen.
        String screenName = uiWebScreenSection.getUiScreen().getScreenName();

        // Get info about the screen section.
        String sectionId = uiWebScreenSection.getSectionId();
        String sectionName = uiWebScreenSection.getSectionName();
        int layoutTypeId = uiWebScreenSection.getLayoutTypeId();

        String primaryEntityName = uiWebScreenSection.getUiScreenSectionEntity(0)
                                                     .getUiEntity()
                                                     .getEntityName();

        Debug.logVerbose("Primary entity name: " + primaryEntityName, module);

        ModelEntity primaryME = uiWebScreenSection.getUiScreenSectionEntity(0)
                                                  .getUiEntity().getModelEntity();
        List primaryPkFieldNames = uiWebScreenSection.getUiScreenSectionEntity(0)
                                                     .getUiEntity()
                                                     .getPrimaryKeyFieldNames();

        // Specify how the primary entity will be retrieved.
        HashMap fields = new HashMap();
        ArrayList orderBy = new ArrayList();
        QueryInfo queryInfo = new QueryInfo(delegator, primaryEntityName);
        Enumeration params = null;
        String searchAttribValue = "";
        String searchEntityName = "";
        String searchAttribName = "";
        String queryName = "";
        String listName = "";
        EntityComparisonOperator entityOperator = null;
        List relatedSearchClauses = new LinkedList();
        List selectFields = new ArrayList();
       
        // Note that we only care about primary entity fields in the select at the moment.
        // TODO:  change the queries so that all related data is retrieved as part of the main retrieve
        //        which it is, but the original code was written before dynamicViewEntities were added
    int selectFieldListSize = uiWebScreenSection.getUiFieldList().size();
    for (int fieldNbr = 0; fieldNbr < selectFieldListSize; fieldNbr++) { 
      UIFieldInfo fieldInfo = uiWebScreenSection.getUiField(fieldNbr);
      String fieldName = fieldInfo.getUiAttribute().getAttributeName();
      String entityName = fieldInfo.getUiAttribute().getUiEntity().getEntityName();
      if ( entityName.equals(primaryEntityName) )
        selectFields.add(fieldName);

/*      if ( fieldInfo.getIsVisible() )
      {
        String fieldName = fieldInfo.getUiAttribute().getAttributeName();
        String entityName = fieldInfo.getUiAttribute().getUiEntity().getEntityName();
        String aliasName = fieldName;
        if ( ! entityName.equals(primaryEntityName))
          aliasName = entityName + "." + fieldName;
        selectFields.add(aliasName);
      }
*/
    }
    queryInfo.setSelectFields(selectFields);

        if (request.getParameter("queryName") != null) {
            queryName = request.getParameter("queryName");
        }

        if (request.getParameter("listName") != null) {
            listName = request.getParameter("listName");
            if ( queryName.length() < 1)
                queryName = listName;
        }

       
        //    HashMap querySaveMap = new HashMap();
        UIQuery uiQuery = null;


    // Specify how associated entities will be retrieved.
    Iterator uiScreenSectionEntityI = uiWebScreenSection.getUiScreenSectionEntityList()
                              .iterator();
    uiScreenSectionEntityI.next(); // Pass up the primary entity.

    while (uiScreenSectionEntityI.hasNext()) {
      UIScreenSectionEntity uiScreenSectionEntity = (UIScreenSectionEntity) uiScreenSectionEntityI.next();
     
      relatedSearchClauses.add(uiScreenSectionEntity);
    }

    uiScreenSectionEntityI = null; // Reset the iterator.




        switch (retrieveMethod) {
        case GenericEventProcessor.RETRIEVE_METHOD_ALL:

            // Find all entities of this type.
            // Don't need to populate the fields map.
            break;

        case GenericEventProcessor.RETRIEVE_METHOD_AND:

            // Find the main entity(ies) by building a WHERE clause using "=" and AND.
            throw new GenericEntityException(
                "RETRIEVE_METHOD_AND not implemented yet.");

        case GenericEventProcessor.RETRIEVE_METHOD_CLAUSE:

            if (TIMER) {
                timer.timerString(1,
                    "[GenericWebEventProcessor.processRetrieve] Start RETRIEVE_METHOD_CLAUSE");
            }

      HashMap joinedEntities = new HashMap();
     
      joinedEntities.put(primaryEntityName, "Y");
     
            // Find the main entity(ies) by building a WHERE clause using LIKE and AND, with one or more tables in the FROM clause.
            // First join all secondary screen section entities in the WHERE and FROM clauses in case
            // we are going to use query values from them.
            Iterator relatedClauseI = relatedSearchClauses.iterator();

            while (relatedClauseI.hasNext()) {
                UIScreenSectionEntity uiScreenSectionEntity = (UIScreenSectionEntity) relatedClauseI.next();
                String relationTitle = uiScreenSectionEntity.getRelationTitle();
                String relatedEntityName = uiScreenSectionEntity.getUiEntity().getEntityName();
        boolean isOuterJoin = uiScreenSectionEntity.getIsOuterJoined();
        String relatedAndFields = uiScreenSectionEntity.getRelationByAndFields();

                Debug.logVerbose("Adding relation clauses for " +
                        relationTitle + "/" + relatedEntityName, module);

                eventProcessor.addOneRelationClause(delegator, relationTitle, relatedAndFields,
                    relatedEntityName, primaryEntityName, primaryME, isOuterJoin,
                    queryInfo);
                   
                joinedEntities.put(relatedEntityName, "Y");
            }

            Debug.logVerbose(
                    "queryId at beginning of RETRIEVE_METHOD_CLAUSE section: " +
                    queryId, module);

            if (queryId.equalsIgnoreCase("NONE")) {
                // Don't retrieve any data. The calling link specified to use the last query, but there wasn't one.
                return STATUS_CONTINUE;
            } else if (!queryId.equals("")) {
                // User selected a saved query.  Get it from the data base.
                uiQuery = new UIQuery(queryId, delegator);

                if (!uiQuery.getQueryId().equals("")) {
                    // Query was found.
                    uiQuery.appendEntityClauses(delegator, queryInfo);

                    //            // Store the attribute ID and value in the query save map.
                    //            querySaveMap.put(attributeId, searchAttribValue);
                }

                // add extra clauses from the hidden query parameters in case this is a detail screen
                addUseQueryParameterClauses(uiWebScreenSection, queryInfo,
                    relatedSearchClauses, primaryEntityName, request);
            } else {
                // Brand new query. Process all the parameters coming in through the request object to get the values to search by.
                uiQuery = new UIQuery();

        String queryListMaxRows = request.getParameter("queryListMaxRows");
        // if queryListMaxRows is set, then we are using advanced query mode
        if ( (queryListMaxRows != null ) && ( queryListMaxRows.length() > 0) )
        {
          int maxRows = Integer.valueOf(queryListMaxRows).intValue();
          for ( int i=1; i <= maxRows; i++ )
          {
            String qlFieldInfo = request.getParameter("queryListField" + i);
            if ( ( qlFieldInfo != null ) && ( qlFieldInfo.length() > 0 ) )
            {
              StringTokenizer tokSemi = new StringTokenizer(qlFieldInfo,";");
              String qlFieldName = "";
              String qlAttributeId = "";
              String qlDisplayObjectId = "";
              String qlDisplayTypeId = "";
             
              if (tokSemi.countTokens() == 4) {
                  qlFieldName = tokSemi.nextToken();
                  qlAttributeId = tokSemi.nextToken();
                  qlDisplayTypeId = tokSemi.nextToken();
                  qlDisplayObjectId = tokSemi.nextToken();
              }
              else
              {
                qlFieldName = qlFieldInfo;
              }

              String qlOperator  = request.getParameter("queryListOperator" + i);
              String qlValue     = request.getParameter("queryListValue" + i);
             
              if ( qlOperator.equals("like"))
                qlValue =  "%" + qlValue.replace('*','%') + "%";
              else if ( qlOperator.equals("startsWith"))
              {
                qlValue =  qlValue.replace('*','%') + "%";
                qlOperator = "like";
              }
              else if ( qlOperator.equals("endsWith"))
              {
                qlValue =  "%" + qlValue.replace('*','%');
                qlOperator = "like";
              }

              searchEntityName = UIWebUtility.getEntityFromParamName(qlFieldName);
 
              String hasJoin = (String) joinedEntities.get(searchEntityName);
             
              if ( ( hasJoin == null ) || ( !hasJoin.equals("Y")) )
              {
                eventProcessor.addOneRelationClause(delegator, "", "",searchEntityName, primaryEntityName, primaryME, false, queryInfo);

                joinedEntities.put(searchEntityName, "Y");
              }
             
              if ((searchEntityName == null) ||
                  searchEntityName.equals("")) {
                searchEntityName = primaryEntityName;
              }
 
              searchAttribName = UIWebUtility.getAttribFromParamName(qlFieldName);
              entityOperator = EntityOperator.lookupComparison(qlOperator);
              Object searchValue = qlValue;
             
              // If this is a set operator, convert the String param into a comma separated List
              if ( (entityOperator.equals(EntityOperator.IN)) || (entityOperator.equals(EntityOperator.NOT_IN)) || (entityOperator.equals(EntityOperator.BETWEEN)))
              {
                List valueList = new ArrayList();
                StringTokenizer tokComma = new StringTokenizer(qlValue, ",");

                while (tokComma.hasMoreTokens()) {
                  String valueItem = tokComma.nextToken();
                  valueList.add(valueItem);
                }
                searchValue = valueList;
              }
             
              try {
                // Figure out the attribute ID for the UiAttribute this parameter corresponds to so we can
                // save the query.
                String attributeId = UIWebUtility.getAttributeId(delegator,
                    searchAttribName, searchEntityName);
 
                // Generate an entry in the WHERE clause for this attribute.  The entityOperator
                // is returned in case appendEntityClause changes it.
                // NOTE:  changes here must also be applied to UIQuery.appendEntityClauses() to work with saved queries
                //
                if ( qlDisplayTypeId.equals(UIDisplayObject.DISPLAY_TYPE_SELECT) || qlDisplayTypeId.equals(UIDisplayObject.DISPLAY_TYPE_SEARCH_TEXT))
                {
                  String aliasName = searchEntityName + searchAttribName + "srch";
                  UIUtility.addSelectSearch( queryInfo, qlDisplayObjectId, searchEntityName, searchAttribName, aliasName, entityOperator, searchValue );
                }
                else
                {
                  if ( searchValue instanceof String )
                  {
                  entityOperator = EventUtility.appendEntityClause(searchEntityName,
                      searchAttribName, (String) searchValue,
                    entityOperator, queryInfo);
                }
                  else if ( searchValue instanceof Collection)
                  {
                    entityOperator = EventUtility.appendEntityClause(searchEntityName,
                      searchAttribName, (Collection) searchValue,
                      entityOperator, queryInfo);
                  }
                  else
                    throw new IllegalArgumentException("Query Param must be String or Collection");
                }

                // Store the attribute ID and value in the query save map.
                //                  querySaveMap.put(attributeId, searchAttribValue);
                uiQuery.addUiQueryValue(attributeId, entityOperator, qlValue, qlDisplayTypeId, qlDisplayObjectId, delegator);
              } catch (GenericEntityException e) {
                //this parameter was not associated with a column in a table, so skip it
                Debug.logVerbose("skipping parameter which is not an entity attribute: " + qlFieldName, module);
              }

            }
          }
        }
        else
        {

                params = request.getParameterNames();

                while (params.hasMoreElements()) {
                    String paramName = (String) params.nextElement();

                    //            boolean useSentQueryParameter =
                    //              !action.equals(uiWebScreenSection.ACTION_QUERY_UPDATE &&
                    //              !action.equals(uiWebScreenSection.ACTION_QUERY &&
                    //              uiWebScreenSection.getUseQueryParameterMap().containsValue(paramName);
                    Debug.logVerbose("paramName: " + paramName, module);
                    Debug.logVerbose("action: " + action, module);
                    Debug.logVerbose(
                            "uiWebScreenSection.getUseQueryParameterMap().containsValue(paramName): " +
                            String.valueOf(uiWebScreenSection.getUseQueryParameterMap()
                                                             .containsValue(paramName)), module);

                    if (UIWebUtility.checkReservedParameterName(paramName)) {
                        //                (  action.equals(uiWebScreenSection.ACTION_QUERY_UPDATE) || action.equals(uiWebScreenSection.ACTION_QUERY))
                        //              ) {
                        // This is a value being passed in from the prior screen in query mode.  Use it to search.
                        if (paramName.equals("nameToSearch")) {
                            // Alpha search using alphabet buttons.
                            HashMap alphaSearchValues = EventUtility.getAlphaSearchValues(delegator,
                                    uiWebScreenSection,
                                    request.getParameter("nameToSearch"));
                            searchEntityName = (String) alphaSearchValues.get(
                                    "searchEntityName");
                            searchAttribName = (String) alphaSearchValues.get(
                                    "searchAttribName");
                            searchAttribValue = (String) alphaSearchValues.get(
                                    "searchAttribValue");
                            entityOperator = null;
                        } else {
                            // Regular search attribute in query mode.
                            searchEntityName = UIWebUtility.getEntityFromParamName(paramName);

                            if ((searchEntityName == null) ||
                                    searchEntityName.equals("")) {
                                searchEntityName = primaryEntityName;
                            }

                            searchAttribName = UIWebUtility.getAttribFromParamName(paramName);

                            String[] searchAttribValueArray = request.getParameterValues(paramName);

                            Debug.logVerbose(
                                    "Number of values for query attribute " +
                                    paramName + ": " +
                                    String.valueOf(
                                        searchAttribValueArray.length), module);

                            searchAttribValue = getRequestParameterValue(paramName,
                                    searchAttribValueArray);

                            //  Determine the entity search operator to use.  If multiple, use IN
                            if ((null != searchAttribValue) &&
                                    (searchAttribValueArray.length > 1)) {
                                entityOperator = EntityOperator.IN;
                            } else {
                                entityOperator = null;
                            }

                            Debug.logVerbose("searchEntityName: " + searchEntityName, module);
                            Debug.logVerbose("searchAttribName: " + searchAttribName, module);
                            Debug.logVerbose("searchAttribValue: " + searchAttribValue, module);
                        }

                        if ((searchAttribValue != null) &&
                                !searchAttribValue.equals("")) {
                            try {
                                // Figure out the attribute ID for the UiAttribute this parameter corresponds to so we can
                                // save the query.
                                String attributeId = UIWebUtility.getAttributeId(delegator,
                                        searchAttribName, searchEntityName);

                                // Generate an entry in the WHERE clause for this attribute.  The entityOperator
                                // is returned in case appendEntityClause changes it.
                                entityOperator = EventUtility.appendEntityClause(searchEntityName,
                                        searchAttribName, searchAttribValue,
                                        entityOperator, queryInfo);

                                // Store the attribute ID and value in the query save map.
                                //                  querySaveMap.put(attributeId, searchAttribValue);
                                  uiQuery.addUiQueryValue(attributeId, entityOperator, searchAttribValue, "", "", delegator);
                            } catch (GenericEntityException e) {
                                //this parameter was not associated with a column in a table, so skip it
                                Debug.logVerbose("skipping parameter which is not an entity attribute: " + paramName, module);
                            }
                        }
                    }
                }
              }
                // add extra clauses from the hidden query parameters in case this is a detail screen
                addUseQueryParameterClauses(uiWebScreenSection, queryInfo,
                    relatedSearchClauses, primaryEntityName, request);
            }

            // Save the Query
            if (!queryName.equals("")) {
                // User entered a name for the query. Save it with the given name.
                // Change the party ID to the current user's party ID, and the section ID to the current section ID
                // in case either of these was -1 (wildcard).
                uiQuery.setSectionId(uiWebScreenSection.getSectionId());
                uiQuery.setPartyId(userInfo.getPartyId());
                uiQuery.setQueryName(queryName);
                queryId = uiQuery.save(delegator);

                //      queryId = UIQuery.saveUiQuery(delegator, userInfo.getPartyId(), sectionId, queryName, querySaveMap);
                Debug.logVerbose("queryId after saving query \"" + queryName + "\": " + queryId, module);

                if (TIMER) {
                    timer.timerString(1,
                        "[GenericWebEventProcessor.processRetrieve] Saved query");
                }
            }

            if ( listName.length() > 0)
            {
          // save the UiList info
                List uiListGVL = delegator.findByAnd("UiList", UtilMisc.toMap("listName", listName, "partyId", userInfo.getAccountId()), null);
                GenericValue uiListGV = null;
                if ( uiListGVL.size() > 0)
                {
                    uiListGV = (GenericValue) uiListGVL.get(0);
                    delegator.removeByAnd("UiListItem", UtilMisc.toMap("listId", uiListGV.getString("listId")));
                }
                else
                {
                    uiListGV = new GenericValue(delegator.getModelEntity("UiList"));
              String listId = GenericReplicator.getNextSeqId("UiList", delegator);
              uiListGV.set("listId", listId);
                }
                String listId = uiListGV.getString("listId");
          uiListGV.setDelegator(delegator);
         
          uiListGV.set("listName", listName);
          uiListGV.set("partyId", userInfo.getAccountId());
          uiListGV.set("queryId", queryId);
          uiListGV.set("sectionId", sectionId);
          uiListGV.set("listType", primaryEntityName);
         
          delegator.createOrStore(uiListGV);

                queryInfo.setSaveResultListId(listId);
            }

            // Save the query as the last query.  First make a new UIQuery using the same values as the original query.
            // Change the party ID to the current user's party ID, and the section ID to the current section ID
            // in case either of these was -1 (wildcard).
            //    UIQuery.saveUiQuery(delegator, userInfo.getPartyId(), sectionId, UIQuery.LAST_QUERY_NAME, querySaveMap);
            UIQuery uiQueryLast = new UIQuery("",
                    uiWebScreenSection.getSectionId(), userInfo.getPartyId(),
                    UIQuery.LAST_QUERY_NAME, uiQuery.getUiQueryValueList());
            String lastQueryId = uiQueryLast.save(delegator);
           
            // if the query was not saved, set the queryId to be returned to lastQueryId so that the query parameters
            // can be used when displaying the page (Primarily to set the params on the next and previous buttons for multi-page datasets
            if ( queryId == null || queryId.equals(""))
              queryId = lastQueryId;
             
            Debug.logVerbose("Saved query as last query. Id=" + lastQueryId + ", returning queryId=" + queryId, module);

            if (TIMER) {
                timer.timerString(1,
                    "[GenericWebEventProcessor.processRetrieve] End RETRIEVE_METHOD_CLAUSE");
            }

            break;

        case GenericEventProcessor.RETRIEVE_METHOD_LIKE:

            // Find the main entity(ies) using findByLike.
            // Process all the parameters coming into through the request object to get the values to search by.
            params = request.getParameterNames();

            while (params.hasMoreElements()) {
                String paramName = (String) params.nextElement();

                if (UIWebUtility.checkReservedParameterName(paramName)) {
                    // This is a value being passed in from the prior screen.  Use it to search.

                    /*                                                if (paramName.equals("nameToSearch")) {
                                                                            // Alpha search using alphabet buttons.
                                                                            HashMap alphaSearchValues = EventUtility.getAlphaSearchValues(
                                                                                    delegator,
                                                                                    uiScreenSectionGV,
                                                                                    request.getParameter("nameToSearch"));
                                                                            searchEntityName = (String)alphaSearchValues.get("searchEntityName");
                                                                            searchAttribName = (String)alphaSearchValues.get("searchAttribName");
                                                                            searchAttribValue = (String)alphaSearchValues.get("searchAttribValue");
                                                                    } else { */

                    // Regular search attribute.
                    searchEntityName = UIWebUtility.getEntityFromParamName(paramName);
                    searchAttribName = UIWebUtility.getAttribFromParamName(paramName);
                    searchAttribValue = request.getParameter(paramName).replace('*',
                            '%') + "%";

                    /*                                                } */
                    if ((searchEntityName != null) &&
                            !searchEntityName.equals("") &&
                            !searchEntityName.equals(primaryEntityName)) {
                        throw new GenericEntityException(
                            "Cannot do a LIKE search using a value from a related entity. Values must be from the primary entity.");
                    }

                    fields.put(searchAttribName, searchAttribValue);
                }
            }

            break;

        case GenericEventProcessor.RETRIEVE_METHOD_PK:

            if (TIMER) {
                timer.timerString(1,
                    "[GenericWebEventProcessor.processRetrieve] Start RETRIEVE_METHOD_PK");
            }

            // Get one main entity using the primary key.
            Iterator primaryPkFieldNameI = primaryPkFieldNames.iterator();

            while (primaryPkFieldNameI.hasNext()) {
                String primaryPkFieldName = (String) primaryPkFieldNameI.next();
                String primaryPkFieldValue = "";

                if (request.getParameter(primaryPkFieldName) != null) {
                    primaryPkFieldValue = request.getParameter(primaryPkFieldName);
                } else if (request.getParameter(primaryEntityName + "_" +
                            primaryPkFieldName) != null) {
                    primaryPkFieldValue = request.getParameter(primaryEntityName +
                            "_" + primaryPkFieldName);
                }

                fields.put(primaryPkFieldName, primaryPkFieldValue);
            }

            if (TIMER) {
                timer.timerString(1,
                    "[GenericWebEventProcessor.processRetrieve] End RETRIEVE_METHOD_PK");
            }

            break;

        default:
            throw new GenericEntityException("Invalid retrieve method.");

            //        break;
        }


        // Specify the sort order.
        orderBy = new DelimitedValueDecoder(uiWebScreenSection.getSortDef()).decode();

        Debug.logVerbose("orderBy: " + orderBy.toString(), module);

        if (TIMER) {
            timer.timerString(1,
                "[GenericWebEventProcessor.processRetrieve] Specified retrieve info");
        }

        // Trigger the pre-retrieve event.
        status = this.preRetrieve(userInfo, uiWebScreenSection, request,
                response, delegator, eventProcessor, dataMatrix,
                primaryEntityName, retrieveMethod, fields, orderBy,
                queryInfo, relatedSearchClauses, queryId);

        if (status != STATUS_CONTINUE) {
            return status;
        }

        // Trigger the retrieve event.
        status = this.retrieve(userInfo, uiWebScreenSection, request, response,
                delegator, eventProcessor, dataMatrix, primaryEntityName,
                retrieveMethod, fields, orderBy, queryInfo,
                relatedSearchClauses, queryId);

        if (status != STATUS_CONTINUE) {
            return status;
        }

        // Trigger the post-retrieve event.
        status = this.postRetrieve(userInfo, uiWebScreenSection, request,
                response, delegator, eventProcessor, dataMatrix,
                primaryEntityName, retrieveMethod, fields, orderBy,
                queryInfo, relatedSearchClauses, queryId);

        Debug.logVerbose("queryId before returning from processRetrieve: " + queryId, module);

        queryIdBuffer.delete(0, queryIdBuffer.length());
        queryIdBuffer.append(queryId);

        if (TIMER) {
            timer.timerString(1,
                "[GenericWebEventProcessor.processRetrieve] End");
        }

        return status;
    }

    /**
     * DOCUMENT ME!
     *
     * @param userInfo
     * @param uiWebScreenSection
     * @param request
     * @param response
     * @param delegator
     * @param eventProcessor
     * @param dataMatrix
     * @param primaryEntityName
     * @param retrieveMethod
     * @param fields
     * @param orderBy
     * @param queryInfo  criteria to be used in search
     * @param relatedSearchClauses
     * @param queryId
     *
     * @return
     */
    protected int preRetrieve(UserInfo userInfo,
        UIWebScreenSection uiWebScreenSection, HttpServletRequest request,
        HttpServletResponse response, GenericDelegator delegator,
        GenericEventProcessor eventProcessor, DataMatrix dataMatrix,
        String primaryEntityName, int retrieveMethod, HashMap fields,
        ArrayList orderBy, QueryInfo queryInfo, List relatedSearchClauses,
        String queryId) {
        return STATUS_CONTINUE;
    }

    /**
     * DOCUMENT ME!
     *
     * @param userInfo
     * @param uiWebScreenSection
     * @param request
     * @param response
     * @param delegator
     * @param eventProcessor
     * @param dataMatrix
     * @param primaryEntityName
     * @param retrieveMethod
     * @param fields
     * @param orderBy
     * @param queryInfo  criteria to be used in search
     * @param relatedSearchClauses
     * @param queryId
     *
     * @return
     *
     * @throws GenericEntityException
     */
    protected int retrieve(UserInfo userInfo,
        UIWebScreenSection uiWebScreenSection, HttpServletRequest request,
        HttpServletResponse response, GenericDelegator delegator,
        GenericEventProcessor eventProcessor, DataMatrix dataMatrix,
        String primaryEntityName, int retrieveMethod, HashMap fields,
        ArrayList orderBy, QueryInfo queryInfo, List relatedSearchClauses,
        String queryId) throws GenericEntityException {

        return eventProcessor.processRetrieve(userInfo, primaryEntityName,
            retrieveMethod, fields, orderBy, queryInfo,
            relatedSearchClauses, delegator, dataMatrix);
    }

    /**
     * DOCUMENT ME!
     *
     * @param userInfo
     * @param uiWebScreenSection
     * @param request
     * @param response
     * @param delegator
     * @param eventProcessor
     * @param dataMatrix
     * @param primaryEntityName
     * @param retrieveMethod
     * @param fields
     * @param orderBy
     * @param queryInfo  criteria to be used in search
     * @param relatedSearchClauses
     * @param queryId
     *
     * @return
     */
    protected int postRetrieve(UserInfo userInfo,
        UIWebScreenSection uiWebScreenSection, HttpServletRequest request,
        HttpServletResponse response, GenericDelegator delegator,
        GenericEventProcessor eventProcessor, DataMatrix dataMatrix,
        String primaryEntityName, int retrieveMethod, HashMap fields,
        ArrayList orderBy, QueryInfo queryInfo, List relatedSearchClauses,
        String queryId) {
        return STATUS_CONTINUE;
    }

    //-------------------------------------------------------------------------
    // UPDATE - Updates a set of entities in the data base.
    //-------------------------------------------------------------------------
    protected int processUpdate(UserInfo userInfo,
        UIWebScreenSection uiWebScreenSection, HttpServletRequest request,
        HttpServletResponse response, GenericDelegator delegator,
        GenericEventProcessor eventProcessor, DataMatrix dataMatrix,
        UICache uiCache) throws GenericEntityException {
        UtilTimer timer = new UtilTimer();

        if (TIMER) {
            timer.timerString(1,
                "[GenericWebEventProcessor.processUpdate] Start");
        }

        int status = STATUS_CONTINUE;

        // Pre fill the data matrix from the info entered on the screen.
        dataMatrix.fillFromHtml(request, uiWebScreenSection);

        if (TIMER) {
            timer.timerString(1,
                "[GenericWebEventProcessor.processUpdate] Filled data matrix");
        }

        // Trigger the pre-update event.
        status = this.preUpdate(userInfo, uiWebScreenSection, request,
                response, delegator, eventProcessor, dataMatrix, uiCache);

        if (status != STATUS_CONTINUE) {
            return status;
        }

        if (TIMER) {
            timer.timerString(1,
                "[GenericWebEventProcessor.processUpdate] Preupdate finished");
        }

        // Trigger the update event.
        status = this.update(userInfo, uiWebScreenSection, request, response,
                delegator, eventProcessor, dataMatrix, uiCache);

        if (status != STATUS_CONTINUE) {
            return status;
        }

        if (TIMER) {
            timer.timerString(1,
                "[GenericWebEventProcessor.processUpdate] Update finished");
        }

        // Trigger the post-update event.
        status = this.postUpdate(userInfo, uiWebScreenSection, request,
                response, delegator, eventProcessor, dataMatrix, uiCache);

        if (TIMER) {
            timer.timerString(1,
                "[GenericWebEventProcessor.processUpdate] Postupdate finished");
        }

        return status;
    }

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

        return STATUS_CONTINUE;
    }

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

        int status = eventProcessor.processUpdate(userInfo, delegator,
                dataMatrix);

        return status;
    }

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

        return STATUS_CONTINUE;
    }

    //-------------------------------------------------------------------------
    // UPDATE_SELECT - Adds and/or deletes entities in a many-to-many relationship table the data base.
    //-------------------------------------------------------------------------
    protected int processUpdateSelect(UserInfo userInfo,
        UIWebScreenSection uiWebScreenSection, HttpServletRequest request,
        HttpServletResponse response, GenericDelegator delegator,
        GenericEventProcessor eventProcessor) throws GenericEntityException {

        int status = STATUS_CONTINUE;

        ModelEntity primaryME = uiWebScreenSection.getUiScreenSectionEntity(0)
                                                  .getUiEntity().getModelEntity();

        // Get the items to add and remove from the request object.
        String unassignedItemString = request.getParameter("inpUnassigned");
        String assignedItemString = request.getParameter("inpAssigned");

        Debug.logVerbose("unassignedItemString: " + unassignedItemString, module);
        Debug.logVerbose("assignedItemString: " + assignedItemString, module);

        // Convert the strings to array lists of primary keys.
        String entityName = primaryME.getEntityName();
        ModelEntity modelEntity = delegator.getModelEntity(entityName);
        HashMap useQueryParameterValueMap = uiWebScreenSection.getUseQueryParameterValueMap();
        ArrayList removeKeyMapList = EventUtility.decodeSelectItem(useQueryParameterValueMap,
                unassignedItemString);
        ArrayList createKeyMapList = EventUtility.decodeSelectItem(useQueryParameterValueMap,
                assignedItemString);

        // Trigger the pre-update event.
        status = this.preUpdateSelect(userInfo, uiWebScreenSection, request,
                response, delegator, eventProcessor, primaryME,
                removeKeyMapList, createKeyMapList);

        if (status != STATUS_CONTINUE) {
            return status;
        }

        // Trigger the update event.
        status = this.updateSelect(userInfo, uiWebScreenSection, request,
                response, delegator, eventProcessor, primaryME,
                removeKeyMapList, createKeyMapList);

        if (status != STATUS_CONTINUE) {
            return status;
        }

        // Trigger the post-update event.
        status = this.postUpdateSelect(userInfo, uiWebScreenSection, request,
                response, delegator, eventProcessor, primaryME,
                removeKeyMapList, createKeyMapList);

        return status;
    }

    /**
     * DOCUMENT ME!
     *
     * @param userInfo
     * @param uiWebScreenSection
     * @param request
     * @param response
     * @param delegator
     * @param eventProcessor
     * @param primaryME
     * @param removeKeyMapList
     * @param createKeyMapList
     *
     * @return
     */
    protected int preUpdateSelect(UserInfo userInfo,
        UIWebScreenSection uiWebScreenSection, HttpServletRequest request,
        HttpServletResponse response, GenericDelegator delegator,
        GenericEventProcessor eventProcessor, ModelEntity primaryME,
        ArrayList removeKeyMapList, ArrayList createKeyMapList) {

        return STATUS_CONTINUE;
    }

    /**
     * DOCUMENT ME!
     *
     * @param userInfo
     * @param uiWebScreenSection
     * @param request
     * @param response
     * @param delegator
     * @param eventProcessor
     * @param primaryME
     * @param removeKeyMapList
     * @param createKeyMapList
     *
     * @return
     *
     * @throws GenericEntityException
     */
    protected int updateSelect(UserInfo userInfo,
        UIWebScreenSection uiWebScreenSection, HttpServletRequest request,
        HttpServletResponse response, GenericDelegator delegator,
        GenericEventProcessor eventProcessor, ModelEntity primaryME,
        ArrayList removeKeyMapList, ArrayList createKeyMapList)
        throws GenericEntityException {

        int status = eventProcessor.processUpdateSelect(userInfo, delegator,
                primaryME, removeKeyMapList, createKeyMapList);

        return status;
    }

    /**
     * DOCUMENT ME!
     *
     * @param userInfo
     * @param uiWebScreenSection
     * @param request
     * @param response
     * @param delegator
     * @param eventProcessor
     * @param primaryME
     * @param removeKeyMapList
     * @param createKeyMapList
     *
     * @return
     */
    protected int postUpdateSelect(UserInfo userInfo,
        UIWebScreenSection uiWebScreenSection, HttpServletRequest request,
        HttpServletResponse response, GenericDelegator delegator,
        GenericEventProcessor eventProcessor, ModelEntity primaryME,
        ArrayList removeKeyMapList, ArrayList createKeyMapList) {

        return STATUS_CONTINUE;
    }

    //-------------------------------------------------------------------------
    // INSERT - Inserts a new set of entities into the data base.
    //-------------------------------------------------------------------------
    protected int processInsert(UserInfo userInfo,
        UIWebScreenSection uiWebScreenSection, HttpServletRequest request,
        HttpServletResponse response, GenericDelegator delegator,
        GenericEventProcessor eventProcessor, DataMatrix dataMatrix,
        UICache uiCache) throws GenericEntityException {

        int status = STATUS_CONTINUE;

        // Pre fill the data matrix from the info entered on the screen.
        dataMatrix.fillFromHtml(request, uiWebScreenSection);

        // Trigger the pre-insert event.
        status = this.preInsert(userInfo, uiWebScreenSection, request,
                response, delegator, eventProcessor, dataMatrix, uiCache);

        if (status != STATUS_CONTINUE) {
            return status;
        }

        // Trigger the insert event.
        status = this.insert(userInfo, uiWebScreenSection, request, response,
                delegator, eventProcessor, dataMatrix, uiCache);

        if (status != STATUS_CONTINUE) {
            return status;
        }

        // Trigger the post-insert event.
        status = this.postInsert(userInfo, uiWebScreenSection, request,
                response, delegator, eventProcessor, dataMatrix, uiCache);

        return status;
    }

    /**
     * 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) {

        return STATUS_CONTINUE;
    }

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

        int status = eventProcessor.processInsert(userInfo, delegator,
                dataMatrix);

        Debug.logVerbose("Data matrix after insert: " +
                dataMatrix.getCurrentBuffer().getContents().toString(), module);

        return status;
    }

    /**
     * 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) {

        return STATUS_CONTINUE;
    }

    //-------------------------------------------------------------------------
    // DELETE - Deletes data for an entity from the data base.
    //-------------------------------------------------------------------------
    protected int processDelete(UserInfo userInfo,
        UIWebScreenSection uiWebScreenSection, HttpServletRequest request,
        HttpServletResponse response, GenericDelegator delegator,
        GenericEventProcessor eventProcessor, UICache uiCache)
        throws GenericEntityException {

        int status = STATUS_CONTINUE;

        UtilTimer timer = new UtilTimer();

        if (TIMER) {
            timer.timerString(1,
                "[GenericWebEventProcessor.processDelete] Start");
        }

        // Get the main entity using the primary key.
        HashMap fields = new HashMap();
        String primaryEntityName = uiWebScreenSection.getUiScreenSectionEntity(0)
                                                     .getUiEntity()
                                                     .getEntityName();

        Debug.logVerbose("Primary entity name: " + primaryEntityName, module);

        ModelEntity primaryME = uiWebScreenSection.getUiScreenSectionEntity(0)
                                                  .getUiEntity().getModelEntity();
        List primaryPkFieldNames = uiWebScreenSection.getUiScreenSectionEntity(0)
                                                     .getUiEntity()
                                                     .getPrimaryKeyFieldNames();
        Iterator primaryPkFieldNameI = primaryPkFieldNames.iterator();

        while (primaryPkFieldNameI.hasNext()) {
            String primaryPkFieldName = (String) primaryPkFieldNameI.next();
            String primaryPkFieldValue = "";

            if (request.getParameter(primaryPkFieldName) != null) {
                primaryPkFieldValue = request.getParameter(primaryPkFieldName);
            } else if (request.getParameter(primaryEntityName + "_" +
                        primaryPkFieldName) != null) {
                primaryPkFieldValue = request.getParameter(primaryEntityName +
                        "_" + primaryPkFieldName);
            } else {
                throw new GenericEntityException("Parameter \"" +
                    primaryPkFieldName + "\" is required for delete.");
            }

            fields.put(primaryPkFieldName, primaryPkFieldValue);
        }

        Debug.logVerbose("Primary key fields: " + fields.toString(), module);

        // Trigger the pre-delete event.
        status = this.preDelete(userInfo, uiWebScreenSection, request,
                response, delegator, eventProcessor, primaryME, fields, uiCache);

        if (status != STATUS_CONTINUE) {
            return status;
        }

        // Trigger the delete event.
        status = this.delete(userInfo, uiWebScreenSection, request, response,
                delegator, eventProcessor, primaryME, fields, uiCache);

        if (status != STATUS_CONTINUE) {
            return status;
        }

        // Trigger the post-create event.
        status = this.postDelete(userInfo, uiWebScreenSection, request,
                response, delegator, eventProcessor, primaryME, fields, uiCache);

        return status;
    }

    /**
     * DOCUMENT ME!
     *
     * @param userInfo
     * @param uiWebScreenSection
     * @param request
     * @param response
     * @param delegator
     * @param eventProcessor
     * @param primaryME
     * @param fields
     * @param uiCache
     *
     * @return
     */
    protected int preDelete(UserInfo userInfo,
        UIWebScreenSection uiWebScreenSection, HttpServletRequest request,
        HttpServletResponse response, GenericDelegator delegator,
        GenericEventProcessor eventProcessor, ModelEntity primaryME,
        HashMap fields, UICache uiCache) {

        return STATUS_CONTINUE;
    }

    /**
     * DOCUMENT ME!
     *
     * @param userInfo
     * @param uiWebScreenSection
     * @param request
     * @param response
     * @param delegator
     * @param eventProcessor
     * @param primaryME
     * @param fields
     * @param uiCache
     *
     * @return
     *
     * @throws GenericEntityException
     */
    protected int delete(UserInfo userInfo,
        UIWebScreenSection uiWebScreenSection, HttpServletRequest request,
        HttpServletResponse response, GenericDelegator delegator,
        GenericEventProcessor eventProcessor, ModelEntity primaryME,
        HashMap fields, UICache uiCache) throws GenericEntityException {

        int status = eventProcessor.processDelete(userInfo, delegator,
                primaryME, fields);

        return status;
    }

    /**
     * DOCUMENT ME!
     *
     * @param userInfo
     * @param uiWebScreenSection
     * @param request
     * @param response
     * @param delegator
     * @param eventProcessor
     * @param primaryME
     * @param fields
     * @param uiCache
     *
     * @return
     */
    protected int postDelete(UserInfo userInfo,
        UIWebScreenSection uiWebScreenSection, HttpServletRequest request,
        HttpServletResponse response, GenericDelegator delegator,
        GenericEventProcessor eventProcessor, ModelEntity primaryME,
        HashMap fields, UICache uiCache) {

        return STATUS_CONTINUE;
    }

    //-------------------------------------------------------------------------
    // CREATE - Creates a blank set of entities to prepare for an INSERT.
    //-------------------------------------------------------------------------
    protected int processCreate(UserInfo userInfo,
        UIWebScreenSection uiWebScreenSection, HttpServletRequest request,
        HttpServletResponse response, GenericDelegator delegator,
        GenericEventProcessor eventProcessor, DataMatrix dataMatrix)
        throws GenericEntityException {

        int status = STATUS_CONTINUE;

        // Create a List of entity names from which the empty entities will be created.
        //    if (DEBUG) Debug.logVerbose("[create] About to create an empty generic value vector List.");
        List entityNameList = uiWebScreenSection.getEntityNameList();

        // Trigger the pre-create event.
        status = this.preCreate(userInfo, uiWebScreenSection, request,
                response, delegator, eventProcessor, dataMatrix, entityNameList);

        if (status != STATUS_CONTINUE) {
            return status;
        }

        // Trigger the create event.
        status = this.create(userInfo, uiWebScreenSection, request, response,
                delegator, eventProcessor, dataMatrix, entityNameList);

        if (status != STATUS_CONTINUE) {
            return status;
        }

        // Trigger the post-create event.
        status = this.postCreate(userInfo, uiWebScreenSection, request,
                response, delegator, eventProcessor, dataMatrix, entityNameList);

        return status;
    }

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

        return STATUS_CONTINUE;
    }

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

        int status = eventProcessor.processCreate(userInfo, entityNameList,
                delegator, dataMatrix);

        // For each attribute in the data matrix, look for HTML parameters in the
        // request object to set default values.
        Vector genericValueVector = dataMatrix.getCurrentBuffer()
                                              .getContentsRow(0);

        for (int entityNbr = 0; entityNbr < genericValueVector.size();
                entityNbr++) {
            GenericValue gV = (GenericValue) genericValueVector.get(entityNbr);
            String entityName = gV.getEntityName();

            //      List fieldNames = gV.getModelEntity().getNoPkFieldNames();
            List fieldNames = gV.getModelEntity().getAllFieldNames();
            Iterator fieldNameI = fieldNames.iterator();

            while (fieldNameI.hasNext()) {
                String fieldName = (String) fieldNameI.next();

                if (request.getParameter(fieldName) != null) {
                    // A parameter was passed in to set this value. Store it in the data matrix.
                    String defaultValue = request.getParameter(fieldName);
                    EventUtility.storeValue(gV, fieldName, defaultValue,
                        delegator);
                } else {
                    // Check for a parameter with the entity name as a prefix.
                    String parameterName = entityName + "_" + fieldName;

                    if (request.getParameter(parameterName) != null) {
                        // A parameter was passed in to set this value. Store it in the data matrix.
                        String defaultValue = request.getParameter(parameterName);
                        EventUtility.storeValue(gV, fieldName, defaultValue,
                            delegator);
                    }
                }
            }
        }

        return status;
    }

    /**
     * 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) {

        return STATUS_CONTINUE;
    }

    //-------------------------------------------------------------------------
    // SHOW_COPY - Creates a copy of the retrieved entity(s) to prepare for an INSERT.
    //-------------------------------------------------------------------------
    protected int processShowCopy(UserInfo userInfo,
        UIWebScreenSection uiWebScreenSection, HttpServletRequest request,
        HttpServletResponse response, GenericDelegator delegator,
        GenericEventProcessor eventProcessor, DataMatrix dataMatrix)
        throws GenericEntityException {

        int status = STATUS_CONTINUE;

        // Trigger the pre-showCopy event.
        status = this.preShowCopy(userInfo, uiWebScreenSection, request,
                response, delegator, eventProcessor, dataMatrix);

        if (status != STATUS_CONTINUE) {
            return status;
        }

        // Trigger the showCopy event.
        status = this.showCopy(userInfo, uiWebScreenSection, request, response,
                delegator, eventProcessor, dataMatrix);

        if (status != STATUS_CONTINUE) {
            return status;
        }

        // Trigger the post-showCopy event.
        status = this.postShowCopy(userInfo, uiWebScreenSection, request,
                response, delegator, eventProcessor, dataMatrix);

        return status;
    }

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

        return STATUS_CONTINUE;
    }

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

        int status = eventProcessor.processShowCopy(userInfo, delegator,
                dataMatrix);

        return status;
    }

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

        return STATUS_CONTINUE;
    }

    //-------------------------------------------------------------------------
    // SHOWQUERY - Creates a blank set of entities to prepare for query mode.
    //-------------------------------------------------------------------------
    protected int processShowQuery(UserInfo userInfo,
        UIWebScreenSection uiWebScreenSection, HttpServletRequest request,
        HttpServletResponse response, GenericDelegator delegator,
        GenericEventProcessor eventProcessor, DataMatrix dataMatrix)
        throws GenericEntityException {

        int status = STATUS_CONTINUE;

        // Create a List of entity names from which the empty entities will be created.
        //    if (DEBUG) Debug.logVerbose("[processShowQuery] About to create an empty generic value vector List for query mode.");
        List entityNameList = uiWebScreenSection.getEntityNameList();

        String queryMode = UtilFormatOut.checkNull(request.getParameter("queryMode"));
        if ( queryMode.length() < 1)
        {
          Preference pref = Preference.getInstance(delegator);
         
          queryMode = pref.getPreference( userInfo.getPartyId(), userInfo.getAccountId(), "QUERY_MODE", "standard");
         
        }
        uiWebScreenSection.setQueryMode(queryMode);
       
        //    if (DEBUG) Debug.logVerbose("[processShowQuery] Entity name List: " + entityNameList.toString());
        // Trigger the pre-create event.
        status = this.preShowQuery(userInfo, uiWebScreenSection, request,
                response, delegator, eventProcessor, dataMatrix, entityNameList);

        if (status != STATUS_CONTINUE) {
            return status;
        }

        // Trigger the create event.
        status = this.showQuery(userInfo, uiWebScreenSection, request,
                response, delegator, eventProcessor, dataMatrix, entityNameList);

        if (status != STATUS_CONTINUE) {
            return status;
        }

        // Trigger the post-create event.
        status = this.postShowQuery(userInfo, uiWebScreenSection, request,
                response, delegator, eventProcessor, dataMatrix, entityNameList);

        return status;
    }

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

        return STATUS_CONTINUE;
    }

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

        int status = eventProcessor.processShowQuery(userInfo, entityNameList,
                delegator, dataMatrix);

        //    if (DEBUG) Debug.logVerbose("[showQuery] Empty generic value vector List: " + genericValueVectorList.toString());
        return status;
    }

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

        return STATUS_CONTINUE;
    }

    /**
     * DOCUMENT ME!
     *
     * @param uiWebScreenSection
     * @param request
     *
     * @throws GenericEntityException
     */
    protected void evalUseQueryParameterList(
        UIWebScreenSection uiWebScreenSection, HttpServletRequest request)
        throws GenericEntityException {
        HashMap useQueryParameterMap = uiWebScreenSection.getUseQueryParameterMap();

        Debug.logVerbose("useQueryParameterMap: \"" + useQueryParameterMap.toString() + "\".", module);

        HashMap useQueryParameterValueMap = new HashMap();
        Iterator useQueryParameterMapIterator = useQueryParameterMap.keySet()
                                                                    .iterator();

        while (useQueryParameterMapIterator.hasNext()) {
            String key = (String) useQueryParameterMapIterator.next();
            String valueSource = (String) useQueryParameterMap.get(key);

            if (request.getParameter(valueSource) != null) {
                String value = request.getParameter(valueSource);

                Debug.logVerbose("key-value pair: " + key + ":" + value, module);

                useQueryParameterValueMap.put(key, value);
            }
        }

        uiWebScreenSection.setUseQueryParameterValueMap(useQueryParameterValueMap);

        Debug.logVerbose("useQueryParameterValueMap: \"" + useQueryParameterValueMap.toString() + "\".", module);
    }

    /**
     * DOCUMENT ME!
     *
     * @param uiWebScreenSection
     * @param request
     * @param dataMatrix
     *
     * @throws GenericEntityException
     */
    protected void evalSendQueryParameterList(
        UIWebScreenSection uiWebScreenSection, HttpServletRequest request,
        DataMatrix dataMatrix) throws GenericEntityException {
        HashMap sendQueryParameterMap = uiWebScreenSection.getSendQueryParameterMap();

        Debug.logVerbose("sendQueryParameterMap: \"" + sendQueryParameterMap.toString() + "\".", module);

        HashMap sendQueryParameterValueMap = new HashMap();
        Iterator sendQueryParameterMapIterator = sendQueryParameterMap.keySet()
                                                                      .iterator();

        while (sendQueryParameterMapIterator.hasNext()) {
            String key = (String) sendQueryParameterMapIterator.next();

            Debug.logVerbose("Setting search key value \"" + key + "\"", module);

            String valueSource = (String) sendQueryParameterMap.get(key);

            if (request.getParameter(valueSource) == null) {
                // This parameter was NOT found in the request object.  Get the value from the first row in the
                // data matrix.
                Debug.logVerbose("Parameter \"" + valueSource +
                        "\" not found in request object. Looking in current buffer.", module);

                if (dataMatrix.getCurrentBuffer().getContents().size() > 0) {

                    Debug.logVerbose("Looking for parameter \"" + valueSource + "\" in current buffer.", module);

                    Vector entityDetailsVector = dataMatrix.getCurrentBuffer()
                                                           .getContentsRow(0);

                    //        String keyParams = UIWebUtility.getHiddenArgs(getButtonKeyMap(), entityDetailsVector, "       ");
                    try {
                        String value = UIUtility.decodeAttributeValue(valueSource,
                                entityDetailsVector, "");

                        Debug.logVerbose( "Search parameter key-value from current buffer: " + key + ":" + value, module);

                        sendQueryParameterValueMap.put(key, value);
                    } catch (GenericEntityException e) {
                        Debug.logError("Error looking for value for " +
                            valueSource + " in data matrix: " +
                            e.getLocalizedMessage(), module);
                    }
                }
            } else {
                // This parameter was found in the request object.  Use that value.
                String value = request.getParameter(valueSource);

                Debug.logVerbose("Search parameter key-value from request object: " + key + ":" + value, module);

                sendQueryParameterValueMap.put(key, value);
            }
        }

        uiWebScreenSection.setSendQueryParameterValueMap(sendQueryParameterValueMap);

        Debug.logVerbose("sendQueryParameterValueMap: \"" + sendQueryParameterValueMap.toString() + "\".", module);
    }

    //-------------------------------------------------------------------------
    // SHOWREPORT - Re-displays the query criteria in query mode..
    //-------------------------------------------------------------------------
    protected int processShowReport(UserInfo userInfo,
        UIWebScreenSection uiWebScreenSection, HttpServletRequest request,
        HttpServletResponse response, GenericDelegator delegator,
        GenericEventProcessor eventProcessor, DataMatrix dataMatrix)
        throws GenericEntityException {

        int status = STATUS_CONTINUE;

        // Trigger the pre-showReport event.
        status = this.preShowReport(userInfo, uiWebScreenSection, request,
                response, delegator, eventProcessor, dataMatrix);

        if (status != STATUS_CONTINUE) {
            return status;
        }

        // Trigger the showReport event.
        status = this.showReport(userInfo, uiWebScreenSection, request,
                response, delegator, eventProcessor, dataMatrix);

        if (status != STATUS_CONTINUE) {
            return status;
        }

        // Trigger the post-showReport event.
        status = this.postShowReport(userInfo, uiWebScreenSection, request,
                response, delegator, eventProcessor, dataMatrix);

        return status;
    }

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

        return STATUS_CONTINUE;
    }

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

        // Pre fill the data matrix from the info entered on the screen.
        Debug.logVerbose("Prefilling data matrix from screen data.", module);

        dataMatrix.fillFromHtml(request, uiWebScreenSection);

        int status = eventProcessor.processShowReport(userInfo, delegator,
                dataMatrix);

        return status;
    }

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

        return STATUS_CONTINUE;
    }

    //-------------------------------------------------------------------------
    // CUSTOM - Performs one or more custom events.
    //-------------------------------------------------------------------------
    public int processCustom(UserInfo userInfo,
        UIWebScreenSection uiWebScreenSection, HttpServletRequest request,
        HttpServletResponse response, GenericDelegator delegator,
        GenericEventProcessor eventProcessor, DataMatrix dataMatrix,
        String action) throws GenericEntityException {

        int status = eventProcessor.processCustom(userInfo, delegator,
                dataMatrix, action);

        return status;
    }

    /**
     * DOCUMENT ME!
     *
     * @param uiWebScreenSection
     * @param queryInfo  criteria to be used in search
     * @param relatedSearchClauses
     * @param primaryEntityName
     * @param request
     */
    protected void addUseQueryParameterClauses(
        UIWebScreenSection uiWebScreenSection, QueryInfo queryInfo,
        List relatedSearchClauses, String primaryEntityName,
        HttpServletRequest request) {

        EventUtility.appendEntityClauses(primaryEntityName,
            uiWebScreenSection.getUseQueryParameterValueMap(), queryInfo);
    }

    /**
     * DOCUMENT ME!
     *
     * @param userInfo
     * @param screenName
     * @param sectionName
     * @param delegator
     * @param uiCache
     *
     * @return
     *
     * @throws GenericEntityException
     */
    protected UIWebScreenSection getUiWebScreenSection(UserInfo userInfo,
        String screenName, String sectionName, GenericDelegator delegator,
        UICache uiCache) throws GenericEntityException {
        // This method is here so a child class can specify a different screen section class.
        Debug.logVerbose("Looking in cache for UIScreenSection", module);

        UIScreenSection uiScreenSection = uiCache.getUiScreenSection(screenName,
                sectionName, userInfo.getPartyId());
        UIWebScreenSection uiWebScreenSection = null;

        if (uiScreenSection == null) {
            Debug.logVerbose("Screen section not found in cache. Creating", module);

            uiWebScreenSection = new UIWebScreenSection(userInfo, screenName,
                    sectionName, delegator, uiCache);
            uiCache.putUiScreenSection(screenName, sectionName,
                userInfo.getPartyId(), (UIScreenSection) uiWebScreenSection);
        } else {
            Debug.logVerbose("Screen section found in cache", module);

            uiWebScreenSection = (UIWebScreenSection) uiScreenSection;
        }

        return uiWebScreenSection;
    }

    //  getRequestParameterValue
    //  This method may be overridden in order to massage or remove parameters passed on the request object.
    //  Removing a value of NULL for any parameter passed in will cause the parameter to NOT be used in the query clause.
    //  Massaging the return value will affect the query accordingly.
    //  Note:  If there is more than one item in the searchAttribValue array, you MUST return a comma delimited list of
    //  values for use with an IN query that will be used for the search.
    protected String getRequestParameterValue(String paramName,
        String[] searchAttribValueArray) {
        String searchAttribValue = "";


        if (searchAttribValueArray.length > 1) {
            // This was a multi-select box, and more than value was selected. Make a string
            // of values with commas in between and use the IN operation in selectByClause
            for (int valueNbr = 0; valueNbr < searchAttribValueArray.length;
                    valueNbr++) {
                if (valueNbr > 0) {
                    searchAttribValue += ", ";
                }

                searchAttribValue += ("'" + searchAttribValueArray[valueNbr] +
                "'");
            }
        } else {
            // This was not a multi-select box, or only one value was selected. Just use the first
            // value in the parameter value list, and use LIKE, or whatever operator is entered by the user.
            searchAttribValue = searchAttribValueArray[0];
        }

        return searchAttribValue;
    }

    /**
     * DOCUMENT ME!
     *
     * @param action
     * @param request
     * @param dataMatrix
     * @param delegator
     * @param userInfo
     * @param uiWebScreenSection
     */
    protected void logUiHistory(String action, HttpServletRequest request,
        DataMatrix dataMatrix, GenericDelegator delegator, UserInfo userInfo,
        UIWebScreenSection uiWebScreenSection) {
        String primaryEntityName = uiWebScreenSection.getUiScreenSectionEntity(0)
                                                     .getUiEntity()
                                                     .getEntityName();


        //    if (action.equals(uiWebScreenSection.ACTION_SHOW) ||
        //      action.equals(uiWebScreenSection.ACTION_SHOW_QUERY_REPORT)) {
        if (action.equals(uiWebScreenSection.ACTION_SHOW)) {
            //  Add an entry in the history tables
            String url = request.getRequestURL().toString();
            String uri = request.getRequestURI();

            String appPath = getUiHistoryAppPath(url);
            String historyUrl = (request.getScheme() + "://" +
                request.getServerName() + ":" + request.getServerPort() +
                "/sfa/control" + appPath);

            java.util.Enumeration parmNames = request.getParameterNames();

            int i = 0;

            while (parmNames.hasMoreElements() == true) {
                String parmName = (String) parmNames.nextElement();

                if (!parmName.equals("historySelect")) {
                    if (i == 0) {
                        historyUrl = historyUrl + "?";
                    } else {
                        historyUrl = historyUrl + "&";
                    }

                    historyUrl = historyUrl + parmName + "=" +
                        request.getParameter(parmName);
                    i++;
                }
            }

            Debug.logVerbose("HISTORY URL: " + historyUrl, module);

            String historyDescription = getUiHistoryDescription(dataMatrix,
                    delegator, action, uiWebScreenSection);

            Debug.logVerbose("HISTORY DESCR: " + historyDescription, module);

            UIHistoryManager historyManager = new UIHistoryManager(delegator);

            try {
                String historySeqId = historyManager.saveHistoryEvent(userInfo.getPartyId(),
                        historyUrl, historyDescription);

                Debug.logVerbose("HISTORY Saved: " + historySeqId, module);
            } catch (GenericEntityException e) {
                Debug.logError("Error Logging History: " +
                    e.getLocalizedMessage(), module);
            }
        }
    }

    /**
     * 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 "";
    }

    /**
     * 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) {
        if (action.equals(UIWebScreenSection.ACTION_SHOW_QUERY_REPORT)) {
            // This is a report.
            return "Report: " + uiWebScreenSection.getSectionDescription();
        } else {
            // This is a standard screen section.  Just set the name to the entity name as a default value.
            // This should be overridden by a child class to set the name for each screen section.
            return dataMatrix.getCurrentBuffer().getGenericValue(0, 0)
                             .getEntityName();
        }
    }
}
TOP

Related Classes of com.sourcetap.sfa.event.GenericWebEventProcessor

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.