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
34315bc5
Commit
34315bc5
authored
Nov 15, 2021
by
qiuchaofei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加接口:1判断两个节点是否存在关系,2给定元模型。返回该模型的元数据之间。的关系.
parent
bb564174
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
186 additions
and
4 deletions
+186
-4
MetaDataController.java
...adata/metadataRelation/controller/MetaDataController.java
+14
-2
MetadataRepository.java
...data/metadataRelation/respository/MetadataRepository.java
+6
-0
IMetadataService.java
...e/metadata/metadataRelation/service/IMetadataService.java
+5
-0
MetadataServiceImpl.java
...ta/metadataRelation/service/impl/MetadataServiceImpl.java
+161
-2
No files found.
src/main/java/com/keymobile/metadata/metadataRelation/controller/MetaDataController.java
View file @
34315bc5
...
@@ -49,7 +49,6 @@ public class MetaDataController {
...
@@ -49,7 +49,6 @@ public class MetaDataController {
* 查询元数据,关系
* 查询元数据,关系
* 返回 node,edge,icon
* 返回 node,edge,icon
*/
*/
@ApiOperation
(
tags
=
""
,
value
=
"获取所有的节点与关系"
)
@ApiOperation
(
tags
=
""
,
value
=
"获取所有的节点与关系"
)
@RequestMapping
(
path
=
"/result1"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
path
=
"/result1"
,
method
=
RequestMethod
.
GET
)
public
ReturnReslult
getAllNodeAndRelation
()
{
public
ReturnReslult
getAllNodeAndRelation
()
{
...
@@ -141,6 +140,19 @@ public class MetaDataController {
...
@@ -141,6 +140,19 @@ public class MetaDataController {
}
}
@ApiOperation
(
tags
=
""
,
value
=
"传入元模型名称,返回该元模型的元数据所有关系"
)
// @RequestMapping(path = "/getNodeAndRelationByModel", method = RequestMethod.GET)
@RequestMapping
(
path
=
"/result"
,
method
=
RequestMethod
.
GET
)
public
ReturnReslult
getNodeAndRelationByModel
()
{
ReturnReslult
returnReslult
=
new
ReturnReslult
();
String
modelName
=
"Table"
;
returnReslult
=
metadataService
.
findResultByModelName
(
modelName
);
return
returnReslult
;
}
/**
/**
* 查询元数据
* 查询元数据
*/
*/
...
@@ -157,7 +169,7 @@ public class MetaDataController {
...
@@ -157,7 +169,7 @@ public class MetaDataController {
@ApiOperation
(
tags
=
""
,
value
=
"系统级的大图"
)
@ApiOperation
(
tags
=
""
,
value
=
"系统级的大图"
)
// @RequestMapping(path = "/getBigGraph", method = RequestMethod.GET)
// @RequestMapping(path = "/getBigGraph", method = RequestMethod.GET)
@RequestMapping
(
path
=
"/result"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
path
=
"/result
0
"
,
method
=
RequestMethod
.
GET
)
public
ReturnReslult
getBigGraph
(){
public
ReturnReslult
getBigGraph
(){
logger
.
info
(
"开始获取系统级的大图"
);
logger
.
info
(
"开始获取系统级的大图"
);
...
...
src/main/java/com/keymobile/metadata/metadataRelation/respository/MetadataRepository.java
View file @
34315bc5
...
@@ -14,6 +14,12 @@ public interface MetadataRepository extends Neo4jRepository<MetaData,Long> {
...
@@ -14,6 +14,12 @@ public interface MetadataRepository extends Neo4jRepository<MetaData,Long> {
MetaData
findMetadataByName
(
String
name
);
MetaData
findMetadataByName
(
String
name
);
@Query
(
"match (n:MetaData ) where n.metadataId =~{modelName} return n"
)
List
<
MetaData
>
findMetaDataByModelName
(
@Param
(
"modelName"
)
String
dataName
);
//MATCH p=(a:MetaData{metadataId:"Table=1=b148ad31504d4487bd81ecebbc7522c3"})-[r:Composition]->() -[*]->()<-[r1:Composition]-(b:MetaData{metadataId:"Table=368=600efbf1fb4a4bd1910dbc1b567d6691"})
//RETURN p
MetaData
findMetaDataByMetadataId
(
String
id
);
MetaData
findMetaDataByMetadataId
(
String
id
);
/**
/**
...
...
src/main/java/com/keymobile/metadata/metadataRelation/service/IMetadataService.java
View file @
34315bc5
...
@@ -13,6 +13,8 @@ public interface IMetadataService {
...
@@ -13,6 +13,8 @@ public interface IMetadataService {
ReturnReslult
findNodeByDataId
(
String
metadataId
,
int
depth
);
ReturnReslult
findNodeByDataId
(
String
metadataId
,
int
depth
);
ReturnReslult
findResultByModelName
(
String
modelName
);
List
<
MetaData
>
findChildrenByParentId
(
String
parentId
);
List
<
MetaData
>
findChildrenByParentId
(
String
parentId
);
List
<
MetaData
>
findChildrenByParentName
(
String
parentName
);
List
<
MetaData
>
findChildrenByParentName
(
String
parentName
);
...
@@ -32,6 +34,9 @@ public interface IMetadataService {
...
@@ -32,6 +34,9 @@ public interface IMetadataService {
void
syschroRelationFromMongo
(
String
catalogName
);
void
syschroRelationFromMongo
(
String
catalogName
);
/**
/**
* 添加元数据对象
* 添加元数据对象
* @param id
* @param id
...
...
src/main/java/com/keymobile/metadata/metadataRelation/service/impl/MetadataServiceImpl.java
View file @
34315bc5
...
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
...
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import
com.keymobile.metadata.metadataRelation.config.Neo4jConfig
;
import
com.keymobile.metadata.metadataRelation.config.Neo4jConfig
;
import
com.keymobile.metadata.metadataRelation.pojo.*
;
import
com.keymobile.metadata.metadataRelation.pojo.*
;
import
com.keymobile.metadata.metadataRelation.pojo.returnBean.Edge
;
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.pojo.returnBean.ReturnReslult
;
import
com.keymobile.metadata.metadataRelation.remote.MetadataRepoRemoteService
;
import
com.keymobile.metadata.metadataRelation.remote.MetadataRepoRemoteService
;
import
com.keymobile.metadata.metadataRelation.respository.*
;
import
com.keymobile.metadata.metadataRelation.respository.*
;
...
@@ -19,11 +20,17 @@ import org.neo4j.driver.v1.types.Relationship;
...
@@ -19,11 +20,17 @@ import org.neo4j.driver.v1.types.Relationship;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.system.ApplicationHome
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.CollectionUtils
;
import
sun.misc.BASE64Encoder
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.*
;
import
java.util.*
;
@Service
@Service
...
@@ -77,11 +84,11 @@ public class MetadataServiceImpl implements IMetadataService {
...
@@ -77,11 +84,11 @@ public class MetadataServiceImpl implements IMetadataService {
logger
.
info
(
"cypher:"
+
cypher
);
logger
.
info
(
"cypher:"
+
cypher
);
StatementResult
result
=
session
.
run
(
cypher
);
StatementResult
result
=
session
.
run
(
cypher
);
Map
<
String
,
MetaModel
>
metaModelMap
=
new
HashMap
<>();
while
(
result
.
hasNext
()
){
while
(
result
.
hasNext
()
){
Record
record
=
result
.
next
();
Record
record
=
result
.
next
();
List
<
Value
>
values
=
record
.
values
();
List
<
Value
>
values
=
record
.
values
();
for
(
Value
value
:
values
)
{
for
(
Value
value
:
values
)
{
System
.
out
.
println
(
";;"
+
value
.
type
());
if
(
value
.
type
().
name
().
equals
(
"PATH"
))
{
if
(
value
.
type
().
name
().
equals
(
"PATH"
))
{
Path
p
=
value
.
asPath
();
Path
p
=
value
.
asPath
();
Iterable
<
Node
>
nodes
=
p
.
nodes
();
Iterable
<
Node
>
nodes
=
p
.
nodes
();
...
@@ -97,6 +104,20 @@ public class MetadataServiceImpl implements IMetadataService {
...
@@ -97,6 +104,20 @@ public class MetadataServiceImpl implements IMetadataService {
returnNode
.
setId
(
metaData
.
getMetadataId
());
returnNode
.
setId
(
metaData
.
getMetadataId
());
returnNode
.
setName
(
metaData
.
getName
());
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
.
getNodes
().
add
(
returnNode
);
nodesMap
.
put
(
node
.
id
(),
metaData
);
nodesMap
.
put
(
node
.
id
(),
metaData
);
}
}
...
@@ -127,7 +148,6 @@ public class MetadataServiceImpl implements IMetadataService {
...
@@ -127,7 +148,6 @@ public class MetadataServiceImpl implements IMetadataService {
if
(
nodesMap
.
containsKey
(
endID
)){
if
(
nodesMap
.
containsKey
(
endID
)){
endMEtaId
=
nodesMap
.
get
(
endID
).
getMetadataId
();
endMEtaId
=
nodesMap
.
get
(
endID
).
getMetadataId
();
}
}
edge
.
setFromId
(
startMetaId
);
edge
.
setFromId
(
startMetaId
);
edge
.
setToId
(
endMEtaId
);
edge
.
setToId
(
endMEtaId
);
edge
.
setType
(
rType
);
edge
.
setType
(
rType
);
...
@@ -143,6 +163,145 @@ public class MetadataServiceImpl implements IMetadataService {
...
@@ -143,6 +163,145 @@ public class MetadataServiceImpl implements IMetadataService {
}
}
@Override
@Override
public
ReturnReslult
findResultByModelName
(
String
modelName
)
{
ReturnReslult
returnReslult
=
new
ReturnReslult
();
// 先获取modelname的元数据,按每两个元数据去查找,查看是否有关系,注意关系方向
Neo4jConfig
neo4jConfig
=
new
Neo4jConfig
();
Driver
neo4jConnection
=
neo4jConfig
.
getNeo4jConnection
();
Session
session
=
neo4jConnection
.
session
();
// match (n:MetaData ) where n.metadataId =~"Table=.*" return n
String
cypher
=
"match (n:MetaData ) where n.metadataId =~\""
+
modelName
+
".*\" return n"
;
logger
.
info
(
"cypher:"
+
cypher
);
Map
<
String
,
MetaModel
>
metaModelMap
=
new
HashMap
<>();
StatementResult
result
=
session
.
run
(
cypher
);
List
<
String
>
metadataIdList
=
new
ArrayList
<>();
while
(
result
.
hasNext
()
){
Record
record
=
result
.
next
();
List
<
Value
>
values
=
record
.
values
();
for
(
Value
value
:
values
)
{
if
(
value
.
type
().
name
().
equals
(
"NODE"
))
{
Node
node
=
value
.
asNode
();
Map
<
Long
,
MetaData
>
nodesMap
=
new
HashMap
<>();
Map
<
String
,
Object
>
stringObjectMap
=
node
.
asMap
();
MetaData
metaData
=
new
MetaData
();
Neo4jTool
.
transMap2Bean
(
stringObjectMap
,
metaData
);
com
.
keymobile
.
metadata
.
metadataRelation
.
pojo
.
returnBean
.
Node
returnNode
=
new
com
.
keymobile
.
metadata
.
metadataRelation
.
pojo
.
returnBean
.
Node
();
returnNode
.
setId
(
metaData
.
getMetadataId
());
returnNode
.
setName
(
metaData
.
getName
());
metadataIdList
.
add
(
metaData
.
getMetadataId
());
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
);
nodesMap
.
put
(
node
.
id
(),
metaData
);
}
}
}
List
<
String
>
analysisId
=
new
ArrayList
<>();
int
count
=
0
;
//遍历每两个节点的关系
for
(
String
metadataId:
metadataIdList
){
logger
.
info
(
"dataId:"
+
metadataId
);
analysisId
.
add
(
metadataId
);
for
(
String
metadataId1:
metadataIdList
){
logger
.
info
(
"---------dataId1:"
+
metadataId1
);
if
(
metadataId
.
equals
(
metadataId1
)){
continue
;
}
if
(
analysisId
.
contains
(
metadataId1
)){
continue
;
}
String
impactCypher
=
"MATCH p=(a:MetaData{metadataId:\""
+
metadataId
+
"\"})-[r:Composition]->() -[*]->()<-[r1:Composition]-(b:MetaData{metadataId:\""
+
metadataId1
+
"\"})\n"
+
"RETURN p"
;
StatementResult
impactResult
=
session
.
run
(
impactCypher
);
if
(
impactResult
.
hasNext
()){
logger
.
info
(
metadataId
+
" --->>"
+
metadataId1
);
Edge
edge
=
new
Edge
();
// edge.setEdgeId();
edge
.
setFromId
(
metadataId
);
edge
.
setToId
(
metadataId1
);
edge
.
setType
(
"流入"
);
edge
.
setEdgeId
(
""
+
count
++);
returnReslult
.
getEdges
().
add
(
edge
);
}
String
lineageCypher
=
"MATCH p=(a:MetaData{metadataId:\""
+
metadataId1
+
"\"})-[r:Composition]->() -[*]->()<-[r1:Composition]-(b:MetaData{metadataId:\""
+
metadataId
+
"\"})\n"
+
"RETURN p"
;
StatementResult
lineageResult
=
session
.
run
(
lineageCypher
);
if
(
lineageResult
.
hasNext
()){
logger
.
info
(
metadataId
+
"<<-- "
+
metadataId1
);
Edge
edge
=
new
Edge
();
edge
.
setEdgeId
(
""
+
count
++);
// edge.setEdgeId();
edge
.
setFromId
(
metadataId1
);
edge
.
setToId
(
metadataId
);
edge
.
setType
(
"流出"
);
returnReslult
.
getEdges
().
add
(
edge
);
}
}
}
returnReslult
.
setMetaModelMap
(
metaModelMap
);
return
returnReslult
;
}
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编码过的字节数组字符串
}
@Override
public
List
<
MetaData
>
findChildrenByParentId
(
String
parentId
)
{
public
List
<
MetaData
>
findChildrenByParentId
(
String
parentId
)
{
return
metadataRepository
.
findMetaDataByParentId
(
parentId
);
return
metadataRepository
.
findMetaDataByParentId
(
parentId
);
...
...
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