package com.vci.client.uif.engine.client.compare.dataloader;
|
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import com.vci.client.bof.ClientBusinessObject;
|
import com.vci.client.bof.ClientLinkObject;
|
import com.vci.client.common.oq.OQTool;
|
import com.vci.client.oq.QTClient;
|
import com.vci.client.uif.actions.client.UIFUtils;
|
import com.vci.client.uif.engine.client.compare.dialog.treenode.TreeNodeObject;
|
import com.vci.client.uif.engine.client.compare.exception.InitializationException;
|
import com.vci.common.qt.object.Condition;
|
import com.vci.common.qt.object.QueryTemplate;
|
import com.vci.corba.query.data.BOAndLO;
|
|
/**
|
* 实现了 DataLoader接口的数据加载器
|
*
|
* DefaultDataLoader 在初始化时进行数据加载
|
*
|
* @author VCI-STGK006
|
*
|
*/
|
public class BusinessObjectDataLoader implements DataLoader<ClientBusinessObject, ClientLinkObject> {
|
|
/**
|
* 根节点OID
|
*/
|
private String rootOid;
|
|
/**
|
* 链接类型
|
*/
|
private String linkType;
|
|
/**
|
* 加载业务对象类型
|
*/
|
private String btmName;
|
|
/**
|
* 正反向
|
*/
|
private boolean direction;
|
|
/**
|
* 版本版次
|
*/
|
private int version;
|
|
/**
|
* 其它查询条件
|
*/
|
private Map<String, String> conditions = null;
|
|
/**
|
* link关系结合
|
* key为fromOid
|
*/
|
private Map<String, List<ClientLinkObject>> cloMap = new HashMap<String, List<ClientLinkObject>>();
|
|
/**
|
* 所有子节点集合,包括根节点
|
* key为业务对象OID
|
*/
|
private Map<String, ClientBusinessObject> cboMap = new HashMap<String, ClientBusinessObject>();
|
|
/**
|
* link关系结合
|
* key = getKey()
|
*/
|
private Map<String, List<ClientLinkObject>> cloKeyMap = new HashMap<String, List<ClientLinkObject>>();
|
|
/**
|
* 所有子节点集合,包括根节点
|
* key = getKey()
|
*/
|
private Map<String, ClientBusinessObject> cboKeyMap = new HashMap<String, ClientBusinessObject>();
|
|
/**
|
* 数据加载器
|
* @param rootOid 根节点OID
|
* @param linkType 链接类型
|
* @param btmName 显示业务类型
|
* @param direction 正反向
|
* @param version 版本版次
|
* @param conditions 其它查询条件,可以为null
|
*/
|
public BusinessObjectDataLoader(String rootOid, String linkType,
|
String btmName, boolean direction, int version, Map<String, String> conditions) {
|
this.rootOid = rootOid;
|
this.linkType = linkType;
|
this.btmName = btmName;
|
this.direction = direction;
|
this.version = version;
|
this.conditions = conditions;
|
}
|
|
/**
|
* 加载数据
|
*/
|
public void loading(){
|
try {
|
BOAndLO[] blos = queryLOAddBO(linkType, btmName, rootOid, direction, -1, version);
|
//查询根节点
|
ClientBusinessObject root = UIFUtils.queryBusinessObject(rootOid, btmName, true);
|
//if(!root.getBusinessObject().oid.equals("")) {
|
// cboMap.put(rootOid, root);
|
//}
|
cboMap.put(rootOid, root);
|
cboKeyMap.put(getKey(root), root);
|
//设置数据
|
if(blos != null && blos.length > 0) {
|
for(BOAndLO blo : blos) {
|
ClientBusinessObject cbo = new ClientBusinessObject();
|
cbo.setBusinessObject(blo.bo);
|
cboMap.put(blo.bo.oid, cbo);
|
cboKeyMap.put(getKey(cbo), cbo);
|
ClientLinkObject clo = new ClientLinkObject();
|
clo.setLinkObject(blo.lo);
|
putData(cloMap, clo);
|
}
|
for(BOAndLO blo : blos) {
|
ClientLinkObject clo = new ClientLinkObject();
|
clo.setLinkObject(blo.lo);
|
putKeyMapData(cloKeyMap, clo);
|
}
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
throw new InitializationException(
|
"数据加载器初始化异常,加载数据失败!" + e.getMessage());
|
}
|
}
|
|
/**
|
* 设置关系集合
|
* @param map
|
* @param clo
|
*/
|
private void putData(Map<String,
|
List<ClientLinkObject>> map, ClientLinkObject clo) {
|
String key = "";
|
if(this.direction) {
|
key = clo.getFromOid();
|
} else {
|
key = clo.getToOid();
|
}
|
if(map.containsKey(key)) {
|
List<ClientLinkObject> cloList = map.get(clo.getFromOid());
|
cloList.add(clo);
|
map.put(key, cloList);
|
} else {
|
List<ClientLinkObject> cloList = new ArrayList<ClientLinkObject>();
|
cloList.add(clo);
|
map.put(key, cloList);
|
}
|
}
|
|
/**
|
* 设置关系集合
|
* @param map
|
* @param clo
|
*/
|
private void putKeyMapData(Map<String,
|
List<ClientLinkObject>> map, ClientLinkObject clo) {
|
String key = getKey(clo);
|
if(map.containsKey(key)) {
|
List<ClientLinkObject> cloList = map.get(key);
|
cloList.add(clo);
|
map.put(key, cloList);
|
} else {
|
List<ClientLinkObject> cloList = new ArrayList<ClientLinkObject>();
|
cloList.add(clo);
|
map.put(key, cloList);
|
}
|
}
|
|
@Override
|
public Map<String, ClientBusinessObject> getRoots() {
|
Map<String, ClientBusinessObject> roots = new HashMap<String, ClientBusinessObject>();
|
roots.put(getKey(this.cboMap.get(this.rootOid)), this.cboMap.get(this.rootOid));
|
return roots;
|
}
|
|
@Override
|
public String getKey(Object object) {
|
if(object instanceof ClientBusinessObject) {
|
return ((ClientBusinessObject) object).getNameoid();
|
} else if(object instanceof ClientLinkObject){
|
String fromOid = "";
|
if(direction) {
|
fromOid = ((ClientLinkObject) object).getFromOid();
|
} else {
|
fromOid = ((ClientLinkObject) object).getToOid();
|
}
|
ClientBusinessObject cbo = this.cboMap.get(fromOid);
|
return getKey(cbo);
|
}
|
return "";
|
}
|
|
@Override
|
public List<ClientLinkObject> getLinksByParent(String parentKey,
|
TreeNodeObject parent) {
|
return this.cloKeyMap.get(parentKey);
|
}
|
|
@Override
|
public String getChildKeyByLink(ClientLinkObject r) {
|
String oid = "";
|
if(this.direction) {
|
oid = r.getToOid();
|
} else {
|
oid = r.getFromOid();
|
}
|
return getKey(this.cboMap.get(oid));
|
}
|
|
@Override
|
public Map<String, ClientBusinessObject> getChildren(String parentKey,
|
TreeNodeObject parent) {
|
Map<String, ClientBusinessObject> result = new HashMap<String, ClientBusinessObject>();
|
List<ClientLinkObject> cloList = this.cloKeyMap.get(parentKey);
|
if(cloList != null && !cloList.isEmpty()) {
|
for(ClientLinkObject clo : cloList) {
|
String key = "";
|
if(this.direction) {
|
key = clo.getToOid();
|
} else {
|
key = clo.getFromOid();
|
}
|
if(this.cboMap.containsKey(key)) {
|
result.put(getKey(this.cboMap.get(key)), this.cboMap.get(key));
|
}
|
}
|
}
|
return result;
|
}
|
|
@Override
|
public ClientLinkObject getChildLink(String parentKey,
|
TreeNodeObject parent, ClientBusinessObject object) {
|
if(object == null) {
|
return null;
|
}
|
List<ClientLinkObject> cloList = this.cloKeyMap.get(parentKey);
|
if(cloList != null && !cloList.isEmpty()) {
|
for(ClientLinkObject clo : cloList) {
|
if(this.direction) {
|
if(clo.getToOid().equals(object.getOid())) {
|
return clo;
|
}
|
} else {
|
if(clo.getFromOid().equals(object.getOid())) {
|
return clo;
|
}
|
}
|
}
|
}
|
return null;
|
}
|
|
@Override
|
public ClientBusinessObject getObject(String key) {
|
return this.cboKeyMap.get(key);
|
}
|
|
/**
|
* 查询数据
|
* @param lintype
|
* @param btmName
|
* @param srcOid
|
* @param direction
|
* @param level
|
* @param version
|
* @return
|
* @throws Exception
|
*/
|
private BOAndLO[] queryLOAddBO(String lintype, String btmName,
|
String srcOid, boolean direction, int level, int version) throws Exception {
|
QueryTemplate qt9 = new QueryTemplate();
|
qt9.setId("ltQuery");
|
qt9.setLinkType(lintype);
|
qt9.setType("link");
|
qt9.setBtmType(btmName);
|
qt9.setRightFlag(false);
|
List<String> clauseList = new ArrayList<String>();
|
clauseList.add("*");
|
qt9.setClauseList(clauseList);
|
qt9.setVersion(version);
|
Map<String, String> conditions = new HashMap<String, String>();
|
if(direction){
|
qt9.setDirection("positive");
|
conditions.put("f_oid", srcOid);
|
}else{
|
qt9.setDirection("opposite");
|
conditions.put("t_oid", srcOid);
|
}
|
if(this.conditions != null) {
|
conditions.putAll(this.conditions);
|
}
|
Condition cond = OQTool.getCondition(conditions);
|
qt9.setCondition(cond);
|
qt9.setLevel(level);
|
|
BOAndLO[] loaddbo = QTClient.getService().getBOAndLOS(
|
qt9.getId(), OQTool.qtTOXMl(qt9).asXML(),"");
|
|
return loaddbo;
|
}
|
}
|