[midPoint] strange crach in groovy

Forest Crowley fbc216 at lehigh.edu
Fri Apr 17 17:24:09 CEST 2020


In your first example Groovy doesn't know that your next line continues the
previous one. It's similar to Python in that new lines end statements. It
evaluates `listeAffectations?.startsWith("HIE")` alone and then it tries to
evaluate `|| listeAffectations?.startsWith("FUN")` which crashes because
the interpreter doesn't understand how to handle || without anything to the
left. When you switch the `||` positioning in your second example, Groovy
is smart enough to look ahead and see something for it OR on the next
line.

If you want to write your ORs like you did in the first example (my
preferred style as well) you can wrap the whole thing in parenthesis, and
then Groovy will evaluate the whole block as one statement.

(listeAffectations?.startsWith("HIE")
 || listeAffectations?.startsWith("FUN")
 || listeAffectations?.startsWith("HOP")
 || listeAffectations?.startsWith("ETU"))

On Fri, Apr 17, 2020 at 6:39 AM Pascal Perichon <
pascal.perichon at parisdescartes.fr> wrote:

> Hello,
>
> the following groovy script in the condition statement crash:
>
> *<attribute id="20">*
> *     <c:ref
> xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3"
> <http://midpoint.evolveum.com/xml/ns/public/resource/instance-3>>ri:supannEntiteAffectation</c:ref>*
> *                <displayName>Affectation Fonctionnelle</displayName>*
> *                <limitations>*
> *                    <minOccurs>0</minOccurs>*
> *                    <maxOccurs>-1</maxOccurs>*
> *                </limitations>*
> *                <outbound>*
> *                    <strength>strong</strength>*
> *                    <source>*
> *
> <c:path>$focus/extension/listeAffectations</c:path>*
> *                        <set>*
> *                            <condition>*
> *                                <script
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> <http://www.w3.org/2001/XMLSchema-instance>
> xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
> <http://midpoint.evolveum.com/xml/ns/public/common/common-3>
> xsi:type="c:ScriptExpressionEvaluatorType">*
> *                                    <code>*
>
>
>
>
> *
> listeAffectations?.startsWith("HIE")
> || listeAffectations?.startsWith("FUN")
>                                        ||
> listeAffectations?.startsWith("HOP")
> || listeAffectations?.startsWith("ETU")
> </code>*
> *                                </script>*
> *                            </condition>*
> *                        </set>*
> *                    </source>*
>
> *                ...*
>
> *                </outbound>*
> *</attribute>*
>
>
> with the follwing error:
>
> *2020-04-17 11:45:09,219 [MODEL] [pool-3-thread-16] ERROR
> (com.evolveum.midpoint.model.common.expression.script.ScriptExpression):
> Expression error: Compilation error in (old) domain of listeAffectations in
> mapping in outbound mapping for
> {.../resource/instance-3}supannEntiteAffectation in
> resource:u75-connecteur-LDAP-UP(LDAP UP): startup failed:*
> *(old) domain of listeAffectations in mapping in outbound mapping for
> {.../resource/instance-3}supannEntiteAffectation in
> resource:u75-connecteur-LDAP-UP(LDAP UP): 3: unexpected token: || @ line 3,
> column 45.*
> *                                 || listeAf*
> *                                 ^*
>
> *1 error*
>
>
> and this one works without problem (the same except that the '||' are at
> the end of lines):
>
> *<attribute id="20">*
> *      <c:ref
> xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3"
> <http://midpoint.evolveum.com/xml/ns/public/resource/instance-3>>ri:supannEntiteAffectation</c:ref>*
> *                 <displayName>Affectation Fonctionnelle</displayName>*
> *                 <limitations>*
> *                     <minOccurs>0</minOccurs>*
> *                     <maxOccurs>-1</maxOccurs>*
> *                 </limitations>*
> *                 <outbound>*
> *                     <strength>strong</strength>*
> *                     <source>*
> *
> <c:path>$focus/extension/listeAffectations</c:path>*
> *                         <set>*
> *                             <condition>*
> *                                 <script
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> <http://www.w3.org/2001/XMLSchema-instance>
> xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
> <http://midpoint.evolveum.com/xml/ns/public/common/common-3>
> xsi:type="c:ScriptExpressionEvaluatorType">*
> *                                     <code>*
>
>
>
>
> *
> listeAffectations?.startsWith("HIE") ||
>                                        listeAffectations?.startsWith("FUN")
> ||
> listeAffectations?.startsWith("HOP") ||
>                                        listeAffectations?.startsWith("ETU")
> **                                    </code>*
> *                                 </script>*
> *                             </condition>*
> *                         </set>*
> *                     </source>*
>
> *                ...*
>
> *                </outbound>*
> * </attribute>*
>
>
> Did I missed something ?
>
> thanks
> _______________________________________________
> midPoint mailing list
> midPoint at lists.evolveum.com
> https://lists.evolveum.com/mailman/listinfo/midpoint
>


-- 
Forest B. Crowley
Information Security
Lehigh University
610-758-3838
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.evolveum.com/pipermail/midpoint/attachments/20200417/dd24918a/attachment.htm>


More information about the midPoint mailing list