/*
* @return 类似于这样的节点列表,json格式:<br> { identifier: 'objectId', label: 'title',
* items: [ { "type":"root","title":"1a","objectId":"1","widgetId":"1",
* "children":[ {"_reference":"21"}, {"objectId":"22","_reference":"22"} ] },
* {"type":"stub","title":"21b","objectId":"21","widgetId":"21"},
* {"type":"stub","title":"22b","objectId":"22","widgetId":"22"} ] }
* @auth: hi.baidu.com/javaroad
*/
public String getRoots() throws JSONException {
ITreeFactory factory = (ITreeFactory) CrmContexts.getBean(CrmContexts.getRequestParam("treeId"));
Object[] nodes = factory.getRoots();
JSONArray ret = new JSONArray();
if (nodes == null) {
return ret.toString();
}
for (int i = 0; i < nodes.length; i++) {
if (nodes[i] == null)
continue;
JSONObject obj = new JSONObject();
Object node = nodes[i];
String id = factory.getId(node);
obj.put("objectId", id);
obj.put("type", "root");
obj.put("title", factory.getTitle(node));
if (!factory.isLeaf(node)) {
// 有子编码
Object[] children = factory.getChildren(node);
if (children != null && children.length > 0) {
// 有孩子节点
JSONArray child = new JSONArray();
for (int j = 0; j < children.length; j++) {
JSONObject node1 = new JSONObject();
node1.put("_reference", factory.getId(children[j])); // root使用reference,
// childer使用stub
// node1.put("objectId", factory.getId(children[j]));
child.put(j, node1);
}
obj.put("children", child);
// root需要把各个下级children也加进去
for (int j = 0; j < children.length; j++) {
JSONObject node1 = new JSONObject();
node1.put("objectId", factory.getId(children[j]));
// node1.put("title", factory.getTitle(children[j]));
node1.put("type", "stub");
ret.put(node1);
}
}
}
ret.put(obj);
}
String retu = "{identifier: 'objectId', label: 'title', items: " + ret.toString() + "}";
return retu;
}
/*
* @return 类似于这样的节点列表,json格式:<br> {
* "type":"node","title":"22b","objectId":"22","widgetId":"22", "children":[
* {"stub":"33"}, {"stub":"44"} ] }
* @auth: hi.baidu.com/javaroad
*/
public String getChildren() throws JSONException {
String id = CrmContexts.getRequestParam("objectId");
ITreeFactory factory = (ITreeFactory) CrmContexts.getBean(CrmContexts.getRequestParam("treeId"));
JSONObject obj = new JSONObject();
Object node = factory.getNodeById(id);
obj.put("objectId", id);
obj.put("title", factory.getTitle(node));
obj.put("type", "node");
if (!factory.isLeaf(node)) {
// 有子节点
Object[] children = factory.getChildren(node);
if (children != null && children.length > 0) {
// 有孩子节点
JSONArray child = new JSONArray();
for (int j = 0; j < children.length; j++) {
JSONObject node1 = new JSONObject();
// 这里统一用reference不用stub了
node1.put("stub", factory.getId(children[j]));
child.put(j, node1);
}
obj.put("children", child);
}
}
return obj.toString();
}
* @return 类似于这样的节点列表,json格式:<br> { identifier: 'objectId', label: 'title',
* items: [ { "type":"root","title":"1a","objectId":"1","widgetId":"1",
* "children":[ {"_reference":"21"}, {"objectId":"22","_reference":"22"} ] },
* {"type":"stub","title":"21b","objectId":"21","widgetId":"21"},
* {"type":"stub","title":"22b","objectId":"22","widgetId":"22"} ] }
* @auth: hi.baidu.com/javaroad
*/
public String getRoots() throws JSONException {
ITreeFactory factory = (ITreeFactory) CrmContexts.getBean(CrmContexts.getRequestParam("treeId"));
Object[] nodes = factory.getRoots();
JSONArray ret = new JSONArray();
if (nodes == null) {
return ret.toString();
}
for (int i = 0; i < nodes.length; i++) {
if (nodes[i] == null)
continue;
JSONObject obj = new JSONObject();
Object node = nodes[i];
String id = factory.getId(node);
obj.put("objectId", id);
obj.put("type", "root");
obj.put("title", factory.getTitle(node));
if (!factory.isLeaf(node)) {
// 有子编码
Object[] children = factory.getChildren(node);
if (children != null && children.length > 0) {
// 有孩子节点
JSONArray child = new JSONArray();
for (int j = 0; j < children.length; j++) {
JSONObject node1 = new JSONObject();
node1.put("_reference", factory.getId(children[j])); // root使用reference,
// childer使用stub
// node1.put("objectId", factory.getId(children[j]));
child.put(j, node1);
}
obj.put("children", child);
// root需要把各个下级children也加进去
for (int j = 0; j < children.length; j++) {
JSONObject node1 = new JSONObject();
node1.put("objectId", factory.getId(children[j]));
// node1.put("title", factory.getTitle(children[j]));
node1.put("type", "stub");
ret.put(node1);
}
}
}
ret.put(obj);
}
String retu = "{identifier: 'objectId', label: 'title', items: " + ret.toString() + "}";
return retu;
}
/*
* @return 类似于这样的节点列表,json格式:<br> {
* "type":"node","title":"22b","objectId":"22","widgetId":"22", "children":[
* {"stub":"33"}, {"stub":"44"} ] }
* @auth: hi.baidu.com/javaroad
*/
public String getChildren() throws JSONException {
String id = CrmContexts.getRequestParam("objectId");
ITreeFactory factory = (ITreeFactory) CrmContexts.getBean(CrmContexts.getRequestParam("treeId"));
JSONObject obj = new JSONObject();
Object node = factory.getNodeById(id);
obj.put("objectId", id);
obj.put("title", factory.getTitle(node));
obj.put("type", "node");
if (!factory.isLeaf(node)) {
// 有子节点
Object[] children = factory.getChildren(node);
if (children != null && children.length > 0) {
// 有孩子节点
JSONArray child = new JSONArray();
for (int j = 0; j < children.length; j++) {
JSONObject node1 = new JSONObject();
// 这里统一用reference不用stub了
node1.put("stub", factory.getId(children[j]));
child.put(j, node1);
}
obj.put("children", child);
}
}
return obj.toString();
}