Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
neo4jRelation
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
qiuchaofei
neo4jRelation
Commits
5694d584
Commit
5694d584
authored
Dec 10, 2021
by
qiuchaofei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.添加帅选多种节点的接口,2修复按名称查询时缺少关系的问题。
parent
88a95721
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
696 additions
and
2 deletions
+696
-2
MetaDataController.java
...adata/metadataRelation/controller/MetaDataController.java
+23
-1
MultiModelService.java
.../metadata/metadataRelation/service/MultiModelService.java
+10
-0
MetadataServiceImpl.java
...ta/metadataRelation/service/impl/MetadataServiceImpl.java
+5
-1
MultiModelServiceImpl.java
.../metadataRelation/service/impl/MultiModelServiceImpl.java
+658
-0
No files found.
src/main/java/com/keymobile/metadata/metadataRelation/controller/MetaDataController.java
View file @
5694d584
...
...
@@ -19,6 +19,7 @@ import com.keymobile.metadata.metadataRelation.pojo.returnBean.ReturnReslult;
import
com.keymobile.metadata.metadataRelation.service.AsyncDataFromMongoToNeo4j
;
import
com.keymobile.metadata.metadataRelation.service.IBaseRelationshipService
;
import
com.keymobile.metadata.metadataRelation.service.IMetadataService
;
import
com.keymobile.metadata.metadataRelation.service.MultiModelService
;
import
com.keymobile.metadata.metadataRelation.service.impl.MongoDbServiceImpl
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
...
...
@@ -29,6 +30,7 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.system.ApplicationHome
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
...
...
@@ -52,6 +54,8 @@ public class MetaDataController {
@Autowired
private
IBaseRelationshipService
baseRelationshipService
;
@Autowired
private
MultiModelService
multiModelService
;
/**
* 获取所有的节点
*/
...
...
@@ -132,6 +136,16 @@ public class MetaDataController {
}
@ApiOperation
(
tags
=
""
,
value
=
"系统级的大图"
)
public
ReturnReslult
getBigGraphByMultiModel
(
String
modelName0
,
String
size
)
{
String
[]
models
=
modelName0
.
split
(
","
);
List
<
String
>
modelNameList
=
new
ArrayList
<>();
for
(
String
modelName:
models
){
modelNameList
.
add
(
modelName
);
}
ReturnReslult
resultByModelNameList
=
multiModelService
.
findResultByModelNameList
(
modelNameList
,
300
);
return
resultByModelNameList
;
}
/**
* 返回一个系统级的大图
...
...
@@ -147,7 +161,15 @@ public class MetaDataController {
if
(
modelName0
==
null
||
modelName0
.
equals
(
""
))
{
modelName0
=
"Table"
;
}
if
(
modelName0
.
toLowerCase
().
equals
(
"system"
)){
if
(
modelName0
.
contains
(
","
)){
String
[]
models
=
modelName0
.
split
(
","
);
List
<
String
>
modelNameList
=
new
ArrayList
<>();
for
(
String
modelName:
models
){
modelNameList
.
add
(
modelName
);
}
returnReslult
=
multiModelService
.
findResultByModelNameList
(
modelNameList
,
sizeInt
);
}
else
if
(
modelName0
.
toLowerCase
().
equals
(
"system"
)){
returnReslult
=
metadataService
.
getSystemGraph
(
sizeInt
);
}
else
if
(
!
modelName0
.
toLowerCase
().
equals
(
"all"
)){
returnReslult
=
metadataService
.
findResultByModelName
(
modelName0
,
sizeInt
);
...
...
src/main/java/com/keymobile/metadata/metadataRelation/service/MultiModelService.java
0 → 100644
View file @
5694d584
package
com
.
keymobile
.
metadata
.
metadataRelation
.
service
;
import
com.keymobile.metadata.metadataRelation.pojo.returnBean.ReturnReslult
;
import
java.util.List
;
public
interface
MultiModelService
{
ReturnReslult
findResultByModelNameList
(
List
<
String
>
modelNameList
,
int
count
);
}
src/main/java/com/keymobile/metadata/metadataRelation/service/impl/MetadataServiceImpl.java
View file @
5694d584
...
...
@@ -787,8 +787,10 @@ public class MetadataServiceImpl implements IMetadataService {
edge
.
setEdgeId
(
returnNode
.
getId
()+
"_"
+
childId
);
edge
.
setFromId
(
returnNode
.
getId
());
edge
.
setToId
(
childId
);
childId
=
returnNode
.
getId
();
edge
.
setType
(
"组合"
);
returnReslult
.
getEdges
().
add
(
edge
);
}
else
if
(
value
.
type
().
name
().
equals
(
"INTEGER"
))
{
}
...
...
@@ -981,7 +983,7 @@ public class MetadataServiceImpl implements IMetadataService {
}
}
for
(
Object
obj
:
edgeMap
.
keySet
()){
Edge
edge
=
(
Edge
)
edgeMap
.
get
(
obj
);
Edge
edge
=
edgeMap
.
get
(
obj
);
returnReslult
.
getEdges
().
add
(
edge
);
}
...
...
@@ -1099,6 +1101,8 @@ public class MetadataServiceImpl implements IMetadataService {
String
metadataName
=
metadataNameList
[
metadataNameList
.
length
-
1
];
cypher
=
"match (n:softplatform{name:\""
+
metadataName
+
"\"}) -[r]->(m:softplatform) return r,n,m"
;
}
else
{
logger
.
info
(
"该类型不支持搜索。"
);
}
StatementResult
result1
=
session
.
run
(
cypher
);
...
...
src/main/java/com/keymobile/metadata/metadataRelation/service/impl/MultiModelServiceImpl.java
0 → 100644
View file @
5694d584
package
com
.
keymobile
.
metadata
.
metadataRelation
.
service
.
impl
;
import
com.keymobile.metadata.metadataRelation.config.Neo4jConfig
;
import
com.keymobile.metadata.metadataRelation.pojo.*
;
import
com.keymobile.metadata.metadataRelation.pojo.returnBean.Edge
;
import
com.keymobile.metadata.metadataRelation.pojo.returnBean.MetaModel
;
import
com.keymobile.metadata.metadataRelation.pojo.returnBean.ReturnReslult
;
import
com.keymobile.metadata.metadataRelation.respository.*
;
import
com.keymobile.metadata.metadataRelation.service.MultiModelService
;
import
com.keymobile.metadata.metadataRelation.util.Neo4jTool
;
import
org.hibernate.boot.Metadata
;
import
org.neo4j.driver.v1.*
;
import
org.neo4j.driver.v1.types.Node
;
import
org.neo4j.driver.v1.types.Path
;
import
org.neo4j.driver.v1.types.Relationship
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.system.ApplicationHome
;
import
org.springframework.stereotype.Service
;
import
sun.misc.BASE64Encoder
;
import
sun.rmi.runtime.Log
;
import
javax.persistence.Table
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
@Service
public
class
MultiModelServiceImpl
implements
MultiModelService
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
MultiModelServiceImpl
.
class
);
@Autowired
private
MetadataRepository
metadataRepository
;
@Autowired
private
CompositionRelationRespository
compositionRelationRespository
;
@Autowired
private
InputRelationReRepository
inputRelationReRepository
;
@Autowired
private
OutputRelationRepository
outputRelationRepository
;
@Autowired
private
ExecuteRelationRepository
executeRelationRepository
;
private
Long
getParentId
(
Long
neo4jId
,
Map
<
Long
,
Long
>
child2Parent
)
{
Long
parentId
=
neo4jId
;
while
(
child2Parent
.
containsKey
(
neo4jId
))
{
parentId
=
child2Parent
.
get
(
neo4jId
);
neo4jId
=
parentId
;
}
return
parentId
;
}
@Override
public
ReturnReslult
findResultByModelNameList
(
List
<
String
>
modelNameList
,
int
count
)
{
//先获取所有节点
List
<
MetaData
>
metaDataList
=(
List
<
MetaData
>)
metadataRepository
.
findAll
();
//获取父子关系,
List
<
CompositionRelation
>
compositionRelationList
=
(
List
<
CompositionRelation
>)
compositionRelationRespository
.
findAll
();
List
<
ExecuteRelation
>
executeRelationList
=
(
List
<
ExecuteRelation
>)
executeRelationRepository
.
findAll
();
Map
<
Long
,
Long
>
child2Parent
=
new
HashMap
<>();
Map
<
Long
,
List
<
Long
>>
parent2Children
=
new
HashMap
<>();
for
(
CompositionRelation
compositionRelation:
compositionRelationList
){
if
(
compositionRelation
==
null
){
continue
;
}
Long
parentId
=
compositionRelation
.
getStart
().
getId
();
Long
childId
=
compositionRelation
.
getEnd
().
getId
();
child2Parent
.
put
(
childId
,
parentId
);
if
(
parent2Children
.
containsKey
(
parentId
)){
parent2Children
.
get
(
parentId
).
add
(
childId
);
}
else
{
List
<
Long
>
children
=
new
ArrayList
<>();
children
.
add
(
childId
);
parent2Children
.
put
(
parentId
,
children
);
}
}
for
(
ExecuteRelation
executeRelation:
executeRelationList
){
Long
parentId
=
executeRelation
.
getStart
().
getId
();
Long
childId
=
executeRelation
.
getEnd
().
getId
();
child2Parent
.
put
(
childId
,
parentId
);
if
(
parent2Children
.
containsKey
(
parentId
)){
parent2Children
.
get
(
parentId
).
add
(
childId
);
}
else
{
List
<
Long
>
children
=
new
ArrayList
<>();
children
.
add
(
childId
);
parent2Children
.
put
(
parentId
,
children
);
}
}
Map
<
Long
,
List
<
Long
>>
source2Targets
=
new
HashMap
<>();
Map
<
Long
,
List
<
Long
>>
target2Sources
=
new
HashMap
<>();
//上升inout output的关系到父级
List
<
InputRelation
>
inputRelationList
=
(
List
<
InputRelation
>)
inputRelationReRepository
.
findAll
();
List
<
OutputRelation
>
outputRelationList
=
(
List
<
OutputRelation
>)
outputRelationRepository
.
findAll
();
for
(
InputRelation
inputRelation:
inputRelationList
){
Long
targetId
=
inputRelation
.
getEnd
().
getId
();
Long
sourceId
=
inputRelation
.
getStart
().
getId
();
if
(
source2Targets
.
containsKey
(
sourceId
)){
source2Targets
.
get
(
sourceId
).
add
(
targetId
);
}
else
{
List
<
Long
>
targets
=
new
ArrayList
<>();
targets
.
add
(
targetId
);
source2Targets
.
put
(
sourceId
,
targets
);
}
if
(
target2Sources
.
containsKey
(
targetId
)){
target2Sources
.
get
(
targetId
).
add
(
sourceId
);
}
else
{
List
<
Long
>
sources
=
new
ArrayList
<>();
sources
.
add
(
sourceId
);
target2Sources
.
put
(
targetId
,
sources
);
}
//
Long
sourceParentId
=
getParentId
(
sourceId
,
child2Parent
);
Long
targetParentId
=
getParentId
(
targetId
,
child2Parent
);
if
(
sourceParentId
!=
null
&&
targetParentId
!=
null
){
if
(
source2Targets
.
containsKey
(
sourceParentId
)){
source2Targets
.
get
(
sourceParentId
).
add
(
targetParentId
);
}
else
{
List
<
Long
>
targets
=
new
ArrayList
<>();
targets
.
add
(
targetParentId
);
source2Targets
.
put
(
sourceParentId
,
targets
);
}
if
(
target2Sources
.
containsKey
(
targetParentId
)){
target2Sources
.
get
(
targetParentId
).
add
(
sourceParentId
);
}
else
{
List
<
Long
>
sources
=
new
ArrayList
<>();
sources
.
add
(
sourceParentId
);
target2Sources
.
put
(
targetParentId
,
sources
);
}
}
}
for
(
OutputRelation
outputRelation:
outputRelationList
){
Long
sourceId
=
outputRelation
.
getStart
().
getId
();
Long
targetId
=
outputRelation
.
getEnd
().
getId
();
if
(
source2Targets
.
containsKey
(
sourceId
)){
source2Targets
.
get
(
sourceId
).
add
(
targetId
);
}
else
{
List
<
Long
>
targets
=
new
ArrayList
<>();
targets
.
add
(
targetId
);
source2Targets
.
put
(
sourceId
,
targets
);
}
if
(
target2Sources
.
containsKey
(
targetId
)){
target2Sources
.
get
(
targetId
).
add
(
sourceId
);
}
else
{
List
<
Long
>
sources
=
new
ArrayList
<>();
sources
.
add
(
sourceId
);
target2Sources
.
put
(
targetId
,
sources
);
}
//
Long
sourceParentId
=
getParentId
(
sourceId
,
child2Parent
);
Long
targetParentId
=
getParentId
(
targetId
,
child2Parent
);
if
(
sourceParentId
!=
null
&&
targetParentId
!=
null
){
if
(
source2Targets
.
containsKey
(
sourceParentId
)){
source2Targets
.
get
(
sourceParentId
).
add
(
targetParentId
);
}
else
{
List
<
Long
>
targets
=
new
ArrayList
<>();
targets
.
add
(
targetParentId
);
source2Targets
.
put
(
sourceParentId
,
targets
);
}
if
(
target2Sources
.
containsKey
(
targetParentId
)){
target2Sources
.
get
(
targetParentId
).
add
(
sourceParentId
);
}
else
{
List
<
Long
>
sources
=
new
ArrayList
<>();
sources
.
add
(
sourceParentId
);
target2Sources
.
put
(
targetParentId
,
sources
);
}
}
}
Map
<
Long
,
MetaData
>
metaDataMapLong
=
new
HashMap
<>();
List
<
Long
>
filterMetadata
=
new
ArrayList
<>();
List
<
Long
>
returnMetadata
=
new
ArrayList
<>();
//得到要过滤的节点过滤节点
for
(
MetaData
metadata:
metaDataList
){
Long
dataId
=
metadata
.
getId
();
String
metadataId
=
metadata
.
getMetadataId
();
String
[]
strings
=
metadataId
.
split
(
"="
);
String
modelName
=
strings
[
0
];
if
(
modelNameList
.
contains
(
modelName
)){
returnMetadata
.
add
(
dataId
);
}
else
{
filterMetadata
.
add
(
dataId
);
}
metaDataMapLong
.
put
(
dataId
,
metadata
);
}
//过滤节点,深度优先从入口节点遍历
for
(
Long
filterNode
:
filterMetadata
){
if
(
source2Targets
.
containsKey
(
filterNode
)
&&
target2Sources
.
containsKey
(
filterNode
)
){
List
<
Long
>
targets
=
source2Targets
.
get
(
filterNode
);
List
<
Long
>
sources
=
target2Sources
.
get
(
filterNode
);
source2Targets
.
remove
(
filterNode
);
target2Sources
.
remove
(
filterNode
);
for
(
Long
target:
targets
){
for
(
Long
source:
sources
){
if
(
source2Targets
.
containsKey
(
source
)){
List
<
Long
>
newTargets
=
source2Targets
.
get
(
source
);
newTargets
.
remove
(
filterNode
);
if
(!
newTargets
.
contains
(
target
))
{
newTargets
.
add
(
target
);
}
source2Targets
.
put
(
source
,
newTargets
);
}
else
{
List
<
Long
>
newTargets
=
new
ArrayList
<>();
newTargets
.
add
(
target
);
source2Targets
.
put
(
source
,
newTargets
);
}
if
(
target2Sources
.
containsKey
(
target
)){
List
<
Long
>
newSources
=
target2Sources
.
get
(
target
);
newSources
.
remove
(
filterNode
);
if
(!
newSources
.
contains
(
source
)){
newSources
.
add
(
source
);
}
target2Sources
.
put
(
target
,
newSources
);
}
else
{
List
<
Long
>
newSources
=
new
ArrayList
<>();
newSources
.
add
(
source
);
target2Sources
.
put
(
target
,
newSources
);
}
}
}
}
}
ReturnReslult
returnReslult
=
new
ReturnReslult
();
for
(
Object
obj:
source2Targets
.
keySet
()){
Long
fromId
=
(
Long
)
obj
;
if
(!
returnMetadata
.
contains
(
fromId
)){
continue
;
}
List
<
Long
>
toIds
=
source2Targets
.
get
(
obj
);
for
(
Long
toId:
toIds
){
if
(!
returnMetadata
.
contains
(
toId
)){
continue
;
}
Edge
edge
=
new
Edge
();
edge
.
setEdgeId
(
fromId
+
"_"
+
toId
);
MetaData
startNode
=
metaDataMapLong
.
get
(
fromId
);
MetaData
endNode
=
metaDataMapLong
.
get
(
toId
);
edge
.
setFromId
(
startNode
.
getMetadataId
());
edge
.
setToId
(
endNode
.
getMetadataId
());
edge
.
setType
(
""
);
returnReslult
.
getEdges
().
add
(
edge
);
}
}
for
(
Object
obj:
parent2Children
.
keySet
()){
Long
fromId
=
(
Long
)
obj
;
if
(!
returnMetadata
.
contains
(
fromId
)){
continue
;
}
List
<
Long
>
toIds
=
parent2Children
.
get
(
obj
);
for
(
Long
toId:
toIds
){
if
(!
returnMetadata
.
contains
(
toId
)){
continue
;
}
Edge
edge
=
new
Edge
();
edge
.
setEdgeId
(
fromId
+
"_"
+
toId
);
MetaData
startNode
=
metaDataMapLong
.
get
(
fromId
);
MetaData
endNode
=
metaDataMapLong
.
get
(
toId
);
edge
.
setFromId
(
startNode
.
getMetadataId
());
edge
.
setToId
(
endNode
.
getMetadataId
());
edge
.
setType
(
""
);
returnReslult
.
getEdges
().
add
(
edge
);
}
}
Map
<
String
,
MetaModel
>
metaModelMap
=
new
HashMap
<>();
for
(
Long
returnMeta:
returnMetadata
){
MetaData
metaData
=
metaDataMapLong
.
get
(
returnMeta
);
com
.
keymobile
.
metadata
.
metadataRelation
.
pojo
.
returnBean
.
Node
returnNode
=
new
com
.
keymobile
.
metadata
.
metadataRelation
.
pojo
.
returnBean
.
Node
();
returnNode
.
setId
(
metaData
.
getMetadataId
());
returnNode
.
setName
(
metaData
.
getName
());
String
[]
strings
=
metaData
.
getMetadataId
().
split
(
"="
);
String
modelName
=
strings
[
0
];
returnNode
.
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
);
}
returnNode
.
setType
(
"MetaData"
);
returnReslult
.
getNodes
().
add
(
returnNode
);
}
return
returnReslult
;
}
// private void ss{
// ReturnReslult returnReslult = new ReturnReslult();
// String metadataId = "Table=368=19155ece609c4b4ca3cf8d23f9349b64";
// //如果包含表,则从表开始分,以当前表开始,到下一个表结束,返回这期间的关系与节点,再进行筛选。
// if(modelNameList.contains("Table")){
//
// /** match
// * p=(table1:MetaData{metadataId:"Table=368=63faab543fac444da171a83df2b809b8"})-[r0:Composition]->
// * (col1) -[r1:Input]->(sql1) -[r2:TempInput*0..]->(sql2)-[r3:Output]->(col2)<-[r4:Composition]-(table2)
// * with p,sql1,sql2,table1,table2,col1,col2
// * match q=(job1)-[r4:Execute]->(script1)-->(sql1),(job2)-[r5:Execute]->(script2)-->(sql2)
// * return p,q
// */
// Neo4jConfig neo4jConfig = new Neo4jConfig();
// Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
// Session session = neo4jConnection.session();
// String cypher = "match\n" +
// " p=(table1:MetaData{metadataId:\""+metadataId+"\"})-[r0:Composition]->\n" +
// " (col1) -[r1:Input]->(sql1) -[r2:TempInput*0..]->(sql2)-[r3:Output]->(col2)<-[r4:Composition]-(table2)\n" +
// " with p,sql1,sql2,table1,table2,col1,col2\n" +
// " match q=(job1)-[r4:Execute]->(script1)-->(sql1),(job2)-[r5:Execute]->(script2)-->(sql2)\n" +
// " return p,q";
//
// logger.info("cypher:" + cypher);
//
// StatementResult result = session.run(cypher);
// Long startId = 0l;
//
// Map<Long, MetaData> metaDataMapLong = new HashMap<>();
//
// Map<String, Edge> edgeMap = new HashMap<>();
//
// List<Long> filterMetadata = new ArrayList<>();
// List<Long> returnMetadata = new ArrayList<>();
//
// Map<Long ,List<Long>> source2Targets = new HashMap<>();
// Map<Long ,List<Long>> target2Sources = new HashMap<>();
//
// while (result.hasNext()) {
//
// Record record = result.next();
// List<Value> values = record.values();
// for (Value value : values) {
// if (value.type().name().equals("PATH")) {
// Path p = value.asPath();
// Iterable<Node> nodes = p.nodes();
// for (Node node : nodes) {
//
// Map<String, Object> stringObjectMap = node.asMap();
// MetaData metaData = new MetaData();
// Neo4jTool.transMap2Bean(stringObjectMap, metaData);
//// metaDataList.add(data);
// if(metaData.getMetadataId() == null ){
// metaData.setMetadataId("System="+metaData.getName());
// }
// if(metaData.getMetadataId().equals(metadataId)){
// startId = node.id();
// }
// String id = metaData.getMetadataId();
// String[] strings = id.split("=");
// String modelName = strings[0];
// if(modelNameList.contains(modelName)){
// returnMetadata.add(node.id());
// }else {
// filterMetadata.add(node.id());
// }
//
// metaDataMapLong.put(node.id(), metaData);
// }
// //先保存关系
// Iterable<Relationship> relationshipList = p.relationships();
// for(Relationship relationship:relationshipList){
//
// Long startID = relationship.startNodeId();
// Long endID = relationship.endNodeId();
//
// if(source2Targets.containsKey(startID)){
// //包含了 startId
// List<Long> targets = source2Targets.get(startID);
// targets.add(endID);
// }else {
// List<Long> targets = new ArrayList<>();
// targets.add(endID);
// source2Targets.put(startID,targets);
// }
// if(target2Sources.containsKey(endID)){
// //包含了 endId
// List<Long> sources = target2Sources.get(endID);
// sources.add(startID);
//
// }else{
// List<Long> sources = new ArrayList<>();
// sources.add(startID);
// target2Sources.put(endID,sources);
// }
//
// String rType = relationship.type();
// Edge edge = new Edge();
// String relationName =
// metaDataMapLong.get(startID).getMetadataId() + "-" + rType + "-"
// + metaDataMapLong.get(endID).getMetadataId();
//
// edge.setEdgeId(String.valueOf(relationship.id()));
//
// String startMetaId = "";
// String endMEtaId = "";
// if (metaDataMapLong.containsKey(startID)) {
// startMetaId = metaDataMapLong.get(startID).getMetadataId();
// }
//
// if (metaDataMapLong.containsKey(endID)) {
// endMEtaId = metaDataMapLong.get(endID).getMetadataId();
// }
// edge.setFromId(startMetaId);
// edge.setToId(endMEtaId);
// edge.setType(rType);
// edgeMap.put(edge.getFromId()+"_"+edge.getToId(),edge);
// }
// }
// }
// }
//
// //过滤节点,深度优先从入口节点遍历
//
// for(Long filterNode :filterMetadata){
// if(source2Targets.containsKey(filterNode) && target2Sources.containsKey(filterNode) ){
// List<Long> targets = source2Targets.get(filterNode);
// List<Long> sources = target2Sources.get(filterNode);
//
// source2Targets.remove(filterNode);
// target2Sources.remove(filterNode);
// for(Long target:targets){
// for(Long source:sources){
// if(source2Targets.containsKey(source)){
// List<Long> newTargets = source2Targets.get(source);
// newTargets.remove(filterNode);
//
// if(!newTargets.contains(target)) {
// newTargets.add(target);
// }
// source2Targets.put(source,newTargets);
// }else{
// List<Long> newTargets = new ArrayList<>();
// newTargets.add(target);
// source2Targets.put(source,newTargets);
// }
//
// if(target2Sources.containsKey(target)){
// List<Long> newSources = target2Sources.get(target);
// newSources.remove(filterNode);
//
// if(!newSources.contains(source)){
// newSources.add(source);
// }
// target2Sources.put(target,newSources);
// }else {
// List<Long> newSources = new ArrayList<>();
// newSources.add(source);
// target2Sources.put(target,newSources);
// }
//
// }
// }
// }
// }
//
// for(Object obj: source2Targets.keySet()){
//
// Long fromId = (Long) obj;
//
// if(!returnMetadata.contains(fromId)){
// continue;
// }
//
// List<Long> toIds = source2Targets.get(obj);
// for(Long toId:toIds){
// if(!returnMetadata.contains(toId)){
// continue;
// }
//
// Edge edge = new Edge();
// edge.setEdgeId(fromId+"_"+toId);
//
// MetaData startNode = metaDataMapLong.get(fromId);
// MetaData endNode = metaDataMapLong.get(toId);
//
// edge.setFromId(startNode.getMetadataId());
// edge.setToId(endNode.getMetadataId());
// edge.setType("");
// returnReslult.getEdges().add(edge);
// }
// }
//
// Map<String, MetaModel> metaModelMap = new HashMap<>();
// for(Long returnMeta:returnMetadata){
// MetaData metaData = metaDataMapLong.get(returnMeta);
//
// com.keymobile.metadata.metadataRelation.pojo.returnBean.Node returnNode = new com.keymobile.metadata.metadataRelation.pojo.returnBean.Node();
// returnNode.setId(metaData.getMetadataId());
// returnNode.setName(metaData.getName());
//
// String[] strings = metaData.getMetadataId().split("=");
// String modelName = strings[0];
//
// returnNode.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);
// }
// returnNode.setType("MetaData");
// returnReslult.getNodes().add(returnNode);
// }
//
// returnReslult.setMetaModelMap(metaModelMap);
// }
// }
public
String
getIconByModelId
(
String
modelId
)
{
ApplicationHome
applicationHome
=
new
ApplicationHome
(
getClass
());
File
jarFile
=
applicationHome
.
getSource
();
String
dirPath
=
jarFile
.
getParentFile
().
toString
()
+
"/Icon/"
+
modelId
+
"/"
;
String
encodeIcon
=
""
;
File
dest
=
new
File
(
dirPath
);
File
[]
files
=
dest
.
listFiles
();
if
(
files
!=
null
&&
files
.
length
!=
0
)
{
File
iconFile
=
files
[
0
];
String
fileName
=
iconFile
.
getAbsolutePath
();
encodeIcon
=
GetImageStr
(
fileName
);
}
else
{
}
return
encodeIcon
;
}
// 图片转化成base64字符串
public
static
String
GetImageStr
(
String
imgFile
)
{
// 将图片文件转化为字节数组字符串,并对其进行Base64编码处理
logger
.
info
(
"存放图标的路径:"
+
imgFile
);
InputStream
in
=
null
;
byte
[]
data
=
null
;
// 读取图片字节数组
try
{
in
=
new
FileInputStream
(
imgFile
);
data
=
new
byte
[
in
.
available
()];
in
.
read
(
data
);
in
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
// 对字节数组Base64编码
BASE64Encoder
encoder
=
new
BASE64Encoder
();
return
encoder
.
encode
(
data
);
// 返回Base64编码过的字节数组字符串
}
private
void
traveNodeDFS
(
Long
edgeStartId
,
Long
sourceId
,
Map
<
Long
,
List
<
Long
>>
source2Targets
,
Map
<
Long
,
List
<
Long
>>
target2sources
,
List
<
Long
>
filterMetadata
,
Map
<
String
,
String
>
newEdges
,
List
<
Long
>
isAnalysised
)
{
if
(
isAnalysised
.
contains
(
sourceId
)){
return
;
}
isAnalysised
.
add
(
sourceId
);
//找出过滤节点的前后端,建立关系
if
(
source2Targets
.
containsKey
(
sourceId
)
&&
target2sources
.
containsKey
(
sourceId
)
){
List
<
Long
>
targets
=
source2Targets
.
get
(
sourceId
);
List
<
Long
>
sources
=
target2sources
.
get
(
sourceId
);
for
(
Long
target:
targets
){
for
(
Long
source:
sources
){
String
edgeId
=
edgeStartId
+
"_"
+
target
;
newEdges
.
put
(
edgeId
,
""
);
traveNodeDFS
(
target
,
target
,
source2Targets
,
target2sources
,
filterMetadata
,
newEdges
,
isAnalysised
);
}
// if(filterMetadata.contains(target)){
// //下一个节点被过滤了,则继续找下一层节点
// traveNodeDFS(edgeStartId,target,source2Targets,target2sources,filterMetadata,newEdges,isAnalysised);
// }else {
// // 不用过滤,就建立关系,然后继续遍历
// String edgeId = edgeStartId+"_"+target;
//
// newEdges.put(edgeId,"");
// traveNodeDFS(target,target,source2Targets,target2sources,filterMetadata,newEdges,isAnalysised);
// }
}
}
else
{
}
if
(
target2sources
.
containsKey
(
sourceId
)){
List
<
Long
>
sources
=
target2sources
.
get
(
sourceId
);
for
(
Long
source:
sources
){
if
(
filterMetadata
.
contains
(
source
)){
//下一个节点被过滤了,则继续找下一层节点
traveNodeDFS
(
edgeStartId
,
source
,
source2Targets
,
target2sources
,
filterMetadata
,
newEdges
,
isAnalysised
);
}
else
{
// 不用过滤,就建立关系,然后继续遍历
String
edgeId
=
source
+
"_"
+
edgeStartId
;
newEdges
.
put
(
edgeId
,
""
);
traveNodeDFS
(
source
,
source
,
source2Targets
,
target2sources
,
filterMetadata
,
newEdges
,
isAnalysised
);
}
}
}
}
// private void getNextReturnNode(Long startId,Long target, Map<Long, List<Long>> source2Targets,
// List<Long> filterMetadata,Map<String, String> newEdges) {
// if(source2Targets.containsKey(target)){
// List<Long> nextTargets = source2Targets.get(target);
// for(Long nextTarget:nextTargets){
//
// if(filterMetadata.contains(nextTarget)){
// //下一个节点被过滤了,则继续找下一层节点
// getNextReturnNode(startId,nextTarget,source2Targets,filterMetadata,newEdges);
// }else {
// // 不用过滤,就建立关系,然后继续遍历
// String edgeId = startId+"_"+target;
//
// newEdges.put(edgeId,"");
// getNextReturnNode(target,target,source2Targets,filterMetadata,newEdges);
//
// }
//
// }
// }
//
//
// }
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment