Search in sources :

Example 51 with Types

use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project siddhi by wso2.

the class ConvertFunctionTestCase method convertFunctionTest3.

@Test
public void convertFunctionTest3() throws InterruptedException {
    log.info("convert function test 3");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "" + "" + "define stream typeStream (typeS string, typeF float, typeD double, typeI int, typeL long, typeB " + "bool) ;";
    String query = "" + "@info(name = 'query1') " + "from typeStream " + "select convert(typeS,'bool') as valueB1, convert(typeF,'bool') as valueB2, convert(typeD,'bool') as " + "valueB3 , convert(typeI,'bool') as valueB4 , convert(typeL,'bool') as valueB5 , convert(typeB," + "'bool') as valueB6 " + "insert into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            count++;
            AssertJUnit.assertTrue(inEvents[0].getData(0) instanceof Boolean && (Boolean) inEvents[0].getData(0));
            AssertJUnit.assertTrue(inEvents[0].getData(1) instanceof Boolean && (Boolean) inEvents[0].getData(1));
            AssertJUnit.assertTrue(inEvents[0].getData(2) instanceof Boolean && (Boolean) inEvents[0].getData(2));
            AssertJUnit.assertTrue(inEvents[0].getData(3) instanceof Boolean && (Boolean) inEvents[0].getData(3));
            AssertJUnit.assertTrue(inEvents[0].getData(4) instanceof Boolean && (Boolean) inEvents[0].getData(4));
            AssertJUnit.assertTrue(inEvents[0].getData(5) instanceof Boolean && (Boolean) inEvents[0].getData(5));
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("typeStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "true", 1f, 1d, 1, 1L, true });
    Thread.sleep(100);
    AssertJUnit.assertEquals(1, count);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 52 with Types

use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project carbon-business-process by wso2.

the class AnalyticsPublisherExtensionOperation method fillDataArray.

private void fillDataArray(Object[] dataArray, List<AnalyticsKey> payloadAnalyticsKeyList, int startIndex, ExtensionContext context, Element element) throws FaultException {
    for (int i = 0; i < payloadAnalyticsKeyList.size(); i++) {
        AnalyticsKey analyticsKey = payloadAnalyticsKeyList.get(i);
        if (analyticsKey.getExpression() != null) {
            String expression = evaluateXPathExpression(context, analyticsKey.getExpression(), element);
            convertDataType(dataArray, (i + startIndex), analyticsKey, expression);
        } else if (analyticsKey.getVariable() != null && analyticsKey.getPart() == null) {
            if (analyticsKey.getQuery() == null) {
                String variable = context.readVariable(analyticsKey.getVariable()).getTextContent();
                convertDataType(dataArray, (i + startIndex), analyticsKey, variable);
            /* simple types should be specified for here */
            } else {
                String errMsg = "This functionality is currently not supported";
                log.error(errMsg);
                handleException(errMsg);
            }
        } else if (analyticsKey.getVariable() != null && analyticsKey.getPart() != null) {
            NodeList childNodes = context.readVariable(analyticsKey.getVariable()).getChildNodes();
            String result = null;
            String part = analyticsKey.getPart();
            for (int j = 0; j < childNodes.getLength(); j++) {
                Node item = childNodes.item(j);
                if (item != null && item.getNodeType() == Node.ELEMENT_NODE && item.getLocalName().equals(part)) {
                    /* remove the payload part */
                    result = DOMUtils.domToString(DOMUtils.getFirstChildElement(item));
                }
            }
            convertDataType(dataArray, (i + startIndex), analyticsKey, result);
            dataArray[i + startIndex] = result;
        }
    }
}
Also used : AnalyticsKey(org.wso2.carbon.bpel.core.ode.integration.config.analytics.AnalyticsKey) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node)

Example 53 with Types

use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project carbon-business-process by wso2.

the class ActivitiEngineBuilder method setSupportedVariableTypes.

/**
 * Function to set supported variable types
 * @param processEngineConfiguration
 */
private void setSupportedVariableTypes(ProcessEngineConfigurationImpl processEngineConfiguration) {
    VariableTypes variableTypes = new DefaultVariableTypes();
    List<VariableType> customPreVariableTypes = processEngineConfiguration.getCustomPreVariableTypes();
    if (customPreVariableTypes != null) {
        for (VariableType customVariableType : customPreVariableTypes) {
            variableTypes.addType(customVariableType);
        }
    }
    // Default types in Activiti
    variableTypes.addType(new NullType());
    variableTypes.addType(new StringType(ProcessEngineConfigurationImpl.DEFAULT_ORACLE_MAX_LENGTH_STRING));
    variableTypes.addType(new LongStringType(ProcessEngineConfigurationImpl.DEFAULT_ORACLE_MAX_LENGTH_STRING + 1));
    variableTypes.addType(new BooleanType());
    variableTypes.addType(new ShortType());
    variableTypes.addType(new IntegerType());
    variableTypes.addType(new LongType());
    variableTypes.addType(new DateType());
    variableTypes.addType(new DoubleType());
    variableTypes.addType(new UUIDType());
    ;
    variableTypes.addType(new JsonType(ProcessEngineConfigurationImpl.DEFAULT_ORACLE_MAX_LENGTH_STRING, objectMapper));
    variableTypes.addType(new LongJsonType(ProcessEngineConfigurationImpl.DEFAULT_ORACLE_MAX_LENGTH_STRING + 1, objectMapper));
    variableTypes.addType(new ByteArrayType());
    variableTypes.addType(new SerializableType());
    variableTypes.addType(new CustomObjectType("item", ItemInstance.class));
    variableTypes.addType(new CustomObjectType("message", MessageInstance.class));
    // types added for WSO2 BPS
    variableTypes.addType(new ExtendedJsonType(ProcessEngineConfigurationImpl.DEFAULT_ORACLE_MAX_LENGTH_STRING, objectMapper));
    variableTypes.addType(new XmlType());
    List<VariableType> customPostVariableTypes = processEngineConfiguration.getCustomPostVariableTypes();
    if (customPostVariableTypes != null) {
        for (VariableType customVariableType : customPostVariableTypes) {
            variableTypes.addType(customVariableType);
        }
    }
    processEngineConfiguration.setVariableTypes(variableTypes);
}
Also used : ExtendedJsonType(org.wso2.carbon.bpmn.core.types.datatypes.json.ExtendedJsonType) LongJsonType(org.activiti.engine.impl.variable.LongJsonType) JsonType(org.activiti.engine.impl.variable.JsonType) VariableTypes(org.activiti.engine.impl.variable.VariableTypes) DefaultVariableTypes(org.activiti.engine.impl.variable.DefaultVariableTypes) LongType(org.activiti.engine.impl.variable.LongType) VariableType(org.activiti.engine.impl.variable.VariableType) ExtendedJsonType(org.wso2.carbon.bpmn.core.types.datatypes.json.ExtendedJsonType) StringType(org.activiti.engine.impl.variable.StringType) LongStringType(org.activiti.engine.impl.variable.LongStringType) SerializableType(org.activiti.engine.impl.variable.SerializableType) ShortType(org.activiti.engine.impl.variable.ShortType) LongStringType(org.activiti.engine.impl.variable.LongStringType) BooleanType(org.activiti.engine.impl.variable.BooleanType) CustomObjectType(org.activiti.engine.impl.variable.CustomObjectType) XmlType(org.wso2.carbon.bpmn.core.types.datatypes.xml.XmlType) DefaultVariableTypes(org.activiti.engine.impl.variable.DefaultVariableTypes) IntegerType(org.activiti.engine.impl.variable.IntegerType) MessageInstance(org.activiti.engine.impl.bpmn.webservice.MessageInstance) DoubleType(org.activiti.engine.impl.variable.DoubleType) ByteArrayType(org.activiti.engine.impl.variable.ByteArrayType) UUIDType(org.activiti.engine.impl.variable.UUIDType) NullType(org.activiti.engine.impl.variable.NullType) DateType(org.activiti.engine.impl.variable.DateType) LongJsonType(org.activiti.engine.impl.variable.LongJsonType) ItemInstance(org.activiti.engine.impl.bpmn.data.ItemInstance)

Example 54 with Types

use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project carbon-business-process by wso2.

the class ActivitiEngineBuilder method buildEngine.

/* Instantiates the engine. Builds the state of the engine
	 *
	 * @return  ProcessEngineImpl object
	 * @throws BPSFault  Throws in the event of failure of ProcessEngine
	 */
public ProcessEngine buildEngine() throws BPSFault {
    try {
        String carbonConfigDirPath = CarbonUtils.getCarbonConfigDirPath();
        String activitiConfigPath = carbonConfigDirPath + File.separator + BPMNConstants.ACTIVITI_CONFIGURATION_FILE_NAME;
        File activitiConfigFile = new File(activitiConfigPath);
        ProcessEngineConfigurationImpl processEngineConfigurationImpl = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration.createProcessEngineConfigurationFromInputStream(new FileInputStream(activitiConfigFile));
        // Add script engine resolvers
        setResolverFactories(processEngineConfigurationImpl);
        // Add supported variable types
        setSupportedVariableTypes(processEngineConfigurationImpl);
        // we have to build the process engine first to initialize session factories.
        processEngine = processEngineConfigurationImpl.buildProcessEngine();
        processEngineConfigurationImpl.getSessionFactories().put(UserIdentityManager.class, new BPSUserManagerFactory());
        processEngineConfigurationImpl.getSessionFactories().put(GroupIdentityManager.class, new BPSGroupManagerFactory());
        dataSourceJndiName = processEngineConfigurationImpl.getProcessEngineConfiguration().getDataSourceJndiName();
    } catch (FileNotFoundException e) {
        String msg = "Failed to create an Activiti engine. Activiti configuration file not found";
        throw new BPSFault(msg, e);
    }
    return processEngine;
}
Also used : BPSGroupManagerFactory(org.wso2.carbon.bpmn.core.integration.BPSGroupManagerFactory) BPSUserManagerFactory(org.wso2.carbon.bpmn.core.integration.BPSUserManagerFactory) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) FileInputStream(java.io.FileInputStream)

Example 55 with Types

use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project carbon-business-process by wso2.

the class OperationAuthorizationUtil method authoriseUser.

/**
 * @param task             : The task against which the user being validated.
 * @param validatee        : The OrganizationalEntityDAO being validated.
 * @param allowedRoleTypes : The allowed role types for the validatee object.
 * @param pqe              : PeopleQueryEvaluator for people queries.
 * @return : true if the user is in the specified roles for the given task. false otherwise.
 */
public static boolean authoriseUser(TaskDAO task, OrganizationalEntityDAO validatee, List<GenericHumanRoleDAO.GenericHumanRoleType> allowedRoleTypes, PeopleQueryEvaluator pqe) {
    List<GenericHumanRoleDAO> humanRolesInTask = task.getHumanRoles();
    if (isExcludedEntity(task, validatee, pqe)) {
        return false;
    }
    for (GenericHumanRoleDAO role : humanRolesInTask) {
        if (allowedRoleTypes.contains(role.getType())) {
            // check for groups
            for (OrganizationalEntityDAO entityForRole : getGroupOrganizationalEntities(role)) {
                if (OrganizationalEntityDAO.OrganizationalEntityType.GROUP.equals(entityForRole.getOrgEntityType())) {
                    String roleName = entityForRole.getName();
                    List<String> userListForRole = pqe.getUserNameListForRole(roleName);
                    if (userListForRole.contains(validatee.getName())) {
                        return true;
                    }
                }
            }
            // check for users
            // TODO validate user existance in the user store.
            List<OrganizationalEntityDAO> orgEntities = getUserOrganizationalEntities(role);
            Collections.sort(orgEntities, PeopleQueryComparators.peopleNameComparator());
            if (Collections.binarySearch(orgEntities, validatee, PeopleQueryComparators.peopleNameComparator()) >= 0) {
                return true;
            }
        }
    }
    return false;
}
Also used : OrganizationalEntityDAO(org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO) GenericHumanRoleDAO(org.wso2.carbon.humantask.core.dao.GenericHumanRoleDAO)

Aggregations

ArrayList (java.util.ArrayList)20 Test (org.testng.annotations.Test)15 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)13 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)12 HashMap (java.util.HashMap)11 Map (java.util.Map)11 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)10 List (java.util.List)8 JsonObject (com.google.gson.JsonObject)5 Test (org.junit.Test)5 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)5 Arrays (java.util.Arrays)4 Collectors (java.util.stream.Collectors)4 JSONObject (org.json.simple.JSONObject)4 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)4 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)4 JsonElement (com.google.gson.JsonElement)3 Paths (java.nio.file.Paths)3 TokenStream (org.antlr.v4.runtime.TokenStream)3 StringUtils (org.apache.commons.lang3.StringUtils)3