package org.sanelib.eboss.api.services;

import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.sanelib.eboss.api.dto.BaseDTO;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.Map;

public class ApiServiceBase {

    @Autowired
    RuntimeService runtimeService;

    @Autowired
    TaskService taskService;

    public void execute(BaseDTO dto, String processKey) throws Exception {
        Map<String, Object> variables = new HashMap<>();
        variables.put("dto", dto);
        runtimeService.startProcessInstanceByKey(processKey, variables);
    }

}

@@ -132,37 +132,135 @@
 org.
-sanelib.eboss.api.dto.BaseDTO
+activiti.engine.runtime.ProcessInstance;%0Aimport org.sanelib.eboss.api.dto.BaseDTO;%0Aimport org.sanelib.eboss.core.dao.UnitOfWork
 ;%0Aim
@@ -377,16 +377,25 @@
 %0Apublic 
+abstract 
 class Ap
@@ -510,22 +510,68 @@
 e;%0A%0A    
-public
+@Autowired%0A    UnitOfWork unitOfWork;%0A%0A    protected
  void ex
@@ -611,25 +611,8 @@
 Key)
- throws Exception
  %7B%0A 
@@ -702,24 +702,25 @@
 , dto);%0A
+%0A
         
 runtimeS
@@ -715,72 +715,373 @@
     
-runtimeService.startProcessInstanceByKey(processKey, variables);
+try %7B%0A            unitOfWork.begin();%0A            ProcessInstance instance = runtimeService.startProcessInstanceByKey(processKey, variables);%0A            System.out.println(instance.getId());%0A            unitOfWork.commit();%0A        %7D catch (Exception exception)%7B%0A            System.out.println(exception.getMessage());%0A            unitOfWork.rollback();%0A        %7D%0A
 %0A   

Modify ApiServiceBase for Transaction support.