Commit 06a96f10 by qiuchaofei

合并获取图形的接口。

parent eda41b4c
...@@ -47,116 +47,6 @@ public class MetaDataController { ...@@ -47,116 +47,6 @@ public class MetaDataController {
private IBaseRelationshipService baseRelationshipService; private IBaseRelationshipService baseRelationshipService;
/** /**
* 查询元数据,关系
* 返回 node,edge,icon
*/
@ApiOperation(tags = "", value = "获取所有的节点与关系")
@RequestMapping(path = "/result1", method = RequestMethod.GET)
public ReturnReslult getAllNodeAndRelation() {
logger.info("开始获取所有的节点与关系");
ReturnReslult result = new ReturnReslult();
List<MetaData> metaDataList = metadataService.finAllMetaData();
Map<Long, Node> nodeMap = new HashMap<>();
Map<String, MetaModel> metaModelMap = new HashMap<>();
for (MetaData metaData : metaDataList) {
Node node = new Node();
String[] strings = metaData.getMetadataId().split("=");
String modelName = strings[0];
node.setId(metaData.getMetadataId());
node.setIcon(modelName);
if (!metaModelMap.containsKey(modelName)) {
MetaModel model = new MetaModel();
String iconContext = getIconByModelId(modelName);
model.setModelName(modelName);
model.setCnName(modelName);
model.setDescription("");
model.setIcon(iconContext);
metaModelMap.put(modelName, model);
}
node.setName(metaData.getName());
node.setType("MetaData");
result.getNodes().add(node);
nodeMap.put(metaData.getId(), node);
}
List<TempNode> allTempNode = metadataService.findAllTempNode();
for (TempNode tempNode : allTempNode) {
Node node = new Node();
String[] strings = tempNode.getMetadataId().split("=");
String modelName = strings[0];
node.setId(tempNode.getMetadataId());
node.setIcon(modelName);
if (!metaModelMap.containsKey(modelName)) {
MetaModel model = new MetaModel();
String iconContext = getIconByModelId(modelName);
model.setModelName(modelName);
model.setCnName(modelName);
model.setDescription("");
model.setIcon(iconContext);
metaModelMap.put(modelName, model);
}
node.setName(tempNode.getName());
node.setType("TempNode");
result.getNodes().add(node);
nodeMap.put(tempNode.getId(), node);
}
logger.info("节点的数量:" + result.getNodes().size());
List<BaseRelationship> baseRelationshipList = baseRelationshipService.findAllRelation();
for (BaseRelationship baseRelationship : baseRelationshipList) {
Edge edge = new Edge();
edge.setEdgeId(String.valueOf(baseRelationship.getId()));
Long startId = baseRelationship.getStart().getId();
Long endId = baseRelationship.getEnd().getId();
String startMetaId = "";
String endMEtaId = "";
if (nodeMap.containsKey(startId)) {
startMetaId = nodeMap.get(startId).getId();
}
if (nodeMap.containsKey(endId)) {
endMEtaId = nodeMap.get(endId).getId();
}
if (StringUtils.isNotBlank(startMetaId) && StringUtils.isNotBlank(endMEtaId)) {
edge.setFromId(startMetaId);
edge.setToId(endMEtaId);
edge.setType(baseRelationship.getName());
result.getEdges().add(edge);
}
}
logger.info("关系的数量:" + result.getEdges().size());
result.setMetaModelMap(metaModelMap);
return result;
}
@ApiOperation(tags = "", value = "传入元模型名称,返回该元模型的元数据所有关系")
// @RequestMapping(path = "/getNodeAndRelationByModel", method = RequestMethod.GET)
@RequestMapping(path = "/getNodeAndRelationByModel", method = RequestMethod.GET)
public ReturnReslult getNodeAndRelationByModel(String modelName) {
if (modelName == null || modelName.equals("")) {
modelName = "Table";
}
ReturnReslult returnReslult = metadataService.findResultByModelName(modelName);
return returnReslult;
}
/**
* 查询元数据 * 查询元数据
*/ */
@RequestMapping(path = "/list", method = RequestMethod.GET) @RequestMapping(path = "/list", method = RequestMethod.GET)
...@@ -170,191 +60,164 @@ public class MetaDataController { ...@@ -170,191 +60,164 @@ public class MetaDataController {
* 返回一个系统级的大图 * 返回一个系统级的大图
*/ */
@ApiOperation(tags = "", value = "系统级的大图") @ApiOperation(tags = "", value = "系统级的大图")
// @RequestMapping(path = "/getBigGraph", method = RequestMethod.GET)
@RequestMapping(path = "/result", method = RequestMethod.GET) @RequestMapping(path = "/result", method = RequestMethod.GET)
public ReturnReslult getBigGraph() { public ReturnReslult getBigGraph(String modelName0) {
logger.info("开始获取系统级的大图");
ReturnReslult result = new ReturnReslult();
List<MetaData> metaDataList = metadataService.finAllMetaData(); logger.info("传入的元模型名称是:"+modelName0);
Map<String, Node> nodeMap = new HashMap<>(); ReturnReslult returnReslult = new ReturnReslult();
if (modelName0 == null || modelName0.equals("")) {
Map<String, String> child2Parent = new HashMap<>(); modelName0 = "Table";
Map<String, List<String>> parent2Children = new HashMap<>(); }
Map<String, List<String>> source2Target = new HashMap<>(); if(!modelName0.toLowerCase().equals("all")){
Map<String, List<String>> target2Source = new HashMap<>(); returnReslult = metadataService.findResultByModelName(modelName0);
}else {
Map<String, MetaModel> metaModelMap = new HashMap<>(); List<MetaData> metaDataList = metadataService.finAllMetaData();
Map<String, Node> nodeMap = new HashMap<>();
for (MetaData metaData : metaDataList) {
Node node = new Node(); Map<String, String> child2Parent = new HashMap<>();
String[] strings = metaData.getMetadataId().split("="); Map<String, List<String>> parent2Children = new HashMap<>();
String modelName = strings[0]; Map<String, List<String>> source2Target = new HashMap<>();
Map<String, List<String>> target2Source = new HashMap<>();
//如果有system,则虚拟创建一个节点,用来做顶层节点
if (metaData.getSystem() != null && !metaData.getSystem().equals("")) { Map<String, MetaModel> metaModelMap = new HashMap<>();
String systemName = metaData.getSystem(); for (MetaData metaData : metaDataList) {
Node node = new Node();
String[] strings = metaData.getMetadataId().split("=");
String modelName = strings[0];
//如果有system,则虚拟创建一个节点,用来做顶层节点
if (metaData.getSystem() != null && !metaData.getSystem().equals("")) {
String systemName = metaData.getSystem();
Node systemNode = new Node();
systemNode.setId("catalog=" + systemName);
systemNode.setName(systemName);
String newModelName = "Catalog";
systemNode.setIcon(newModelName);
if (!metaModelMap.containsKey(newModelName)) {
MetaModel model = new MetaModel();
String iconContext = getIconByModelId(newModelName);
model.setModelName(newModelName);
model.setCnName(newModelName);
model.setDescription("");
model.setIcon(iconContext);
metaModelMap.put(newModelName, model);
}
Node systemNode = new Node(); systemNode.setType("MetaData");
systemNode.setId("catalog=" + systemName); returnReslult.getNodes().add(systemNode);
systemNode.setName(systemName); nodeMap.put("" + systemNode.getId(), systemNode);
String newModelName = "Catalog"; child2Parent.put("" + metaData.getId(), systemNode.getId());
systemNode.setIcon(newModelName); }
if (!metaModelMap.containsKey(newModelName)) { node.setId(metaData.getMetadataId());
node.setIcon(modelName);
if (!metaModelMap.containsKey(modelName)) {
MetaModel model = new MetaModel(); MetaModel model = new MetaModel();
String iconContext = getIconByModelId(newModelName); String iconContext = getIconByModelId(modelName);
model.setModelName(newModelName); model.setModelName(modelName);
model.setCnName(newModelName); model.setCnName(modelName);
model.setDescription(""); model.setDescription("");
model.setIcon(iconContext); model.setIcon(iconContext);
metaModelMap.put(newModelName, model); metaModelMap.put(modelName, model);
} }
node.setName(metaData.getName());
node.setType("MetaData");
returnReslult.getNodes().add(node);
nodeMap.put("" + metaData.getId(), node);
systemNode.setType("MetaData");
result.getNodes().add(systemNode);
nodeMap.put("" + systemNode.getId(), systemNode);
child2Parent.put("" + metaData.getId(), systemNode.getId());
}
node.setId(metaData.getMetadataId());
node.setIcon(modelName);
if (!metaModelMap.containsKey(modelName)) {
MetaModel model = new MetaModel();
String iconContext = getIconByModelId(modelName);
model.setModelName(modelName);
model.setCnName(modelName);
model.setDescription("");
model.setIcon(iconContext);
metaModelMap.put(modelName, model);
} }
node.setName(metaData.getName()); logger.info("节点的数量:" + returnReslult.getNodes().size());
node.setType("MetaData"); List<BaseRelationship> baseRelationshipList = baseRelationshipService.findAllRelation();
result.getNodes().add(node); /**
nodeMap.put("" + metaData.getId(), node); * 分成两部分,一个是组合关系,一个是依赖关系。
*
} */
logger.info("节点的数量:" + result.getNodes().size());
for (BaseRelationship baseRelationship : baseRelationshipList) {
Long startId = baseRelationship.getStart().getId();
List<BaseRelationship> baseRelationshipList = baseRelationshipService.findAllRelation(); Long endId = baseRelationship.getEnd().getId();
/**
* 分成两部分,一个是组合关系,一个是依赖关系。 if (baseRelationship.getName().equals("流入")
* || baseRelationship.getName().equals("流出")) {
*/
if (source2Target.get(startId) != null) {
for (BaseRelationship baseRelationship : baseRelationshipList) { source2Target.get(startId).add("" + endId);
Long startId = baseRelationship.getStart().getId(); } else {
Long endId = baseRelationship.getEnd().getId(); List<String> targets = new ArrayList<>();
targets.add("" + endId);
if (baseRelationship.getName().equals("流入") source2Target.put("" + startId, targets);
|| baseRelationship.getName().equals("流出")) { }
if (target2Source.get(endId) != null) {
if (source2Target.get(startId) != null) { target2Source.get(endId).add("" + startId);
source2Target.get(startId).add("" + endId); } else {
} else { List<String> sources = new ArrayList<>();
List<String> targets = new ArrayList<>(); sources.add("" + startId);
targets.add("" + endId); target2Source.put("" + endId, sources);
source2Target.put("" + startId, targets); }
}
if (target2Source.get(endId) != null) {
target2Source.get(endId).add("" + startId);
} else {
List<String> sources = new ArrayList<>();
sources.add("" + startId);
target2Source.put("" + endId, sources);
}
} else if (baseRelationship.getName().equals("流出")) { } else if (baseRelationship.getName().equals("流出")) {
} else if (baseRelationship.getName().equals("组合")) { } else if (baseRelationship.getName().equals("组合")) {
child2Parent.put("" + endId, "" + startId); child2Parent.put("" + endId, "" + startId);
if (parent2Children.get("" + startId) != null) { if (parent2Children.get("" + startId) != null) {
parent2Children.get("" + startId).add("" + endId); parent2Children.get("" + startId).add("" + endId);
} else { } else {
List<String> children = new ArrayList<>(); List<String> children = new ArrayList<>();
children.add("" + endId); children.add("" + endId);
parent2Children.put("" + startId, children); parent2Children.put("" + startId, children);
}
} }
} }
}
//专门处理流入 流出的关系 //专门处理流入 流出的关系
for (BaseRelationship baseRelationship : baseRelationshipList) { for (BaseRelationship baseRelationship : baseRelationshipList) {
String startId = baseRelationship.getStart().getId() + ""; String startId = baseRelationship.getStart().getId() + "";
String endId = baseRelationship.getEnd().getId() + ""; String endId = baseRelationship.getEnd().getId() + "";
String startMetaId = ""; String startMetaId = "";
String endMetaId = ""; String endMetaId = "";
if (baseRelationship.getName().equals("流入") if (baseRelationship.getName().equals("流入")
|| baseRelationship.getName().equals("流出")) { || baseRelationship.getName().equals("流出")) {
startId = getParentId("" + startId, child2Parent); startId = getParentId("" + startId, child2Parent);
// if(child2Parent . containsKey(startId)){ // if(child2Parent . containsKey(startId)){
// startId = child2Parent.get(startId); // startId = child2Parent.get(startId);
// } // }
endId = getParentId("" + endId, child2Parent); endId = getParentId("" + endId, child2Parent);
// if(child2Parent . containsKey(endId)){ // if(child2Parent . containsKey(endId)){
// endId = child2Parent.get(endId); // endId = child2Parent.get(endId);
// } // }
if (nodeMap.containsKey("" + startId)) { if (nodeMap.containsKey("" + startId)) {
Node startNode = nodeMap.get("" + startId); Node startNode = nodeMap.get("" + startId);
startMetaId = nodeMap.get("" + startId).getId(); startMetaId = nodeMap.get("" + startId).getId();
} }
if (nodeMap.containsKey("" + endId)) { if (nodeMap.containsKey("" + endId)) {
endMetaId = nodeMap.get("" + endId).getId(); endMetaId = nodeMap.get("" + endId).getId();
}
Edge edge = new Edge();
edge.setEdgeId("" + baseRelationship.getId());
edge.setFromId(startMetaId);
edge.setToId(endMetaId);
edge.setType(baseRelationship.getName());
returnReslult.getEdges().add(edge);
} }
Edge edge = new Edge();
edge.setEdgeId("" + baseRelationship.getId());
edge.setFromId(startMetaId);
edge.setToId(endMetaId);
edge.setType(baseRelationship.getName());
result.getEdges().add(edge);
} }
}
// for(Object obj : child2Parent.keySet()){ logger.info("关系的数量:" + returnReslult.getEdges().size());
// logger.info("child:"+ obj + " ,parent:"+ child2Parent.get(obj)); returnReslult.setMetaModelMap(metaModelMap);
// } }
// for(Object obj : parent2Children.keySet()){
// List<String> children = parent2Children.get(obj);
// logger.info("parent:"+ obj);
// for(String child:children){
// logger.info(" child:" + child );
// }
// }
//
// for(Object obj : source2Target.keySet()){
// List<String> targets = source2Target.get(obj);
// logger.info("source:"+ obj);
// for(String target:targets){
// logger.info(" target:" + target );
// }
// }
//
//
// for(Object obj : target2Source.keySet()){
// List<String> sources = target2Source.get(obj);
// logger.info("target:"+ obj);
// for(String source:sources){
// logger.info(" source:" + source );
// }
// }
logger.info("关系的数量:" + result.getEdges().size());
result.setMetaModelMap(metaModelMap);
return result; return returnReslult;
} }
private String getParentId(String neo4jId, Map<String, String> child2Parent) { private String getParentId(String neo4jId, Map<String, String> child2Parent) {
...@@ -530,7 +393,6 @@ public class MetaDataController { ...@@ -530,7 +393,6 @@ public class MetaDataController {
@ApiOperation(tags = "", value = "传入元数据id,显示的层数,查找出与该元数据有关系的数据") @ApiOperation(tags = "", value = "传入元数据id,显示的层数,查找出与该元数据有关系的数据")
@RequestMapping(path = "/getNodeByDataId", method = RequestMethod.GET) @RequestMapping(path = "/getNodeByDataId", method = RequestMethod.GET)
public ReturnReslult getNodeByDataId(String metadataId, int depth) { public ReturnReslult getNodeByDataId(String metadataId, int depth) {
return metadataService.findNodeByDataId(metadataId, depth); return metadataService.findNodeByDataId(metadataId, depth);
} }
...@@ -544,17 +406,6 @@ public class MetaDataController { ...@@ -544,17 +406,6 @@ public class MetaDataController {
} }
/**
* 添加元数据的接口
*/
@RequestMapping(path = "/addMetadata", method = RequestMethod.POST)
public MetaData addMetadata(@RequestBody MetaData metaData) {
System.out.println("这是写入元数据的方法。");
MetaData metaData1 = metadataService.addMetaData(metaData);
return metaData1;
}
/** /**
* 同步元数据关系的接口,传入一个环境名称(catalognName),从mongo读取关系,存入到neo4j中 * 同步元数据关系的接口,传入一个环境名称(catalognName),从mongo读取关系,存入到neo4j中
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment