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();
}
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;
}
}
}
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);
}
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;
}
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;
}
Aggregations