Search in sources :

Example 1 with BPMNDataPublisherException

use of org.wso2.carbon.bpmn.analytics.publisher.BPMNDataPublisherException in project carbon-business-process by wso2.

the class BPMNAnalyticsServiceComponent method initAnalyticsServer.

// Initializing the analytics server .
private void initAnalyticsServer(BPMNAnalyticsHolder bpmnAnalyticsHolder) throws BPMNDataPublisherException {
    bpmnAnalyticsHolder.setBPSAnalyticsServer(new BPSAnalyticsServer());
    bpmnAnalyticsHolder.getBPSAnalyticsServer().init();
}
Also used : BPSAnalyticsServer(org.wso2.carbon.bpmn.analytics.publisher.BPSAnalyticsServer)

Example 2 with BPMNDataPublisherException

use of org.wso2.carbon.bpmn.analytics.publisher.BPMNDataPublisherException in project carbon-business-process by wso2.

the class ProcessTerminationKPIListener method notify.

@Override
public void notify(DelegateExecution delegateExecution) throws IOException {
    try {
        List<ProcessInstance> runtimeProcessInstances = delegateExecution.getEngineServices().getRuntimeService().createProcessInstanceQuery().processInstanceId(delegateExecution.getProcessInstanceId()).list();
        if (runtimeProcessInstances.size() == 1) {
            ProcessInstance runtimeProcessInstance = runtimeProcessInstances.get(0);
            BPMNAnalyticsHolder.getInstance().getBpmnDataPublisher().publishKPIvariableData(runtimeProcessInstance);
        }
    } catch (BPMNDataPublisherException e) {
        String errMsg = "Process Variable Data Publishing failed.";
        log.error(errMsg, e);
    // Caught exception is not thrown as we do not need to stop the process termination, due to an error in
    // process data publishing (for analytics)
    }
}
Also used : ProcessInstance(org.activiti.engine.runtime.ProcessInstance) BPMNDataPublisherException(org.wso2.carbon.bpmn.analytics.publisher.BPMNDataPublisherException)

Example 3 with BPMNDataPublisherException

use of org.wso2.carbon.bpmn.analytics.publisher.BPMNDataPublisherException in project carbon-business-process by wso2.

the class BPMNDataPublisher method publishKPIvariableData.

/**
 * Publish the separate event to the DAS for the process variables for the called process instance
 *
 * @param processInstance process instance object
 * @throws BPMNDataPublisherException
 * @throws IOException
 */
public void publishKPIvariableData(ProcessInstance processInstance) throws BPMNDataPublisherException, IOException {
    String processDefinitionId = processInstance.getProcessDefinitionId();
    String processInstanceId = processInstance.getId();
    String eventStreamId;
    Object[] payload = new Object[0];
    try {
        JsonNode kpiConfig = getKPIConfiguration(processDefinitionId);
        // do not publish the KPI event if DAS configurations are not done by the PC
        if (kpiConfig == null) {
            return;
        }
        JsonNode configedProcessVariables = kpiConfig.withArray(AnalyticsPublisherConstants.PROCESS_VARIABLES_JSON_ENTRY_NAME);
        if (log.isDebugEnabled()) {
            log.debug("Publishing Process Variables (KPI) for the process instance " + processInstanceId + " of the " + "process : " + processDefinitionId);
        }
        /* Keeps configured process variable data as a JSON. These variables are sent as payload data to DAS.
            Example value:
            [{"name":"processInstanceId","type":"string","isAnalyzeData":"false","isDrillDownData":"false"},
            {"name":"valuesAvailability","type":"string","isAnalyzeData":"false","isDrillDownData":"false"},
            {"name":"custid","type":"string","isAnalyzeData":false,"isDrillDownData":false},
            {"name":"amount","type":"long","isAnalyzeData":false,"isDrillDownData":false},
            {"name":"confirm","type":"bool","isAnalyzeData":false,"isDrillDownData":false}]
            */
        JsonNode fieldsConfigedForStreamPayload = kpiConfig.withArray(AnalyticsPublisherConstants.PROCESS_VARIABLES_JSON_ENTRY_NAME);
        eventStreamId = kpiConfig.get("eventStreamId").textValue();
        Map<String, VariableInstance> variableInstances = ((ExecutionEntity) processInstance).getVariableInstances();
        payload = new Object[fieldsConfigedForStreamPayload.size()];
        // set process instance id as the 1st payload variable value
        payload[0] = processInstanceId;
        // availability of values for each process variable is represented by this char array as '1' (value available)
        // or '0' (not available) in respective array index
        char[] valueAvailabiliy = new char[fieldsConfigedForStreamPayload.size() - 2];
        for (int i = 2; i < configedProcessVariables.size(); i++) {
            String varName = (fieldsConfigedForStreamPayload.get(i)).get("name").textValue();
            String varType = (fieldsConfigedForStreamPayload.get(i)).get("type").textValue();
            Object varValue = variableInstances.get(varName).getValue();
            switch(varType) {
                case "int":
                    if (varValue == null) {
                        payload[i] = 0;
                        valueAvailabiliy[i - 2] = PROC_VAR_VALUE_UNAVAILABLE;
                    } else {
                        payload[i] = Integer.parseInt(varValue.toString());
                        valueAvailabiliy[i - 2] = PROC_VAR_VALUE_AVAILABLE;
                    }
                    break;
                case "float":
                    if (varValue == null) {
                        payload[i] = 0;
                        valueAvailabiliy[i - 2] = PROC_VAR_VALUE_UNAVAILABLE;
                    } else {
                        payload[i] = Float.parseFloat(varValue.toString());
                        valueAvailabiliy[i - 2] = PROC_VAR_VALUE_AVAILABLE;
                    }
                    break;
                case "long":
                    if (varValue == null) {
                        payload[i] = 0;
                        valueAvailabiliy[i - 2] = PROC_VAR_VALUE_UNAVAILABLE;
                    } else {
                        payload[i] = Long.parseLong(varValue.toString());
                        valueAvailabiliy[i - 2] = PROC_VAR_VALUE_AVAILABLE;
                    }
                    break;
                case "double":
                    if (varValue == null) {
                        payload[i] = 0;
                        valueAvailabiliy[i - 2] = PROC_VAR_VALUE_UNAVAILABLE;
                    } else {
                        payload[i] = Double.parseDouble(varValue.toString());
                        valueAvailabiliy[i - 2] = PROC_VAR_VALUE_AVAILABLE;
                    }
                    break;
                case "string":
                    if (varValue == null) {
                        payload[i] = "NA";
                        valueAvailabiliy[i - 2] = PROC_VAR_VALUE_UNAVAILABLE;
                    } else {
                        payload[i] = varValue;
                        valueAvailabiliy[i - 2] = PROC_VAR_VALUE_AVAILABLE;
                    }
                    break;
                case "bool":
                    if (varValue == null) {
                        payload[i] = false;
                        valueAvailabiliy[i - 2] = PROC_VAR_VALUE_UNAVAILABLE;
                    } else {
                        payload[i] = Boolean.parseBoolean(varValue.toString());
                        valueAvailabiliy[i - 2] = PROC_VAR_VALUE_AVAILABLE;
                    }
                    break;
                default:
                    String errMsg = "Configured process variable type: \"" + varType + "\" of the variable \"" + varName + "\" is not a WSO2 DAS applicable type for the process:" + processDefinitionId;
                    throw new BPMNDataPublisherException(errMsg);
            }
        }
        // set meta data string value representing availability of values for each process variable
        payload[1] = String.valueOf(valueAvailabiliy);
        boolean dataPublishingSuccess = dataPublisher.tryPublish(eventStreamId, getMeta(), null, payload);
        if (dataPublishingSuccess) {
            if (log.isDebugEnabled()) {
                log.debug("Published BPMN process instance KPI event...  Process Instance Id :" + processInstanceId + ", Process Definition Id:" + processDefinitionId);
            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Failed Publishing BPMN process instance KPI event... Process Instance Id :" + processInstanceId + ", Process Definition Id:" + processDefinitionId);
            }
        }
    } catch (RegistryException | RuntimeException | BPMNDataPublisherException e) {
        String strMsg = "Failed Publishing BPMN process instance KPI event... Process Instance Id :" + processInstanceId + ", Process Definition Id:" + processDefinitionId;
        throw new BPMNDataPublisherException(strMsg, e);
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) RegistryException(org.wso2.carbon.registry.api.RegistryException) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) VariableInstance(org.activiti.engine.impl.persistence.entity.VariableInstance)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)1 VariableInstance (org.activiti.engine.impl.persistence.entity.VariableInstance)1 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)1 BPMNDataPublisherException (org.wso2.carbon.bpmn.analytics.publisher.BPMNDataPublisherException)1 BPSAnalyticsServer (org.wso2.carbon.bpmn.analytics.publisher.BPSAnalyticsServer)1 RegistryException (org.wso2.carbon.registry.api.RegistryException)1