📄 uiquery.java
字号:
/*
*
* 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");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -