Package com.sourcetap.sfa.ui

Source Code of com.sourcetap.sfa.ui.UIQuery

/*
*
* 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.ui;

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

import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilFormatOut;
import org.ofbiz.base.util.UtilMisc;
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.EntityCondition;
import org.ofbiz.entity.condition.EntityConditionList;
import org.ofbiz.entity.condition.EntityExpr;
import org.ofbiz.entity.condition.EntityOperator;
import org.ofbiz.entity.model.DynamicViewEntity;
import org.ofbiz.entity.model.ModelKeyMap;

import com.sourcetap.sfa.event.EventUtility;
import com.sourcetap.sfa.replication.GenericReplicator;
import com.sourcetap.sfa.util.EntityHelper;
import com.sourcetap.sfa.util.QueryInfo;


/**
* This class is used by the UI builder to store and retrieve queries so they can be reused.
*
* @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
* @see  #UIQueryValue
*/
public class UIQuery {
  public static final String module = UIQuery.class.getName();

    /**
     * Constant containing the name of the last query used
     */
    public static final String LAST_QUERY_NAME = ".Last Query";
    public static final String LAST_QUERY_NAME_URL_ENCODED = ".Last+Query";

    /**
     * Query ID - Uniquely identifies this query
     */
    protected String queryId = "";

    /**
     * Section ID - Identifies the UI screen section on which this query can be used
     */
    protected String sectionId = "";

    /**
     * Party ID - Identifies the user who created the query, and who can re-use it.
     */
    protected String partyId = "";

    /**
     * Query Name - Name of this query to appear on the screen in the drop list of available queries
     */
    protected String queryName = "";

    /**
     * Query Value List - List of objects that contain the query values for this query
     *
     * @see #UIQueryValue
     */
    protected ArrayList uiQueryValueList = new ArrayList();

    /**
     * Basic constructor
     * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
     */
    public UIQuery() {
    }

    /**
     * Constructor to create a UI Query from the data base using the specified query ID
     * @param queryId_ Query ID - Uniquely identifies this query
     * @param delegator Generic delegator object required to attach to the correct data source
     * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
     */
    public UIQuery(String queryId_, GenericDelegator delegator) {

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

        try {
            // Get the query from the data base.
            GenericValue uiQueryGV = delegator.findByPrimaryKey("UiQuery",
                    uiQueryFindMap);

            if (uiQueryGV == null) {
                Debug.logWarning(
                    "[UIQuery.UIQuery(queryId)] UiQuery not found with query ID" + queryId_, module);

                return;
            }

            setQueryId((uiQueryGV.getString("queryId") == null) ? ""
                                                                : uiQueryGV.getString(
                    "queryId"));
            setSectionId((uiQueryGV.getString("sectionId") == null) ? ""
                                                                    : uiQueryGV.getString(
                    "sectionId"));
            setPartyId((uiQueryGV.getString("partyId") == null) ? ""
                                                                : uiQueryGV.getString(
                    "partyId"));
            setQueryName((uiQueryGV.getString("queryName") == null) ? ""
                                                                    : uiQueryGV.getString(
                    "queryName"));

            try {

    // Get the query values.
    HashMap uiQueryValueFindMap = new HashMap();
    uiQueryValueFindMap.put("queryId", queryId_);

                // Get the query from the data base.
                List uiQueryValueGVL = delegator.findByAnd("UiQueryValue",
                        uiQueryValueFindMap);
                Iterator uiQueryValueGVI = uiQueryValueGVL.iterator();

                while (uiQueryValueGVI.hasNext()) {
                    GenericValue uiQueryValueGV = (GenericValue) uiQueryValueGVI.next();
                    String entityOperatorIdString = (uiQueryValueGV.getString(
                            "queryOperatorId") == null) ? "1"
                                                        : uiQueryValueGV.getString(
                            "queryOperatorId");
                    int entityOperatorId = Integer.valueOf(entityOperatorIdString)
                                                  .intValue();
                    addUiQueryValue( UtilFormatOut.checkNull(uiQueryValueGV.getString("attributeId")),
                    EntityOperator.lookup(EntityHelper.getEntityOperator(entityOperatorId)),
                    UtilFormatOut.checkNull(uiQueryValueGV.getString("attributeValue")),
                   UtilFormatOut.checkNull(uiQueryValueGV.getString("displayTypeId")),
                    UtilFormatOut.checkNull(uiQueryValueGV.getString("displayObjectId")),
                               delegator);
                }
            } catch (GenericEntityException e2) {
                Debug.logError(
                    "[UIQuery.UIQuery(queryId)] Error looking for UiQueryValues with query ID" +
                    queryId_ + ": " + e2.getLocalizedMessage(), module);
            }
        } catch (GenericEntityException e1) {
            Debug.logError(
                "[UIQuery.UIQuery(queryId)] Error looking for UiQuery with query ID" +
                queryId_ + ": " + e1.getLocalizedMessage(), module);
        }
    }

    /**
     * Constructor with initial values
     * @param queryId_ Query ID - Uniquely identifies this query
     * @param sectionId_ Section ID - Identifies the UI screen section on which this query can be used
     * @param partyId_ Party ID - Identifies the user who created the query, and who can re-use it.
     * @param queryName_ Query Name - Name of this query to appear on the screen in the drop list of available queries
     * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
     */
    public UIQuery(String queryId_, String sectionId_, String partyId_,
        String queryName_, ArrayList uiQueryValueList_) {
        setQueryId(queryId_);
        setSectionId(sectionId_);
        setPartyId(partyId_);
        setQueryName(queryName_);
        setUiQueryValueList(uiQueryValueList_);
    }

    /**
     * Gets the Query ID
     * @return Query ID - Uniquely identifies this query
     * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
     */
    public String getQueryId() {
        return (queryId == null) ? "" : queryId;
    }

    /**
     * Sets the Query ID
     * @param queryId_ Query ID - Uniquely identifies this query
     * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
     */
    public void setQueryId(String queryId_) {
        queryId = queryId_;

        return;
    }

    /**
     * Gets the Section ID
     * @param sectionId_ Section ID - Identifies the UI screen section on which this query can be used
     * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
     */
    public String getSectionId() {
        return (sectionId == null) ? "" : sectionId;
    }

    /**
     * Sets the Section ID
     * @return Section ID - Identifies the UI screen section on which this query can be used
     * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
     */
    public void setSectionId(String sectionId_) {
        sectionId = sectionId_;

        return;
    }

    /**
     * Gets the Party ID
     * @return Party ID - Identifies the user who created the query, and who can re-use it.
     * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
     */
    public String getPartyId() {
        return (partyId == null) ? "" : partyId;
    }

    /**
     * Sets the Party ID
     * @param partyId_ Party ID - Identifies the user who created the query, and who can re-use it.
     * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
     */
    public void setPartyId(String partyId_) {
        partyId = partyId_;

        return;
    }

    /**
     * Gets the Query Name
     * @param queryName_ Query Name - Name of this query to appear on the screen in the drop list of available queries
     * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
     */
    public String getQueryName() {
        return (queryName == null) ? "" : queryName;
    }

    /**
     * Sets the Query Name
     * @return_ Query Name - Name of this query to appear on the screen in the drop list of available queries
     * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
     */
    public void setQueryName(String queryName_) {
        queryName = queryName_;

        return;
    }

    /**
     * Gets a reference to the Query Value List
     *
     * @return_ Query Value List - List of objects that contain the query values for this query
     * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
     * @see #UIQueryValue
     */
    public ArrayList getUiQueryValueList() {
        return uiQueryValueList;
    }

    /**
     * Stores an ArrayList containing values of type UIQueryValue into the Query Value List
     *
     * @param uiQueryValueList_ Query Value List - List of objects that contain the query values for this query
     * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
     * @see #UIQueryValue
     */
    public void setUiQueryValueList(ArrayList uiQueryValueList_) {
        uiQueryValueList = uiQueryValueList_;

        return;
    }

    /**
     * Gets a reference to the UIQueryValue stored in the query value list at the position specified by the queryValueNbr parameter
     *
     * @param queryValueNbr Position in the query value list from which to get the query value object
     * @return Query value object from the specified position in the query value list
     * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
     * @see #UIQueryValue
     */
    public UIQueryValue getUiQueryValue(int queryValueNbr) {

        return (UIQueryValue) uiQueryValueList.get(queryValueNbr);
    }

    /**
     * Adds an object of class UIQueryValue to the query value list
     *
     * @param attributeId_ Attribute ID - Uniquely identifies an attribute defined in the UI data
     * @param attributeValue_ The value to be compared to the specified attribute on entities in the data base
     *    when the query is executed
     * @param entityOperator_ The operand to be used to compare the value to the specified attribute on
     *    entities in the data base when the query is executed
     * @param delegator Generic delegator object required to attach to the correct data source
     * @return ID of new query value
     * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
     * @see #UIQueryValue
     */
    public void addUiQueryValue(String attributeId, EntityOperator entityOperator, String attributeValue,
         String displayTypeId, String displayObjectId, GenericDelegator delegator) {

        uiQueryValueList.add(new UIQueryValue("", getQueryId(), attributeId,
                attributeValue, (EntityComparisonOperator) entityOperator, displayTypeId, displayObjectId));

        //    return queryValueId;
        return;
    }

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

        // Add all queries not tied to any particular party ID or screen section.
        HashMap uiQueryFindMap = new HashMap();
        uiQueryFindMap.put("partyId", "-1");
        uiQueryFindMap.put("sectionId", "-1");

        ArrayList uiQueryFindOrder = new ArrayList();
        uiQueryFindOrder.add("queryName");

        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;
    }
}
TOP

Related Classes of com.sourcetap.sfa.ui.UIQuery

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.