use of org.wso2.carbon.registry.core.Collection in project carbon-business-process by wso2.
the class BaseExecutionService method createExecutionVariable.
protected Response createExecutionVariable(Execution execution, boolean override, int variableType, HttpServletRequest httpServletRequest, UriInfo uriInfo) {
Object result = null;
Response.ResponseBuilder responseBuilder = Response.ok();
List<RestVariable> inputVariables = new ArrayList<>();
List<RestVariable> resultVariables = new ArrayList<>();
if (Utils.isApplicationJsonRequest(httpServletRequest)) {
try {
ObjectMapper objectMapper = new ObjectMapper();
@SuppressWarnings("unchecked") List<Object> variableObjects = (List<Object>) objectMapper.readValue(httpServletRequest.getInputStream(), List.class);
for (Object restObject : variableObjects) {
RestVariable restVariable = objectMapper.convertValue(restObject, RestVariable.class);
inputVariables.add(restVariable);
}
} catch (Exception e) {
throw new ActivitiIllegalArgumentException("Failed to serialize to a RestVariable instance", e);
}
} else if (Utils.isApplicationXmlRequest(httpServletRequest)) {
JAXBContext jaxbContext = null;
try {
jaxbContext = JAXBContext.newInstance(RestVariableCollection.class);
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
inputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(new StreamSource(httpServletRequest.getInputStream()));
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
RestVariableCollection restVariableCollection = (RestVariableCollection) jaxbUnmarshaller.unmarshal(xmlReader);
if (restVariableCollection == null) {
throw new ActivitiIllegalArgumentException("xml request body could not be transformed to a " + "RestVariable Collection instance.");
}
List<RestVariable> restVariableList = restVariableCollection.getRestVariables();
if (restVariableList.size() == 0) {
throw new ActivitiIllegalArgumentException("xml request body could not identify any rest " + "variables to be updated");
}
for (RestVariable restVariable : restVariableList) {
inputVariables.add(restVariable);
}
} catch (JAXBException | IOException | XMLStreamException e) {
throw new ActivitiIllegalArgumentException("xml request body could not be transformed to a " + "RestVariable instance.", e);
}
}
if (inputVariables.size() == 0) {
throw new ActivitiIllegalArgumentException("Request didn't contain a list of variables to create.");
}
RestVariable.RestVariableScope sharedScope = null;
RestVariable.RestVariableScope varScope = null;
Map<String, Object> variablesToSet = new HashMap<String, Object>();
for (RestVariable var : inputVariables) {
// Validate if scopes match
varScope = var.getVariableScope();
if (var.getName() == null) {
throw new ActivitiIllegalArgumentException("Variable name is required");
}
if (varScope == null) {
varScope = RestVariable.RestVariableScope.LOCAL;
}
if (sharedScope == null) {
sharedScope = varScope;
}
if (varScope != sharedScope) {
throw new ActivitiIllegalArgumentException("Only allowed to update multiple variables in the same scope.");
}
if (!override && hasVariableOnScope(execution, var.getName(), varScope)) {
throw new BPMNConflictException("Variable '" + var.getName() + "' is already present on execution '" + execution.getId() + "'.");
}
Object actualVariableValue = new RestResponseFactory().getVariableValue(var);
variablesToSet.put(var.getName(), actualVariableValue);
resultVariables.add(new RestResponseFactory().createRestVariable(var.getName(), actualVariableValue, varScope, execution.getId(), variableType, false, uriInfo.getBaseUri().toString()));
}
if (!variablesToSet.isEmpty()) {
RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
if (sharedScope == RestVariable.RestVariableScope.LOCAL) {
runtimeService.setVariablesLocal(execution.getId(), variablesToSet);
} else {
if (execution.getParentId() != null) {
// Explicitly set on parent, setting non-local variables on execution itself will override local-variables if exists
runtimeService.setVariables(execution.getParentId(), variablesToSet);
} else {
// Standalone task, no global variables possible
throw new ActivitiIllegalArgumentException("Cannot set global variables on execution '" + execution.getId() + "', task is not part of process.");
}
}
}
RestVariableCollection restVariableCollection = new RestVariableCollection();
restVariableCollection.setRestVariables(resultVariables);
responseBuilder.entity(restVariableCollection);
return responseBuilder.status(Response.Status.CREATED).build();
}
use of org.wso2.carbon.registry.core.Collection in project ballerina by ballerina-lang.
the class TaintAnalyzer method visit.
public void visit(BLangForeach foreach) {
SymbolEnv blockEnv = SymbolEnv.createBlockEnv(foreach.body, env);
// Propagate the tainted status of collection to foreach variables.
foreach.collection.accept(this);
if (getObservedTaintedStatus()) {
foreach.varRefs.forEach(varRef -> setTaintedStatus((BLangVariableReference) varRef, getObservedTaintedStatus()));
}
analyzeNode(foreach.body, blockEnv);
}
use of org.wso2.carbon.registry.core.Collection in project ballerina by ballerina-lang.
the class PackageActionFunctionAndTypesFilter method populateIterableOperations.
private void populateIterableOperations(SymbolInfo variable, List<SymbolInfo> symbolInfoList) {
BType bType = variable.getScopeEntry().symbol.getType();
if (bType instanceof BArrayType || bType instanceof BMapType || bType instanceof BJSONType || bType instanceof BXMLType || bType instanceof BTableType || bType instanceof BIntermediateCollectionType) {
fillForeachIterableOperation(bType, symbolInfoList);
fillMapIterableOperation(bType, symbolInfoList);
fillFilterIterableOperation(bType, symbolInfoList);
fillCountIterableOperation(symbolInfoList);
if (bType instanceof BArrayType && (((BArrayType) bType).eType.toString().equals("int") || ((BArrayType) bType).eType.toString().equals("float"))) {
fillMinIterableOperation(symbolInfoList);
fillMaxIterableOperation(symbolInfoList);
fillAverageIterableOperation(symbolInfoList);
fillSumIterableOperation(symbolInfoList);
}
// TODO: Add support for Table and Tuple collection
}
}
use of org.wso2.carbon.registry.core.Collection in project ballerina by ballerina-lang.
the class BallerinaFunctionDocGenTest method testABalWithMultipleFunctions.
@Test(description = "Test a Bal file with multiple Functions")
public void testABalWithMultipleFunctions() {
try {
Map<String, BLangPackage> docsMap = BallerinaDocGenerator.generatePackageDocsFromBallerina(sourceRoot, "balWith2Functions.bal");
Assert.assertNotNull(docsMap);
Assert.assertEquals(docsMap.size(), 1);
BallerinaDocGenTestUtils.printDocMap(docsMap);
BLangPackage doc = docsMap.get(".");
Collection<BLangFunction> functions = doc.getFunctions();
Assert.assertEquals(functions.size(), 2);
Iterator<BLangFunction> iterator = functions.iterator();
BLangFunction function = iterator.next();
Assert.assertEquals(function.getParameters().size(), 1);
Assert.assertEquals(function.getReturnParameters().size(), 1);
BLangFunction function1 = iterator.next();
Assert.assertEquals(function1.getParameters().size(), 2);
Assert.assertEquals(function1.getReturnParameters().size(), 0);
} catch (IOException e) {
Assert.fail();
} finally {
BallerinaDocGenTestUtils.cleanUp();
}
}
use of org.wso2.carbon.registry.core.Collection in project jaggery by wso2.
the class RegistryHostObject method jsFunction_get.
public static Scriptable jsFunction_get(Context cx, Scriptable thisObj, Object[] arguments, Function funObj) throws ScriptException {
RegistryHostObject rho = (RegistryHostObject) thisObj;
if (arguments.length == 1) {
if (arguments[0] instanceof String) {
try {
Scriptable hostObject;
Resource resource = rho.registry.get((String) arguments[0]);
if (resource instanceof Collection) {
hostObject = cx.newObject(rho, "Collection", new Object[] { resource });
} else {
hostObject = cx.newObject(rho, "Resource", new Object[] { resource });
}
return hostObject;
} catch (RegistryException e) {
throw new ScriptException("Registry error occurred while executing get() operation", e);
}
} else {
throw new ScriptException("Path argument of method get() should be a string");
}
} else if (arguments.length == 3) {
if (arguments[0] instanceof String && arguments[1] instanceof Number && arguments[2] instanceof Number) {
try {
Collection collection = rho.registry.get((String) arguments[0], ((Number) arguments[1]).intValue(), ((Number) arguments[2]).intValue());
CollectionHostObject cho = (CollectionHostObject) cx.newObject(rho, "Collection", new Object[] { collection });
return cho;
} catch (RegistryException e) {
throw new ScriptException("Registry error occurred while executing get() operation", e);
}
} else {
throw new ScriptException("Invalid argument types for get() method");
}
} else {
throw new ScriptException("Invalid no. of arguments for get() method");
}
}
Aggregations