<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright (c) 2017 Evolveum
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~     http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<!-- This is a meta-role. A Role indented to be assigned to other roles.
     I really mean assigned, not included or induced. -->

<role oid="bb1adfda-cbee-11e5-a445-3c970e44b9e2"
        xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
        xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
        xmlns:t="http://prism.evolveum.com/xml/ns/public/types-3"
        xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3"
    xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3">
    <name>Functional Orgstruct Metarole</name>

   <inducement>
        <construction>
                <!-- OpenLDAP -->
                <resourceRef oid="40be7fa0-cbec-11e5-926a-3c970e44b9e2" type="c:ResourceType"/>
                <kind>generic</kind>
                <intent>ou-customer</intent>
        </construction>
        <condition>
            <source>
                <path>$immediateRole/subtype</path>
            </source>
                <expression>
                    <script>
                        <code>subtype == 'customer'</code>
                    </script>
                </expression>
        </condition>
   </inducement>
   <inducement>
        <construction>
                <!-- OpenLDAP -->
                <resourceRef oid="40be7fa0-cbec-11e5-926a-3c970e44b9e2" type="c:ResourceType"/>
                <kind>entitlement</kind>
                <intent>group-org-admin</intent>
        </construction>
        <condition>
            <source>
                <path>$immediateRole/subtype</path>
            </source>
                <expression>
                    <script>
                        <code>subtype == 'customer'</code>
                    </script>
                </expression>
        </condition>
    </inducement>
   <inducement>
        <construction>
                <!-- OpenLDAP -->
                <resourceRef oid="40be7fa0-cbec-11e5-926a-3c970e44b9e2" type="c:ResourceType"/>
                <kind>entitlement</kind>
                <intent>group-org-poweruser</intent>
        </construction>
        <condition>
            <source>
                <path>$immediateRole/subtype</path>
            </source>
                <expression>
                    <script>
                        <code>subtype == 'customer'</code>
                    </script>
                </expression>
        </condition>
    </inducement>
   <inducement>
        <construction>
                <!-- OpenLDAP -->
                <resourceRef oid="40be7fa0-cbec-11e5-926a-3c970e44b9e2" type="c:ResourceType"/>
                <kind>entitlement</kind>
                <intent>group-org-user</intent>
        </construction>
        <condition>
            <source>
                <path>$immediateRole/subtype</path>
            </source>
                <expression>
                    <script>
                        <code>subtype == 'customer'</code>
                    </script>
                </expression>
        </condition>
    </inducement>

   <inducement>
       <focusMappings>
           <mapping>
               <name>Set organizationalUnit from organization name</name>
               <strength>weak</strength><!-- XXX -->
               <source>
                   <path>$immediateRole/name</path>
               </source>
               <target>
                   <path>$user/organizationalUnit</path>
               </target>
           </mapping>
       </focusMappings>
       <order>2</order>
       <focusType>c:UserType</focusType>
    </inducement>

</role>
