Search in sources :

Example 1 with BPMNRestException

use of org.wso2.carbon.bpmn.rest.common.exception.BPMNRestException in project carbon-business-process by wso2.

the class ProcessInstanceService method createBinaryExecutionVariable.

@POST
@Path("/{processInstanceId}/variables")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response createBinaryExecutionVariable(@PathParam("processInstanceId") String processInstanceId, @Context HttpServletRequest httpServletRequest, MultipartBody multipartBody) {
    Execution execution = getExecutionInstanceFromRequest(processInstanceId);
    Response response;
    try {
        response = createBinaryExecutionVariable(execution, false, RestResponseFactory.VARIABLE_PROCESS, multipartBody);
    } catch (IOException | ServletException e) {
        throw new BPMNRestException("Exception occured during creating binary execution variable", e);
    }
    return response;
}
Also used : DataResponse(org.wso2.carbon.bpmn.rest.model.common.DataResponse) Response(javax.ws.rs.core.Response) ProcessInstanceResponse(org.wso2.carbon.bpmn.rest.model.runtime.ProcessInstanceResponse) ServletException(javax.servlet.ServletException) Execution(org.activiti.engine.runtime.Execution) BPMNRestException(org.wso2.carbon.bpmn.rest.common.exception.BPMNRestException) IOException(java.io.IOException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 2 with BPMNRestException

use of org.wso2.carbon.bpmn.rest.common.exception.BPMNRestException in project carbon-business-process by wso2.

the class ProcessInstanceService method createOrUpdateExecutionVariable.

@PUT
@Path("/{processInstanceId}/variables")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response createOrUpdateExecutionVariable(@PathParam("processInstanceId") String processInstanceId, @Context HttpServletRequest httpServletRequest) {
    Execution execution = getExecutionInstanceFromRequest(processInstanceId);
    Response result;
    try {
        result = createExecutionVariable(execution, true, RestResponseFactory.VARIABLE_PROCESS, httpServletRequest);
    } catch (IOException | ServletException e) {
        throw new BPMNRestException("Exception occured during creating execution variable", e);
    }
    return result;
}
Also used : DataResponse(org.wso2.carbon.bpmn.rest.model.common.DataResponse) Response(javax.ws.rs.core.Response) ProcessInstanceResponse(org.wso2.carbon.bpmn.rest.model.runtime.ProcessInstanceResponse) ServletException(javax.servlet.ServletException) Execution(org.activiti.engine.runtime.Execution) BPMNRestException(org.wso2.carbon.bpmn.rest.common.exception.BPMNRestException) IOException(java.io.IOException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 3 with BPMNRestException

use of org.wso2.carbon.bpmn.rest.common.exception.BPMNRestException in project carbon-business-process by wso2.

the class AnalyticsConfigurationService method configureProcessLevelEvents.

@PUT
@Path("/processes/{process_id}")
@Consumes({ MediaType.APPLICATION_JSON })
public void configureProcessLevelEvents(@PathParam("process_id") String processDefinitionId, DataPublisherConfig dataPublisherConfig) {
    try {
        RepositoryService repositoryService = BPMNOSGIService.getRepositoryService();
        ProcessDefinition process = repositoryService.getProcessDefinition(processDefinitionId);
        if (process != null && process instanceof ProcessDefinitionEntity) {
            ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) process;
            if (dataPublisherConfig.isEnabled()) {
                List<ExecutionListener> endListeners = processDefinitionEntity.getExecutionListeners(PvmEvent.EVENTNAME_END);
                ExecutionListener processTerminationListener = null;
                for (ExecutionListener listener : endListeners) {
                    if (listener instanceof ProcessTerminationListener) {
                        processTerminationListener = listener;
                        break;
                    }
                }
                if (processTerminationListener == null) {
                    if (log.isDebugEnabled()) {
                        log.debug("Adding process termination listener to process: " + processDefinitionId);
                    }
                    processDefinitionEntity.addExecutionListener(PvmEvent.EVENTNAME_END, new ProcessTerminationListener());
                }
            } else {
                List<ExecutionListener> endListeners = processDefinitionEntity.getExecutionListeners(PvmEvent.EVENTNAME_END);
                ExecutionListener processTerminationListener = null;
                for (ExecutionListener listener : endListeners) {
                    if (listener instanceof ProcessTerminationListener) {
                        processTerminationListener = listener;
                        break;
                    }
                }
                if (processTerminationListener != null) {
                    if (log.isDebugEnabled()) {
                        log.debug("Removing process termination listener from process: " + processDefinitionId);
                    }
                    endListeners.remove(processTerminationListener);
                }
            }
        }
    } catch (Exception e) {
        String msg = "Failed to configure events for process: " + processDefinitionId;
        log.error(msg, e);
        throw new BPMNRestException(msg, e);
    }
}
Also used : ProcessTerminationListener(org.wso2.carbon.bpmn.analytics.publisher.listeners.ProcessTerminationListener) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) BPMNRestException(org.wso2.carbon.bpmn.rest.common.exception.BPMNRestException) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) BPMNRestException(org.wso2.carbon.bpmn.rest.common.exception.BPMNRestException) RepositoryService(org.activiti.engine.RepositoryService) ExecutionListener(org.activiti.engine.delegate.ExecutionListener)

Example 4 with BPMNRestException

use of org.wso2.carbon.bpmn.rest.common.exception.BPMNRestException in project carbon-business-process by wso2.

the class AnalyticsConfigurationService method configureTaskLevelEvents.

@PUT
@Path("/processes/{process_id}/tasks/{task_id}")
@Consumes({ MediaType.APPLICATION_JSON })
public void configureTaskLevelEvents(@PathParam("process_id") String processDefinitionId, @PathParam("task_id") String taskId, DataPublisherConfig dataPublisherConfig) {
    try {
        RepositoryService repositoryService = BPMNOSGIService.getRepositoryService();
        ProcessDefinition process = repositoryService.getProcessDefinition(processDefinitionId);
        if (process != null && process instanceof ProcessDefinitionEntity) {
            ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) process;
            Map<String, TaskDefinition> taskDefinitions = processDefinitionEntity.getTaskDefinitions();
            TaskDefinition taskDefinition = taskDefinitions.get(taskId);
            if (taskDefinition != null) {
                if (dataPublisherConfig.isEnabled()) {
                    List<TaskListener> completionListeners = taskDefinition.getTaskListener(TaskListener.EVENTNAME_COMPLETE);
                    TaskListener taskCompletionListener = null;
                    for (TaskListener listener : completionListeners) {
                        if (listener instanceof TaskCompletionListener) {
                            taskCompletionListener = listener;
                            break;
                        }
                    }
                    if (taskCompletionListener == null) {
                        if (log.isDebugEnabled()) {
                            log.debug("Adding task completion listener to task: " + taskId + " of process: " + processDefinitionId);
                        }
                        taskDefinition.addTaskListener(TaskListener.EVENTNAME_COMPLETE, new TaskCompletionListener());
                    }
                } else {
                    List<TaskListener> completionListeners = taskDefinition.getTaskListener(TaskListener.EVENTNAME_COMPLETE);
                    TaskListener taskCompletionListener = null;
                    for (TaskListener listener : completionListeners) {
                        if (listener instanceof TaskCompletionListener) {
                            taskCompletionListener = listener;
                            break;
                        }
                    }
                    if (taskCompletionListener != null) {
                        if (log.isDebugEnabled()) {
                            log.debug("Removing task completion listener from task: " + taskId + " of process: " + processDefinitionId);
                        }
                        completionListeners.remove(taskCompletionListener);
                    }
                }
            }
        }
    } catch (Exception e) {
        String msg = "Failed to configure events for task: " + taskId + " of process: " + processDefinitionId;
        log.error(msg, e);
        throw new BPMNRestException(msg, e);
    }
}
Also used : TaskCompletionListener(org.wso2.carbon.bpmn.analytics.publisher.listeners.TaskCompletionListener) TaskDefinition(org.activiti.engine.impl.task.TaskDefinition) TaskListener(org.activiti.engine.delegate.TaskListener) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) BPMNRestException(org.wso2.carbon.bpmn.rest.common.exception.BPMNRestException) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) BPMNRestException(org.wso2.carbon.bpmn.rest.common.exception.BPMNRestException) RepositoryService(org.activiti.engine.RepositoryService)

Example 5 with BPMNRestException

use of org.wso2.carbon.bpmn.rest.common.exception.BPMNRestException in project carbon-business-process by wso2.

the class ProcessInstanceService method createOrUpdateBinaryExecutionVariable.

@PUT
@Path("/{processInstanceId}/variables")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response createOrUpdateBinaryExecutionVariable(@PathParam("processInstanceId") String processInstanceId, MultipartBody multipartBody) {
    Execution execution = getExecutionInstanceFromRequest(processInstanceId);
    Response response;
    try {
        response = createBinaryExecutionVariable(execution, true, RestResponseFactory.VARIABLE_PROCESS, multipartBody);
    } catch (IOException | ServletException e) {
        throw new BPMNRestException("Exception occured during creating execution variable", e);
    }
    return response;
}
Also used : DataResponse(org.wso2.carbon.bpmn.rest.model.common.DataResponse) Response(javax.ws.rs.core.Response) ProcessInstanceResponse(org.wso2.carbon.bpmn.rest.model.runtime.ProcessInstanceResponse) ServletException(javax.servlet.ServletException) Execution(org.activiti.engine.runtime.Execution) BPMNRestException(org.wso2.carbon.bpmn.rest.common.exception.BPMNRestException) IOException(java.io.IOException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Aggregations

BPMNRestException (org.wso2.carbon.bpmn.rest.common.exception.BPMNRestException)7 IOException (java.io.IOException)5 ServletException (javax.servlet.ServletException)5 Consumes (javax.ws.rs.Consumes)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 Execution (org.activiti.engine.runtime.Execution)5 Response (javax.ws.rs.core.Response)4 DataResponse (org.wso2.carbon.bpmn.rest.model.common.DataResponse)4 ProcessInstanceResponse (org.wso2.carbon.bpmn.rest.model.runtime.ProcessInstanceResponse)4 PUT (javax.ws.rs.PUT)3 POST (javax.ws.rs.POST)2 RepositoryService (org.activiti.engine.RepositoryService)2 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)2 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)2 ExecutionListener (org.activiti.engine.delegate.ExecutionListener)1 TaskListener (org.activiti.engine.delegate.TaskListener)1 TaskDefinition (org.activiti.engine.impl.task.TaskDefinition)1 ProcessTerminationListener (org.wso2.carbon.bpmn.analytics.publisher.listeners.ProcessTerminationListener)1 TaskCompletionListener (org.wso2.carbon.bpmn.analytics.publisher.listeners.TaskCompletionListener)1