[midPoint] Re. Referring to resource variable inside expression.

Radovan Semancik radovan.semancik at evolveum.com
Thu Jan 9 10:20:32 CET 2014


Hi,

You cannot access $account in object templates. There are several 
reasons for this. And as you are not the first to ask this question I 
have added an answer to our documentation:

https://wiki.evolveum.com/display/midPoint/Object+Template

Object template works just with a single object which is typically a 
user. Therefore it only has the data from this object and no other 
objects. It means that variables such as |$account| cannot be used in an 
object template. The reason for this is the separation of concerns 
<http://en.wikipedia.org/wiki/Separation_of_concerns> principle. We try 
to design each component or mechanism in midPoint to do a single thing. 
This allows us a significant development advantage (debugging, testing) 
and also provides a better code reusability. The power of midPoint is to 
have simple principles (such as object template) that used over and over 
again and combined with other simple principles (such as 
inbound/outbound mappings) to create a flexible and comprehensive solution.

There is also another reason for *not* including account in object 
templates. The object template may be used even if the account is not 
available, e.g. when user is changed from the GUI. MidPoint is using 
?relative changes 
<https://wiki.evolveum.com/display/midPoint/Relativity>? therefore it is 
not always required to read all the accounts to process a change. And in 
fact the account may not even be available (e.g. because resource is 
temporarily down). Therefore it would be a very inconvenient and 
inefficient if account attributes are used in object templates.

Therefore if a property from an account (or other object) is needed in 
an object template there are several ways how to do it:

  * Use ?inbound mappings
    <https://wiki.evolveum.com/display/midPoint/Inbound+Mapping>
    instead. Inbound mappings can compute the value and place it
    directly in the user property. Inbound mappings can see both the
    account and the user. And midPoint can make sure that these mappings
    are executed at the right moment and are not executed when not
    needed. E.g. the mappings will be executed only when midPoint
    detects a change on the resource.
  * Use combination of inbound mappings
    <https://wiki.evolveum.com/display/midPoint/Inbound+Mapping>,
    extended user properties and object template. Use object template to
    the computation. Use inbound mappings to copy data from account to
    the user extended properties (|extension| part of user object). Then
    use the extended properties as input in the user template. This
    works around the separation of concerns boundaries. And as the
    extended properties are stored with the user in midPoint repository
    they are always available without the need to read the account all
    the time. Inbound mappings will make sure that these data are as
    fresh as possible.


-- 

                                            Radovan Semancik
                                           Software Architect
                                              evolveum.com



On 01/02/2014 03:11 PM, Deepak Natarajan wrote:
>
>
> Hi Ivan -
>
> Thanks - I tried with $c:input and it worked.
>
> It's a bit weird since in an object template (which I use for 
> post-creation assignments etc),  doing it like this worked :
>
> <mapping>
>     <source>
>         <name>varname</name>
>         <path>varpath</path>
>     </source>
>     <expression>
>         <script>
>             <code>
>                     tokenize(varname...)
>             </code>
>         </script>
>     </expression>
>
> seems to work, but this fails when I try something similar in a 
> resource configuration...thought it is quite possible my varpath had 
> an error in it...(i used $account/attributes/ri:var)
>
> but using 'input' works, thanks!
>> Ivan Noris <mailto:ivan.noris at evolveum.com>
>> January 2, 2014 at 4:03 PM
>> Hi Deepak,
>>
>> just a blind shot - try to use implicit variable named "input" (it is 
>> mapped to the "source" of the inbound expression, in your case, 
>> ri:orgdesc).
>>
>> See an example (adapted from my customer's resource) written in 
>> Groovy (not XPath):
>>
>> <attribute>
>>     <ref>ri:orgUnitHierarchy</ref>
>>     <displayName>Organizational Hierarchy</displayName>
>>     <access>read</access>
>>     <inbound>
>>     <expression>
>>         <script>
>>             <code>
>> String[] tmpHierarchyList = *input* ? *input*?.split('\\.') : []
>> tmpHierarchyListNew = []
>>
>> <!-- some processing skipped here . . . -->
>>
>> return tmpHierarchyListNew.join(':')
>> </code>
>>         </script>
>>     </expression>
>>       <target>
>>     <path>$user/extension/mycustomer:ouPath</path>
>>       </target>
>>     </inbound>
>> </attribute>
>>
>> I do not use XPath in expressions unless absolutely necessary because 
>> the debugging is quite _challenging_ ;) and it's lot easier to debug 
>> Groovy statements.
>>
>> Regards,
>> Ivan
>>
>> On 01/02/2014 02:50 PM, Deepak Natarajan wrote:
>>
>> -- 
>> Ing. Ivan Noris
>> Consultant
>> Evolveum, s.r.o
>> ___________________________________________________
>> "Semper cautus - semper paratus - semper idem Vix."
>> _______________________________________________
>> midPoint mailing list
>> midPoint at lists.evolveum.com
>> http://lists.evolveum.com/mailman/listinfo/midpoint
>> Deepak Natarajan <mailto:dnataraj at trilobytesystems.com>
>> January 2, 2014 at 3:50 PM
>>
>> Hi -
>>
>> I'm struggling with a simple evaluation (I've removed namespace 
>> declarations for readability) :
>>
>>                 <attribute>
>>                     <ref>ri:orgdesc</ref>
>>                     <inbound>
>>                         <expression>
>>                             <script>
>>                                 
>> <language>http://www.w3.org/TR/xpath/</language>
>>                                 <code ...>
>> tokenize($account/attributes/ri:orgdesc,"/")[last()]
>>                                 </code>
>>                             </script>
>>                         </expression>
>>                         <target>
>> <path>$user/extension/apos:aposUnitAttributes</path>
>>                         </target>
>>                     </inbound>
>>                 </attribute>
>>
>> I've tried everything, but the variable passed to the XPath tokenize 
>> function is always nil (I know the function works correctly, since I 
>> use it elsewhere, and using a literal string above produces the 
>> correct results)
>>
>> I've tried including a <source> before the expression with an 
>> explicit <name> but that doesn't seem to work either.
>>
>> Thanks for any input! - I'm using build Version: 2.3-SNAPSHOT, 
>> describe: git-v2.3devel-383-g6ef8f72
>>
>> BR/Deepak
>>
>
>
> _______________________________________________
> midPoint mailing list
> midPoint at lists.evolveum.com
> http://lists.evolveum.com/mailman/listinfo/midpoint


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.evolveum.com/pipermail/midpoint/attachments/20140109/977a5de7/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: compose-unknown-contact.jpg
Type: image/jpeg
Size: 770 bytes
Desc: not available
URL: <https://lists.evolveum.com/pipermail/midpoint/attachments/20140109/977a5de7/attachment.jpg>


More information about the midPoint mailing list