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

📄 uiquery.java

📁 国外的一套开源CRM
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        List uiQueryGVL = delegator.findByAnd("UiQuery", uiQueryFindMap,
                uiQueryFindOrder);

        // Add all queries not tied to any particular party ID, but tied to the current screen section.
		// Find the last query used by this party ID for this screen section.
		// select X from ui_query q, ui_screen_section ss, ui_screen s where q.section_id = ss.section_id and q.party_id = -1 and ss.section_name = <section_name>
		//      and s.screen_name = <screenName> and s.screen_id = ss.screen_id order by query_name       
		DynamicViewEntity dve = EntityHelper.createDynamicViewEntity( delegator, "UiQuery"); 
		dve.addMemberEntity("UiScreenSection", "UiScreenSection");
		dve.addViewLink("UiQuery", "UiScreenSection", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("sectionId", "sectionId")));
		dve.addMemberEntity("UiScreen", "UiScreen");
		dve.addViewLink("UiScreenSection", "UiScreen", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("screenId", "screenId")));
		dve.addAlias("UiScreen", "screenName", null, null, null, null, null);
		dve.addAlias("UiScreenSection", "sectionName", null, null, null, null, null);
     
		EntityCondition condition = new EntityConditionList(UtilMisc.toList(
				new EntityExpr("partyId", EntityOperator.EQUALS, "-1"),
				new EntityExpr("screenName", EntityOperator.EQUALS, screenName),
				new EntityExpr("sectionName", EntityOperator.EQUALS, sectionName)),
				EntityOperator.AND);
        
	    uiQueryGVL.addAll(EntityHelper.findByCondition( delegator, dve, condition, uiQueryFindOrder ));

        // Add all queries tied to the current party ID and screen section.
		// select X from ui_query q, ui_screen_section ss, ui_screen s where q.section_id = ss.section_id and q.party_id = <partyId> and ss.section_name = <section_name>
		//      and s.screen_name = <screenName> and s.screen_id = ss.screen_id order by query_name       
		condition = new EntityConditionList(UtilMisc.toList(
				new EntityExpr("partyId", EntityOperator.EQUALS, partyId),
				new EntityExpr("screenName", EntityOperator.EQUALS, screenName),
				new EntityExpr("sectionName", EntityOperator.EQUALS, sectionName)),
				EntityOperator.AND);
        
		uiQueryGVL.addAll(EntityHelper.findByCondition( delegator, dve, condition, uiQueryFindOrder ));

        return uiQueryGVL;
    }

    /**
     * DOCUMENT ME!
     *
     * @param delegator 
     * @param partyId 
     * @param sectionName 
     * @param screenName 
     * @param savedQueryName 
     *
     * @return 
     *
     * @throws GenericEntityException 
     */
    public static GenericValue getUiQueryByName(GenericDelegator delegator,
        String partyId, String sectionName, String screenName,
        String savedQueryName) throws GenericEntityException {

        GenericValue uiQueryGV = null;

        // Find the last query used by this party ID for this screen section.
        // select X from ui_query q, ui_screen_section ss, ui_screen s where q.section_id = ss.section_id and q.party_id = <party_id> and ss.section_name = <section_name>
        //      and s.screen_name = <screenName> and s.screen_id = ss.screen_id and q.queryName = <queryName>        
		DynamicViewEntity dve = EntityHelper.createDynamicViewEntity( delegator, "UiQuery"); 
		dve.addMemberEntity("UiScreenSection", "UiScreenSection");
		dve.addViewLink("UiQuery", "UiScreenSection", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("sectionId", "sectionId")));
		dve.addMemberEntity("UiScreen", "UiScreen");
		dve.addViewLink("UiScreenSection", "UiScreen",Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("screenId", "screenId")));
		dve.addAlias("UiScreen", "screenName", null, null, null, null, null);
		dve.addAlias("UiScreenSection", "sectionName", null, null, null, null, null);
     
		EntityCondition condition = new EntityConditionList(UtilMisc.toList(
				new EntityExpr("partyId", EntityOperator.EQUALS, partyId),
   				new EntityExpr("queryName", EntityOperator.EQUALS, savedQueryName),
				new EntityExpr("screenName", EntityOperator.EQUALS, screenName),
				new EntityExpr("sectionName", EntityOperator.EQUALS, sectionName)),
				EntityOperator.AND);
        
		List uiQueryGVL = EntityHelper.findByCondition( delegator, dve, condition, null );
        
        if (uiQueryGVL.size() == 0) {
            // There is no last query to pull up.
            Debug.logWarning(
                    "[UIQuery.getUiQueryByName]: Named query not found for query name " +
                    savedQueryName + ", partyId " + partyId + ", sectionName " +
                    sectionName + ", and screenName " + screenName + ".", module);

            return uiQueryGV;
        } else {
            // The last query was found. Get it from the List.
            Debug.logVerbose(
                    "[UIQuery.getUiQueryByName]: Named query found for query name " +
                    savedQueryName + ", partyId " + partyId + ", sectionName " +
                    sectionName + ", and screenName " + screenName + ".", module);

            uiQueryGV = (GenericValue) uiQueryGVL.iterator().next();
        }

        /*
                        // Add the query values to the "other" array of the query generic value object.
                        List uiQueryValueL = (List)delegator.getRelated("UiQueryValue", uiQueryGV);
                        uiQueryGV.preStoreOthers(uiQueryValueL);
        */
        return uiQueryGV;
    }

    /**
     * DOCUMENT ME!
     *
     * @param delegator 
     * @param queryId 
     *
     * @return 
     *
     * @throws GenericEntityException 
     */
    public static List getUiQueryValues(GenericDelegator delegator,
        String queryId) throws GenericEntityException {

        HashMap uiQueryFindMap = new HashMap();
        uiQueryFindMap.put("queryId", queryId);

        GenericValue uiQueryGV = delegator.findByPrimaryKey("UiQuery",
                uiQueryFindMap);

        if (uiQueryGV == null) {
            throw new GenericEntityException("No UI Query was found with ID \"" +
                queryId + "\".");
        }

        // Get the query values for this query ID.
        List uiQueryValueL = (List) delegator.getRelated("UiQueryValue",
                uiQueryGV);

        return uiQueryValueL;
    }

    /**
     * Save the query to the data base
     * @param delegator Generic delegator object required to attach to the correct data source
     * @return Query ID - Uniquely identifies this query
     * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
     */
    public String save(GenericDelegator delegator) {
        // Find out if there is already a query saved with this name for this section ID and party ID.  If so,
        // just retrieve and update that one.

        HashMap uiQueryFindMap = new HashMap();
        uiQueryFindMap.put("partyId", getPartyId());
        uiQueryFindMap.put("sectionId", getSectionId());
        uiQueryFindMap.put("queryName", getQueryName());

        Debug.logVerbose("[UIQuery.save] About to search for UiQuery - " +
                "partyId:" + getPartyId() + ", sectionId:" + getSectionId() +
                ", queryName:" + getQueryName(), module);

        try {
            List storeGVL = new LinkedList();
            List uiQueryGVL = delegator.findByAnd("UiQuery", uiQueryFindMap,
                    null);
            GenericValue uiQueryGV = null;

            if (uiQueryGVL.size() == 0) {
                // Query not found. Create a new one.

                setQueryId(GenericReplicator.getNextSeqId("UiQuery", delegator));
                uiQueryGV = toGenericValue(delegator);
            } else {

                // Query already exists. Prepare to update existing.
                uiQueryGV = (GenericValue) uiQueryGVL.iterator().next();

                // Store the existing query ID from the data base to this query object.
                setQueryId(uiQueryGV.getString("queryId"));

                // Remove existing query values from the data base.
                List uiQueryValueL = (List) delegator.getRelated("UiQueryValue",
                        uiQueryGV);
                Iterator uiQueryValueI = uiQueryValueL.iterator();

                while (uiQueryValueI.hasNext()) {
                    // Remove this attribute from the database.
                    GenericValue uiQueryValueGV = (GenericValue) uiQueryValueI.next();
                    uiQueryValueGV.remove();
                }
            }

            // Add the query onto the List of records to be saved.
            storeGVL.add(uiQueryGV);

            // Append all the attributes onto the query so they will be inserted into the data base.

            ArrayList uiQueryValueList = getUiQueryValueList();

            for (int uiQueryValueNbr = 0;
                    uiQueryValueNbr < uiQueryValueList.size();
                    uiQueryValueNbr++) {

                UIQueryValue uiQueryValue = getUiQueryValue(uiQueryValueNbr);

                // Copy the query ID onto the query value in case it is not already set.
                uiQueryValue.setQueryId(getQueryId());

                // Set the query VALUE ID now so it will change each time we save the query.
                String queryValueId = GenericReplicator.getNextSeqId("UiQueryValue", delegator);

                uiQueryValue.setQueryValueId(queryValueId);

                // Create a generic value for this query value, and attach it to the query's generic value so it will be saved.
                GenericValue uiQueryValueGV = uiQueryValue.toGenericValue(delegator);

                // Add the query value onto the List of records to be saved.
                storeGVL.add(uiQueryValueGV);
            }

            try {
                // Insert or update the query and associated values.
                delegator.storeAll(storeGVL);
            } catch (GenericEntityException e2) {
                Debug.logError("[UIQuery.save] Error saving query: " +
                    e2.getLocalizedMessage(), module);
            }
        } catch (GenericEntityException e) {
            Debug.logError(
                "[UIQuery.save] Error looking for existing query: " +
                e.getLocalizedMessage(), module);
        }

        return getQueryId();
    }

    /**
     * Create entity clauses for this query that can be used by the GenericDelegator.findByCondition method
     * @param delegator Generic delegator object required to attach to the correct data source
     * @param queryInfo  criteria to be used in search
     * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
     */
    public void appendEntityClauses(GenericDelegator delegator,
        QueryInfo queryInfo) {

        // Append an entity clause for each query value.
        for (int uiQueryValueNbr = 0;
                uiQueryValueNbr < uiQueryValueList.size(); uiQueryValueNbr++) {
            UIQueryValue uiQueryValue = getUiQueryValue(uiQueryValueNbr);

            try {
		// Find the UI attribute generic value.
		HashMap uiAttributeSearchMap = new HashMap();
		uiAttributeSearchMap.put("attributeId",
			uiQueryValue.getAttributeId());

                GenericValue uiAttributeGV = delegator.findByPrimaryKey("UiAttribute",
                        uiAttributeSearchMap);
                String searchAttribName = uiAttributeGV.getString(
                        "attributeName");
                String entityId = uiAttributeGV.getString("entityId");

                // Find the UI entity generic value.
                HashMap uiEntitySearchMap = new HashMap();
                uiEntitySearchMap.put("entityId", entityId);

                List queryEntities = queryInfo.getEntities();
                HashMap joinedEntities = new HashMap();
                for ( int i = 0; i < queryEntities.size(); i++)
                {
                	joinedEntities.put( (String) queryEntities.get(i), "Y");
                }

                try {
                    GenericValue uiEntityGV = delegator.findByPrimaryKey("UiEntity",
                            uiEntitySearchMap);
                    String searchEntityName = uiEntityGV.getString("entityName");

		            String hasJoin = (String) joinedEntities.get(searchEntityName);
							
					if ( ( hasJoin == null ) || ( !hasJoin.equals("Y")) )
					{
						String primaryEntityName = queryInfo.getPrimaryEntity();
						EventUtility.addOneRelationClause(delegator, "", "",searchEntityName, primaryEntityName, delegator.getModelEntity(primaryEntityName), false, queryInfo);

						joinedEntities.put(searchEntityName, "Y");
					}

					String displayTypeId = uiQueryValue.getDisplayTypeId();
							
					EntityComparisonOperator entityOperator = uiQueryValue.getEntityOperator();
					String searchValueStr = uiQueryValue.getAttributeValue();
					Object searchValue = searchValueStr;
					
					// 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(searchValueStr, ",");

						while (tokComma.hasMoreTokens()) {
							String valueItem = tokComma.nextToken();
							valueList.add(valueItem);
						}
						searchValue = valueList;
					}
							
							
					// Generate an entry in the WHERE clause for this attribute.  
					// If this is a select field, we need to search on the lookup value, not the lookup ID
					if ( displayTypeId.equals(UIDisplayObject.DISPLAY_TYPE_SELECT) || displayTypeId.equals(UIDisplayObject.DISPLAY_TYPE_SEARCH_TEXT))
					{
						String aliasName = searchEntityName + searchAttribName + "srch";
						UIUtility.addSelectSearch( queryInfo, uiQueryValue.getDisplayObjectId(), searchEntityName, searchAttribName, aliasName, 
										           entityOperator, searchValue );
					}
					else
					{
                    // Generate an entry in the WHERE clause for this attribute.
						if ( searchValue instanceof Collection )
							EventUtility.appendEntityClause(searchEntityName, searchAttribName, (Collection) searchValue, entityOperator, queryInfo);
						else
							EventUtility.appendEntityClause(searchEntityName, searchAttribName, searchValueStr, entityOperator, queryInfo);
					}



                } catch (GenericEntityException e2) {
                    Debug.logError(
                        "[UIQuery.appendEntityClauses] Error looking for UiEntity: " +
                        e2.getLocalizedMessage(), module);
                }
            } catch (GenericEntityException e1) {
                Debug.logError(
                    "[UIQuery.appendEntityClauses] Error looking for UiAttribute: " +
                    e1.getLocalizedMessage(), module);
            }
        }
    }

    /**
     * Creates a generic value for this query.
     * @param delegator Generic delegator object required to attach to the correct data source
     * @return Generic value representing this query
     * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
     */
    public GenericValue toGenericValue(GenericDelegator delegator) {

        GenericValue uiQueryGV = new GenericValue(delegator.getModelEntity(
                    "UiQuery"));
        uiQueryGV.setDelegator( delegator );
        uiQueryGV.set("queryId", getQueryId());
        uiQueryGV.set("sectionId", getSectionId());
        uiQueryGV.set("partyId", getPartyId());
        uiQueryGV.set("queryName", getQueryName());

        return uiQueryGV;
    }
}

⌨️ 快捷键说明

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