Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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.

...

TransformationDescriptionUse
fullJson Creates JSON representation of the AsyncProvisioningOperationRequestedType object. (It is the serializable form of OperationRequested instances.) The JSON produced is in midPoint-style serialization, using e.g. @ns elements for namespace declarations, @type/@value elements, and so on.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 prism midPoint module at the receiving side. Therefore we suggest using simplified JSON serialization (described below) instead.
fullJsonWithoutShadow 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 fullJson transformation but the reader still needs to be quite sophisticated.
simplifiedJsonCreates simplified JSON representation of the request. The structure is described by the JsonAsyncProvisioningRequest class. The messages are serialized in JSON-native way.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 icfs:name and ri:name).
simplifiedQualifiedJson Creates simplified JSON representation, but with qualified names of attributes and object class.It is more complex than simplifiedJson but suitable for cases when there can be ambiguities in attribute or object class names.

...

Code Block
languagexml
<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 jsonRequestFormatter 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 JsonAsyncProvisioningRequest.

Custom transformation script can expect the following variables:

VariableTypeDescription
operationRequestedOperationRequestedThe abstract operation that is being requested by midPoint.
transformerHelperTransformerHelperHelper methods. Please see javadoc for the class.
requestFormatterJsonRequestFormatterCreates requests and optionally serializes them into JSON.

Using Apache Velocity

When creating custom text messages, Apache Velocity can help a lot. An example:

Code Block
languagexml
<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 login, fullName, and description, and creates text messages like these:

Code Block
languagetext
titleAccount creation message
operation: add
login: jack
fullName: Jack Sparrow
description: This is 'jack' called 'Jack Sparrow'


Code Block
languagetext
titleAccount modification message
operation: modify
login: jack
fullName: Jack SPARROW
description: This is 'jack' called 'Jack SPARROW'


Code Block
languagetext
titleAccount deletion message
operation: delete
login: jack
fullName: 
description: 

The template works like this:

  1. $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 $request variable will contain a reference to JsonAsyncProvisioningRequest with attributes filled-in for all three kinds of operations (add, modify, delete).
  2. $attrs = $request.attributesSimplified obtains 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.
  3. 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.)