Commit a9a410e1 by qiuchaofei

1.去掉es属性,2返回的结果添加属性列表,3同步的数据添加path属性,4添加外部接口包括资产与标准。

parent 2a1db326
......@@ -2,7 +2,6 @@ package com.keymobile.metadata.metadataRelation;
import com.ulisesbocchio.jasyptspringboot.environment.StandardEncryptableEnvironment;
import org.jasypt.encryption.StringEncryptor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.openfeign.EnableFeignClients;
......@@ -13,7 +12,6 @@ import com.keymobile.config.security.ApplicationHelper;
public class MetadataRelationApplication {
public static void main(String[] args) {
System.setProperty("es.set.netty.runtime.available.processors", "false");
new SpringApplicationBuilder()
.environment(StandardEncryptableEnvironment.builder().encryptor(stringEncryptor()).build())
.sources(MetadataRelationApplication.class).run(args);
......
......@@ -3,6 +3,8 @@ package com.keymobile.metadata.metadataRelation.controller;
import com.keymobile.metadata.metadataRelation.pojo.metadata.Neo4jSchema;
import com.keymobile.metadata.metadataRelation.pojo.returnBean.ReturnNode;
import com.keymobile.metadata.metadataRelation.pojo.returnBean.ReturnReslult;
import com.keymobile.metadata.metadataRelation.remote.DataAssertRemoteService;
import com.keymobile.metadata.metadataRelation.remote.DataStandardRemoteService;
import com.keymobile.metadata.metadataRelation.service.IMetadataService;
import com.keymobile.metadata.metadataRelation.service.ISchemaService;
import com.keymobile.metadata.metadataRelation.service.ISystemService;
......@@ -10,6 +12,7 @@ import com.keymobile.metadata.metadataRelation.service.ITableService;
import com.keymobile.metadata.metadataRelation.service.impl.SystemServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONObject;
import org.hibernate.loader.custom.Return;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -18,6 +21,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.sql.SQLOutput;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
......@@ -37,7 +43,29 @@ public class RelationalGraphController {
@Autowired
private ITableService tableService;
@Autowired
private DataStandardRemoteService dataStandardRemoteService;
//测试标准的接口
@ApiOperation(tags = "", value = "测试标准的接口")
@RequestMapping(path = "/dataAssertRemoteService", method = RequestMethod.GET)
public void dataAssertRemoteService(String metadataid){
int size = 300;
Map<String,Object> maps = new HashMap<>();
maps.put("metadataId",metadataid);
Map<String, Object> standardMaps = dataStandardRemoteService.findStandardByMetadatId(1, 10,
maps);
List<LinkedHashMap<String,Object>> contentList = (List<LinkedHashMap<String,Object>>) standardMaps.get("content");
for(LinkedHashMap<String,Object> contentString:contentList){
for(Object obj :contentString.keySet()){
String standardId = (String)contentString.get("standardId");
String enName = (String)contentString.get("enName");
String cnName = (String)contentString.get("cnName");
}
}
}
//系统总图的接口
@ApiOperation(tags = "", value = "系统总图")
@RequestMapping(path = "/getAllSystemGraph", method = RequestMethod.GET)
......@@ -86,14 +114,32 @@ public class RelationalGraphController {
}
//表的分析,关系分析--表与模型,表与质量,表与标准,表与作业的关系
//表的分析,链路分析,表与其他表的上下游关系,其他表可以继续下钻,并且可以收缩。
@ApiOperation(tags = "", value = "传入表的id,返回与表相关的模型,标准,质量,资产,作业等对象")
@RequestMapping(path = "/getRelationObjectByTableId", method = RequestMethod.GET)
public Map<String,List<ReturnNode>> getRelationObjectByTableId(String tableId){
return tableService.getRelationObjectByTableId (tableId);
}
//搜索接口,多个搜索结果,则先弹出列表(对象的全路径),再进行选择哪个对象
@ApiOperation(tags = "", value = "传入表的id,返回与表相关的模型,标准,质量,资产,作业等对象")
@RequestMapping(path = "/searchByMetadataId", method = RequestMethod.GET)
public Map<String,List<ReturnNode>> searchByMetadataId(String tableId){
return tableService.getRelationObjectByTableId (tableId);
}
/**
* 搜索的自动匹配接口,按照输入的字符,自动匹配名字,返回前10个匹配到的。
*/
@ApiOperation(tags = "", value = "模糊匹配输入结果,不区分大小写")
@RequestMapping(path = "/autoMatchByInputWord", method = RequestMethod.GET)
public List<ReturnNode> autoMatchByInputWord(String name,String count,String offset) {
if(count == null || count .equals("")){
count = "1000";
}
int offsetInt = Integer.valueOf(offset);
int countInt = Integer.valueOf(count);
return tableService.autoMatchByInputWord(name,countInt,offsetInt);
}
//同步数据,从mongo到neo4j,从“环境,系统,schema,表”的结构---完成
}
......@@ -23,6 +23,15 @@ public class BaseNode extends AllBaseEntity {
private String metadataId;
private String cnName;
public String getDataPath() {
return dataPath;
}
public void setDataPath(String dataPath) {
this.dataPath = dataPath;
}
private String dataPath;
// @Relationship(type= NodeType.REF)
// private Set<BaseRelationship> relationships; //关系列表
......
......@@ -14,6 +14,17 @@ public class ReturnNode {
private String cnName;
private String dataPath;
public String getDataPath() {
return dataPath;
}
public void setDataPath(String dataPath) {
this.dataPath = dataPath;
}
public Map<String, String> getAttributeMaps() {
return attributeMaps;
}
......
package com.keymobile.metadata.metadataRelation.remote;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
import java.util.Map;
@FeignClient(name = "dataAssetManager")
public interface DataAssertRemoteService {
@RequestMapping(value = "/dataAssetApi/getDataAssetGraphInfoByMetadataId", method = RequestMethod.GET)
List<Map<String,String>> getDataAssetGraphInfoByMetadataId(@RequestParam("metadataId") String metadataId);
}
package com.keymobile.metadata.metadataRelation.remote;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.Map;
@FeignClient(name="STANDARD")
public interface DataStandardRemoteService {
@RequestMapping(value = "/rest/standard/match/find", method = RequestMethod.POST)
Map<String, Object> findStandardByMetadatId(@RequestParam("page") int page,
@RequestParam("size") int size,
@RequestBody Map<String,Object> entity );
}
......@@ -47,7 +47,7 @@ public class AsyncDataFromMongoToNeo4j {
}
});
// metadataService.syschroMetadataFromMongo(catalogName,mongoDataList);
metadataService.syschroMetadataFromMongo(catalogName,mongoDataList);
//先同步元数据,纵向关系,root开始
//再同步元数据的横向关系
......
......@@ -9,4 +9,6 @@ public interface ITableService {
Map<String , List<ReturnNode>> getSourceAndTargetTableByTableId(String tableId);
Map<String, List<ReturnNode>> getRelationObjectByTableId(String tableId);
public List<ReturnNode> autoMatchByInputWord(String name,int offsetInt,int countInt);
}
......@@ -1263,7 +1263,8 @@ public class MetadataServiceImpl implements IMetadataService {
neo4jSystem.setMetadataId(systemId);
neo4jSystem.setName(systemData.getName());
neo4jSystem.setCnName(systemData.getCnName());
String systemPath = catalogName+";"+systemData.getName();
neo4jSystem.setDataPath(systemPath);
//如果存在,就不用创建
List<Neo4jSystem> neo4jSchemaList = neo4jSystemRepository.findNeo4jSystemByMetadataId(systemId);
if(neo4jSchemaList==null || neo4jSchemaList.size()==0){
......@@ -1285,6 +1286,16 @@ public class MetadataServiceImpl implements IMetadataService {
neo4jSchema.setMetadataId(schemaData.get_id());
neo4jSchema.setName(schemaData.getName());
neo4jSchema.setCnName(schemaData.getCnName());
Neo4jSystem neo4jSystem = null;
List<String> systemIdList = dataBaseData.getSysList();
for(String systemId:systemIdList){
if(systemDataMap.containsKey(systemId)){
neo4jSystem = systemDataMap.get(systemId);
}
}
String schemaPath = neo4jSystem.getDataPath()+";"+schemaData.getName();
neo4jSchema.setDataPath(schemaPath);
//如果存在,就不用创建
int ran1 = r.nextInt(6);
if(ran1>6){
......@@ -1300,13 +1311,6 @@ public class MetadataServiceImpl implements IMetadataService {
neo4jSchemaRepository.save(neo4jSchema);
}
Neo4jSystem neo4jSystem = null;
List<String> systemIdList = dataBaseData.getSysList();
for(String systemId:systemIdList){
if(systemDataMap.containsKey(systemId)){
neo4jSystem = systemDataMap.get(systemId);
}
}
relationshipService.saveRelation(neo4jSystem.getMetadataId(),neo4jSchema.getMetadataId(),"Composition");
......@@ -1323,12 +1327,16 @@ public class MetadataServiceImpl implements IMetadataService {
String endId = tableClassData.get_id();
String tablePath = schemaPath+";"+tableClassData.getName();
neo4jSchema.setDataPath(schemaPath);
if(metadataId.startsWith("Table=")){
Neo4jTable neo4jTable = new Neo4jTable();
neo4jTable.setMetadataId(tableClassData.get_id());
neo4jTable.setName(tableClassData.getName());
neo4jTable.setCnName(tableClassData.getCnName());
neo4jTable.setDataPath(tablePath);
List<Neo4jTable> neo4jTableList = neo4jTableRepository.findNeo4jTableByMetadataId(metadataId);
if(neo4jTableList==null || neo4jTableList.size()==0){
neo4jTableRepository.save(neo4jTable);
......@@ -1339,6 +1347,7 @@ public class MetadataServiceImpl implements IMetadataService {
neo4jView.setName(tableClassData.getName());
neo4jView.setCnName(tableClassData.getCnName());
neo4jView.setDataPath(tablePath);
List<Neo4jView> neo4jTableList = neo4jViewRepository.findNeo4jViewByMetadataId(metadataId);
if(neo4jTableList==null || neo4jTableList.size()==0){
neo4jViewRepository.save(neo4jView);
......@@ -1349,6 +1358,7 @@ public class MetadataServiceImpl implements IMetadataService {
neo4jFunction.setName(tableClassData.getName());
neo4jFunction.setCnName(tableClassData.getCnName());
neo4jFunction.setDataPath(tablePath);
List<Neo4jFunction> neo4jFunctionList = neo4jFunctionRepository.findNeo4jFunctionByMetadataId(metadataId);
if(neo4jFunctionList==null || neo4jFunctionList.size()==0){
neo4jFunctionRepository.save(neo4jFunction);
......@@ -1358,7 +1368,7 @@ public class MetadataServiceImpl implements IMetadataService {
neo4jProcedure.setMetadataId(tableClassData.get_id());
neo4jProcedure.setName(tableClassData.getName());
neo4jProcedure.setCnName(tableClassData.getCnName());
neo4jProcedure.setDataPath(tablePath);
List<Neo4jProcedure> neo4jProcedureList = neo4jProcedureRepository.findNeo4jProcedureByMetadataId(metadataId);
if(neo4jProcedureList==null || neo4jProcedureList.size()==0){
neo4jProcedureRepository.save(neo4jProcedure);
......@@ -1366,8 +1376,6 @@ public class MetadataServiceImpl implements IMetadataService {
}else{
}
relationshipService.saveRelation(neo4jSchema.getMetadataId(),endId,"Composition");
}
......
package com.keymobile.metadata.metadataRelation.service.impl;
import com.keymobile.metadata.metadataRelation.config.Neo4jConfig;
import com.keymobile.metadata.metadataRelation.pojo.BaseNode;
import com.keymobile.metadata.metadataRelation.pojo.MetaData;
import com.keymobile.metadata.metadataRelation.pojo.metadata.Neo4jSystem;
import com.keymobile.metadata.metadataRelation.pojo.metadata.Neo4jTable;
import com.keymobile.metadata.metadataRelation.pojo.returnBean.ReturnNode;
import com.keymobile.metadata.metadataRelation.remote.DataAssertRemoteService;
import com.keymobile.metadata.metadataRelation.remote.DataStandardRemoteService;
import com.keymobile.metadata.metadataRelation.remote.MetadataRepoRemoteService;
import com.keymobile.metadata.metadataRelation.respository.metadata.Neo4jSystemRepository;
import com.keymobile.metadata.metadataRelation.respository.metadata.Neo4jTableRepository;
import com.keymobile.metadata.metadataRelation.service.ITableService;
import com.keymobile.metadata.metadataRelation.util.Neo4jTool;
import org.neo4j.driver.v1.*;
import org.neo4j.driver.v1.types.Node;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -29,14 +36,21 @@ public class TableServiceImpl implements ITableService {
@Autowired
private MetadataRepoRemoteService metadataRepoRemoteService;
@Autowired
private DataStandardRemoteService dataStandardRemoteService;
@Autowired
private DataAssertRemoteService dataAssertRemoteService;
@Override
public Map<String, List<ReturnNode>> getRelationObjectByTableId(String tableId) {
//传入表id,查找与该表相关的“模型,资产,标准,质量,作业”,
Map<String, List<ReturnNode>> relationObjects = new HashMap<>();
//作业
List<ReturnNode> etlJobs = new ArrayList<>();
//获取关联作业,
List<BaseNode> sourceBaseNodes = neo4jTableRepository.getSourceTable(tableId);
List<ReturnNode> etlJobs = new ArrayList<>();
for(BaseNode sourceBaseNode:sourceBaseNodes){
if(sourceBaseNode.getMetadataId().startsWith("EtlJob")){
ReturnNode returnNode = new ReturnNode();
......@@ -56,23 +70,134 @@ public class TableServiceImpl implements ITableService {
etlJobs.add(returnNode);
}
}
relationObjects.put("作业",etlJobs);
//质量
List<ReturnNode> qualityList = new ArrayList<>();
relationObjects.put("质量",qualityList);
//模型
List<ReturnNode> modelList = new ArrayList<>();
List<ReturnNode> assetList = new ArrayList<>();
List<ReturnNode> standardList = new ArrayList<>();
relationObjects.put("模型",modelList);
//资产
List<ReturnNode> assetList = new ArrayList<>();
List<Map<String, String>> dataAssetGraphInfos = dataAssertRemoteService.getDataAssetGraphInfoByMetadataId(tableId);
for(Map<String, String> map : dataAssetGraphInfos){
ReturnNode returnNode = new ReturnNode();
returnNode.setId(map.get("dataAssetId"));
returnNode.setName(map.get("enName"));
returnNode.setCnName(map.get("cnName"));
assetList.add(returnNode);
}
relationObjects.put("资产",assetList);
//标准
List<ReturnNode> standardList = new ArrayList<>();
Map<String,Object> maps = new HashMap<>();
maps.put("metadataId",tableId);
Map<String, Object> standardMaps = dataStandardRemoteService.findStandardByMetadatId(1, 10,
maps);
List<LinkedHashMap<String,Object>> contentList = (List<LinkedHashMap<String,Object>>) standardMaps.get("content");
for(LinkedHashMap<String,Object> contentString:contentList){
String standardId = (String)contentString.get("standardId");
String enName = (String)contentString.get("enName");
String cnName = (String)contentString.get("cnName");
ReturnNode returnNode = new ReturnNode();
returnNode.setId(standardId);
returnNode.setName(enName);
returnNode.setCnName(cnName);
standardList.add(returnNode);
}
relationObjects.put("标准",standardList);
relationObjects.put("质量",qualityList);
relationObjects.put("作业",etlJobs);
List<ReturnNode> neo4jTableList = getCurrentTableInfo(tableId);
relationObjects.put("当前表",neo4jTableList);
return relationObjects;
}
private List<ReturnNode> getCurrentTableInfo(String tableId) {
List<Neo4jTable> neo4jTableList = neo4jTableRepository.findNeo4jTableByMetadataId(tableId);
List<ReturnNode> returnTableList = new ArrayList<>();
Map<String ,String> systemIdAndName = new HashMap<>();
Iterable<Neo4jSystem> neo4jSystems = neo4jSystemRepository.findAll();
for(Neo4jSystem neo4jSystem:neo4jSystems ){
systemIdAndName.put(neo4jSystem.getMetadataId(),neo4jSystem.getName());
}
for(Neo4jTable neo4jTable:neo4jTableList){
ReturnNode returnNode = new ReturnNode();
returnNode.setId(neo4jTable.getMetadataId());
returnNode.setName(neo4jTable.getName());
returnNode.setType("Table");
returnTableList.add(returnNode);
// 获取属性
Map<String,String> attributeMap = getAttributeMap(tableId);
String systemString = attributeMap.get("所属系统");
String belongSystem = "";
String[] systemList = systemString.split(",");
for(String system :systemList ){
if(systemIdAndName.containsKey("System="+system)){
belongSystem += systemIdAndName.get("System="+system)+",";
}
}
attributeMap.put("所属系统",belongSystem);
returnNode.setAttributeMaps(attributeMap);
}
return returnTableList;
}
//传入一个元数据id,返回查询结果的名称,路径,类型,id。
public List<ReturnNode> autoMatchByInputWord(String name,int countInt,int offsetInt){
logger.info("开始模糊查找:" + name);
List<ReturnNode> returnNodeList = new ArrayList<>();
Neo4jConfig neo4jConfig = new Neo4jConfig();
Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
Session session = neo4jConnection.session();
//match (n:MetaData) where n.name=~'(?i).*APP.*' return n
String cypher ="match (n) where n.name=~'(?i).*"+name+".*' or n.name=~'(?i).*"+name+".*' return n skip "+offsetInt+" limit "+countInt;
//"match (n:MetaData ) where n.name =~\"" + name + ".*\" return n";
long starttime = System.currentTimeMillis();
StatementResult result = session.run(cypher);
while(result.hasNext()){
Record record = result.next();
List<Value> values = record.values();
for (Value value : values) {
System.out.println("type:"+value.type().name());
if(value.type().name().equals("NODE")){
Node node = value.asNode();
Map<String, Object> stringObjectMap = node.asMap();
MetaData metaData = new MetaData();
Neo4jTool.transMap2Bean(stringObjectMap, metaData);
if(metaData.getMetadataId() == null ){
metaData.setMetadataId("System="+metaData.getName());
}
ReturnNode returnNode = new ReturnNode();
returnNode.setId(metaData.getMetadataId());
returnNode.setName(metaData.getName());
returnNode.setCnName(metaData.getCnName());
returnNode.setDataPath(metaData.getPath());
returnNodeList.add(returnNode);
}
}
}
long endtime = System.currentTimeMillis();
logger.info("模糊查找结束,返回数量:" + returnNodeList.size()+",耗时:"+(endtime-starttime));
return returnNodeList;
}
@Override
public Map<String, List<ReturnNode>> getSourceAndTargetTableByTableId(String tableId) {
Map<String, List<ReturnNode>> sourceAndTargetTable = new HashMap<>();
......@@ -84,6 +209,9 @@ public class TableServiceImpl implements ITableService {
systemIdAndName.put(neo4jSystem.getMetadataId(),neo4jSystem.getName());
}
List<ReturnNode> neo4jTableList = getCurrentTableInfo(tableId);
sourceAndTargetTable.put("当前表",neo4jTableList);
getSourceTable(tableId ,sourceTables,systemIdAndName);
List<ReturnNode> targetTables = new ArrayList<>();
......
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