MidPoint represents operations that are to be executed on the target as internal Java objects of
OperationRequested class. In order to send them to the target, they have to be transformed into text or binary form. There are a couple of predefined transformations; or we can create our own.
|Creates JSON representation of the ||This is the most comprehensive representation of the request, but requires rather sophisticated client to parse it. The usual way of reading this structure is to use |
|This is a variant of the above that omits current resource object shadow from the message (because it is usually not needed).||The messages are shorter than in |
|Creates simplified JSON representation of the request. The structure is described by the ||This is probably the best generic request serialization to start with. There is one limitation, though: because namespaces are not used, it is not possible to have more attributes with the same local name, but different namespace (like |
|Creates simplified JSON representation, but with qualified names of attributes and object class.||It is more complex than |
<conf:transformExpression> <script> <code> transformerHelper.jsonRequestFormatter(operationRequested)requestFormatter .changeMapAsAttributes() .format() </code> </script> </conf:transformExpression>
Because the (universal) construction of the JSON message change requests is quite laborious, midPoint provides a helper
requestFormatter. It operates on the standard structure of "simplified JSON" (i.e.
JsonAsyncProvisioningRequest) but allows the script to configure formatting process by e.g. setting various formatting options as well as directly supplying parts of the resulting request.
Note: For a description of individual items in this structure, please see
Custom transformation script can expect the following variables:
|The abstract operation that is being requested by midPoint.|
|Helper methods. Please see javadoc for the class.|
|Creates requests and optionally serializes them into JSON.|
Using Apache Velocity
When creating custom text messages, Apache Velocity can help a lot. An example:
<conf:transformExpression> <script> <language>http://midpoint.evolveum.com/xml/ns/public/expression/language#velocity</language> <code>#set ( $request = $requestFormatter.changeMapAsAttributes().identifiersAsAttributes().createRequest() ) #set ( $attrs = $request.attributesSimplified ) operation: $request.operation login: $!attrs["login"] fullName: $!attrs["fullName"] description: $!attrs["description"]</code> </script> </conf:transformExpression>
This script expects single-valued attributes
description, and creates text messages like these:
operation: add login: jack fullName: Jack Sparrow description: This is 'jack' called 'Jack Sparrow'
operation: modify login: jack fullName: Jack SPARROW description: This is 'jack' called 'Jack SPARROW'
operation: delete login: jack fullName: description:
The template works like this:
$request = $requestFormatter.changeMapAsAttributes().identifiersAsAttributes().createRequest()configures a formatter to represents both changes and identifiers as regular attributes, and then creates a request object (without serialization into JSON). So the
$requestvariable will contain a reference to
JsonAsyncProvisioningRequestwith attributes filled-in for all three kinds of operations (add, modify, delete).
$attrs = $request.attributesSimplifiedobtains a simplified version of the attributes to the variable
attrs. The simplification means that we get a map where single-valued attributes will not be represented as collection of values (as is the case of
request.attributes), but as simple values instead.
- Therefore, expressions like
$!attrs["login"]return single values of specified attributes – or null, if the given attribute has no value.
Please see Velocity User Guide for more information. (MidPoint currently uses Velocity 1.7.)