From 69aeb706db5f58d6147ef43edab21b1468803fd2 Mon Sep 17 00:00:00 2001 From: Zoe Date: Tue, 12 Mar 2024 11:40:05 +0800 Subject: [PATCH] fix: delete automation trigger (#1657) Co-authored-by: Zoe <13400804+zoe-icu@users.noreply.github.com> --- .../controller/AutomationRobotController.java | 2 +- .../service/IAutomationTriggerService.java | 10 ++++++ .../impl/AutomationTriggerServiceImpl.java | 15 ++++++++ .../facede/AutomationServiceFacade.java | 8 +++++ .../DefaultAutomationServiceFacadeImpl.java | 5 +++ .../AutomationTriggerServiceImplTest.java | 34 +++++++++++++++++++ 6 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 backend-server/application/src/test/java/com/apitable/automation/service/impl/AutomationTriggerServiceImplTest.java diff --git a/backend-server/application/src/main/java/com/apitable/automation/controller/AutomationRobotController.java b/backend-server/application/src/main/java/com/apitable/automation/controller/AutomationRobotController.java index 1a9abffc38..b76379ab4a 100644 --- a/backend-server/application/src/main/java/com/apitable/automation/controller/AutomationRobotController.java +++ b/backend-server/application/src/main/java/com/apitable/automation/controller/AutomationRobotController.java @@ -328,7 +328,7 @@ public ResponseData deleteTrigger(@PathVariable String resourceId, iPermissionService.checkPermissionBySessionOrShare(resourceId, null, NodePermission.EDIT_NODE, status -> ExceptionUtil.isTrue(status, PermissionException.NODE_OPERATION_DENIED)); - iAutomationTriggerService.deleteByDatabus(robotId, triggerId, userId); + iAutomationTriggerService.deleteByTriggerId(robotId, triggerId, userId); return ResponseData.success(); } diff --git a/backend-server/application/src/main/java/com/apitable/automation/service/IAutomationTriggerService.java b/backend-server/application/src/main/java/com/apitable/automation/service/IAutomationTriggerService.java index a7837bbc4f..868a887830 100644 --- a/backend-server/application/src/main/java/com/apitable/automation/service/IAutomationTriggerService.java +++ b/backend-server/application/src/main/java/com/apitable/automation/service/IAutomationTriggerService.java @@ -79,6 +79,16 @@ public interface IAutomationTriggerService { */ void deleteByDatabus(String robotId, String triggerId, Long userId); + + /** + * Delete trigger. + * + * @param robotId robot id + * @param triggerId trigger id + * @param userId operator user id + */ + void deleteByTriggerId(String robotId, String triggerId, Long userId); + /** * copy trigger. * diff --git a/backend-server/application/src/main/java/com/apitable/automation/service/impl/AutomationTriggerServiceImpl.java b/backend-server/application/src/main/java/com/apitable/automation/service/impl/AutomationTriggerServiceImpl.java index 4caf029673..46584d5414 100644 --- a/backend-server/application/src/main/java/com/apitable/automation/service/impl/AutomationTriggerServiceImpl.java +++ b/backend-server/application/src/main/java/com/apitable/automation/service/impl/AutomationTriggerServiceImpl.java @@ -29,6 +29,7 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONUtil; +import com.apitable.automation.entity.AutomationRobotEntity; import com.apitable.automation.entity.AutomationTriggerEntity; import com.apitable.automation.enums.AutomationTriggerType; import com.apitable.automation.mapper.AutomationTriggerMapper; @@ -182,6 +183,20 @@ public void deleteByDatabus(String robotId, String triggerId, Long userId) { } } + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteByTriggerId(String robotId, String triggerId, Long userId) { + AutomationTriggerEntity trigger = triggerMapper.selectByTriggerId(triggerId); + ExceptionUtil.isNotNull(trigger, AUTOMATION_TRIGGER_NOT_EXIST); + String scheduleTriggerTypeId = iAutomationTriggerTypeService.getTriggerTypeByEndpoint( + AutomationTriggerType.SCHEDULED_TIME_ARRIVE.getType()); + if (trigger.getTriggerTypeId().equals(scheduleTriggerTypeId)) { + automationServiceFacade.deleteSchedule(triggerId, userId); + } + triggerMapper.deleteById(trigger.getId()); + iAutomationRobotService.updateUpdaterByRobotId(robotId, userId); + } + @Override public TriggerCopyResultDto copy(Long userId, AutomationCopyOptions options, Map newRobotMap, diff --git a/backend-server/application/src/main/java/com/apitable/interfaces/automation/facede/AutomationServiceFacade.java b/backend-server/application/src/main/java/com/apitable/interfaces/automation/facede/AutomationServiceFacade.java index 976499e8a4..bbdc79dd64 100644 --- a/backend-server/application/src/main/java/com/apitable/interfaces/automation/facede/AutomationServiceFacade.java +++ b/backend-server/application/src/main/java/com/apitable/interfaces/automation/facede/AutomationServiceFacade.java @@ -54,4 +54,12 @@ public interface AutomationServiceFacade { * @param scheduleConfig config */ void updateSchedule(String triggerId, String scheduleConfig); + + /** + * delete schedule. + * + * @param triggerId trigger id + * @param userId user id + */ + void deleteSchedule(String triggerId, Long userId); } diff --git a/backend-server/application/src/main/java/com/apitable/interfaces/automation/facede/DefaultAutomationServiceFacadeImpl.java b/backend-server/application/src/main/java/com/apitable/interfaces/automation/facede/DefaultAutomationServiceFacadeImpl.java index d66e56198b..0aa11f45c7 100644 --- a/backend-server/application/src/main/java/com/apitable/interfaces/automation/facede/DefaultAutomationServiceFacadeImpl.java +++ b/backend-server/application/src/main/java/com/apitable/interfaces/automation/facede/DefaultAutomationServiceFacadeImpl.java @@ -43,4 +43,9 @@ public void createSchedule(String spaceId, String triggerId, String scheduleConf public void updateSchedule(String triggerId, String scheduleConfig) { } + + @Override + public void deleteSchedule(String triggerId, Long userId) { + + } } diff --git a/backend-server/application/src/test/java/com/apitable/automation/service/impl/AutomationTriggerServiceImplTest.java b/backend-server/application/src/test/java/com/apitable/automation/service/impl/AutomationTriggerServiceImplTest.java new file mode 100644 index 0000000000..4594b16335 --- /dev/null +++ b/backend-server/application/src/test/java/com/apitable/automation/service/impl/AutomationTriggerServiceImplTest.java @@ -0,0 +1,34 @@ +package com.apitable.automation.service.impl; + + +import static org.assertj.core.api.Assertions.assertThat; + +import com.apitable.AbstractIntegrationTest; +import com.apitable.automation.entity.AutomationTriggerEntity; +import com.apitable.automation.model.AutomationTriggerDto; +import com.apitable.mock.bean.MockUserSpace; +import com.apitable.shared.util.IdUtil; +import com.baomidou.mybatisplus.core.toolkit.IdWorker; +import java.math.BigInteger; +import java.util.Collections; +import java.util.List; +import org.junit.jupiter.api.Test; + +public class AutomationTriggerServiceImplTest extends AbstractIntegrationTest { + @Test + public void testDeleteAutomationTrigger() { + MockUserSpace userSpace = createSingleUserAndSpace(); + AutomationTriggerEntity trigger = AutomationTriggerEntity.builder() + .id(BigInteger.valueOf(IdWorker.getId())) + .robotId(IdUtil.createAutomationRobotId()) + .triggerId(IdUtil.createAutomationTriggerId()) + .triggerTypeId(IdUtil.createAutomationTriggerTypeId()) + .build(); + iAutomationTriggerService.create(trigger); + iAutomationTriggerService.deleteByTriggerId(trigger.getRobotId(), trigger.getTriggerId(), + userSpace.getUserId()); + List triggers = iAutomationTriggerService.getTriggersByRobotIds( + Collections.singletonList(trigger.getRobotId())); + assertThat(triggers).isEmpty(); + } +}