Hi,
We have made some changes for adding support for native JS JSON variables
with Script task that we planned above as follows.
The Activiti BPMN Engine provides the ability to introduce data types
supported by the engine by implementing
org.activiti.engine.impl.variable.VariableType[1] interface and register
the variable type before building the process engine. So the implementation
of VariableType is responsible for serialization and deserialization of
target data type.
ATM we have implemented to support to set native JS JSON typed variables to
the activiti engine.
The native JS JSON variables can set as follows:
var jsonJSVar = {
"execInfo":{"execJava":executeJava },
"firstName":"John",
"lastName":"Doe"
};
execution.setVariable("jsonJSVar", jsonJSVar);
But in the case of retrieving the JSON variable, the JS script won't
receive the native JS JSON object. The reason is at the stage of
VariableType implementation we are unable to differentiate getVariable()
request is originated from a JS Script task or Java Service task, .. etc.
Hence we decided to consider *com.fasterxml.jackson.databind.JsonNode* type
as return type for JSON variables (as used ATM in Activiti engine)
So retrieving and manipulation of JSON variables in JS Script task can be
achieved in following two ways:
1. Parse to native JS JSON object
var savedJsonVar =
JSON.parse(execution.getVariable("jsonJSVar"));
var fullName = savedJsonVar.firstName
2. Without parsing, treat as com.fasterxml.jackson.databind.JsonNode object
and use JsonNode functions [2] as follows:
var test = execution.getVariable("jsonJSVar");
var fullName = test.get("firstName").asText() + " " +
test.get("lastName").asText();
Refer [3] as a sample.
[1]
http://grepcode.com/file/repo1.maven.org/maven2/org.activiti/activiti-engine/5.16/org/activiti/engine/impl/variable/VariableType.java
[2]
http://fasterxml.github.io/jackson-databind/javadoc/2.5/com/fasterxml/jackson/databind/JsonNode.html
[3]
https://github.com/milindaperera/Samples-4-WSO2BPS/tree/master/bpmn/JSONVariableUssageWithScriptTask
Thanks,
Milinda
On Fri, May 20, 2016 at 10:27 AM, Chathura Ekanayake <[email protected]>
wrote:
> Hi Milinda,
>
> JSON support in the REST API has to cover JSON arrays as well. For
> example, if a POST is done with a json array, each element/json object in
> the array can be added to a java collection with the given variable name.
> Therefore, data given as json arrays can be easily referred within bpmn and
> can be used in multi-instance activities.
>
> Regards,
> Chathura
>
> On Mon, May 16, 2016 at 12:44 PM, Milinda Perera <[email protected]>
> wrote:
>
>> Hi,
>>
>>
>> We are planning to introduce/enhance XML and JSON variable (ATM JSON
>> support is available partially) support for BPMN in WSO2 BPS.
>>
>> Case 01 : JSON Support
>>
>> ATM Activiti provides JSON as a data type. Hence, I did some
>> investigation on how extend JSON support is provided. The following table
>> depicts results summary.
>>
>> Access From
>>
>> Read
>>
>> Create/Update
>>
>> Java Service Task
>>
>> ✓
>>
>> ✓
>>
>> Condition Expressions
>>
>> ✓
>>
>> -
>>
>> Script Task
>>
>> ✓
>>
>> ✗
>>
>> BPMN REST API
>>
>> ✗
>>
>> ✗
>>
>> We are planning to enhance JSON support by introducing following in WSO2
>> BPS BPMN support:
>>
>> 1.
>>
>> Create/Update JSON variables from Script Task.
>> 2.
>>
>> Create/Update and Read JSON variables from BPMN REST API.
>>
>>
>> For more information how JSON variables can be used within BPMN processes
>> ATM (with WSO2 BPS 3.5.1), refer [1].
>>
>>
>>
>> Case 02 : XML Support
>>
>> XML support is not provided in Activiti BPMN engine. So we are going to
>> provide it from ground up.
>>
>> With XML support users can create variables in “xml” as the data type and
>> able to extract or set XML content with the help of simple Java API that
>> will provided in BPS.
>>
>> Consider there is an XML variable with name “userInfo” for example with
>> the content:
>>
>> <User>
>>
>> <Name>Mark</Name>
>>
>> <Country>SL</Country>
>>
>> <Address>
>>
>> <State>Western</State>
>>
>> <City>Colombo<City>
>>
>> <Street>ABC Street</Street>
>>
>> </Address>
>>
>> </User>
>>
>> To provide XML support, we have to provide XML manipulation
>> (Create/Update/Read) support in Java Service Task, Condition Expressions,
>> Script Task and BPMN REST API
>>
>>
>> 1.
>>
>> Java Service Task
>>
>> Within Java service task users can use XML Java api that will provided
>> within BPS to create, update, and read/query xml.
>>
>>
>> 1.
>>
>> Create
>>
>> When creating new XML variable and setting it process variable
>>
>> XML VARIABLE = XML.createInstance(“[XML String]”);
>>
>> execution.setVariable(“[Variable_name]”, VARIABLE);
>>
>>
>> 1.
>>
>> Read/Query
>>
>> When querying, user should be able to access element contents as follows:
>>
>> [VARIABLE NAME].XPath(“[XPATH EXPRESSION]”)
>>
>> Eg: To retrieve City : userInfo.XPath(“/User/Address/City”)
>>
>>
>> 1.
>>
>> Update
>>
>> To update an element in a XML variable
>>
>> VARIABLE.set(“[XPATH EXPRESSION]”, [String Value])
>>
>> Eg: To update City : userInfo.set(“/User/Address/City”, “Kandy”)
>>
>>
>> 1.
>>
>> Condition Expressions
>>
>> Within condition expression users can use the same methods provided from
>> the Java API to query xml element contents
>>
>> <conditionExpression xsi:type="tFormalExpression">
>>
>> <![CDATA[${xmlVar.XPath("[XPATH EXPRESSION]").asInt() > 10}]]>
>>
>> </conditionExpression>
>>
>>
>> 1.
>>
>> Script Task
>>
>> Within script task users will be able to use XML DOM (which is standard
>> way of manipulating XML in javascript) for manipulating xml within the
>> script (ATM we are focusing in JavaScript)
>>
>>
>>
>> 1.
>>
>> BPMN REST API
>>
>> Same as for JSON, need to introduce way to create, update and read xml
>> variables.
>>
>> REST API Improvements
>>
>> Create/Update xml and json variables over REST API
>>
>> POST runtime/process-instances/{processInstanceId}/variables
>>
>> PUT runtime/process-instances/{processInstanceId}/variables
>>
>> Suggested payload for JSON:
>>
>> [
>>
>> {
>>
>> "name":"VariableName",
>>
>> "type":"json",
>>
>> "value":"{\"id\":1,\"name\":{\"first\":\"Yong\",\"last\":\"Mook
>> Kim\"},\"priority\":5}"
>>
>> }
>>
>> ]
>>
>> Suggested payload for XML:
>>
>> [
>>
>> {
>>
>> "name":"VariableName",
>>
>> "Type":"xml",
>>
>>
>> "value":"<root><id>1</id><name><first>fname</first><last>lname</last></name><priority>5</priority></root>"
>>
>> }
>>
>> ]
>>
>> Get xml and json variables over REST API
>>
>> GET runtime/process-instances/{processInstanceId}/variables/{variableName}
>>
>> Response will be (for JSON):
>>
>> {
>> "name":"variableName",
>> "type":"json",
>> "value":"{\"id\":1,\"name\":{\"first\":\"Yong\",\"last\":\"Mook
>> Kim\"},\"priority\":5}",
>> "scope":"local"
>> }
>>
>> XML variable response will be similar.
>>
>> The details mentioned above are to share the rough idea about XML/JSON
>> enhancements that we planned to do. Appreciate for your suggestion and
>> feedbacks on this.
>>
>> [1]
>> http://milindaperera.blogspot.com/2016/05/json-variable-ussage-within-bpmn.html
>>
>> Thanks,
>> Milinda
>>
>> --
>> Milinda Perera
>> Software Engineer;
>> WSO2 Inc. http://wso2.com ,
>> Mobile: (+94) 714 115 032
>>
>>
>> _______________________________________________
>> Architecture mailing list
>> [email protected]
>> https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture
>>
>>
>
--
Milinda Perera
Software Engineer;
WSO2 Inc. http://wso2.com ,
Mobile: (+94) 714 115 032
_______________________________________________
Architecture mailing list
[email protected]
https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture