<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright (c) 2020 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.
  -->

<role oid="fbb4d564-9c10-4c92-9140-7bdd6af50fdc" xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3" xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3" xmlns:icfs="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-3" xmlns:org="http://midpoint.evolveum.com/xml/ns/public/common/org-3" xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3" xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3" xmlns:t="http://prism.evolveum.com/xml/ns/public/types-3">

    <name>Email Account</name>
    <inducement>
        <focusMappings>
            <!--
              ~ NOTE: There are two mutually exclusive email mappings.
              ~ We need to minimize sources of the mapping because of the provenance metadata.
              ~ Otherwise provenance metadata would contain also source which might not be used in the mapping computaton.
            -->
            <mapping>
                <name>Email mapping</name>
                <strength>strong</strength>
                <source>
                    <path>nickName</path>
                </source>
                <expression>
                    <script>
                        <code>nickName + "@myuniversity.eu"</code>
                    </script>
                </expression>
                <target>
                    <path>emailAddress</path>
                </target>
                <condition>
                    <script>
                        <code>
                            nickName != null
                        </code>
                    </script>
                </condition>
            </mapping>

            <mapping>
                <name>Email mapping</name>
                <strength>strong</strength>
                <source>
                    <path>familyName</path>
                </source>
                <expression>
                    <script>
                        <code>familyName + "@myuniversity.eu"</code>
                    </script>
                </expression>
                <target>
                    <path>emailAddress</path>
                </target>
                <condition>
                    <script>
                        <code>
                            user.nickName == null &amp;&amp; familyName != null
                        </code>
                    </script>
                </condition>
            </mapping>
        </focusMappings>
    </inducement>

</role>