From 4283cfd7a1c928aa370324a19dc6dffdd67040f6 Mon Sep 17 00:00:00 2001 From: Tq Date: Mon, 5 Sep 2022 20:29:03 +0800 Subject: [PATCH] [fix][API]fix task types sequence (#11775) * fix task types sequence * fix mapper table name t_ds_fav_task * fix sequence --- .../configuration/TaskTypeConfiguration.java | 41 +++++++++++++++---- .../dolphinscheduler/api/dto/FavTaskDto.java | 7 +++- .../api/service/impl/FavTaskServiceImpl.java | 6 +-- .../dao/mapper/FavTaskMapper.xml | 4 +- 4 files changed, 42 insertions(+), 16 deletions(-) diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/configuration/TaskTypeConfiguration.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/configuration/TaskTypeConfiguration.java index 448f2d55b5..1db441495d 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/configuration/TaskTypeConfiguration.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/configuration/TaskTypeConfiguration.java @@ -17,19 +17,22 @@ package org.apache.dolphinscheduler.api.configuration; -import lombok.Getter; -import lombok.Setter; import org.apache.dolphinscheduler.api.dto.FavTaskDto; import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.config.YamlPropertySourceFactory; + +import java.util.ArrayList; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.PropertySource; import org.springframework.stereotype.Component; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import lombok.Getter; +import lombok.Setter; @Component @EnableConfigurationProperties @@ -39,18 +42,21 @@ import java.util.Set; @Setter public class TaskTypeConfiguration { + private static final Logger logger = LoggerFactory.getLogger(TaskTypeConfiguration.class); + private List universal; private List cloud; private List logic; private List dataIntegration; private List dataQuality; private List other; - private List machineLearning; - public Set getDefaultTaskTypes() { - Set defaultTaskTypes = new HashSet<>(); + private static final List defaultTaskTypes = new ArrayList<>(); + + public List getDefaultTaskTypes() { if (defaultTaskTypes.size() <= 0) { + printDefaultTypes(); universal.forEach(task -> defaultTaskTypes.add(new FavTaskDto(task, false, Constants.TYPE_UNIVERSAL))); cloud.forEach(task -> defaultTaskTypes.add(new FavTaskDto(task, false, Constants.TYPE_CLOUD))); logic.forEach(task -> defaultTaskTypes.add(new FavTaskDto(task, false, Constants.TYPE_LOGIC))); @@ -60,7 +66,24 @@ public class TaskTypeConfiguration { other.forEach(task -> defaultTaskTypes.add(new FavTaskDto(task, false, Constants.TYPE_OTHER))); } + List result = new ArrayList<>(); + defaultTaskTypes.forEach(e -> { + try { + result.add((FavTaskDto) e.clone()); + } catch (CloneNotSupportedException ex) { + throw new RuntimeException(ex); + } + }); + return result; + } - return defaultTaskTypes; + public void printDefaultTypes() { + logger.info("support default universal task types: {}", universal); + logger.info("support default cloud task types: {}", cloud); + logger.info("support default logic task types: {}", logic); + logger.info("support default dataIntegration task types: {}", dataIntegration); + logger.info("support default dataQuality task types: {}", dataQuality); + logger.info("support default machineLearning task types: {}", machineLearning); + logger.info("support default other task types: {}", other); } } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/FavTaskDto.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/FavTaskDto.java index 91e107b5ad..71a8b5299d 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/FavTaskDto.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/FavTaskDto.java @@ -26,7 +26,7 @@ import lombok.Setter; @Getter @Setter @AllArgsConstructor -public class FavTaskDto { +public class FavTaskDto implements Cloneable { private String taskName; private boolean isCollection; @@ -46,4 +46,9 @@ public class FavTaskDto { public int hashCode() { return super.hashCode(); } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/FavTaskServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/FavTaskServiceImpl.java index fb13d548fb..81019b08ec 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/FavTaskServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/FavTaskServiceImpl.java @@ -40,17 +40,15 @@ public class FavTaskServiceImpl extends BaseServiceImpl implements FavTaskServic @Override public List getFavTaskList(User loginUser) { - List result = new ArrayList<>(); Set userFavTaskTypes = favMapper.getUserFavTaskTypes(loginUser.getId()); - Set defaultTaskTypes = taskTypeConfiguration.getDefaultTaskTypes(); + List defaultTaskTypes = taskTypeConfiguration.getDefaultTaskTypes(); defaultTaskTypes.forEach(e -> { if (userFavTaskTypes.contains(e.getTaskName())) { e.setCollection(true); } - result.add(e); }); - return result; + return defaultTaskTypes; } @Override diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/FavTaskMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/FavTaskMapper.xml index c5da1bf7a9..891529bb04 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/FavTaskMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/FavTaskMapper.xml @@ -21,13 +21,13 @@ delete - from t_ds_fav + from t_ds_fav_task where user_id = #{userId} and task_name = #{taskName}