You've already forked DataMate
fix: prevent deletion of predefined operators and improve error handling (#192)
* fix: prevent deletion of predefined operators and improve error handling * fix: prevent deletion of predefined operators and improve error handling
This commit is contained in:
@@ -95,6 +95,9 @@ public class OperatorService {
|
||||
if (operatorRepo.operatorInTemplateOrRunning(id)) {
|
||||
throw BusinessException.of(OperatorErrorCode.OPERATOR_IN_INSTANCE);
|
||||
}
|
||||
if (relationRepo.operatorIsPredefined(id)) {
|
||||
throw BusinessException.of(OperatorErrorCode.CANT_DELETE_PREDEFINED_OPERATOR);
|
||||
}
|
||||
operatorRepo.deleteOperator(id);
|
||||
relationRepo.deleteByOperatorId(id);
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ public class OperatorConstant {
|
||||
|
||||
public static String CATEGORY_STAR_ID = "51847c24-bba9-11f0-888b-5b143cb738aa";
|
||||
|
||||
public static String CATEGORY_PREDEFINED_ID = "96a3b07a-3439-4557-a835-525faad60ca3";
|
||||
|
||||
public static Map<String, String> CATEGORY_MAP = new HashMap<>();
|
||||
|
||||
static {
|
||||
|
||||
@@ -15,4 +15,6 @@ public interface CategoryRelationRepository extends IRepository<CategoryRelation
|
||||
void batchUpdate(String operatorId, List<String> categories);
|
||||
|
||||
void deleteByOperatorId(String operatorId);
|
||||
|
||||
boolean operatorIsPredefined(String operatorId);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,9 @@ public enum OperatorErrorCode implements ErrorCode {
|
||||
|
||||
SETTINGS_PARSE_FAILED("op.0004", "settings字段解析失败"),
|
||||
|
||||
OPERATOR_IN_INSTANCE("op.0005", "算子已被编排在模板或未完成的任务中");
|
||||
OPERATOR_IN_INSTANCE("op.0005", "算子已被编排在模板或未完成的任务中"),
|
||||
|
||||
CANT_DELETE_PREDEFINED_OPERATOR("op.0006", "预置算子无法删除");
|
||||
|
||||
private final String code;
|
||||
private final String message;
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.datamate.operator.infrastructure.persistence.Impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.repository.CrudRepository;
|
||||
import com.datamate.operator.domain.contants.OperatorConstant;
|
||||
import com.datamate.operator.domain.model.CategoryRelation;
|
||||
import com.datamate.operator.domain.repository.CategoryRelationRepository;
|
||||
import com.datamate.operator.infrastructure.converter.CategoryRelationConverter;
|
||||
@@ -48,4 +49,12 @@ public class CategoryRelationRepositoryImpl extends CrudRepository<CategoryRelat
|
||||
queryWrapper.eq(CategoryRelation::getOperatorId, operatorId);
|
||||
mapper.delete(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean operatorIsPredefined(String operatorId) {
|
||||
LambdaQueryWrapper<CategoryRelation> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(CategoryRelation::getOperatorId, operatorId)
|
||||
.eq(CategoryRelation::getCategoryId, OperatorConstant.CATEGORY_PREDEFINED_ID);
|
||||
return this.exists(queryWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user