Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public ResponseData<Void> 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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -182,6 +183,20 @@ public void deleteByDatabus(String robotId, String triggerId, Long userId) {
}
}

@Override
Copy link
Collaborator

@ChambersChan ChambersChan Mar 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+事务

@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<String, String> newRobotMap,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

}
}
Original file line number Diff line number Diff line change
@@ -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<AutomationTriggerDto> triggers = iAutomationTriggerService.getTriggersByRobotIds(
Collections.singletonList(trigger.getRobotId()));
assertThat(triggers).isEmpty();
}
}