use of org.wso2.carbon.bpmn.analytics.publisher.listeners.TaskCompletionListener in project carbon-business-process by wso2.
the class BPMNDataPublisher method configDataPublishing.
/**
* Configure for data publishing to DAS for analytics
*
* @param receiverURLSet Analytics receiver's url
* @param username Analytics server's username
* @param password Analytics server's password
* @param authURLSet Analytics Auth URL set
* @param type Bpmn Analytics Publisher Type
* @param asyncDataPublishingEnabled is async Data Publishing Enabled
* @param genericAnalyticsEnabled is generic Analytics Enabled
* @param kpiAnalyticsEnabled is KPI Analytics Enabled
* @throws DataEndpointAuthenticationException
* @throws DataEndpointAgentConfigurationException
* @throws TransportException
* @throws DataEndpointException
* @throws DataEndpointConfigurationException
*/
void configDataPublishing(String receiverURLSet, String username, String password, String authURLSet, String type, boolean asyncDataPublishingEnabled, boolean genericAnalyticsEnabled, boolean kpiAnalyticsEnabled) throws DataEndpointAuthenticationException, DataEndpointAgentConfigurationException, TransportException, DataEndpointException, DataEndpointConfigurationException {
if (receiverURLSet != null && username != null && password != null) {
// Configure data publisher to be used by all data publishing listeners
if (log.isDebugEnabled()) {
log.debug("Creating BPMN analytics data publisher with Receiver URL: " + receiverURLSet + ", Auth URL: " + authURLSet + " and Data publisher type: " + type);
}
dataPublisher = new DataPublisher(type, receiverURLSet, authURLSet, username, password);
BPMNAnalyticsHolder.getInstance().setAsyncDataPublishingEnabled(asyncDataPublishingEnabled);
BPMNEngineService engineService = BPMNAnalyticsHolder.getInstance().getBpmnEngineService();
// Attach data publishing listeners to all existing processes
if (log.isDebugEnabled()) {
log.debug("Attaching data publishing listeners to already deployed processes...");
}
RepositoryService repositoryService = engineService.getProcessEngine().getRepositoryService();
List<ProcessDefinition> processDefinitions = repositoryService.createProcessDefinitionQuery().list();
for (ProcessDefinition processDefinition : processDefinitions) {
// Process definition returned by the query does not contain all details such as task definitions.
// And it is also not the actual process definition, but a copy of it, so attaching listners to
// them is useless. Therefore, we have to fetch the complete process definition from the repository
// again.
ProcessDefinition completeProcessDefinition = repositoryService.getProcessDefinition(processDefinition.getId());
if (completeProcessDefinition instanceof ProcessDefinitionEntity) {
ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) completeProcessDefinition;
if (genericAnalyticsEnabled) {
processDefinitionEntity.addExecutionListener(PvmEvent.EVENTNAME_END, new ProcessTerminationListener());
}
if (kpiAnalyticsEnabled) {
processDefinitionEntity.addExecutionListener(PvmEvent.EVENTNAME_END, new ProcessTerminationKPIListener());
}
Map<String, TaskDefinition> tasks = processDefinitionEntity.getTaskDefinitions();
List<ActivityImpl> activities = processDefinitionEntity.getActivities();
for (ActivityImpl activity : activities) {
if (activity.getProperty("type").toString().equalsIgnoreCase("usertask")) {
tasks.get(activity.getId()).addTaskListener(TaskListener.EVENTNAME_COMPLETE, new TaskCompletionListener());
}
// We are publishing analytics data of service tasks in process termination ATM.
// else if(activity.getProperty("type").toString().equalsIgnoreCase("servicetask")){
// activity.addExecutionListener(PvmEvent.EVENTNAME_END,new
// ServiceTaskCompletionListener());
// }
}
}
}
// Configure parse handlers, which attaches data publishing listeners to new processes
if (log.isDebugEnabled()) {
log.debug("Associating parse handlers for processes and tasks, so that data publishing listeners " + "will be attached to new processes.");
}
ProcessEngineConfigurationImpl engineConfig = (ProcessEngineConfigurationImpl) engineService.getProcessEngine().getProcessEngineConfiguration();
if (engineConfig.getPostBpmnParseHandlers() == null) {
engineConfig.setPostBpmnParseHandlers(new ArrayList<BpmnParseHandler>());
}
if (genericAnalyticsEnabled) {
engineConfig.getPostBpmnParseHandlers().add(new ProcessParseHandler());
engineConfig.getPostBpmnParseHandlers().add(new TaskParseHandler());
engineConfig.getBpmnDeployer().getBpmnParser().getBpmnParserHandlers().addHandler(new ProcessParseHandler());
engineConfig.getBpmnDeployer().getBpmnParser().getBpmnParserHandlers().addHandler(new TaskParseHandler());
}
if (kpiAnalyticsEnabled) {
engineConfig.getPostBpmnParseHandlers().add(new ProcessKPIParseHandler());
engineConfig.getBpmnDeployer().getBpmnParser().getBpmnParserHandlers().addHandler(new ProcessKPIParseHandler());
}
} else {
log.warn("Required fields for data publisher are not configured. Receiver URLs, username and password " + "are mandatory. Data publishing will not be enabled.");
}
}
use of org.wso2.carbon.bpmn.analytics.publisher.listeners.TaskCompletionListener 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);
}
}
use of org.wso2.carbon.bpmn.analytics.publisher.listeners.TaskCompletionListener in project carbon-business-process by wso2.
the class TaskParseHandler method executeParse.
@Override
protected void executeParse(BpmnParse bpmnParse, BaseElement element) {
TaskDefinition taskDefinition = (TaskDefinition) bpmnParse.getCurrentActivity().getProperty(UserTaskParseHandler.PROPERTY_TASK_DEFINITION);
// We have to check if data publishing listener has already been associated at server startup
TaskListener taskCompletionListener = null;
List<TaskListener> completionListeners = taskDefinition.getTaskListener(TaskListener.EVENTNAME_COMPLETE);
if (completionListeners != null) {
for (TaskListener listener : completionListeners) {
if (listener instanceof TaskCompletionListener) {
taskCompletionListener = listener;
break;
}
}
}
if (taskCompletionListener == null) {
if (log.isDebugEnabled()) {
log.debug("Adding data publishing listener to task: " + taskDefinition.getKey());
}
taskDefinition.addTaskListener(TaskListener.EVENTNAME_COMPLETE, new TaskCompletionListener());
}
}
Aggregations