Search in sources :

Example 11 with Example

use of org.wso2.siddhi.annotation.Example in project carbon-business-process by wso2.

the class HumanTaskPackageRepository method createHumanTaskPackageParentCollectionWithProperties.

/**
 * Create parent collection to persisting human task package information. For example, if you deploy
 * a human task archive called 'ClaimsApprovalTask.zip', we store information of that package in collection
 * named 'ClaimsApprovalTask'. This will be the root for 'ClaimsApprovalTask' human task package information and
 * there will several versions of this human task package in this registry collection which relates
 * to the versions deployed in human task engine.
 *
 * @param humanTaskDeploymentUnit containing information on current deployment
 * @throws RegistryException when there is a error accessing registry
 */
private void createHumanTaskPackageParentCollectionWithProperties(HumanTaskDeploymentUnit humanTaskDeploymentUnit) throws RegistryException {
    Collection humanPackage = configRegistry.newCollection();
    humanPackage.setProperty(HumanTaskConstants.HUMANTASK_PACKAGE_PROP_LATEST_CHECKSUM, humanTaskDeploymentUnit.getMd5sum());
    if (log.isDebugEnabled()) {
        log.debug(humanTaskDeploymentUnit.getPackageName() + " updating checksum: " + humanTaskDeploymentUnit.getMd5sum() + " in registry");
    }
    humanPackage.setProperty(HumanTaskConstants.HUMANTASK_PACKAGE_PROP_STATUS, String.valueOf(humanTaskDeploymentUnit.getTaskPackageStatus()));
    humanPackage.setProperty(HumanTaskConstants.HUMANTASK_PACKAGE_PROP_LATEST_VERSION, Long.toString(humanTaskDeploymentUnit.getVersion()));
    configRegistry.put(HumanTaskPackageRepositoryUtils.getResourcePathForHumanTaskPackage(humanTaskDeploymentUnit), humanPackage);
}
Also used : Collection(org.wso2.carbon.registry.core.Collection)

Example 12 with Example

use of org.wso2.siddhi.annotation.Example in project carbon-business-process by wso2.

the class BPELPackageRepository method createBPELPackageParentCollectionWithProperties.

/**
 * Create parent collection to persisting BPEL package information. For example, if you deploy
 * a BPEL archive called 'HelloWorld.zip', we store information of that package in collection
 * named 'HelloWorld'. This will be the root for 'HelloWorld' BPEL package information and
 * there will several versions of this BPEL package in this registry collection which relates
 * to the versions deployed in BPEL engine.
 *
 * @param deploymentContext containing information on current deployment
 * @throws RegistryException        when there is a error accessing registry
 * @throws IOException              if file access error occurred during MD5 checksum generation
 * @throws NoSuchAlgorithmException when there is a error during MD5 generation
 */
private void createBPELPackageParentCollectionWithProperties(BPELDeploymentContext deploymentContext) throws RegistryException, IOException, NoSuchAlgorithmException {
    Collection bpelPackage = configRegistry.newCollection();
    bpelPackage.setProperty(BPELConstants.BPEL_PACKAGE_PROP_LATEST_CHECKSUM, Utils.getMD5Checksum(deploymentContext.getBpelArchive()));
    if (log.isDebugEnabled()) {
        log.debug(deploymentContext.getBpelPackageName() + " updating checksum: " + Utils.getMD5Checksum(deploymentContext.getBpelArchive()) + " in registry");
    }
    if (deploymentContext.isFailed()) {
        bpelPackage.setProperty(BPELConstants.BPEL_PACKAGE_PROP_STATUS, BPELConstants.STATUS_FAILED);
        bpelPackage.setProperty(BPELConstants.BPEL_PACKAGE_PROP_DEPLOYMENT_ERROR_LOG, deploymentContext.getDeploymentFailureCause());
    // bpelPackage.setProperty(BPELConstants.BPEL_PACKAGE_PROP_DEPLOYMENT_STACK_TRACE,
    // ExceptionUtils.getStackTrace(deploymentContext.getStackTrace()));
    } else {
        bpelPackage.setProperty(BPELConstants.BPEL_PACKAGE_PROP_STATUS, BPELConstants.STATUS_DEPLOYED);
    }
    bpelPackage.setProperty(BPELConstants.BPEL_PACKAGE_PROP_LATEST_VERSION, Long.toString(deploymentContext.getVersion()));
    configRegistry.put(BPELPackageRepositoryUtils.getResourcePathForBPELPackage(deploymentContext), bpelPackage);
}
Also used : Collection(org.wso2.carbon.registry.core.Collection)

Example 13 with Example

use of org.wso2.siddhi.annotation.Example in project carbon-business-process by wso2.

the class BPELPackageRepository method createCollectionWithBPELPackageWithoutContentForCurrentVersion.

/**
 * This repository persist the BPEL package versions inside the BPEL Package collection
 * under the child collection 'versions'. The collection name is same as directory with version
 * attached to it's name(Example: HelloWorld-3).
 * <p/>
 * For the 'HelloWorld' BPEL package, extracted BPEL package will be stored in a registry
 * location like '<config_registry_root>/bpel/packages/HelloWorld/versions/HelloWorld-3'.
 *
 * @param deploymentContext containing information on current BPEL deployment.
 * @throws RegistryException if an error occurred during import of file system content to
 *                           registry.
 */
private void createCollectionWithBPELPackageWithoutContentForCurrentVersion(BPELDeploymentContext deploymentContext) throws RegistryException {
    String collectionLocation = BPELPackageRepositoryUtils.getResourcePathForBPELPackageContent(deploymentContext);
    Collection collection = configRegistry.newCollection();
    configRegistry.put(collectionLocation, collection);
}
Also used : Collection(org.wso2.carbon.registry.core.Collection)

Example 14 with Example

use of org.wso2.siddhi.annotation.Example 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)

Example 15 with Example

use of org.wso2.siddhi.annotation.Example in project ballerina by ballerina-lang.

the class Desugar method visit.

@Override
public void visit(BLangMatch matchStmt) {
    // Here we generate an if-else statement for the match statement
    // Here is an example match statement
    // 
    // match expr {
    // int k => io:println("int value: " + k);
    // string s => io:println("string value: " + s);
    // json j => io:println("json value: " + s);
    // 
    // }
    // 
    // Here is how we convert the match statement to an if-else statement. The last clause should always be the
    // else clause
    // 
    // string | int | json | any _$$_matchexpr = expr;
    // if ( _$$_matchexpr isassignable int ){
    // int k = (int) _$$_matchexpr; // unbox
    // io:println("int value: " + k);
    // 
    // } else if (_$$_matchexpr isassignable string ) {
    // string s = (string) _$$_matchexpr; // unbox
    // io:println("string value: " + s);
    // 
    // } else if ( _$$_matchexpr isassignable float ||    // should we consider json[] as well
    // _$$_matchexpr isassignable boolean ||
    // _$$_matchexpr isassignable json) {
    // 
    // } else {
    // // handle the last pattern
    // any case..
    // }
    // 
    // First create a block statement to hold generated statements
    BLangBlockStmt matchBlockStmt = (BLangBlockStmt) TreeBuilder.createBlockNode();
    matchBlockStmt.pos = matchStmt.pos;
    // Create a variable definition to store the value of the match expression
    String matchExprVarName = GEN_VAR_PREFIX.value;
    BLangVariable matchExprVar = ASTBuilderUtil.createVariable(matchStmt.expr.pos, matchExprVarName, matchStmt.expr.type, matchStmt.expr, new BVarSymbol(0, names.fromString(matchExprVarName), this.env.scope.owner.pkgID, matchStmt.expr.type, this.env.scope.owner));
    // Now create a variable definition node
    BLangVariableDef matchExprVarDef = ASTBuilderUtil.createVariableDef(matchBlockStmt.pos, matchExprVar);
    // Add the var def statement to the block statement
    // string | int _$$_matchexpr = expr;
    matchBlockStmt.stmts.add(matchExprVarDef);
    // Create if/else blocks with typeof binary expressions for each pattern
    matchBlockStmt.stmts.add(generateIfElseStmt(matchStmt, matchExprVar));
    rewrite(matchBlockStmt, this.env);
    result = matchBlockStmt;
}
Also used : BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) BLangVariableDef(org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef) BLangXMLQuotedString(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)

Aggregations

CompileResult (org.ballerinalang.launcher.util.CompileResult)7 PackageNode (org.ballerinalang.model.tree.PackageNode)7 Test (org.testng.annotations.Test)7 BLangDocumentation (org.wso2.ballerinalang.compiler.tree.BLangDocumentation)6 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)6 ArrayList (java.util.ArrayList)3 Collection (org.wso2.carbon.registry.core.Collection)3 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)2 BPackageSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol)2 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)2 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)2 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)2 BLangBlockStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)2 BLangVariableDef (org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)2 Example (org.wso2.siddhi.annotation.Example)2 Extension (org.wso2.siddhi.annotation.Extension)2 Parameter (org.wso2.siddhi.annotation.Parameter)2 ReturnAttribute (org.wso2.siddhi.annotation.ReturnAttribute)2 SystemParameter (org.wso2.siddhi.annotation.SystemParameter)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1