Skip to content

Commit

Permalink
fix: delete automation trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
zoe-icu committed Mar 12, 2024
1 parent 698a296 commit 28f62f2
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
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,19 @@ public void deleteByDatabus(String robotId, String triggerId, Long userId) {
}
}

@Override
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.getTriggerId().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();
}
}

0 comments on commit 28f62f2

Please sign in to comment.