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
3343e307
Commit
3343e307
authored
Feb 18, 2022
by
qiuchaofei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加接口:入口是作业,与脚本
parent
621bbda2
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
254 additions
and
4 deletions
+254
-4
RelationalGraphController.java
...etadataRelation/controller/RelationalGraphController.java
+11
-1
Neo4jETLJobRepository.java
...aRelation/respository/metadata/Neo4jETLJobRepository.java
+8
-0
Neo4jETLScriptRepository.java
...lation/respository/metadata/Neo4jETLScriptRepository.java
+14
-0
IETLJobService.java
...ile/metadata/metadataRelation/service/IETLJobService.java
+2
-0
IETLScriptService.java
.../metadata/metadataRelation/service/IETLScriptService.java
+5
-0
ETLJobServiceImpl.java
...data/metadataRelation/service/impl/ETLJobServiceImpl.java
+101
-0
ETLScriptServiceImpl.java
...a/metadataRelation/service/impl/ETLScriptServiceImpl.java
+113
-3
No files found.
src/main/java/com/keymobile/metadata/metadataRelation/controller/RelationalGraphController.java
View file @
3343e307
...
...
@@ -228,8 +228,18 @@ public class RelationalGraphController {
@ApiOperation
(
tags
=
""
,
value
=
"传入表的id,返回表的上下游一层关系。"
)
@RequestMapping
(
path
=
"/getRelationTablesTableId"
,
method
=
RequestMethod
.
GET
)
public
Map
<
String
,
List
<
ReturnNode
>>
getRelationTablesTableId
(
String
tableId
){
Map
<
String
,
List
<
ReturnNode
>>
relationTables
=
new
HashMap
<>();
long
start
=
System
.
currentTimeMillis
();
Map
<
String
,
List
<
ReturnNode
>>
relationTables
=
tableService
.
getSourceAndTargetTableByTableId
(
tableId
);
if
(
tableId
.
startsWith
(
"Table="
)){
relationTables
=
tableService
.
getSourceAndTargetTableByTableId
(
tableId
);
}
else
if
(
tableId
.
startsWith
(
"ETLJob="
)){
relationTables
=
etlJobService
.
getSourceAndTargetObjectByMedataDataId
(
tableId
);
}
else
if
(
tableId
.
startsWith
(
"ETLScript="
)){
relationTables
=
etlScriptService
.
getSourceAndTargetObjectByMedataDataId
(
tableId
);
}
long
end
=
System
.
currentTimeMillis
();
logger
.
info
(
"获取关联的表,用时:"
+(
end
-
start
));
return
relationTables
;
...
...
src/main/java/com/keymobile/metadata/metadataRelation/respository/metadata/Neo4jETLJobRepository.java
View file @
3343e307
package
com
.
keymobile
.
metadata
.
metadataRelation
.
respository
.
metadata
;
import
com.keymobile.metadata.metadataRelation.pojo.BaseNode
;
import
com.keymobile.metadata.metadataRelation.pojo.metadata.Neo4jETLJob
;
import
com.keymobile.metadata.metadataRelation.pojo.metadata.Neo4jFunction
;
import
org.springframework.data.neo4j.annotation.Query
;
import
org.springframework.data.neo4j.repository.Neo4jRepository
;
import
org.springframework.data.repository.query.Param
;
import
org.springframework.stereotype.Repository
;
import
java.util.List
;
...
...
@@ -12,4 +15,9 @@ public interface Neo4jETLJobRepository extends Neo4jRepository<Neo4jETLJob, Long
Neo4jETLJob
findNeo4jETLJobByMetadataId
(
String
metadataId
);
@Query
(
"match(n:Neo4jETLJob{metadataId:{jobId}}) -[r:Composition]->(m)-[r1:流向]->(t) return t"
)
List
<
BaseNode
>
getSources
(
@Param
(
"jobId"
)
String
jobId
);
@Query
(
"match(n:Neo4jETLJob{metadataId:{jobId}}) -[r:Composition]->(m)<-[r1:流向]-(t) return t"
)
List
<
BaseNode
>
getTarget
(
@Param
(
"jobId"
)
String
jobId
);
}
src/main/java/com/keymobile/metadata/metadataRelation/respository/metadata/Neo4jETLScriptRepository.java
View file @
3343e307
package
com
.
keymobile
.
metadata
.
metadataRelation
.
respository
.
metadata
;
import
com.keymobile.metadata.metadataRelation.pojo.BaseNode
;
import
com.keymobile.metadata.metadataRelation.pojo.metadata.Neo4jETLScript
;
import
org.springframework.data.neo4j.annotation.Query
;
import
org.springframework.data.neo4j.repository.Neo4jRepository
;
import
org.springframework.data.repository.query.Param
;
import
org.springframework.stereotype.Repository
;
import
java.util.List
;
@Repository
public
interface
Neo4jETLScriptRepository
extends
Neo4jRepository
<
Neo4jETLScript
,
Long
>
{
Neo4jETLScript
findNeo4jETLScriptByMetadataId
(
String
metadataId
);
@Query
(
"match(n:Neo4jETLScript{metadataId:{scriptId}})<-[r1:流向]-(t) return t"
+
" union match(n:Neo4jETLScript{metadataId:{scriptId}})<-[r1:TempRelation*1..]-(t) return t"
)
List
<
BaseNode
>
getSources
(
@Param
(
"scriptId"
)
String
scriptId
);
@Query
(
"match(n:Neo4jETLScript{metadataId:{scriptId}})-[r1:流向]->(t) return t"
+
" union match(n:Neo4jETLScript{metadataId:{scriptId}})-[r1:TempRelation*1..]->(t) return t"
)
List
<
BaseNode
>
getTargets
(
@Param
(
"scriptId"
)
String
scriptId
);
}
src/main/java/com/keymobile/metadata/metadataRelation/service/IETLJobService.java
View file @
3343e307
...
...
@@ -11,4 +11,6 @@ public interface IETLJobService {
Map
<
String
,
String
>
getAttributeByETLJobId
(
String
etlJobId
);
Map
<
String
,
List
<
ReturnNode
>>
getchildrenByEtlJobId
(
String
etlJobId
);
Map
<
String
,
List
<
ReturnNode
>>
getSourceAndTargetObjectByMedataDataId
(
String
tableId
);
}
src/main/java/com/keymobile/metadata/metadataRelation/service/IETLScriptService.java
View file @
3343e307
package
com
.
keymobile
.
metadata
.
metadataRelation
.
service
;
import
com.keymobile.metadata.metadataRelation.pojo.returnBean.ReturnNode
;
import
java.util.List
;
import
java.util.Map
;
public
interface
IETLScriptService
{
Map
<
String
,
String
>
getAttributeByETLScriptId
(
String
tableId
);
Map
<
String
,
List
<
ReturnNode
>>
getSourceAndTargetObjectByMedataDataId
(
String
tableId
);
}
src/main/java/com/keymobile/metadata/metadataRelation/service/impl/ETLJobServiceImpl.java
View file @
3343e307
package
com
.
keymobile
.
metadata
.
metadataRelation
.
service
.
impl
;
import
com.keymobile.metadata.metadataRelation.pojo.BaseNode
;
import
com.keymobile.metadata.metadataRelation.pojo.MetaData
;
import
com.keymobile.metadata.metadataRelation.pojo.metadata.Neo4jETLJob
;
import
com.keymobile.metadata.metadataRelation.pojo.metadata.Neo4jTable
;
import
com.keymobile.metadata.metadataRelation.pojo.returnBean.ReturnNode
;
import
com.keymobile.metadata.metadataRelation.remote.MetadataRepoRemoteService
;
import
com.keymobile.metadata.metadataRelation.respository.metadata.Neo4jETLJobRepository
;
import
com.keymobile.metadata.metadataRelation.service.IETLJobService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
@@ -16,6 +19,8 @@ public class ETLJobServiceImpl implements IETLJobService {
@Autowired
private
MetadataRepoRemoteService
metadataRepoRemoteService
;
@Autowired
private
Neo4jETLJobRepository
neo4jETLJobRepository
;
@Override
public
Map
<
String
,
List
<
ReturnNode
>>
getEtlJobByCatalogName
(
String
catalogName
)
{
...
...
@@ -52,6 +57,102 @@ public class ETLJobServiceImpl implements IETLJobService {
return
columnMap
;
}
@Override
public
Map
<
String
,
List
<
ReturnNode
>>
getSourceAndTargetObjectByMedataDataId
(
String
jobId
)
{
Map
<
String
,
List
<
ReturnNode
>>
sourceAndTargetTable
=
new
HashMap
<>();
List
<
ReturnNode
>
sourceTables
=
new
ArrayList
<>();
List
<
ReturnNode
>
neo4jTableList
=
getCurrentTableInfo
(
jobId
);
sourceAndTargetTable
.
put
(
"当前作业"
,
neo4jTableList
);
getSource
(
jobId
,
sourceTables
);
List
<
ReturnNode
>
targetTables
=
new
ArrayList
<>();
getTarget
(
jobId
,
targetTables
);
sourceAndTargetTable
.
put
(
"来源"
,
sourceTables
);
sourceAndTargetTable
.
put
(
"目标"
,
targetTables
);
return
sourceAndTargetTable
;
}
private
void
getTarget
(
String
jobId
,
List
<
ReturnNode
>
targets
)
{
List
<
BaseNode
>
sourceBaseNodeList
=
neo4jETLJobRepository
.
getTarget
(
jobId
);
for
(
BaseNode
baseNode:
sourceBaseNodeList
){
String
metadataId
=
baseNode
.
getMetadataId
();
if
(
metadataId
.
startsWith
(
"Table="
)){
ReturnNode
returnNode
=
new
ReturnNode
();
returnNode
.
setId
(
baseNode
.
getMetadataId
());
returnNode
.
setName
(
baseNode
.
getName
());
returnNode
.
setType
(
"Table"
);
// 获取属性
// Map<String,String> attributeMap = getAttributeMap(metadataId);
// List<BaseNode> sourceEtlScriptBetween2TableList = neo4jTableRepository.getSourceEtlScriptBetween2Table(tableId, metadataId);
// Map<String,String> relationMap = new HashMap<>();
// for(BaseNode sourceEtlScriptBetween2Table:sourceEtlScriptBetween2TableList){
// relationMap.put("name",sourceEtlScriptBetween2Table.getName());
// relationMap.put("metadataId",sourceEtlScriptBetween2Table.getMetadataId());
// }
if
(!
targets
.
contains
(
returnNode
)){
targets
.
add
(
returnNode
);
}
// returnNode.setRelationMaps(relationMap);
// returnNode.setAttributeMaps(attributeMap);
}
else
{
// getSource(metadataId,sourceTables);
}
}
}
private
void
getSource
(
String
jobId
,
List
<
ReturnNode
>
sources
)
{
List
<
BaseNode
>
sourceBaseNodeList
=
neo4jETLJobRepository
.
getSources
(
jobId
);
for
(
BaseNode
baseNode:
sourceBaseNodeList
){
String
metadataId
=
baseNode
.
getMetadataId
();
if
(
metadataId
.
startsWith
(
"Table="
)){
ReturnNode
returnNode
=
new
ReturnNode
();
returnNode
.
setId
(
baseNode
.
getMetadataId
());
returnNode
.
setName
(
baseNode
.
getName
());
returnNode
.
setType
(
"Table"
);
// 获取属性
// Map<String,String> attributeMap = getAttributeMap(metadataId);
// List<BaseNode> sourceEtlScriptBetween2TableList = neo4jTableRepository.getSourceEtlScriptBetween2Table(tableId, metadataId);
// Map<String,String> relationMap = new HashMap<>();
// for(BaseNode sourceEtlScriptBetween2Table:sourceEtlScriptBetween2TableList){
// relationMap.put("name",sourceEtlScriptBetween2Table.getName());
// relationMap.put("metadataId",sourceEtlScriptBetween2Table.getMetadataId());
// }
if
(!
sources
.
contains
(
returnNode
)){
sources
.
add
(
returnNode
);
}
// returnNode.setRelationMaps(relationMap);
// returnNode.setAttributeMaps(attributeMap);
}
else
{
// getSource(metadataId,sourceTables);
}
}
}
private
List
<
ReturnNode
>
getCurrentTableInfo
(
String
tableId
)
{
Neo4jETLJob
neo4jETLJob
=
neo4jETLJobRepository
.
findNeo4jETLJobByMetadataId
(
tableId
);
List
<
ReturnNode
>
returnTableList
=
new
ArrayList
<>();
ReturnNode
returnNode
=
new
ReturnNode
();
returnNode
.
setId
(
neo4jETLJob
.
getMetadataId
());
returnNode
.
setName
(
neo4jETLJob
.
getName
());
returnNode
.
setType
(
"Table"
);
returnTableList
.
add
(
returnNode
);
// 获取属性
// Map<String,String> attributeMap = getAttributeMap(tableId);
//
// returnNode.setAttributeMaps(attributeMap);
return
returnTableList
;
}
private
Map
<
String
,
String
>
getAttributeMap
(
String
EtlJobId
){
Map
<
String
,
String
>
returnMap
=
new
LinkedHashMap
<>();
Map
<
String
,
Object
>
attriuteMap
=
metadataRepoRemoteService
.
getMetadata
(
EtlJobId
);
...
...
src/main/java/com/keymobile/metadata/metadataRelation/service/impl/ETLScriptServiceImpl.java
View file @
3343e307
package
com
.
keymobile
.
metadata
.
metadataRelation
.
service
.
impl
;
import
com.keymobile.metadata.metadataRelation.pojo.BaseNode
;
import
com.keymobile.metadata.metadataRelation.pojo.metadata.Neo4jETLJob
;
import
com.keymobile.metadata.metadataRelation.pojo.metadata.Neo4jETLScript
;
import
com.keymobile.metadata.metadataRelation.pojo.returnBean.ReturnNode
;
import
com.keymobile.metadata.metadataRelation.remote.MetadataRepoRemoteService
;
import
com.keymobile.metadata.metadataRelation.respository.metadata.Neo4jETLScriptRepository
;
import
com.keymobile.metadata.metadataRelation.service.IETLScriptService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
import
java.util.*
;
@Service
public
class
ETLScriptServiceImpl
implements
IETLScriptService
{
...
...
@@ -15,12 +19,118 @@ public class ETLScriptServiceImpl implements IETLScriptService {
@Autowired
private
MetadataRepoRemoteService
metadataRepoRemoteService
;
@Autowired
Neo4jETLScriptRepository
neo4jETLScriptRepository
;
@Override
public
Map
<
String
,
String
>
getAttributeByETLScriptId
(
String
tableId
)
{
Map
<
String
,
String
>
attributeMap
=
getAttributeMap
(
tableId
);
return
attributeMap
;
}
@Override
public
Map
<
String
,
List
<
ReturnNode
>>
getSourceAndTargetObjectByMedataDataId
(
String
scriptId
)
{
Map
<
String
,
List
<
ReturnNode
>>
sourceAndTargetTable
=
new
HashMap
<>();
List
<
ReturnNode
>
sourceTables
=
new
ArrayList
<>();
List
<
ReturnNode
>
neo4jTableList
=
getCurrentTableInfo
(
scriptId
);
sourceAndTargetTable
.
put
(
"当前脚本"
,
neo4jTableList
);
getSource
(
scriptId
,
sourceTables
);
List
<
ReturnNode
>
targetTables
=
new
ArrayList
<>();
getTarget
(
scriptId
,
targetTables
);
sourceAndTargetTable
.
put
(
"来源"
,
sourceTables
);
sourceAndTargetTable
.
put
(
"目标"
,
targetTables
);
return
sourceAndTargetTable
;
}
private
void
getTarget
(
String
scriptId
,
List
<
ReturnNode
>
targets
)
{
List
<
BaseNode
>
sourceBaseNodeList
=
neo4jETLScriptRepository
.
getTargets
(
scriptId
);
for
(
BaseNode
baseNode:
sourceBaseNodeList
){
String
metadataId
=
baseNode
.
getMetadataId
();
if
(
metadataId
.
startsWith
(
"Table="
)||
metadataId
.
startsWith
(
"ETLScript="
)){
ReturnNode
returnNode
=
new
ReturnNode
();
returnNode
.
setId
(
baseNode
.
getMetadataId
());
returnNode
.
setName
(
baseNode
.
getName
());
if
(
metadataId
.
startsWith
(
"Table="
)){
returnNode
.
setType
(
"Table"
);
}
else
{
returnNode
.
setType
(
"ETLScript"
);
}
// 获取属性
// Map<String,String> attributeMap = getAttributeMap(metadataId);
// List<BaseNode> sourceEtlScriptBetween2TableList = neo4jTableRepository.getSourceEtlScriptBetween2Table(tableId, metadataId);
// Map<String,String> relationMap = new HashMap<>();
// for(BaseNode sourceEtlScriptBetween2Table:sourceEtlScriptBetween2TableList){
// relationMap.put("name",sourceEtlScriptBetween2Table.getName());
// relationMap.put("metadataId",sourceEtlScriptBetween2Table.getMetadataId());
// }
if
(!
targets
.
contains
(
returnNode
)){
targets
.
add
(
returnNode
);
}
// returnNode.setRelationMaps(relationMap);
// returnNode.setAttributeMaps(attributeMap);
}
else
{
getTarget
(
metadataId
,
targets
);
}
}
}
private
void
getSource
(
String
scriptId
,
List
<
ReturnNode
>
sources
)
{
List
<
BaseNode
>
sourceBaseNodeList
=
neo4jETLScriptRepository
.
getSources
(
scriptId
);
for
(
BaseNode
baseNode:
sourceBaseNodeList
){
String
metadataId
=
baseNode
.
getMetadataId
();
if
(
metadataId
.
startsWith
(
"Table="
)||
metadataId
.
startsWith
(
"ETLScript="
)){
ReturnNode
returnNode
=
new
ReturnNode
();
returnNode
.
setId
(
baseNode
.
getMetadataId
());
returnNode
.
setName
(
baseNode
.
getName
());
if
(
metadataId
.
startsWith
(
"Table="
)){
returnNode
.
setType
(
"Table"
);
}
else
{
returnNode
.
setType
(
"ETLScript"
);
}
// 获取属性
// Map<String,String> attributeMap = getAttributeMap(metadataId);
// List<BaseNode> sourceEtlScriptBetween2TableList = neo4jTableRepository.getSourceEtlScriptBetween2Table(tableId, metadataId);
// Map<String,String> relationMap = new HashMap<>();
// for(BaseNode sourceEtlScriptBetween2Table:sourceEtlScriptBetween2TableList){
// relationMap.put("name",sourceEtlScriptBetween2Table.getName());
// relationMap.put("metadataId",sourceEtlScriptBetween2Table.getMetadataId());
// }
if
(!
sources
.
contains
(
returnNode
)){
sources
.
add
(
returnNode
);
}
// returnNode.setRelationMaps(relationMap);
// returnNode.setAttributeMaps(attributeMap);
}
else
{
getSource
(
metadataId
,
sources
);
}
}
}
private
List
<
ReturnNode
>
getCurrentTableInfo
(
String
tableId
)
{
Neo4jETLScript
neo4jETLScript
=
neo4jETLScriptRepository
.
findNeo4jETLScriptByMetadataId
(
tableId
);
List
<
ReturnNode
>
returnTableList
=
new
ArrayList
<>();
ReturnNode
returnNode
=
new
ReturnNode
();
returnNode
.
setId
(
neo4jETLScript
.
getMetadataId
());
returnNode
.
setName
(
neo4jETLScript
.
getName
());
returnNode
.
setType
(
"ETLScript"
);
returnTableList
.
add
(
returnNode
);
// 获取属性
// Map<String,String> attributeMap = getAttributeMap(tableId);
//
// returnNode.setAttributeMaps(attributeMap);
return
returnTableList
;
}
private
Map
<
String
,
String
>
getAttributeMap
(
String
EtlJobId
){
Map
<
String
,
String
>
returnMap
=
new
LinkedHashMap
<>();
Map
<
String
,
Object
>
attriuteMap
=
metadataRepoRemoteService
.
getMetadata
(
EtlJobId
);
...
...
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