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
f086fb99
Commit
f086fb99
authored
Oct 21, 2021
by
qiuchaofei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.修改auth的依赖包,2添加icon的接口,3添加获取节点类型的接口
parent
01c518bf
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
198 additions
and
14 deletions
+198
-14
pom.xml
pom.xml
+11
-1
MetaDataController.java
...adata/metadataRelation/controller/MetaDataController.java
+134
-6
Node.java
...obile/metadata/metadataRelation/pojo/returnBean/Node.java
+19
-0
IMetadataService.java
...e/metadata/metadataRelation/service/IMetadataService.java
+1
-0
MetadataServiceImpl.java
...ta/metadataRelation/service/impl/MetadataServiceImpl.java
+33
-7
No files found.
pom.xml
View file @
f086fb99
...
@@ -133,11 +133,21 @@
...
@@ -133,11 +133,21 @@
<artifactId>
cas-security-spring-boot-starter
</artifactId>
<artifactId>
cas-security-spring-boot-starter
</artifactId>
<version>
1.0.0-beta-1
</version>
<version>
1.0.0-beta-1
</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
com.keymobile.auth
</groupId>
<groupId>
com.keymobile.auth
</groupId>
<artifactId>
common
</artifactId>
<artifactId>
common
</artifactId>
<version>
3.0.3-SNAPSHOT
</version>
<version>
3.0.6-release
</version>
</dependency>
<dependency>
<groupId>
com.keymobile.auth
</groupId>
<artifactId>
security
</artifactId>
<version>
3.0.6-release
</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
com.github.ulisesbocchio
</groupId>
<groupId>
com.github.ulisesbocchio
</groupId>
<artifactId>
jasypt-spring-boot-starter
</artifactId>
<artifactId>
jasypt-spring-boot-starter
</artifactId>
...
...
src/main/java/com/keymobile/metadata/metadataRelation/controller/MetaDataController.java
View file @
f086fb99
...
@@ -7,21 +7,35 @@ import com.keymobile.metadata.metadataRelation.pojo.returnBean.Node;
...
@@ -7,21 +7,35 @@ import com.keymobile.metadata.metadataRelation.pojo.returnBean.Node;
import
com.keymobile.metadata.metadataRelation.pojo.returnBean.ReturnReslult
;
import
com.keymobile.metadata.metadataRelation.pojo.returnBean.ReturnReslult
;
import
com.keymobile.metadata.metadataRelation.service.IBaseRelationshipService
;
import
com.keymobile.metadata.metadataRelation.service.IBaseRelationshipService
;
import
com.keymobile.metadata.metadataRelation.service.IMetadataService
;
import
com.keymobile.metadata.metadataRelation.service.IMetadataService
;
import
com.keymobile.metadata.metadataRelation.service.impl.MongoDbServiceImpl
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiParam
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.
web.bind.annotation.RequestBody
;
import
org.springframework.
boot.system.ApplicationHome
;
import
org.springframework.web.bind.annotation.
RequestMapping
;
import
org.springframework.web.bind.annotation.
*
;
import
org.springframework.web.
bind.annotation.RequestMethod
;
import
org.springframework.web.
multipart.MultipartFile
;
import
org.springframework.web.bind.annotation.RestControll
er
;
import
sun.misc.BASE64Encod
er
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.UUID
;
@RequestMapping
(
value
=
"api/metadata"
)
@RequestMapping
(
value
=
"api/metadata"
)
@RestController
@RestController
@Api
(
value
=
"metadata"
,
tags
=
"把metadata写入neo4j数据库"
)
@Api
(
value
=
"metadata"
,
tags
=
"把metadata写入neo4j数据库"
)
public
class
MetaDataController
{
public
class
MetaDataController
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
MetaDataController
.
class
);
@Autowired
@Autowired
private
IMetadataService
metadataService
;
private
IMetadataService
metadataService
;
...
@@ -30,23 +44,30 @@ public class MetaDataController {
...
@@ -30,23 +44,30 @@ public class MetaDataController {
/**
/**
* 查询元数据,关系
* 查询元数据,关系
*/
*/
@ApiOperation
(
"获取所有的节点与关系"
)
@RequestMapping
(
path
=
"/result"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
path
=
"/result"
,
method
=
RequestMethod
.
GET
)
public
ReturnReslult
getAllNodeAndRelation
()
{
public
ReturnReslult
getAllNodeAndRelation
()
{
logger
.
info
(
"开始获取所有的节点与关系"
);
ReturnReslult
result
=
new
ReturnReslult
();
ReturnReslult
result
=
new
ReturnReslult
();
List
<
MetaData
>
metaDataList
=
metadataService
.
finAllMetaData
();
List
<
MetaData
>
metaDataList
=
metadataService
.
finAllMetaData
();
Map
<
Long
,
Node
>
nodeMap
=
new
HashMap
<>();
Map
<
Long
,
Node
>
nodeMap
=
new
HashMap
<>();
for
(
MetaData
metaData:
metaDataList
){
for
(
MetaData
metaData:
metaDataList
){
Node
node
=
new
Node
();
Node
node
=
new
Node
();
String
[]
strings
=
metaData
.
getMetadataId
().
split
(
"="
);
String
modelName
=
strings
[
0
];
node
.
setId
(
metaData
.
getMetadataId
());
node
.
setId
(
metaData
.
getMetadataId
());
node
.
setIcon
(
getIconByModelId
(
modelName
));
node
.
setName
(
metaData
.
getName
());
node
.
setName
(
metaData
.
getName
());
node
.
setType
(
"MetaData"
);
result
.
getNodes
().
add
(
node
);
result
.
getNodes
().
add
(
node
);
nodeMap
.
put
(
metaData
.
getId
(),
node
);
nodeMap
.
put
(
metaData
.
getId
(),
node
);
}
}
logger
.
info
(
"节点的数量:"
+
result
.
getNodes
().
size
());
List
<
BaseRelationship
>
baseRelationshipList
=
baseRelationshipService
.
findAllRelation
();
List
<
BaseRelationship
>
baseRelationshipList
=
baseRelationshipService
.
findAllRelation
();
for
(
BaseRelationship
baseRelationship:
baseRelationshipList
){
for
(
BaseRelationship
baseRelationship:
baseRelationshipList
){
Edge
edge
=
new
Edge
();
Edge
edge
=
new
Edge
();
edge
.
setEdgeId
(
String
.
valueOf
(
baseRelationship
.
getId
()));
edge
.
setEdgeId
(
String
.
valueOf
(
baseRelationship
.
getId
()));
Long
startId
=
baseRelationship
.
getStart
().
getId
();
Long
startId
=
baseRelationship
.
getStart
().
getId
();
Long
endId
=
baseRelationship
.
getEnd
().
getId
();
Long
endId
=
baseRelationship
.
getEnd
().
getId
();
...
@@ -66,6 +87,8 @@ public class MetaDataController {
...
@@ -66,6 +87,8 @@ public class MetaDataController {
result
.
getEdges
().
add
(
edge
);
result
.
getEdges
().
add
(
edge
);
}
}
logger
.
info
(
"关系的数量:"
+
result
.
getEdges
().
size
());
return
result
;
return
result
;
}
}
...
@@ -73,14 +96,107 @@ public class MetaDataController {
...
@@ -73,14 +96,107 @@ public class MetaDataController {
/**
/**
* 查询元数据
* 查询元数据
*/
*/
@RequestMapping
(
path
=
"/list"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
path
=
"/list"
,
method
=
RequestMethod
.
GET
)
public
List
<
MetaData
>
getUserNodeList
()
{
public
List
<
MetaData
>
getUserNodeList
()
{
logger
.
info
(
"获取所有的节点"
);
return
metadataService
.
finAllMetaData
();
return
metadataService
.
finAllMetaData
();
}
}
/**
* 修改图片的接口,传入元模型id,新图标
*/
@ApiOperation
(
"修改元模型图标的接口"
)
@PostMapping
(
value
=
"/modifyIcon"
,
consumes
=
"multipart/*"
,
headers
=
"content-type=multipart/form-date"
)
public
String
modifyIcon
(
String
modelId
,
@ApiParam
(
value
=
"上传的文件"
,
required
=
true
)
MultipartFile
file
)
{
if
(
file
.
isEmpty
())
{
logger
.
info
(
"文件为空空"
);
}
String
fileName
=
file
.
getOriginalFilename
();
// 文件名
String
suffixName
=
fileName
.
substring
(
fileName
.
lastIndexOf
(
"."
));
// 后缀名
ApplicationHome
applicationHome
=
new
ApplicationHome
(
getClass
());
File
jarFile
=
applicationHome
.
getSource
();
String
dirPath
=
jarFile
.
getParentFile
().
toString
()+
"/Icon/"
+
modelId
+
"/"
;
logger
.
info
(
"存放图标的路径:"
+
dirPath
);
// fileName = "Icon_"+modelId + suffixName; // 新文件名
File
dest
=
new
File
(
dirPath
+
fileName
);
if
(!
dest
.
getParentFile
().
exists
())
{
//如果文件夹不存在,就创建,
dest
.
getParentFile
().
mkdirs
();
}
else
{
//如果文件夹存在,就先清空里面的文件
File
[]
files
=
dest
.
getParentFile
().
listFiles
();
if
(
files
!=
null
)
{
//如果包含文件进行删除操作
for
(
int
i
=
0
;
i
<
files
.
length
;
i
++)
{
if
(
files
[
i
].
isFile
())
{
files
[
i
].
delete
();
}
}
// dest.getParentFile().deleteOnExit();
// dest.getParentFile().mkdirs();
}
}
try
{
file
.
transferTo
(
dest
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
"file"
;
}
/**
* 获取元模型的图标,
*/
@ApiOperation
(
"获取元模型的图标"
)
@RequestMapping
(
value
=
"/getIconByModelId"
,
method
=
RequestMethod
.
GET
)
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编码过的字节数组字符串
}
/**
/**
* 查询所有的关系类型
* 查询所有的关系类型
*/
*/
@ApiOperation
(
"查询所有的关系类型"
)
@RequestMapping
(
path
=
"/listAllRelationType"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
path
=
"/listAllRelationType"
,
method
=
RequestMethod
.
GET
)
public
List
<
String
>
getAllRelationType
()
{
public
List
<
String
>
getAllRelationType
()
{
...
@@ -88,8 +204,18 @@ public class MetaDataController {
...
@@ -88,8 +204,18 @@ public class MetaDataController {
}
}
/**
/**
* 查询所有的节点类型
*/
@ApiOperation
(
"查询所有的节点类型"
)
@RequestMapping
(
path
=
"/listAllNodeType"
,
method
=
RequestMethod
.
GET
)
public
List
<
String
>
getAllNodeType
()
{
return
metadataService
.
findAllNodeTypes
();
}
/**
* 传入元数据id,显示的层数,查找出与该元数据有关系的数据
* 传入元数据id,显示的层数,查找出与该元数据有关系的数据
*/
*/
@ApiOperation
(
"传入元数据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
)
{
...
@@ -122,8 +248,10 @@ public class MetaDataController {
...
@@ -122,8 +248,10 @@ public class MetaDataController {
* 同步元数据关系的接口,传入一个环境名称(catalognName),从mongo读取关系,存入到neo4j中
* 同步元数据关系的接口,传入一个环境名称(catalognName),从mongo读取关系,存入到neo4j中
* @return
* @return
*/
*/
@ApiOperation
(
"同步元数据关系的接口"
)
@RequestMapping
(
path
=
"/syschroRelationFromMongo"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
path
=
"/syschroRelationFromMongo"
,
method
=
RequestMethod
.
GET
)
public
String
syschroRelationFromMongo
(
String
catalogName
){
public
String
syschroRelationFromMongo
(
String
catalogName
){
logger
.
info
(
"开始同步元数据:从mongo到neo4j"
);
String
flag
=
"success"
;
String
flag
=
"success"
;
metadataService
.
syschroRelationFromMongo
(
catalogName
);
metadataService
.
syschroRelationFromMongo
(
catalogName
);
return
flag
;
return
flag
;
...
...
src/main/java/com/keymobile/metadata/metadataRelation/pojo/returnBean/Node.java
View file @
f086fb99
...
@@ -5,6 +5,25 @@ public class Node {
...
@@ -5,6 +5,25 @@ public class Node {
private
String
name
;
private
String
name
;
private
String
id
;
private
String
id
;
public
String
getIcon
()
{
return
icon
;
}
public
void
setIcon
(
String
icon
)
{
this
.
icon
=
icon
;
}
private
String
icon
;
private
String
type
;
public
String
getType
()
{
return
type
;
}
public
void
setType
(
String
type
)
{
this
.
type
=
type
;
}
public
String
getId
()
{
public
String
getId
()
{
return
id
;
return
id
;
}
}
...
...
src/main/java/com/keymobile/metadata/metadataRelation/service/IMetadataService.java
View file @
f086fb99
...
@@ -65,4 +65,5 @@ public interface IMetadataService {
...
@@ -65,4 +65,5 @@ public interface IMetadataService {
List
<
BaseRelationship
>
getMetadataRelationship
(
String
name
,
String
startName
,
String
endName
);
List
<
BaseRelationship
>
getMetadataRelationship
(
String
name
,
String
startName
,
String
endName
);
List
<
String
>
findAllNodeTypes
();
}
}
src/main/java/com/keymobile/metadata/metadataRelation/service/impl/MetadataServiceImpl.java
View file @
f086fb99
...
@@ -160,17 +160,21 @@ public class MetadataServiceImpl implements IMetadataService {
...
@@ -160,17 +160,21 @@ public class MetadataServiceImpl implements IMetadataService {
List
<
RelationMongo
>
relationMongoList
=
mongoDbServiceImpl
.
findAll
(
catalogName
);
List
<
RelationMongo
>
relationMongoList
=
mongoDbServiceImpl
.
findAll
(
catalogName
);
for
(
RelationMongo
relationMongo:
relationMongoList
){
for
(
RelationMongo
relationMongo:
relationMongoList
){
// 获取元数据属性
// 获取元数据属性
System
.
out
.
println
(
relationMongo
.
getId
());
//
System.out.println(relationMongo.getId());
// logger.info("同步元数据:从mongo到neo4j");
String
sourceId
=
relationMongo
.
getSource
();
String
sourceId
=
relationMongo
.
getSource
();
String
targetId
=
relationMongo
.
getTarget
();
String
targetId
=
relationMongo
.
getTarget
();
String
type
=
relationMongo
.
getType
();
String
type
=
relationMongo
.
getType
();
if
(!
metaDataMap
.
containsKey
(
sourceId
)){
if
(!
metaDataMap
.
containsKey
(
sourceId
)){
//不存在源
//不存在源
MetaData
metaData
=
new
MetaData
();
MetaData
metaData
=
new
MetaData
();
metaData
.
setMetadataId
(
sourceId
);
metaData
.
setMetadataId
(
sourceId
);
Map
<
String
,
Object
>
attriuteMap
=
metadataRepoRemoteService
.
getMetadata
(
sourceId
);
Map
<
String
,
Object
>
attriuteMap
=
metadataRepoRemoteService
.
getMetadata
(
sourceId
);
if
(
attriuteMap
==
null
){
continue
;
}
String
name
=
(
String
)
attriuteMap
.
get
(
"name"
);
String
name
=
(
String
)
attriuteMap
.
get
(
"name"
);
if
(
attriuteMap
.
get
(
"cnName"
)!=
null
&&
!
attriuteMap
.
get
(
"cnName"
).
equals
(
""
)){
if
(
attriuteMap
.
get
(
"cnName"
)!=
null
&&
!
attriuteMap
.
get
(
"cnName"
).
equals
(
""
)){
name
=
(
String
)
attriuteMap
.
get
(
"cnName"
);
name
=
(
String
)
attriuteMap
.
get
(
"cnName"
);
...
@@ -186,6 +190,9 @@ public class MetadataServiceImpl implements IMetadataService {
...
@@ -186,6 +190,9 @@ public class MetadataServiceImpl implements IMetadataService {
if
(
sourceId
.
startsWith
(
"Column="
)
||
sourceId
.
startsWith
(
"Header="
)
){
if
(
sourceId
.
startsWith
(
"Column="
)
||
sourceId
.
startsWith
(
"Header="
)
){
Map
<
String
,
Object
>
parentAlttriuteMap
=
metadataRepoRemoteService
.
getParent
(
sourceId
);
Map
<
String
,
Object
>
parentAlttriuteMap
=
metadataRepoRemoteService
.
getParent
(
sourceId
);
if
(
parentAlttriuteMap
==
null
){
continue
;
}
String
parentId
=
(
String
)
parentAlttriuteMap
.
get
(
"_id"
);
String
parentId
=
(
String
)
parentAlttriuteMap
.
get
(
"_id"
);
if
(!
metaDataMap
.
containsKey
(
parentId
)){
if
(!
metaDataMap
.
containsKey
(
parentId
)){
...
@@ -200,7 +207,6 @@ public class MetadataServiceImpl implements IMetadataService {
...
@@ -200,7 +207,6 @@ public class MetadataServiceImpl implements IMetadataService {
}
else
{
}
else
{
metadataRepository
.
save
(
parentData
);
metadataRepository
.
save
(
parentData
);
}
}
// metadataRepository.save(parentData);
metaDataMap
.
put
(
parentId
,
parentData
);
metaDataMap
.
put
(
parentId
,
parentData
);
}
}
List
<
CompositionRelation
>
relationship
=
compositionRelationRespository
.
findCompositionRelationship
(
parentId
,
sourceId
);
List
<
CompositionRelation
>
relationship
=
compositionRelationRespository
.
findCompositionRelationship
(
parentId
,
sourceId
);
...
@@ -279,13 +285,9 @@ public class MetadataServiceImpl implements IMetadataService {
...
@@ -279,13 +285,9 @@ public class MetadataServiceImpl implements IMetadataService {
if
(
relationship
==
null
||
relationship
.
size
()==
0
){
if
(
relationship
==
null
||
relationship
.
size
()==
0
){
executeRelationRepository
.
addExecuteRelation
(
sourceId
,
targetId
);
executeRelationRepository
.
addExecuteRelation
(
sourceId
,
targetId
);
}
}
}
}
}
}
}
}
@Override
@Override
...
@@ -348,4 +350,28 @@ public class MetadataServiceImpl implements IMetadataService {
...
@@ -348,4 +350,28 @@ public class MetadataServiceImpl implements IMetadataService {
public
List
<
BaseRelationship
>
getMetadataRelationship
(
String
name
,
String
startName
,
String
endName
)
{
public
List
<
BaseRelationship
>
getMetadataRelationship
(
String
name
,
String
startName
,
String
endName
)
{
return
null
;
return
null
;
}
}
@Override
public
List
<
String
>
findAllNodeTypes
()
{
List
<
String
>
labels
=
new
ArrayList
<>();
Neo4jConfig
neo4jConfig
=
new
Neo4jConfig
();
Driver
neo4jConnection
=
neo4jConfig
.
getNeo4jConnection
();
Session
session
=
neo4jConnection
.
session
();
String
getLabels
=
" MATCH (n) RETURN distinct labels(n) as name "
;
StatementResult
result
=
session
.
run
(
getLabels
);
while
(
result
.
hasNext
())
{
Record
record
=
(
Record
)
result
.
next
();
String
labelName
=
record
.
get
(
"name"
).
toString
();
Value
name
=
record
.
get
(
"name"
);
List
<
Object
>
objects
=
name
.
asList
();
int
size
=
objects
.
size
();
String
type
=
""
;
Object
object
=
objects
.
get
(
size
-
1
);
labels
.
add
(
object
.
toString
());
}
return
labels
;
}
}
}
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