...
For more info regarding the Camunda API see: https://docs.camunda.org/manual/7.3/api-references/rest/
Kinvey Console
Current Akioma Kinvey console URL: https://kvy-eu3-console.kinvey.com/
From here, you can view/edit applications, services, custom endpoints/functions and test kinvey collections.
Kinvey Configuration
Kinvey Profile Configuration File
First, make sure kinvey cli is installed on your machine. If not, you can use the following command: npm install kinvey-cli
When deploying the Kinvey service locally, you need to have a config file in the current folder from which you are deploying the service. The file name will be '.kinevy'. This will be configured using the kinvey init command.
Once you run this command, you will need to supply your kinvey console credentials and the Kinvey instance ID (optional - in our case this is kvy-eu3).
Alternatively, if you already have a profile configure, you can use it with the command kinvey profile use.
Pasoe Config
In order to connect the application to to Kinvey, we need to set 3 session properties in the pasoe-config.xml file from the ofr-config project: kinveyAppSecret, kinveyInstanceId, kinveyAppKey.
The above 3 properties can be found by selecting an environment within a Kinvey App and clicking on the 3 dots:
After you set the properties in the file, restart the PASOE.
Kinevy Service/Functions
https://devcenter.kinvey.com/rest/guides/flex-services
https://devcenter.kinvey.com/rest/guides/flexservice-runtime
https://devcenter.kinvey.com/rest/reference/flex/reference.html#FlexDataEvents
Flex Service
Flex Events are exposed by the service object and invoked by the kinvey collections. Each event takes a single function as a handler. Events include: onInsert, onUpdate, onDelete, onGetAll etc. See doc above for more details.
Each handler function bound to an event, has the following parameters: : context, complete, and modules.
- context: current context of the request made to kinvey; here we will find any parameters passed as input in the query
- complete: handler for completing the data request
- module: contains several libraries for accessing kinvey functionality
On our end, we define a function for each desired event, then we
Flex Functions
Flex functions are used to execute custom code by either hooks, or in our case, endpoints.
In the code, you can access the flex functions through the functins property:
const functions = flex.functions;
Then, you can register a custom function using this property:
flex.functions.register('someEventHandlerName', 'someFunctionHandlerName');
Custom flex functions must recive as parameters: (context, complete, modules).
Kinvey Create/Deploy Service
Test collection - kinvey console command
To deploy the Kinvey Camunda service, use the following command: kinvey flex deploy --runtime node12.
NOTE: Each time you redeploy the service, you need to bump the version in the package.json.
After you run the deploy command, you can check de deploy status using kinvey flex status.
For more details, you can use the kinvey flex logs command to see deploy logs or even request logs from Kinvey.
For more details on each commands options, you can use kinvey flex <command> --help
Once your service was deployed, you can check your collection from the API console, under Dashboard →Data (see below screenshot).
Here, you can test your collection/service with different requests: GET, POST, PUT, DELETE:
Kinvey Collections
Kinevy collections are essentially data abstractions, representing a group of related data entities. They are defined in the Environment → Data → Collections tab:
To define a new collection, click on Add collection. Then, select the data service, environment and service for which you want to define a collection for. Finally, click on activate service.
Collections will be used to make data available in the application UI, in grids. This will be explained below.
Kinevy DSO Setup
After we set the Kinvey parameters in the pasoe-config.xml file and we define a kinvey collection, for the dataSource we can use the SimpleSwatBusinessEntity.
Here, we would need to set 2 attributes:
- SUBTYPE : 'KinveyCollection' (without the quotes)
- resourceName: name-of-camunda-collection
Then simply create a DATA link from the DSO to the grid and you should be able to see the collection data.
Kinvey Custom Endpoints
Custom endpoints are defined on the Application Environment settings. They can be called from the frontend using akioma.InvokeServerTask. A custom endpoint is linked to a service flex function. Essentially, when a custom endpoint is called, we are calling the the flex function defined in the service.
Custom endpoints can be defined on the application environment from the Business Logic → Custom Endpoints:
Click on the add new Endpoint button, give the new endpoint a name and select the Business Logic Type.
In our case, that is Microservice (Execute a handler function running inside a Flex Services Runtime service).
Once the endpoint is created, select the service, then environment and finally the handler function:
Kinvey Calling the Custom Endpoints
Calling a Kinvey custom endpoint is done using akioma.InvokeServerTask.
The only thing we need to specify is the methodType: "kinvey" in the request.
akioma.invokeServerTask({ name: "completeTask", methodType: "kinvey", paramObj: { id: "id-of-task" } })
...
More information regarding Kinvey Flex Services here: Kinvey Flex Services
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
const sdk = require('kinvey-flex-sdk');
const DigestFetch = require('digest-fetch');
Class CamundaService {
?? ?? ?? ?? constructor(){
?? ?? ?? ?? ?? ?? this.client = new DigestFetch(userName, password);
?? ?? ?? ?? ?? ?? this.logger = flex.logger;
}
getAll (context, complete, modules) {
?? ?? this.logger.info('getAll Context:' + JSON.stringify(context));
?? ?? const backendUrl = "url to camunda backend";
?? ?? this.client.fetch(backendUrl)
?? ?? ?? ?? .then(response => response.json())
?? ?? ?? ?? .then(data => {
?? ?? ?? ?? data.forEach(item => {
?? ?? ?? ?? ?? ?? item._id = item.id;
?? ?? ?? ?? });
?? ?? ?? ?? complete().setBody(data).ok().next();
?? ?? })
?? ?? .catch(e => console.error(e));
}
}
sdk.service((err, flex) => {
?? ?? ?? ?? const data = flex.data;?? ?? ?? ?? ?? ?? ?? ??//get data object
?? ?? ?? ?? const flexLogger = flex.logger;??//get logger
?? ?? ?? ????const camundaFlexServive = data.serviceObject('task');??//get service object from data object
?? ?? ?? ????camundaService = new CamundaService(key, flex);?? ?? ?? ??//instantiate new service class
?? ?? ?? ?? camundaFlexServive.onGetAll(camundaService.getAll.bind(camundaService)); //bind handler function to getAll event
} |