caishunfeng commented on a change in pull request #7214:
URL: https://github.com/apache/dolphinscheduler/pull/7214#discussion_r775245787
##########
File path:
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java
##########
@@ -865,6 +883,166 @@ public DagDataSchedule
exportProcessDagData(ProcessDefinition processDefinition)
return result;
}
+ @Override
+ @Transactional(rollbackFor = RuntimeException.class)
+ public Map<String, Object> importSqlProcessDefinition(User loginUser, long
projectCode, MultipartFile file) {
Review comment:
I think the main point is not reuse but make code clearly and easy to
read.
And it can be more easier to replace some logic by another method too.
What do you think?
##########
File path:
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java
##########
@@ -865,6 +883,166 @@ public DagDataSchedule
exportProcessDagData(ProcessDefinition processDefinition)
return result;
}
+ @Override
+ @Transactional(rollbackFor = RuntimeException.class)
+ public Map<String, Object> importSqlProcessDefinition(User loginUser, long
projectCode, MultipartFile file) {
+ Map<String, Object> result = new HashMap<>();
+ String processDefinitionName = file.getOriginalFilename() == null ?
file.getName() : file.getOriginalFilename();
+ int index = processDefinitionName.lastIndexOf(".");
+ if (index > 0) {
+ processDefinitionName = processDefinitionName.substring(0, index);
+ }
+ processDefinitionName = processDefinitionName + "_import_" +
DateUtils.getCurrentTimeStamp();
+
+ ProcessDefinition processDefinition;
+ List<TaskDefinitionLog> taskDefinitionList = new ArrayList<>();
+ List<ProcessTaskRelationLog> processTaskRelationList = new
ArrayList<>();
+
+ // In most cases, there will be only one data source
+ Map<String, DataSource> dataSourceCache = new HashMap<>(1);
+ Map<String, Long> taskNameToCode = new HashMap<>(16);
+ Map<String, List<String>> taskNameToUpstream = new HashMap<>(16);
+ try (ZipInputStream zIn = new ZipInputStream(file.getInputStream());
+ BufferedReader bufferedReader = new BufferedReader(new
InputStreamReader(zIn))) {
+ // build process definition
+ processDefinition = new ProcessDefinition(projectCode,
+ processDefinitionName,
+ CodeGenerateUtils.getInstance().genCode(),
+ "",
+ "[]", null,
+ 0, loginUser.getId(), loginUser.getTenantId());
+ ZipEntry entry;
+ while ((entry = zIn.getNextEntry()) != null) {
+ if (!entry.isDirectory()) {
+ StringBuilder sql = new StringBuilder();
+ String taskName = null;
+ String datasourceName = null;
+ List<String> upstreams = Collections.emptyList();
+ String line;
+ while ((line = bufferedReader.readLine()) != null) {
+ int commentIndex = line.indexOf("-- ");
Review comment:
> Can you give me some examples
It seems that the import must contains `-- `, so it can add a check like
`if (commentIndex == -1){
throw new FormatException("error format, please check the format like
xxxx");
}`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]