package plm.portal.utility;
|
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.Iterator;
|
import java.util.LinkedHashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import org.dom4j.DocumentException;
|
import org.dom4j.DocumentHelper;
|
|
import com.vci.corba.common.VCIError;
|
|
|
import plm.bs.bom.common.BusinessObject;
|
import plm.bs.bom.common.LinkObject;
|
import plm.corba.portal.PortalVI;
|
import plm.corba.qt.BOAndLO;
|
import plm.corba.qt.QTWrapper;
|
import plm.corba.refquery.RefPath;
|
import plm.oq.objectQuery.client.QTClient;
|
import plm.oq.objectQuery.common.Condition;
|
import plm.oq.objectQuery.common.Connector;
|
import plm.oq.objectQuery.common.OrderInfo;
|
import plm.oq.objectQuery.common.PageInfo;
|
import plm.oq.objectQuery.common.QTConstants;
|
import plm.oq.objectQuery.common.QueryTemplate;
|
import plm.portal.constants.QueryConditionConstants;
|
import plm.refquery.parser.ui.PLMReferenceQueryFacade;
|
|
public class DataModelProcessor implements IDataModelProcessor{
|
|
/**
|
* 根据输入参数自定义查询模板,根据自定义的查询模板获取符合条件的业务对象查询结果
|
* @param btmName,业务类型名称
|
* @param clauseList,返回的字段列表,暂时默认支持*
|
* @param queryChildrenFlag,是否查询子业务类型的数据
|
* @param rightFlag,是否根据数据授权过滤,true:进行数据授权过滤,false:不进行数据授权过滤
|
* @param queryCondition,查询条件map,即需要附加到业务类型的查询语句的查询条件
|
* @param version,1:当前版本当前版次;2代表当前版本最新版次;3:代表最新版本最新版次;4代表当前发布有效版
|
* @param pageInfo,分页信息,不需要分页时将其设为null即可,其包含两个属性:pageNO:页数和rowCount:当前页显示条数
|
* @param orderInfoList,排序信息,不需要是将其设置为null, 其包含三个属性:level:排序优先级,数越小越优先; orderField:排序字段名称;orderMode:属性ASC或DESC;
|
* @return
|
* @throws VCIError
|
* @throws DocumentException
|
*/
|
@Override
|
public BusinessObject[] getBusinessObjectByCondition(String btmName, List<String> clauseList, boolean queryChildrenFlag, boolean rightFlag,
|
Map<String, String> queryCondition, int version, PageInfo pageInfo, List<OrderInfo> orderInfoList) throws VCIError {
|
BusinessObject[] bos = null;
|
try{
|
QueryTemplate qt2 = new QueryTemplate();
|
qt2.setId("btmQuery");
|
qt2.setBtmType(btmName);
|
qt2.setType("btm");
|
clauseList = new ArrayList<String>();
|
clauseList.add("*");
|
qt2.setClauseList(clauseList);
|
qt2.setQueryChildrenFlag(queryChildrenFlag);
|
qt2.setRightFlag(rightFlag);
|
qt2.setVersion(version);
|
if (pageInfo != null && pageInfo.getPageNO() > 0 && pageInfo.getRowCount() > 0) {
|
qt2.setPageInfo(pageInfo);
|
}
|
if (orderInfoList != null && orderInfoList.size() > 0) {
|
qt2.setOrderInfoList(orderInfoList);
|
}
|
|
if (queryCondition != null && queryCondition.size() > 0) {
|
Condition cond = plm.oq.objectQuery.common.Tool.getCondition(queryCondition);
|
qt2.setCondition(cond);
|
}
|
bos = QTClient.getService().findBTMObjects(qt2.getId(), plm.oq.objectQuery.common.Tool.qtTOXMl(qt2).asXML());
|
}
|
catch(VCIError vcie)
|
{
|
throw vcie;
|
}
|
catch(java.lang.Exception se)
|
{
|
VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
|
throw vcierror;
|
}
|
return bos;
|
}
|
|
/**
|
* 自定义查询模板,根据查询条件查询符合条件的链接类型查询结果
|
* @param linkName,link名称
|
* @param clauseList,返回的字段列表,暂时默认支持*
|
* @param queryISLeaf,是否查询叶子节点,true代表查询,false代表不查询
|
* @param rightFlag,是否根据数据授权过滤,true:进行数据授权过滤,false:不进行数据授权过滤
|
* @param direction,查询方向,true代表正向查询,false代表反向查询
|
* @param queryCondition,是否查询子业务类型的数据
|
* @param version,1:当前版本当前版次;2代表当前版本最新版次;3:代表最新版本最新版次;4代表当前发布有效版
|
* @param pageInfo,分页信息,不需要分页时将其设为null即可,其包含两个属性:pageNO:页数和rowCount:当前页显示条数
|
* @param level,查询的层级,-1代表所有,其他数字代码查询的具体层数
|
* @param orderInfoList,排序信息,不需要是将其设置为null, 其包含三个属性:level:排序优先级,数越小越优先; orderField:排序字段名称;orderMode:属性ASC或DESC;
|
* @param recReturnMode,是否去重,true代表去重,false代表不去重
|
* @param objId,源对象ID
|
* @param btmType,查询目标对象的业务类型
|
* @return
|
* @throws VCIError
|
*/
|
@Override
|
public LinkObject[] getLinkObjectByCondition(String linkName, List<String> clauseList, boolean queryISLeaf, boolean rightFlag, boolean direction,
|
Map<String, String> queryCondition, int version, PageInfo pageInfo, int level, List<OrderInfo> orderInfoList, boolean recReturnMode, String objId, String btmType) throws VCIError {
|
LinkObject[] linkObjects = null;
|
try
|
{
|
QueryTemplate qt2 = new QueryTemplate();
|
qt2.setId("ltQuery");
|
qt2.setLinkType(linkName);
|
qt2.setType("link");
|
clauseList = new ArrayList<String>();
|
clauseList.add("*");
|
qt2.setClauseList(clauseList);
|
qt2.setQueryISLeaf(queryISLeaf);
|
qt2.setRightFlag(rightFlag);
|
|
if(direction){
|
qt2.setDirection(QTConstants.DIRECTION_POSITIVE);
|
}else{
|
qt2.setDirection(QTConstants.DIRECTION_OPPOSITE);
|
}
|
if (pageInfo != null && pageInfo.getPageNO() > 0 && pageInfo.getRowCount() > 0) {
|
qt2.setPageInfo(pageInfo);
|
}
|
if (orderInfoList != null && orderInfoList.size() > 0) {
|
qt2.setOrderInfoList(orderInfoList);
|
}
|
if (queryCondition != null && queryCondition.size() > 0) {
|
Condition cond = plm.oq.objectQuery.common.Tool.getConditionForLink(qt2.getDirection(), objId, btmType, queryCondition);
|
qt2.setCondition(cond);
|
}
|
|
qt2.setVersion(version);
|
qt2.setPageInfo(pageInfo);
|
qt2.setLevel(level);
|
if (recReturnMode) {
|
qt2.setRecReturnMode(1);
|
} else {
|
qt2.setRecReturnMode(2);
|
}
|
|
linkObjects = QTClient.getService().findLTObjects(qt2.getId(), plm.oq.objectQuery.common.Tool.qtTOXMl(qt2).asXML());
|
}
|
catch(VCIError vcie)
|
{
|
throw vcie;
|
}
|
catch(java.lang.Exception se)
|
{
|
VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
|
throw vcierror;
|
}
|
return linkObjects;
|
}
|
|
/**
|
* 自定义查询模板,根据查询条件查询符合条件的业务对象和链接类型查询结果
|
* @param linkName,link名称
|
* @param clauseList,返回的字段列表,暂时默认支持*
|
* @param queryISLeaf,是否查询叶子节点,true代表查询,false代表不查询
|
* @param rightFlag,是否根据数据授权过滤,true:进行数据授权过滤,false:不进行数据授权过滤
|
* @param direction,查询方向,true代表正向查询,false代表反向查询
|
* @param queryCondition,是否查询子业务类型的数据
|
* @param version,1:当前版本当前版次;2代表当前版本最新版次;3:代表最新版本最新版次;4代表当前发布有效版
|
* @param pageInfo,分页信息,不需要分页时将其设为null即可,其包含两个属性:pageNO:页数和rowCount:当前页显示条数
|
* @param level,查询的层级,-1代表所有,其他数字代码查询的具体层数
|
* @param orderInfoList,排序信息,不需要是将其设置为null, 其包含三个属性:level:排序优先级,数越小越优先; orderField:排序字段名称;orderMode:属性ASC或DESC;
|
* @param recReturnMode,是否去重,true代表去重,false代表不去重
|
* @param objId,源对象ID
|
* @param btmType,查询目标对象的业务类型
|
* @return
|
* @throws VCIError
|
*/
|
@Override
|
public BOAndLO[] getBOLOsByCondition(String linkName, List<String> clauseList, boolean queryISLeaf, boolean rightFlag, boolean direction,
|
Map<String, String> queryCondition, int version, PageInfo pageInfo, int level, List<OrderInfo> orderInfoList, boolean recReturnMode, String objId, String btmType) throws VCIError {
|
BOAndLO[] bolos = null;
|
try
|
{
|
QueryTemplate qt2 = new QueryTemplate();
|
qt2.setId("ltQuery");
|
qt2.setLinkType(linkName);
|
qt2.setType("link");
|
clauseList = new ArrayList<String>();
|
clauseList.add("*");
|
qt2.setClauseList(clauseList);
|
qt2.setQueryISLeaf(queryISLeaf);
|
qt2.setRightFlag(rightFlag);
|
|
if(direction){
|
qt2.setDirection(QTConstants.DIRECTION_POSITIVE);
|
}else{
|
qt2.setDirection(QTConstants.DIRECTION_OPPOSITE);
|
}
|
if (pageInfo != null && pageInfo.getPageNO() > 0 && pageInfo.getRowCount() > 0) {
|
qt2.setPageInfo(pageInfo);
|
}
|
if (orderInfoList != null && orderInfoList.size() > 0) {
|
qt2.setOrderInfoList(orderInfoList);
|
}
|
if (queryCondition != null && queryCondition.size() > 0) {
|
Condition cond = plm.oq.objectQuery.common.Tool.getConditionForLink(qt2.getDirection(), objId, btmType, queryCondition);
|
qt2.setCondition(cond);
|
}
|
|
qt2.setVersion(version);
|
qt2.setPageInfo(pageInfo);
|
qt2.setLevel(level);
|
if (recReturnMode) {
|
qt2.setRecReturnMode(1);
|
} else {
|
qt2.setRecReturnMode(2);
|
}
|
|
bolos = QTClient.getService().getBOAndLOS(qt2.getId(), plm.oq.objectQuery.common.Tool.qtTOXMl(qt2).asXML(), "");
|
}
|
catch(VCIError vcie)
|
{
|
throw vcie;
|
}
|
catch(java.lang.Exception se)
|
{
|
VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
|
throw vcierror;
|
}
|
return bolos;
|
}
|
|
/**
|
* 根据查询模板及附加条件查询业务对象
|
* @param queryTemplate,查询模板名称
|
* @param replaceMap,替换属性map
|
* @param conditionMap,查询条件map
|
* @param pageInfo,分页信息,其包含两个属性:pageNO:页数和rowCount:当前页显示条数
|
* @return
|
* @throws VCIError
|
* @throws DocumentException
|
*/
|
@Override
|
public BusinessObject[] getBusinessObjectByQueryTemplate(String queryTemplate, Map<String, String> replaceMap, Map<String, String> conditionMap, PageInfo pageInfo) throws VCIError {
|
BusinessObject[] v = null;
|
try
|
{
|
QueryTemplate qt_ = getCustomQt(queryTemplate, replaceMap, conditionMap, pageInfo);
|
v = QTClient.getService().findBTMObjects(qt_.getId(), plm.oq.objectQuery.common.Tool.qtTOXMl(qt_).asXML());
|
}
|
catch(VCIError vcie)
|
{
|
throw vcie;
|
}
|
catch(java.lang.Exception se)
|
{
|
VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
|
throw vcierror;
|
}
|
return v;
|
}
|
|
/**
|
* 根据查询模板及附加条件查询业务对象
|
* @param queryTemplate,查询模板名称
|
* @param replaceMap,替换属性map
|
* @param conditionMap,查询条件map
|
* @param pageInfo,分页信息,其包含两个属性:pageNO:页数和rowCount:当前页显示条数
|
* @param orderInfos: 排序信息
|
* @return
|
* @throws VCIError
|
* @throws DocumentException
|
*/
|
@Override
|
public BusinessObject[] getBusinessObjectByQueryTemplate(String queryTemplate, Map<String, String> replaceMap, Map<String, String> conditionMap, PageInfo pageInfo, List<OrderInfo> orderInfos) throws VCIError {
|
BusinessObject[] v = null;
|
try
|
{
|
QueryTemplate qt_ = getCustomQt(queryTemplate, replaceMap, conditionMap, pageInfo, orderInfos);
|
v = QTClient.getService().findBTMObjects(qt_.getId(), plm.oq.objectQuery.common.Tool.qtTOXMl(qt_).asXML());
|
}
|
catch(VCIError vcie)
|
{
|
throw vcie;
|
}
|
catch(java.lang.Exception se)
|
{
|
VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
|
throw vcierror;
|
}
|
return v;
|
}
|
|
/**
|
* 根据查询模板查询符合要求的link对象
|
* @param queryTemplate,查询模板
|
* @param replaceMap,替换map,
|
* @param conditionMap,附件的查询条件
|
* @param pageInfo,分页信息,其包含两个属性:pageNO:页数和rowCount:当前页显示条数
|
* @return
|
* @throws VCIError
|
* @throws DocumentException
|
*/
|
@Override
|
public LinkObject[] getLinkObjectByQueryTemplate(String queryTemplate, Map<String, String> replaceMap, Map<String, String> conditionMap, PageInfo pageInfo) throws VCIError {
|
LinkObject[] linkObjects = null;
|
try
|
{
|
QueryTemplate qt_ = getCustomQt(queryTemplate, replaceMap, conditionMap, pageInfo);
|
linkObjects = QTClient.getService().findLTObjects(qt_.getId(), plm.oq.objectQuery.common.Tool.qtTOXMl(qt_).asXML());
|
}
|
catch(VCIError vcie)
|
{
|
throw vcie;
|
}
|
catch(java.lang.Exception se)
|
{
|
VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
|
throw vcierror;
|
}
|
return linkObjects;
|
}
|
|
/**
|
* 根据查询模板查询符合要求的业务对象和链接对象
|
* @param queryTemplate,查询模板
|
* @param replaceMap,替换map,
|
* @param conditionMap,附件的查询条件
|
* @param pageInfo,分页信息,其包含两个属性:pageNO:页数和rowCount:当前页显示条数
|
* @return
|
* @throws VCIError
|
* @throws DocumentException
|
*/
|
@Override
|
public BOAndLO[] getBOLOsByQueryTemplate(String queryTemplate, Map<String, String> replaceMap, Map<String, String> conditionMap, PageInfo pageInfo) throws VCIError {
|
BOAndLO[] bolos = null;
|
try
|
{
|
QueryTemplate qt_ = getCustomQt(queryTemplate, replaceMap, conditionMap, pageInfo);
|
bolos = QTClient.getService().getBOAndLOS(qt_.getId(), plm.oq.objectQuery.common.Tool.qtTOXMl(qt_).asXML(), "");
|
}
|
catch(VCIError vcie)
|
{
|
throw vcie;
|
}
|
catch(java.lang.Exception se)
|
{
|
VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
|
throw vcierror;
|
}
|
return bolos;
|
}
|
|
/**
|
* 根据查询模板查询符合要求的业务对象和链接对象
|
* @param queryTemplate,查询模板
|
* @param replaceMap,替换map,
|
* @param conditionMap,附件的查询条件
|
* @param pageInfo,分页信息,其包含两个属性:pageNO:页数和rowCount:当前页显示条数
|
* @return
|
* @throws VCIError
|
* @throws DocumentException
|
*/
|
@Override
|
public BOAndLO[] getBOLOsByQueryTemplate(String queryTemplate, Map<String, String> replaceMap, Map<String, String> conditionMap, PageInfo pageInfo, List<OrderInfo> orderInfos) throws VCIError {
|
BOAndLO[] bolos = null;
|
try
|
{
|
QueryTemplate qt_ = getCustomQt(queryTemplate, replaceMap, conditionMap, pageInfo, orderInfos);
|
bolos = QTClient.getService().getBOAndLOS(qt_.getId(), plm.oq.objectQuery.common.Tool.qtTOXMl(qt_).asXML(), "");
|
}
|
catch(VCIError vcie)
|
{
|
throw vcie;
|
}
|
catch(java.lang.Exception se)
|
{
|
VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
|
throw vcierror;
|
}
|
return bolos;
|
}
|
|
@Override
|
public Map<String, String> getFormColumnMap(PortalVI formDef) {
|
Map<String, String> colMap = new LinkedHashMap<String, String>();
|
PRM sheetPrm = Tool.getPRM(formDef.prm);
|
for (int i = 0; i < sheetPrm.getPrmItemList().size(); i++) {
|
String key = sheetPrm.getPrmItemList().get(i).getItemField();
|
colMap.put(key, sheetPrm.getPrmItemList().get(i).getItemName());
|
}
|
|
return colMap;
|
}
|
|
@Override
|
public String getTableQueryTemplate(PRM prm) {
|
return prm.getPrmItemList().get(0).getItemQtName();
|
}
|
|
@Override
|
public Map<String, String> getSheetColumnMap(PortalVI formDef,
|
String[] tableCol) {
|
Map<String, String> colMap = new LinkedHashMap<String, String>();
|
for (int i = 0; i < tableCol.length; i++) {
|
String key = tableCol[i];
|
String value = getSheetColumnName(key, formDef);
|
colMap.put(tableCol[i], value);
|
}
|
|
return colMap;
|
}
|
|
/**
|
* 根据主键获取对应的名称
|
*
|
* @param key
|
* @param formDef
|
* @return
|
*/
|
private String getSheetColumnName(String key, PortalVI formDef) {
|
PRM sheetPrm = Tool.getPRM(formDef.prm);
|
for (int i = 0; i < sheetPrm.getPrmItemList().size(); i++) {
|
String ckey = sheetPrm.getPrmItemList().get(i).getItemField();
|
if (ckey.equals(key)) {
|
return sheetPrm.getPrmItemList().get(i).getItemName();
|
}
|
}
|
return "";
|
}
|
|
@Override
|
public String getSelectDisplayValue(String key, String value, List<String> selectValues) {
|
for (int i = 0; i < selectValues.size(); i++) {
|
String valueStr = selectValues.get(i);
|
String ckey = valueStr.substring(0, valueStr.indexOf("{"));
|
String cvalue = valueStr.substring(valueStr.indexOf("{") + 1, valueStr.indexOf("}"));
|
if (value.equals(cvalue)) {
|
return ckey;
|
}
|
}
|
return value;
|
}
|
|
@Override
|
public Map<String, PRMItem> getMultiFileCol(PortalVI formDef) {
|
Map<String, PRMItem> multiFiles = new HashMap<String, PRMItem>();
|
PRM sheetPrm = Tool.getPRM(formDef.prm);
|
for (int i = 0; i < sheetPrm.getPrmItemList().size(); i++) {
|
String key = sheetPrm.getPrmItemList().get(i).getItemField();
|
if (sheetPrm.getPrmItemList().get(i).getItemType().equalsIgnoreCase(PRMConstants.MULTIFILE)) {
|
multiFiles.put(key, sheetPrm.getPrmItemList().get(i));
|
}
|
}
|
return multiFiles;
|
}
|
|
@Override
|
public Map<String, PRMItem> getFileCol(PortalVI formDef) {
|
Map<String, PRMItem> files = new HashMap<String, PRMItem>();
|
PRM sheetPrm = Tool.getPRM(formDef.prm);
|
for (int i = 0; i < sheetPrm.getPrmItemList().size(); i++) {
|
String key = sheetPrm.getPrmItemList().get(i).getItemField();
|
if (sheetPrm.getPrmItemList().get(i).getItemType().equalsIgnoreCase(PRMConstants.MULTIFILE)
|
|| sheetPrm.getPrmItemList().get(i).getItemType().equalsIgnoreCase("file")) {
|
files.put(key, sheetPrm.getPrmItemList().get(i));
|
}
|
}
|
return files;
|
}
|
|
@Override
|
public Map<String, PRMItem> getCustomCol(PortalVI formDef) {
|
Map<String, PRMItem> customCols = new HashMap<String, PRMItem>();
|
PRM sheetPrm = Tool.getPRM(formDef.prm);
|
for (int i = 0; i < sheetPrm.getPrmItemList().size(); i++) {
|
String key = sheetPrm.getPrmItemList().get(i).getItemField();
|
if (sheetPrm.getPrmItemList().get(i).getItemType().equalsIgnoreCase(PRMConstants.CUSTOM)) {
|
customCols.put(key, sheetPrm.getPrmItemList().get(i));
|
}
|
}
|
|
return customCols;
|
}
|
|
@Override
|
public Map<String, List<String>> getReferenceCol(Map<String, String> queryCol) {
|
Map<String, List<String>> referenceKeyMap = new HashMap<String, List<String>>(); //引用首字段Map
|
Iterator<String> itor = queryCol.keySet().iterator();
|
while (itor.hasNext()) {
|
String key = itor.next();
|
String[] keyArray = key.split("\\.");
|
if (keyArray.length > 1) {
|
List<String> refList = null;
|
if (referenceKeyMap.get(keyArray[0]) == null) {
|
refList = new ArrayList<String>();
|
} else {
|
refList = referenceKeyMap.get(keyArray[0]);
|
}
|
refList.add(key);
|
referenceKeyMap.put(keyArray[0], refList);
|
}
|
}
|
|
return referenceKeyMap;
|
}
|
|
|
@Override
|
public String getFormQueryTemplate(PRM prm) {
|
return prm.getFormQtName();
|
}
|
|
public static void main(String[] args) {
|
DataModelProcessor p = new DataModelProcessor();
|
// String queryTemplate = "ProductQueryPartsTemplate";
|
Map<String, String> replaceMap = new HashMap<String, String>();
|
replaceMap.put("name_oid", "A389B604-5483-ABA1-D8D8-FA29DFC373DD");
|
replaceMap.put("_TRAINSITIONOID", "81FAB5BF-969F-C549-BF80-88BC27B044FB");
|
replaceMap.put("ISLASTR", "1");
|
replaceMap.put("f_oid", "81FAB5BF-969F-C549-BF80-88BC27B044FB");
|
replaceMap.put("ISLASTV", "1");
|
replaceMap.put("type", "Parts");
|
|
Map<String, String> queryCondition = new HashMap<String, String>();
|
queryCondition.put("id", "CP-001");
|
try {
|
// LinkObject[] los = p.getLinkObjectByQueryTemplate(queryTemplate, replaceMap);
|
BusinessObject[] bos = p.getBusinessObjectByCondition("part", null, true, false, queryCondition, 1, null, null);
|
System.out.println(bos.length);
|
} catch (VCIError e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
} catch (Exception e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
}
|
|
@Override
|
public int getObjectCountByTemplate(String queryTemplate, Map<String, String> replaceMap, Map<String, String> conditionMap) throws VCIError {
|
int count = 0;
|
try
|
{
|
QueryTemplate qt_ = getCustomQt(queryTemplate, replaceMap, conditionMap);
|
count = QTClient.getService().findTotalCount(qt_.getId(),plm.oq.objectQuery.common.Tool.qtTOXMl(qt_).asXML());
|
}
|
catch(VCIError vcie)
|
{
|
throw vcie;
|
}
|
catch(java.lang.Exception se)
|
{
|
VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
|
throw vcierror;
|
}
|
return count;
|
}
|
|
@Override
|
public LinkObject[] getLinkObjectByQueryTemplate(String queryTemplate, Map<String, String> replaceMap, Map<String, String> conditionMap) throws VCIError {
|
LinkObject[] linkObjects = null;
|
|
try
|
{
|
QueryTemplate qt_ = getCustomQt(queryTemplate, replaceMap, conditionMap);
|
linkObjects = QTClient.getService().findLTObjects(qt_.getId(), plm.oq.objectQuery.common.Tool.qtTOXMl(qt_).asXML());
|
}
|
catch(VCIError vcie)
|
{
|
throw vcie;
|
}
|
catch(java.lang.Exception se)
|
{
|
VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
|
throw vcierror;
|
}
|
return linkObjects;
|
}
|
|
@Override
|
public LinkObject[] getLinkObjectByQueryTemplate(String queryTemplate, Map<String, String> replaceMap) throws VCIError, DocumentException {
|
LinkObject[] linkObjects = null;
|
try{
|
QTWrapper wrapper = QTClient.getService().getQT(queryTemplate);
|
QueryTemplate qt = plm.oq.objectQuery.common.Tool.getQTByDoc(DocumentHelper.parseText(wrapper.qtText), queryTemplate);
|
PageInfo pageInfo = null;
|
if(replaceMap.containsKey(QueryConditionConstants.PAGESIZE) && replaceMap.containsKey(QueryConditionConstants.PAGENO)){
|
int pageSize = Integer.valueOf(replaceMap.get(QueryConditionConstants.PAGESIZE));
|
int pageNO = Integer.valueOf(replaceMap.get(QueryConditionConstants.PAGENO));
|
replaceMap.remove(QueryConditionConstants.PAGESIZE);
|
replaceMap.remove(QueryConditionConstants.PAGENO);
|
pageInfo = new PageInfo();
|
pageInfo.setPageNO(pageNO);
|
pageInfo.setRowCount(pageSize);
|
}
|
QueryTemplate qt_ = plm.oq.objectQuery.common.Tool.replaceQTValues(qt, replaceMap);
|
if(pageInfo != null){
|
qt_.setPageInfo(pageInfo);
|
}
|
linkObjects = QTClient.getService().findLTObjects(qt.getId(), plm.oq.objectQuery.common.Tool.qtTOXMl(qt_).asXML());
|
}
|
catch(VCIError vcie)
|
{
|
throw vcie;
|
}
|
catch(java.lang.Exception se)
|
{
|
VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
|
throw vcierror;
|
}
|
return linkObjects;
|
}
|
|
@Override
|
public LinkObject[] getLinkObjectByCondition(Map<String, String> conditions, boolean direction) throws VCIError {
|
if (conditions == null || conditions.size() == 0) {
|
return null;
|
}
|
LinkObject[] linkObjects = null;
|
try
|
{
|
QueryTemplate qt2 = new QueryTemplate();
|
qt2.setId("ltQuery");
|
qt2.setLinkType(conditions.get(QueryConditionConstants.LO_TYPE));
|
qt2.setType("link");
|
List<String> clauseList = new ArrayList<String>();
|
clauseList.add("*");
|
qt2.setClauseList(clauseList);
|
String queryType = conditions.get(QueryConditionConstants.BO_TYPE);
|
String fromOrToOid = conditions.get(QueryConditionConstants.FROM_OR_TO_OID);
|
conditions.remove(QueryConditionConstants.BO_TYPE);
|
conditions.remove(QueryConditionConstants.LO_TYPE);
|
conditions.remove(QueryConditionConstants.FROM_OR_TO_OID);
|
if(direction){
|
qt2.setDirection(QTConstants.DIRECTION_POSITIVE);
|
}else{
|
qt2.setDirection(QTConstants.DIRECTION_OPPOSITE);
|
}
|
if(conditions.containsKey(QueryConditionConstants.PAGESIZE) && conditions.containsKey(QueryConditionConstants.PAGENO)){
|
int pageSize = Integer.valueOf(conditions.get(QueryConditionConstants.PAGESIZE));
|
int pageNO = Integer.valueOf(conditions.get(QueryConditionConstants.PAGENO));
|
conditions.remove(QueryConditionConstants.PAGESIZE);
|
conditions.remove(QueryConditionConstants.PAGENO);
|
PageInfo pageInfo = new PageInfo();
|
pageInfo.setPageNO(pageNO);
|
pageInfo.setRowCount(pageSize);
|
qt2.setPageInfo(pageInfo);
|
}
|
Condition cond = plm.oq.objectQuery.common.Tool.getConditionForLink(qt2.getDirection(), fromOrToOid, queryType, conditions);
|
qt2.setCondition(cond);
|
|
linkObjects = QTClient.getService().findLTObjects(qt2.getId(), plm.oq.objectQuery.common.Tool.qtTOXMl(qt2).asXML());
|
}
|
catch(VCIError vcie)
|
{
|
throw vcie;
|
}
|
catch(java.lang.Exception se)
|
{
|
VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
|
throw vcierror;
|
}
|
return linkObjects;
|
}
|
|
@Override
|
public BusinessObject[] getBusinessObjectByQueryTemplate(String queryTemplate, Map<String, String> replaceMap, Map<String, String> conditionMap) throws VCIError, DocumentException {
|
BusinessObject[] v = null;
|
try
|
{
|
QueryTemplate qt_ = getCustomQt(queryTemplate, replaceMap, conditionMap);
|
v = QTClient.getService().findBTMObjects(qt_.getId(), plm.oq.objectQuery.common.Tool.qtTOXMl(qt_).asXML());
|
}
|
catch(VCIError vcie)
|
{
|
throw vcie;
|
}
|
catch(java.lang.Exception se)
|
{
|
VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
|
throw vcierror;
|
}
|
return v;
|
}
|
|
/**
|
* 根据传递的参数构建新的查询模版
|
* @param queryTemplate
|
* @param replaceMap
|
* @param conditionMap
|
* @return
|
* @throws VCIError
|
* @throws DocumentException
|
*/
|
private QueryTemplate getCustomQt(String queryTemplate, Map<String, String> replaceMap, Map<String, String> conditionMap) throws VCIError, DocumentException {
|
QueryTemplate qt_ = null;
|
try
|
{
|
QTWrapper wrapper = QTClient.getService().getQT(queryTemplate);
|
QueryTemplate qt = plm.oq.objectQuery.common.Tool.getQTByDoc(DocumentHelper.parseText(wrapper.qtText), queryTemplate);
|
PageInfo pageInfo = null;
|
if(replaceMap.containsKey(QueryConditionConstants.PAGESIZE) && replaceMap.containsKey(QueryConditionConstants.PAGENO)){
|
int pageSize = Integer.valueOf(replaceMap.get(QueryConditionConstants.PAGESIZE));
|
int pageNO = Integer.valueOf(replaceMap.get(QueryConditionConstants.PAGENO));
|
replaceMap.remove(QueryConditionConstants.PAGESIZE);
|
replaceMap.remove(QueryConditionConstants.PAGENO);
|
pageInfo = new PageInfo();
|
pageInfo.setPageNO(pageNO);
|
pageInfo.setRowCount(pageSize);
|
}
|
qt_ = plm.oq.objectQuery.common.Tool.replaceQTValues(qt, replaceMap);
|
if (conditionMap != null && conditionMap.size() > 0) {
|
Condition condition = plm.oq.objectQuery.common.Tool.getCondition(conditionMap);
|
Condition mergeCondition = plm.oq.objectQuery.common.Tool.mergeCondition(qt_.getCondition(), condition, Connector.AND);
|
qt_.setCondition(mergeCondition);
|
}
|
if(pageInfo != null){
|
qt_.setPageInfo(pageInfo);
|
}
|
}
|
catch(VCIError vcie)
|
{
|
throw vcie;
|
}
|
catch(java.lang.Exception se)
|
{
|
VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
|
throw vcierror;
|
}
|
return qt_;
|
}
|
|
/**
|
* 根据传递的参数构建新的查询模版
|
* @param queryTemplate, 查询模板
|
* @param replaceMap,替换map
|
* @param conditionMap,查询条件
|
* @param pageInfo,分页信息,其包含两个属性:pageNO:页数和rowCount:当前页显示条数
|
* @return
|
* @throws VCIError
|
* @throws DocumentException
|
*/
|
QueryTemplate getCustomQt(String queryTemplate, Map<String, String> replaceMap, Map<String, String> conditionMap, PageInfo pageInfo) throws VCIError, DocumentException {
|
QueryTemplate qt_ = null;
|
try
|
{
|
QTWrapper wrapper = QTClient.getService().getQT(queryTemplate);
|
QueryTemplate qt = plm.oq.objectQuery.common.Tool.getQTByDoc(DocumentHelper.parseText(wrapper.qtText), queryTemplate);
|
qt_ = plm.oq.objectQuery.common.Tool.replaceQTValues(qt, replaceMap);
|
if (conditionMap != null && conditionMap.size() > 0) {
|
Condition condition = plm.oq.objectQuery.common.Tool.getCondition(conditionMap);
|
Condition mergeCondition = plm.oq.objectQuery.common.Tool.mergeCondition(qt_.getCondition(), condition, Connector.AND);
|
qt_.setCondition(mergeCondition);
|
}
|
if(pageInfo != null){
|
qt_.setPageInfo(pageInfo);
|
}
|
}
|
catch(VCIError vcie)
|
{
|
throw vcie;
|
}
|
catch(java.lang.Exception se)
|
{
|
VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
|
throw vcierror;
|
}
|
return qt_;
|
}
|
|
/**
|
* 根据传递的参数构建新的查询模版
|
*
|
* @param queryTemplate, 查询模板
|
* @param replaceMap,替换map
|
* @param conditionMap,查询条件
|
* @param pageInfo,分页信息,其包含两个属性:pageNO:页数和rowCount:当前页显示条数
|
* @param orderInfos: 排序信息
|
* @return
|
* @throws VCIError
|
* @throws DocumentException
|
*/
|
private QueryTemplate getCustomQt(String queryTemplate, Map<String, String> replaceMap, Map<String, String> conditionMap, PageInfo pageInfo, List<OrderInfo> orderInfos) throws VCIError, DocumentException {
|
QueryTemplate qt_ = null;
|
try
|
{
|
QTWrapper wrapper = QTClient.getService().getQT(queryTemplate);
|
QueryTemplate qt = plm.oq.objectQuery.common.Tool.getQTByDoc(DocumentHelper.parseText(wrapper.qtText), queryTemplate);
|
qt_ = plm.oq.objectQuery.common.Tool.replaceQTValues(qt, replaceMap);
|
if (conditionMap != null && conditionMap.size() > 0) {
|
Condition condition = plm.oq.objectQuery.common.Tool.getCondition(conditionMap);
|
Condition mergeCondition = plm.oq.objectQuery.common.Tool.mergeCondition(qt_.getCondition(), condition, Connector.AND);
|
qt_.setCondition(mergeCondition);
|
}
|
if(pageInfo != null){
|
qt_.setPageInfo(pageInfo);
|
}
|
if(orderInfos != null){
|
qt_.setOrderInfoList(orderInfos);
|
}
|
}
|
catch(VCIError vcie)
|
{
|
throw vcie;
|
}
|
catch(java.lang.Exception se)
|
{
|
VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
|
throw vcierror;
|
}
|
return qt_;
|
}
|
|
@Override
|
public BusinessObject[] getBusinessObjectByQueryTemplate(String queryTemplate, Map<String, String> replaceMap) throws VCIError, DocumentException {
|
BusinessObject[] v = null;
|
try
|
{
|
QTWrapper wrapper = QTClient.getService().getQT(queryTemplate);
|
if (replaceMap != null && replaceMap.size() > 0){
|
QueryTemplate qt = plm.oq.objectQuery.common.Tool.getQTByDoc(DocumentHelper.parseText(wrapper.qtText), queryTemplate);
|
PageInfo pageInfo = null;
|
if(replaceMap.containsKey(QueryConditionConstants.PAGESIZE) && replaceMap.containsKey(QueryConditionConstants.PAGENO)){
|
int pageSize = Integer.valueOf(replaceMap.get(QueryConditionConstants.PAGESIZE));
|
int pageNO = Integer.valueOf(replaceMap.get(QueryConditionConstants.PAGENO));
|
replaceMap.remove(QueryConditionConstants.PAGESIZE);
|
replaceMap.remove(QueryConditionConstants.PAGENO);
|
pageInfo = new PageInfo();
|
pageInfo.setPageNO(pageNO);
|
pageInfo.setRowCount(pageSize);
|
}
|
QueryTemplate qt_ = plm.oq.objectQuery.common.Tool.replaceQTValues(qt, replaceMap);
|
if(pageInfo != null){
|
qt_.setPageInfo(pageInfo);
|
}
|
v = QTClient.getService().findBTMObjects(qt.getId(), plm.oq.objectQuery.common.Tool.qtTOXMl(qt_).asXML());
|
} else {
|
v = QTClient.getService().findBTMObjects(wrapper.qtName, wrapper.qtText);
|
}
|
}
|
catch(VCIError vcie)
|
{
|
throw vcie;
|
}
|
catch(java.lang.Exception se)
|
{
|
VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
|
throw vcierror;
|
}
|
return v;
|
}
|
|
@Override
|
public BusinessObject[] getBusinessObjectByCondition(Map<String, String> conditions) throws VCIError {
|
BusinessObject[] bos = null;
|
try
|
{
|
QueryTemplate qt2 = new QueryTemplate();
|
qt2.setId("btmQuery");
|
qt2.setBtmType(conditions.get(QueryConditionConstants.BO_TYPE));
|
qt2.setType("btm");
|
List<String> clauseList = new ArrayList<String>();
|
clauseList.add("*");
|
qt2.setClauseList(clauseList);
|
conditions.remove(QueryConditionConstants.BO_TYPE);
|
if(conditions.containsKey(QueryConditionConstants.PAGESIZE) && conditions.containsKey(QueryConditionConstants.PAGENO)){
|
int pageSize = Integer.valueOf(conditions.get(QueryConditionConstants.PAGESIZE));
|
int pageNO = Integer.valueOf(conditions.get(QueryConditionConstants.PAGENO));
|
conditions.remove(QueryConditionConstants.PAGESIZE);
|
conditions.remove(QueryConditionConstants.PAGENO);
|
PageInfo pageInfo = new PageInfo();
|
pageInfo.setPageNO(pageNO);
|
pageInfo.setRowCount(pageSize);
|
qt2.setPageInfo(pageInfo);
|
}
|
Condition cond = plm.oq.objectQuery.common.Tool.getCondition(conditions);
|
qt2.setCondition(cond);
|
bos = QTClient.getService().findBTMObjects(qt2.getId(), plm.oq.objectQuery.common.Tool.qtTOXMl(qt2).asXML());
|
}
|
catch(VCIError vcie)
|
{
|
throw vcie;
|
}
|
catch(java.lang.Exception se)
|
{
|
VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
|
throw vcierror;
|
}
|
return bos;
|
}
|
|
@Override
|
public Map<String, String> getQueryBusinessObjectCondition(String type, Map<String, Map<String, String>> rowRefMap, Map<String, List<String>> referenceKeyMap) {
|
Map<String, String> queryMap = new LinkedHashMap<String, String>();
|
Iterator<String> itor = rowRefMap.keySet().iterator();
|
boolean isFirstRow = true;
|
|
while (itor.hasNext()) {
|
String key = itor.next();
|
Map<String, String> instanceMap = rowRefMap.get(key);
|
Iterator<String> citor = instanceMap.keySet().iterator();
|
while (citor.hasNext()) {
|
String ckey = citor.next();
|
String cVal = instanceMap.get(ckey);
|
if (cVal == null) {
|
cVal = "";
|
}
|
List<String> list = referenceKeyMap.get(ckey);
|
if (list == null || list.size() == 0) {
|
continue;
|
}
|
if (isFirstRow) {
|
queryMap.put(ckey, type + "." + ckey + "=" + cVal);
|
} else {
|
queryMap.put(ckey, queryMap.get(ckey) + "," + cVal);
|
}
|
for (int i = 0; i < list.size(); i++) {
|
if (isFirstRow) {
|
queryMap.put(list.get(i), type + "." + list.get(i) + "=" + cVal);
|
} else {
|
queryMap.put(list.get(i), queryMap.get(list.get(i)) + "," + cVal);
|
}
|
}
|
}
|
isFirstRow = false;
|
}
|
itor = queryMap.keySet().iterator();
|
ArrayList<String> emptyValKey = new ArrayList<String>();
|
while (itor.hasNext()) {
|
String key = itor.next();
|
String value = queryMap.get(key);
|
String[] values = value.split("=");
|
if (values.length == 1) {
|
emptyValKey.add(key);
|
} else {
|
int repeatTime = computerStrAppearTimes(values[1], ",");
|
if (values[1].length() == repeatTime) {
|
emptyValKey.add(key);
|
} else if (values[1].lastIndexOf(",") + 1 == values[1].length()) {
|
value = connectStr(values[1].split(","), ",");
|
queryMap.put(key, new StringBuffer(values[0]).append("=").append(value).toString());
|
}
|
}
|
}
|
for (int i = 0; i < emptyValKey.size(); i++) {
|
queryMap.remove(emptyValKey.get(i));
|
}
|
return queryMap;
|
}
|
|
private int computerStrAppearTimes(String source, String str) {
|
if (source == null || source.length() == 0) {
|
return 0;
|
}
|
int sLen = source.length();
|
String des = source.replaceAll(str, "##");
|
int dLen = des.length();
|
return dLen - sLen;
|
}
|
|
private String connectStr(String[] values, String split) {
|
StringBuffer buffer = new StringBuffer();
|
for (int i = 0; i < values.length; i++) {
|
if (i != 0) {
|
buffer.append(split);
|
}
|
buffer.append(values[i]);
|
}
|
return buffer.toString();
|
}
|
|
@Override
|
public Map<String, String> getQueryLinkObjectCondition(String linkType, Map<String, String> rowKeyMap, Map<String, String> rowRefMap, Map<String, List<String>> referenceKeyMap) {
|
Map<String, String> queryMap = new LinkedHashMap<String, String>();
|
Iterator<String> itor = rowKeyMap.keySet().iterator();
|
boolean isFirstRow = true;
|
|
while (itor.hasNext()) {
|
String rowKey = itor.next();
|
String id = rowKeyMap.get(rowKey);
|
String key = rowRefMap.get(id);
|
List<String> list = referenceKeyMap.get(key);
|
if (list == null || list.size() == 0) {
|
continue;
|
}
|
|
if (isFirstRow) {
|
queryMap.put(key, linkType + "." + key + "=" + id);
|
} else {
|
queryMap.put(key, queryMap.get(key) + "," + id);
|
}
|
|
for (int i = 0; i < list.size(); i++) {
|
if (isFirstRow) {
|
queryMap.put(list.get(i), linkType + "." + list.get(i) + "=" + id);
|
} else {
|
queryMap.put(list.get(i), queryMap.get(list.get(i)) + "," + id);
|
}
|
}
|
isFirstRow = false;
|
}
|
return queryMap;
|
}
|
|
@Override
|
public RefPath[] queryReference(Map<String, String> map, String typeName) {
|
PLMReferenceQueryFacade facade = new PLMReferenceQueryFacade();
|
try {
|
List<String> queryList = new ArrayList<String>();
|
Iterator<String> itor = map.keySet().iterator();
|
while(itor.hasNext()) {
|
queryList.add(map.get(itor.next()));
|
}
|
RefPath[] refPath = facade.query(queryList.toArray(new String[queryList.size()]), typeName);
|
return refPath;
|
} catch (Throwable e) {
|
e.printStackTrace();
|
}
|
return null;
|
}
|
|
@Override
|
public RefPath[] queryReference(Map<String, String> map, String[] typeNames) {
|
PLMReferenceQueryFacade facade = new PLMReferenceQueryFacade();
|
try {
|
List<String> queryList = new ArrayList<String>();
|
Iterator<String> itor = map.keySet().iterator();
|
while(itor.hasNext()) {
|
queryList.add(map.get(itor.next()));
|
}
|
RefPath[] refPath = facade.query(queryList.toArray(new String[queryList.size()]), typeNames);
|
return refPath;
|
} catch (Throwable e) {
|
e.printStackTrace();
|
}
|
return null;
|
}
|
}
|