package cn.axzo.workflow.core.service.impl;

import cn.axzo.workflow.core.common.exception.WorkflowEngineException;
import cn.axzo.workflow.core.service.BpmnProcessActivityService;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.runtime.ActivityInstance;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

@Service
@Slf4j
public class BpmnProcessActivityServiceImpl implements BpmnProcessActivityService {

    @Resource
    private RuntimeService runtimeService;

    @Override
    public void trigger(String processActivityId) {
        ActivityInstance activityInstance =
                runtimeService.createActivityInstanceQuery().activityInstanceId(processActivityId).singleResult();
        if (Objects.isNull(activityInstance)) {
            throw new WorkflowEngineException("");
        }
        runtimeService.trigger(activityInstance.getExecutionId());
    }
}
