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

📄 genericwebeventprocessor.java

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

⌨️ 快捷键说明

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