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
b2b279c4
Commit
b2b279c4
authored
Dec 03, 2021
by
qiuchaofei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.查询对象为系统的图形,2 system节点的筛选
parent
688bcbda
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
290 additions
and
26 deletions
+290
-26
MetaDataController.java
...adata/metadataRelation/controller/MetaDataController.java
+13
-5
IMetadataService.java
...e/metadata/metadataRelation/service/IMetadataService.java
+3
-1
MetadataServiceImpl.java
...ta/metadataRelation/service/impl/MetadataServiceImpl.java
+274
-20
No files found.
src/main/java/com/keymobile/metadata/metadataRelation/controller/MetaDataController.java
View file @
b2b279c4
...
...
@@ -88,8 +88,13 @@ public class MetaDataController {
@RequestMapping
(
path
=
"/searchGraphByMetadataId"
,
method
=
RequestMethod
.
GET
)
public
ReturnReslult
searchGraphByMetadataId
(
String
metadataId
,
String
layer
){
int
layerLong
=
Integer
.
valueOf
(
layer
);
return
metadataService
.
searchGraph
(
metadataId
,
layerLong
);
ReturnReslult
returnReslult
=
null
;
if
(
metadataId
.
startsWith
(
"System="
)){
returnReslult
=
metadataService
.
searchGraphBySystem
(
metadataId
,
layerLong
);
}
else
{
returnReslult
=
metadataService
.
searchGraph
(
metadataId
,
layerLong
);
}
return
returnReslult
;
}
...
...
@@ -138,9 +143,11 @@ public class MetaDataController {
if
(
modelName0
==
null
||
modelName0
.
equals
(
""
))
{
modelName0
=
"Table"
;
}
if
(!
modelName0
.
toLowerCase
().
equals
(
"all"
)){
if
(
modelName0
.
toLowerCase
().
equals
(
"system"
)){
returnReslult
=
metadataService
.
getSystemGraph
(
sizeInt
);
}
else
if
(
!
modelName0
.
toLowerCase
().
equals
(
"all"
)){
returnReslult
=
metadataService
.
findResultByModelName
(
modelName0
,
sizeInt
);
}
else
{
}
else
{
List
<
MetaData
>
metaDataList
=
metadataService
.
finAllMetaData
();
Map
<
String
,
Node
>
nodeMap
=
new
HashMap
<>();
...
...
@@ -305,7 +312,8 @@ public class MetaDataController {
@ApiOperation
(
tags
=
""
,
value
=
"系统总图"
)
@RequestMapping
(
path
=
"/getSystemGraph"
,
method
=
RequestMethod
.
GET
)
public
ReturnReslult
getSystemGraph
(){
return
metadataService
.
getSystemGraph
();
int
size
=
300
;
return
metadataService
.
getSystemGraph
(
size
);
}
...
...
src/main/java/com/keymobile/metadata/metadataRelation/service/IMetadataService.java
View file @
b2b279c4
...
...
@@ -16,7 +16,7 @@ public interface IMetadataService {
ReturnReslult
findResultByModelName
(
String
modelName
,
int
count
);
ReturnReslult
getSystemGraph
();
ReturnReslult
getSystemGraph
(
int
size
);
ReturnReslult
searchGraph
(
String
metadataId
,
int
layer
);
...
...
@@ -95,4 +95,6 @@ public interface IMetadataService {
List
<
TempNode
>
findAllTempNode
();
Map
<
String
,
String
>
getAutoMatchByInput
(
String
name
,
int
countInt
,
int
offsetInt
);
ReturnReslult
searchGraphBySystem
(
String
metadataId
,
int
layerLong
);
}
src/main/java/com/keymobile/metadata/metadataRelation/service/impl/MetadataServiceImpl.java
View file @
b2b279c4
...
...
@@ -344,25 +344,27 @@ public class MetadataServiceImpl implements IMetadataService {
}
@Override
public
ReturnReslult
getSystemGraph
()
{
public
ReturnReslult
getSystemGraph
(
int
size
)
{
ReturnReslult
returnReslult
=
new
ReturnReslult
();
Neo4jConfig
neo4jConfig
=
new
Neo4jConfig
();
Driver
neo4jConnection
=
neo4jConfig
.
getNeo4jConnection
();
Session
session
=
neo4jConnection
.
session
();
// match (n:MetaData ) where n.metadataId =~"Table=.*" return n
String
cypher
=
"match data=(na:softplatform)-[r]->(nb:softplatform) return data"
;
logger
.
info
(
"
cypher
:"
+
cypher
);
String
cypher
=
"match data=(na:softplatform)-[r]->(nb:softplatform) return data
"
;
logger
.
info
(
"
系统总图的查询语句
:"
+
cypher
);
Map
<
String
,
MetaModel
>
metaModelMap
=
new
HashMap
<>();
long
starttime
=
System
.
currentTimeMillis
();
StatementResult
result
=
session
.
run
(
cypher
);
long
endtime
=
System
.
currentTimeMillis
();
logger
.
info
(
"查询耗时:"
+(
endtime
-
starttime
));
String
modelName
=
"System"
;
List
<
String
>
metadataIdList
=
new
ArrayList
<>();
Map
<
Long
,
com
.
keymobile
.
metadata
.
metadataRelation
.
pojo
.
returnBean
.
Node
>
nodesMap
=
new
HashMap
<>();
Map
<
String
,
MetaModel
>
metaModelMap
=
new
HashMap
<>();
while
(
result
.
hasNext
())
{
Record
record
=
result
.
next
();
List
<
Value
>
values
=
record
.
values
();
...
...
@@ -370,8 +372,10 @@ public class MetadataServiceImpl implements IMetadataService {
if
(
value
.
type
().
name
().
equals
(
"PATH"
))
{
Path
p
=
value
.
asPath
();
Iterable
<
Node
>
nodes
=
p
.
nodes
();
Map
<
Long
,
MetaData
>
nodesMap
=
new
HashMap
<>();
for
(
Node
node
:
nodes
)
{
if
(
nodesMap
.
size
()>=
size
){
continue
;
}
Map
<
String
,
Object
>
stringObjectMap
=
node
.
asMap
();
MetaData
metaData
=
new
MetaData
();
...
...
@@ -395,9 +399,9 @@ public class MetadataServiceImpl implements IMetadataService {
model
.
setIcon
(
iconContext
);
metaModelMap
.
put
(
modelName
,
model
);
}
returnNode
.
setType
(
"MetaData"
);
returnReslult
.
getNodes
().
add
(
returnNode
);
nodesMap
.
put
(
node
.
id
(),
metaData
);
nodesMap
.
put
(
node
.
id
(),
returnNode
);
}
Iterable
<
Relationship
>
relationships
=
p
.
relationships
();
for
(
Relationship
relationship
:
relationships
)
{
...
...
@@ -410,32 +414,39 @@ public class MetadataServiceImpl implements IMetadataService {
*/
// relationship.id();
//
Edge
edge
=
new
Edge
();
String
relationName
=
nodesMap
.
get
(
startID
).
getMetadataId
()
+
"-"
+
rType
+
"-"
+
nodesMap
.
get
(
endID
).
getMetadataId
();
edge
.
setEdgeId
(
String
.
valueOf
(
relationship
.
id
()));
String
startMetaId
=
""
;
String
endMEtaId
=
""
;
if
(
nodesMap
.
containsKey
(
startID
))
{
startMetaId
=
nodesMap
.
get
(
startID
).
get
Metadata
Id
();
startMetaId
=
nodesMap
.
get
(
startID
).
getId
();
}
if
(
nodesMap
.
containsKey
(
endID
))
{
endMEtaId
=
nodesMap
.
get
(
endID
).
get
Metadata
Id
();
endMEtaId
=
nodesMap
.
get
(
endID
).
getId
();
}
if
(!
StringUtils
.
isBlank
(
startMetaId
)
&&
!
StringUtils
.
isBlank
(
endMEtaId
)){
Edge
edge
=
new
Edge
();
String
relationName
=
nodesMap
.
get
(
startID
).
getId
()
+
"-"
+
rType
+
"-"
+
nodesMap
.
get
(
endID
).
getId
();
edge
.
setEdgeId
(
String
.
valueOf
(
relationship
.
id
()));
edge
.
setFromId
(
startMetaId
);
edge
.
setToId
(
endMEtaId
);
edge
.
setType
(
rType
);
returnReslult
.
getEdges
().
add
(
edge
);
}
}
}
}
}
for
(
Object
object:
nodesMap
.
keySet
()){
com
.
keymobile
.
metadata
.
metadataRelation
.
pojo
.
returnBean
.
Node
node
=
nodesMap
.
get
(
object
);
returnReslult
.
getNodes
().
add
(
node
);
}
returnReslult
.
setMetaModelMap
(
metaModelMap
);
return
returnReslult
;
...
...
@@ -452,10 +463,9 @@ public class MetadataServiceImpl implements IMetadataService {
Driver
neo4jConnection
=
neo4jConfig
.
getNeo4jConnection
();
Session
session
=
neo4jConnection
.
session
();
//match (n:MetaData) where n.name=~'(?i).*APP.*' return n
String
cypher
=
"match (n
:MetaData
) where n.name=~'(?i).*"
+
name
+
".*' return n skip "
+
offsetInt
+
" limit "
+
countInt
;
String
cypher
=
"match (n) where 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
);
...
...
@@ -476,7 +486,9 @@ public class MetadataServiceImpl implements IMetadataService {
Map
<
String
,
Object
>
stringObjectMap
=
node
.
asMap
();
MetaData
metaData
=
new
MetaData
();
Neo4jTool
.
transMap2Bean
(
stringObjectMap
,
metaData
);
if
(
metaData
.
getMetadataId
()
==
null
){
metaData
.
setMetadataId
(
"System="
+
metaData
.
getName
());
}
metadataId2Name
.
put
(
metaData
.
getMetadataId
(),
metaData
.
getName
());
}
}
...
...
@@ -487,6 +499,228 @@ public class MetadataServiceImpl implements IMetadataService {
return
metadataId2Name
;
}
public
void
getPreNodeBySystemName
(
String
metadataName
,
Session
session
,
ReturnReslult
returnReslult
,
Map
<
Long
,
com
.
keymobile
.
metadata
.
metadataRelation
.
pojo
.
returnBean
.
Node
>
longMetaDataMap
,
Map
<
String
,
MetaModel
>
metaModelMap
,
Map
<
String
,
Edge
>
edgeMap
,
int
layer
){
String
cypher
=
"match p=(n:softplatform{name:\""
+
metadataName
+
"\"}) <-[r]-(m:softplatform) return p"
;
int
count
=
returnReslult
.
getCount
();
System
.
out
.
println
(
count
+
" ;cypher:"
+
cypher
);
if
(
count
>
layer
){
return
;
}
// count = count+1;
// returnReslult.setCount(count);
StatementResult
result
=
session
.
run
(
cypher
);
while
(
result
.
hasNext
()){
Record
record
=
result
.
next
();
List
<
Value
>
values
=
record
.
values
();
for
(
Value
value
:
values
)
{
if
(
value
.
type
().
name
().
equals
(
"PATH"
)){
Path
path
=
value
.
asPath
();
Iterable
<
Node
>
nodes
=
path
.
nodes
();
for
(
Node
node:
nodes
){
if
(
longMetaDataMap
.
containsKey
(
node
.
id
())){
continue
;
}
count
=
returnReslult
.
getCount
();
count
++;
returnReslult
.
setCount
(
count
);
Map
<
String
,
Object
>
stringObjectMap
=
node
.
asMap
();
MetaData
metaData
=
new
MetaData
();
Neo4jTool
.
transMap2Bean
(
stringObjectMap
,
metaData
);
if
(
metaData
.
getMetadataId
()
==
null
){
metaData
.
setMetadataId
(
"System="
+
metaData
.
getName
());
}
com
.
keymobile
.
metadata
.
metadataRelation
.
pojo
.
returnBean
.
Node
returnNode
=
new
com
.
keymobile
.
metadata
.
metadataRelation
.
pojo
.
returnBean
.
Node
();
returnNode
.
setId
(
metaData
.
getMetadataId
());
returnNode
.
setName
(
metaData
.
getName
());
returnNode
.
setType
(
"MetaData"
);
String
modelName
=
"System"
;
returnNode
.
setIcon
(
modelName
);
longMetaDataMap
.
put
(
node
.
id
(),
returnNode
);
if
(
returnNode
.
getName
().
equals
(
metadataName
)){
continue
;
}
else
{
getPreNodeBySystemName
(
metaData
.
getName
(),
session
,
returnReslult
,
longMetaDataMap
,
metaModelMap
,
edgeMap
,
layer
);
}
count
=
returnReslult
.
getCount
();
count
=
count
-
1
;
returnReslult
.
setCount
(
count
);
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
);
}
}
Iterable
<
Relationship
>
relationships
=
path
.
relationships
();
for
(
Relationship
relationship:
relationships
){
long
startLong
=
relationship
.
startNodeId
();
long
endLong
=
relationship
.
endNodeId
();
if
(
longMetaDataMap
.
containsKey
(
startLong
)&&
longMetaDataMap
.
containsKey
(
endLong
)){
Edge
edge
=
new
Edge
();
String
edgeId
=
startLong
+
"_"
+
endLong
;
if
(
edgeMap
.
containsKey
(
edgeId
)){
continue
;
}
edge
.
setFromId
(
longMetaDataMap
.
get
(
startLong
).
getId
());
edge
.
setToId
(
longMetaDataMap
.
get
(
endLong
).
getId
());
edge
.
setType
(
relationship
.
type
());
edgeMap
.
put
(
edgeId
,
edge
);
// returnReslult.getEdges().add(edge);
}
}
}
}
}
}
public
void
getToNodeBySystemName
(
String
metadataName
,
Session
session
,
ReturnReslult
returnReslult
,
Map
<
Long
,
com
.
keymobile
.
metadata
.
metadataRelation
.
pojo
.
returnBean
.
Node
>
longMetaDataMap
,
Map
<
String
,
MetaModel
>
metaModelMap
,
Map
<
String
,
Edge
>
edgeMap
,
int
layer
){
String
cypher
=
"match p=(n:softplatform{name:\""
+
metadataName
+
"\"}) -[r]->(m:softplatform) return p"
;
int
count
=
returnReslult
.
getCount
();
System
.
out
.
println
(
count
+
" ;cypher:"
+
cypher
);
if
(
count
>
layer
){
return
;
}
// count = count+1;
// returnReslult.setCount(count);
StatementResult
result
=
session
.
run
(
cypher
);
while
(
result
.
hasNext
()){
Record
record
=
result
.
next
();
List
<
Value
>
values
=
record
.
values
();
for
(
Value
value
:
values
)
{
if
(
value
.
type
().
name
().
equals
(
"PATH"
)){
Path
path
=
value
.
asPath
();
Iterable
<
Node
>
nodes
=
path
.
nodes
();
for
(
Node
node:
nodes
){
if
(
longMetaDataMap
.
containsKey
(
node
.
id
())){
continue
;
}
count
=
returnReslult
.
getCount
();
count
++;
returnReslult
.
setCount
(
count
);
Map
<
String
,
Object
>
stringObjectMap
=
node
.
asMap
();
MetaData
metaData
=
new
MetaData
();
Neo4jTool
.
transMap2Bean
(
stringObjectMap
,
metaData
);
if
(
metaData
.
getMetadataId
()
==
null
){
metaData
.
setMetadataId
(
"System="
+
metaData
.
getName
());
}
com
.
keymobile
.
metadata
.
metadataRelation
.
pojo
.
returnBean
.
Node
returnNode
=
new
com
.
keymobile
.
metadata
.
metadataRelation
.
pojo
.
returnBean
.
Node
();
returnNode
.
setId
(
metaData
.
getMetadataId
());
returnNode
.
setName
(
metaData
.
getName
());
longMetaDataMap
.
put
(
node
.
id
(),
returnNode
);
if
(
returnNode
.
getName
().
equals
(
metadataName
)){
continue
;
}
else
{
getToNodeBySystemName
(
metaData
.
getName
(),
session
,
returnReslult
,
longMetaDataMap
,
metaModelMap
,
edgeMap
,
layer
);
}
count
=
returnReslult
.
getCount
();
count
=
count
-
1
;
returnReslult
.
setCount
(
count
);
String
modelName
=
"System"
;
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"
);
}
Iterable
<
Relationship
>
relationships
=
path
.
relationships
();
for
(
Relationship
relationship:
relationships
){
long
startLong
=
relationship
.
startNodeId
();
long
endLong
=
relationship
.
endNodeId
();
if
(
longMetaDataMap
.
containsKey
(
startLong
)&&
longMetaDataMap
.
containsKey
(
endLong
)){
Edge
edge
=
new
Edge
();
String
edgeId
=
startLong
+
"_"
+
endLong
;
if
(
edgeMap
.
containsKey
(
edgeId
)){
continue
;
}
edge
.
setFromId
(
longMetaDataMap
.
get
(
startLong
).
getId
());
edge
.
setToId
(
longMetaDataMap
.
get
(
endLong
).
getId
());
edge
.
setType
(
relationship
.
type
());
edgeMap
.
put
(
edgeId
,
edge
);
// returnReslult.getEdges().add(edge);
}
}
}
}
}
}
@Override
public
ReturnReslult
searchGraphBySystem
(
String
metadataId
,
int
layer
)
{
logger
.
info
(
"开始获取图形。。。"
);
long
start
=
System
.
currentTimeMillis
();
ReturnReslult
returnReslult
=
new
ReturnReslult
();
//横向关系,纵向关系
Neo4jConfig
neo4jConfig
=
new
Neo4jConfig
();
Driver
neo4jConnection
=
neo4jConfig
.
getNeo4jConnection
();
Session
session
=
neo4jConnection
.
session
();
String
[]
strings
=
metadataId
.
split
(
"="
);
String
metadataName
=
strings
[
strings
.
length
-
1
];
Map
<
Long
,
com
.
keymobile
.
metadata
.
metadataRelation
.
pojo
.
returnBean
.
Node
>
longMetaDataMap
=
new
HashMap
<>();
Map
<
String
,
Edge
>
edgeMap
=
new
HashMap
<>();
Map
<
String
,
MetaModel
>
metaModelMap
=
new
HashMap
<>();
getPreNodeBySystemName
(
metadataName
,
session
,
returnReslult
,
longMetaDataMap
,
metaModelMap
,
edgeMap
,
layer
);
for
(
Object
obj
:
longMetaDataMap
.
keySet
()){
com
.
keymobile
.
metadata
.
metadataRelation
.
pojo
.
returnBean
.
Node
node
=
longMetaDataMap
.
get
(
obj
);
returnReslult
.
getNodes
().
add
(
node
);
}
for
(
Object
obj
:
edgeMap
.
keySet
()){
Edge
edge
=
edgeMap
.
get
(
obj
);
returnReslult
.
getEdges
().
add
(
edge
);
}
edgeMap
.
clear
();
longMetaDataMap
.
clear
();
returnReslult
.
setCount
(
0
);
getToNodeBySystemName
(
metadataName
,
session
,
returnReslult
,
longMetaDataMap
,
metaModelMap
,
edgeMap
,
layer
);
for
(
Object
obj
:
longMetaDataMap
.
keySet
()){
com
.
keymobile
.
metadata
.
metadataRelation
.
pojo
.
returnBean
.
Node
node
=
longMetaDataMap
.
get
(
obj
);
returnReslult
.
getNodes
().
add
(
node
);
}
for
(
Object
obj
:
edgeMap
.
keySet
()){
Edge
edge
=
edgeMap
.
get
(
obj
);
returnReslult
.
getEdges
().
add
(
edge
);
}
returnReslult
.
setMetaModelMap
(
metaModelMap
);
return
returnReslult
;
}
@Override
public
ReturnReslult
searchGraph
(
String
metadataId
,
int
layer
)
{
...
...
@@ -698,7 +932,6 @@ public class MetadataServiceImpl implements IMetadataService {
returnNode
.
setId
(
metaData
.
getMetadataId
());
returnNode
.
setName
(
metaData
.
getName
());
returnReslult
.
getNodes
().
add
(
returnNode
);
String
[]
strings
=
metaData
.
getMetadataId
().
split
(
"="
);
String
modelName
=
strings
[
0
];
...
...
@@ -744,6 +977,22 @@ public class MetadataServiceImpl implements IMetadataService {
returnReslult
.
getEdges
().
add
(
edge
);
}
}
else
if
(
metadataId
.
startsWith
(
"System="
)){
//获取纵向节点,目前system与table没有关系,先不处理
// String cypher = "match p=(n:MetaData{metadataId:\""+metadataId+"\"})-[r:Execute*0..10]->(m) return p";
// logger.info("cypher:" + cypher);
//
// Map<Long,MetaData> longMetaDataMap = new HashMap<>();
// Map<String,Edge> edgeMap = new HashMap<>();
// //先获取纵向节点,
// StatementResult result = session.run(cypher);
//
// while(result.hasNext()){
//
// }
}
else
{
logger
.
info
(
"暂不支持该类型节点。"
);
}
...
...
@@ -836,6 +1085,11 @@ public class MetadataServiceImpl implements IMetadataService {
}
else
if
(
metadataId
.
startsWith
(
"EtlJob="
)){
cypher
=
"match (n:MetaData{metadataId:\""
+
metadataId
+
"\"})-->(n1)-->(n2)<-[r:Input]->(p)-[r0:Output]-(p1)<-[r2:Execute]-(m0)<-[r3:Execute]-(job) "
+
"return job"
;
}
else
if
(
metadataId
.
startsWith
(
"System="
)){
String
[]
metadataNameList
=
metadataId
.
split
(
"="
);
String
metadataName
=
metadataNameList
[
metadataNameList
.
length
-
1
];
cypher
=
"match (n:softplatform{name:\""
+
metadataName
+
"\"}) -[r]->(m:softplatform) return r,n,m"
;
}
StatementResult
result1
=
session
.
run
(
cypher
);
...
...
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