This sample shows the usage of a service provider to react on the execution of a business rule in the CP backend, creating a notification about a then triggered long-running task for the user. The user is able to cancel that task from the CP UI.
The service provider waits for a BusinessRuleFired
event for a specific rule. The following steps are then performed:
- Gather created content ids into batches
- After an inactivity timeout elapsed or a batch is complete, a business process is created
- For each content, the original is downloaded into a local folder. After every content, the notification shown to the user in the CP UI is updated to reflect the progress
- As long as the business process is not cancelled, this is repeated for each content
- On cancellation by the user, the process is stopped
- At the end, the business process is marked as finished (or cancelled)
To create the service provider, run the following call against the CP management API:
POST {{cloudmanager-url}}/service/serviceProvider:
{
"externalId": "bpedemo",
"name": "Business Process Engine Provider (POC)",
"secret": "CHANGEME"
}
Note: The externalId
must match the serviceProviderId
setting in the application configuration.
To register the service provider for a customer, run the following call against the CP management API:
POST {{cloudmanager-url}}/service/customer/serviceProvider:
{
"customerAlias" : "{{customer-alias}}",
"serviceProvider": {
"id": "bpedemo",
"scopes": [
"$.[?(@.applicationEvent.kind == 'BusinessRuleFiredEvent' && @.applicationEvent.details..*.ruleIds[*] == 'ImageUploaded')]",
"$.[?(@.applicationEvent.kind == 'BusinessProcessCancellationRequestedEvent')]"
],
"allowedMessages": [],
"allowedCommands": []
}
}
Note: The ruleId
in the scopes
property of the registration request must match the triggeringBusinessRuleId
setting in the application configuration.
Note: The externalId
in the registration request must match the externalId
in the creation request above.
Create a business rule either using the API or the CP UI with the id
matching the ruleId
specified when registering the service provider for the customer.
Use the example rule that triggers whenever a new image has been uploaded as a starting point:
{
"kind": "BusinessRuleConfigurable",
"condition": {
"kind": "ContentSchemaCondition",
"schemaId": "ImageMetadata"
},
"actions": [
{
"kind": "ProduceMessageAction"
}
],
"id": "ImageUploaded",
"triggerPoint": {
"executionScope": "MainDoc",
"documentType": "Content",
"action": "Create"
},
"isEnabled": true,
"names": {
"en": "Image uploaded trigger"
},
"description": {
"en": "Triggers when a new content is created having ContentSchemaId = 'ImageMetadata'"
}
}
Copy the appsettings_template.json
file to appsettings.json
and adjust it to suite your environment.
Below follows a description of all settings in the config
section of appsettings.json
:
apiUrl
: URL to the API of your CP instancecustomerAlias
: the customer alias of your customeraccessToken
: your access token for the CP APIserviceProviderId
: ID your created the service provider withintegrationHost
: Hostname/address of the integration bus hostintegrationPort
: Port of the integration bususeSsl
: set totrue
to use an encrypted connection to the integration bussecret
: the secret you provided when creating the service providertriggeringBusinessRuleId
: ID of the business rule that should trigger the service providerbatchSize
: Maximum number of contents to download in each batchinactivityTimeout
: Timeout after which a batch is downloaded regardless of the sizeoutputDownloadDirectory
: Path where the downloaded outputs should be stored
- Run the application
- Upload images to CP
- The service provider will download the images, creating a notification in the UI
Namespaces:
Config
: Contains the configuration for the sample, see below for instructionsMessageHandler
: Contains handlers for the incoming messages on the livestreamBusinessProcess
: Contains infrastructure to work with business processesUtil
: Utilities
Important classes:
LiveStreamSubscriber
: Subscribes to the livestream, handles incoming messages by calling anIApplicationEventHandler
ContentBatchOperationPerformer
: Gathers created contents into batches and then downloads each batch into a local folder.