<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright (c) 2010-2017 Evolveum and contributors
  ~
  ~ This work is dual-licensed under the Apache License 2.0
  ~ and European Union Public License. See LICENSE file for details.
  -->

<resource oid="10000000-0000-0000-0000-000000000004"
          xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
          xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
          xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3"
          xmlns:icfs="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-3"
          xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3"
          xmlns:piracy="http://midpoint.evolveum.com/xml/ns/samples/piracy"
          xmlns:xsd="http://www.w3.org/2001/XMLSchema"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <name>Dummy Resource</name>
    <connectorRef type="c:ConnectorType">
        <filter>
            <q:and>
                <q:equal>
                    <q:path>connectorType</q:path>
                    <q:value>com.evolveum.icf.dummy.connector.DummyConnector</q:value>
                </q:equal>
                <q:equal>
                    <q:path>connectorVersion</q:path>
                    <q:value>2.0</q:value>
                </q:equal>
            </q:and>
        </filter>
    </connectorRef>
    <connectorConfiguration xmlns:icfi="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/bundle/com.evolveum.icf.dummy/com.evolveum.icf.dummy.connector.DummyConnector"
                   xmlns:icfc="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/connector-schema-3">

        <icfc:configurationProperties>
            <icfi:instanceId></icfi:instanceId> <!-- Default instance. -->
        </icfc:configurationProperties>

    </connectorConfiguration>

    <schemaHandling>
        <objectType>
            <kind>account</kind>
            <intent>default</intent>
            <displayName>Default Account</displayName>
            <default>true</default>
            <objectClass>ri:AccountObjectClass</objectClass>
            <attribute>
                <ref>icfs:name</ref>
                <displayName>Username</displayName>
                <outbound>
                    <name>ICFS NAME outbound mapping</name>
                    <strength>weak</strength>
                    <source>
                        <path>$user/name</path>
                    </source>
                    <expression>
                        <script>
                            <code>
                                name + iterationToken
                            </code>
                        </script>
                    </expression>
                </outbound>
                <inbound>
                    <name>ICFS NAME inbound mapping</name>
                    <!-- This avoids "kickback" of a name from account to a user. -->
                    <strength>weak</strength>
                    <target>
                        <path>$c:user/c:name</path>
                    </target>
                </inbound>
            </attribute>
            <attribute>
                <ref>icfs:uid</ref>
                <displayName>UID</displayName>
            </attribute>
            <attribute>
                <ref>ri:fullname</ref>
                <displayName>Full Name</displayName>
                <outbound>
                    <name>fullname outbound mapping</name>
                    <source>
                        <path>$user/fullName</path>
                    </source>
                </outbound>
                <inbound>
                    <name>fullname inbound mapping</name>
                    <strength>weak</strength>
                    <target>
                        <path>$user/fullName</path>
                    </target>
                </inbound>
            </attribute>
            <attribute>
                <ref>ri:location</ref>
                <displayName>Location</displayName>
                <outbound>
                    <name>location outbound mapping</name>
                    <strength>strong</strength>
                    <source>
                        <path>declare namespace c="http://midpoint.evolveum.com/xml/ns/public/common/common-3";
                            $c:user/c:locality</path>
                    </source>
                </outbound>
                <inbound>
                    <name>location inbound mapping</name>
                    <channel>http://midpoint.evolveum.com/xml/ns/public/common/channels-3#import</channel>
                    <expression>
                        <script>
                            <code>'Came from ' + input</code>
                        </script>
                    </expression>
                    <target>
                        <path>description</path>
                    </target>
                </inbound>
            </attribute>
            <attribute>
                <ref>ri:ship</ref>
                <displayName>Ship</displayName>
                <inbound>
                    <expression>
                        <script>
                            <includeNullInputs>false</includeNullInputs>
                            <code>'The crew of ' + input</code>
                        </script>
                    </expression>
                    <target>
                        <path>organizationalUnit</path>
                    </target>
                </inbound>
            </attribute>
            <attribute>
                <ref>ri:loot</ref>
                <displayName>Loot</displayName>
                <fetchStrategy>explicit</fetchStrategy>
                <outbound>
                    <channel>http://pirates.net/avast</channel>
                    <expression>
                        <value>10000</value>
                    </expression>
                </outbound>
                <inbound>
                    <channel>http://midpoint.evolveum.com/xml/ns/public/common/channels-3#liveSync</channel>
                    <target>
                        <path>costCenter</path>
                    </target>
                </inbound>
            </attribute>
            <attribute>
                <ref>ri:weapon</ref>
                <displayName>Weapon</displayName>
                <outbound>
                    <source>
                        <path>declare namespace piracy="http://midpoint.evolveum.com/xml/ns/samples/piracy";
                            $user/extension/piracy:weapon
                        </path>
                    </source>
                </outbound>
            </attribute>
            <attribute>
                <ref>ri:drink</ref>
                <displayName>Drink</displayName>
                <tolerant>false</tolerant>
                <outbound>
                    <strength>strong</strength>
                    <expression>
                        <value>rum</value>
                    </expression>
                </outbound>
            </attribute>
            <attribute>
                <ref>ri:quote</ref>
                <displayName>Quote</displayName>
                <tolerant>true</tolerant>
                <outbound>
                    <strength>strong</strength>
                    <expression>
                        <value>Arr!</value>
                    </expression>
                </outbound>
            </attribute>

            <association>
                <ref>ri:group</ref>
                <kind>entitlement</kind>
                <intent>group</intent>
                <direction>objectToSubject</direction>
                <associationAttribute>ri:members</associationAttribute>
                <valueAttribute>icfs:name</valueAttribute>
            </association>

            <association>
                <ref>ri:priv</ref>
                <kind>entitlement</kind>
                <intent>privilege</intent>
                <direction>subjectToObject</direction>
                <associationAttribute>ri:privileges</associationAttribute>
                <valueAttribute>icfs:name</valueAttribute>
            </association>

            <iteration>
                <maxIterations>5</maxIterations>
            </iteration>

            <protected>
                <filter>
                    <q:equal>
                        <q:path>attributes/name</q:path>
                        <q:value>daviejones</q:value>
                    </q:equal>
                </filter>
            </protected>
            <protected>
                <filter>
                    <q:equal>
                        <q:path>attributes/name</q:path>
                        <q:value>calypso</q:value>
                    </q:equal>
                </filter>
            </protected>

            <activation>
                <existence>
                    <outbound>
                        <timeTo>
                            <referenceTime>
                                <path>$shadow/activation/disableTimestamp</path>
                            </referenceTime>
                            <offset>P1M</offset>
                        </timeTo>
                        <expression>
                            <asIs/>
                        </expression>
                    </outbound>
                    <outbound>
                        <timeFrom>
                            <referenceTime>
                                <path>$shadow/activation/disableTimestamp</path>
                            </referenceTime>
                            <offset>P1M</offset>
                        </timeFrom>
                        <expression>
                            <value>false</value>
                        </expression>
                    </outbound>
                </existence>
                <administrativeStatus>
                    <outbound>
                        <expression>
                            <asIs/>
                        </expression>
                    </outbound>
                </administrativeStatus>
            </activation>

            <credentials>
                <password>
                    <outbound>
                        <expression>
                            <asIs/>
                        </expression>
                    </outbound>
                    <inbound>
                        <strength>weak</strength>
                        <expression>
                            <generate/>
                        </expression>
                    </inbound>
                </password>
            </credentials>

        </objectType>

        <objectType>
            <kind>entitlement</kind>
            <intent>group</intent>
            <default>false</default>
            <objectClass>ri:GroupObjectClass</objectClass>
            <attribute>
                <ref>icfs:name</ref>
                <displayName>Groupname</displayName>
                <outbound>
                    <source>
                        <path>$focus/name</path>
                    </source>
                </outbound>
                <inbound>
                    <strength>weak</strength>
                    <target>
                        <path>name</path>
                    </target>
                </inbound>
            </attribute>
            <attribute>
                <ref>ri:description</ref>
                <outbound>
                    <strength>weak</strength>
                    <source>
                        <path>$focus/description</path>
                    </source>
                </outbound>
                <inbound>
                    <strength>weak</strength>
                    <target>
                        <path>description</path>
                    </target>
                </inbound>
            </attribute>
        </objectType>

        <objectType>
            <!-- Not really used. It is here just to confuse the tests. -->
            <kind>entitlement</kind>
            <default>true</default>
            <objectClass>ri:CustomprivilegeObjectClass</objectClass>
        </objectType>

        <objectType>
            <!-- Not really used. It is here just to confuse the tests. -->
            <kind>entitlement</kind>
            <intent>fakePrivilege</intent>
            <objectClass>ri:CustomprivilegeObjectClass</objectClass>
        </objectType>

        <objectType>
            <!-- Not really used. It is here just to confuse the tests. -->
            <kind>entitlement</kind>
            <intent>badPrivilege</intent>
            <objectClass>ri:CustomprivilegeObjectClass</objectClass>
        </objectType>

        <objectType>
            <kind>entitlement</kind>
            <intent>privilege</intent>
            <objectClass>ri:CustomprivilegeObjectClass</objectClass>
        </objectType>

        <objectType>
            <!-- Not really used. It is here just to confuse the tests. -->
            <kind>entitlement</kind>
            <intent>uglyPrivilege</intent>
            <objectClass>ri:CustomprivilegeObjectClass</objectClass>
        </objectType>

    </schemaHandling>
    <scripts>
        <script>
            <host>resource</host>
            <language>Shell</language>
            <argument>
                            <script>
                               <code>
tmpSuffix = 'OU=vix,DC=win,DC=evolveum,DC=com'
switch (basic.stringify(user.getEmployeeType())) {
    case 'T':
        tmpSuffix = 'OU=Prefix1,' + tmpSuffix
        break
    case 'R':
        tmpSuffix = 'OU=Prefix1,' + tmpSuffix
        break
    case 'D':
        tmpSuffix = 'OU=Prefix1,' + tmpSuffix
        break
    case 'S':
        tmpSuffix = 'OU=Prefix1,' + tmpSuffix
        break
    default:
        tmpSuffix = 'OU=Prefix2,' + tmpSuffix
}
return tmpSuffix
                               </code>
                            </script>
                <name>midpoint_suffix</name>
            </argument>
            <argument>
                <path>$user/name</path>
                <name>midpoint_usercn</name><!-- this is sAMAccountName -->
            </argument>
            <argument>
                <script>
                    <code>
                '/dir/id/' + user.getFamilyName() + '_' + user.getName()
                    </code>
                </script>
                <name>midpoint_idpath</name>
            </argument>
            <argument>
                <script>
                    <code>
                '/dir/temp/' + user.getFamilyName() + '_' + user.getName()
                    </code>
                </script>
                <name>midpoint_temppath</name>
            </argument>
<code>user.getFamilyName() + '_' + user.getName()</code>

<!--             <operation>add</operation> -->
            <operation>reconcile</operation>
            <kind>account</kind>
            <order>before</order>
            <condition>
                <script>
                    <code>
                        return true
                    </code>
                </script>
            </condition>
        </script>

        <script>
            <host>resource</host>
            <language>Shell</language>
            <argument>
                            <script>
                               <code>
tmpSuffix = 'OU=vix,DC=win,DC=evolveum,DC=com'
switch (basic.stringify(user.getEmployeeType())) {
    case 'T':
        tmpSuffix = 'OU=Prefix1,' + tmpSuffix
        break
    case 'R':
        tmpSuffix = 'OU=Prefix1,' + tmpSuffix
        break
    case 'D':
        tmpSuffix = 'OU=Prefix1,' + tmpSuffix
        break
    case 'S':
        tmpSuffix = 'OU=Prefix1,' + tmpSuffix
        break
    default:
        tmpSuffix = 'OU=Prefix2,' + tmpSuffix
}
return tmpSuffix
                               </code>
                            </script>
                <name>midpoint_suffix</name>
            </argument>
            <argument>
                <path>$user/name</path>
                <name>midpoint_usercn</name><!-- this is sAMAccountName -->
            </argument>
            <argument>
                <script>
                    <code>
                '/dir/id/' + user.getFamilyName() + '_' + user.getName()
                    </code>
                </script>
                <name>midpoint_idpath</name>
            </argument>
            <argument>
                <script>
                    <code>
                '/dir/temp/' + user.getFamilyName() + '_' + user.getName()
                    </code>
                </script>
                <name>midpoint_temppath</name>
            </argument>
<code>user.getFamilyName() + '_' + user.getName()</code>

<!--             <operation>add</operation> -->
            <operation>reconcile</operation>
            <kind>account</kind>
            <order>before</order>
            <condition>
                <script>
                    <code>
                        //just for testing condition evaluation
                        return false
                    </code>
                </script>
            </condition>
        </script>

    </scripts>
    <consistency>
        <avoidDuplicateValues>true</avoidDuplicateValues>
    </consistency>

    <synchronization>
        <objectSynchronization>
            <name>Account sync policy</name>
            <objectClass>ri:AccountObjectClass</objectClass>
            <enabled>true</enabled>
            <correlation>
                <q:equal>
                    <q:path>c:name</q:path>
                    <expression>
                        <path>declare namespace icfs="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-3";
                        $account/attributes/icfs:name</path>
                    </expression>
                </q:equal>
            </correlation>
            <reaction>
                <situation>linked</situation>
                <synchronize>true</synchronize>
            </reaction>
            <reaction>
                <situation>deleted</situation>
                <synchronize>true</synchronize>
            </reaction>
            <reaction>
                <situation>unlinked</situation>
                <synchronize>true</synchronize>
                <action>
                     <handlerUri>http://midpoint.evolveum.com/xml/ns/public/model/action-3#link</handlerUri>
                 </action>
            </reaction>
            <reaction>
                <situation>unmatched</situation>
                <synchronize>true</synchronize>
<!--             <channel>http://midpoint.evolveum.com/xml/ns/public/common/channels-3#import</channel> -->
                <action>
                    <handlerUri>http://midpoint.evolveum.com/xml/ns/public/model/action-3#addFocus</handlerUri>
                </action>
            </reaction>
        </objectSynchronization>

        <objectSynchronization>
            <name>Group sync policy</name>
            <objectClass>ri:GroupObjectClass</objectClass>
            <kind>entitlement</kind>
            <intent>group</intent>
            <focusType>c:RoleType</focusType>
            <enabled>true</enabled>
            <correlation>
                <q:equal>
                    <q:path>c:name</q:path>
                    <expression>
                        <path>declare namespace icfs="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-3";$shadow/attributes/icfs:name</path>
                    </expression>
                </q:equal>
            </correlation>
            <reaction>
                <situation>linked</situation>
                <synchronize>true</synchronize>
            </reaction>
            <reaction>
                <situation>deleted</situation>
                <synchronize>true</synchronize>
                <action>
                    <handlerUri>http://midpoint.evolveum.com/xml/ns/public/model/action-3#unlink</handlerUri>
                </action>
            </reaction>
            <reaction>
                <situation>unlinked</situation>
                <synchronize>true</synchronize>
                <action>
                    <handlerUri>http://midpoint.evolveum.com/xml/ns/public/model/action-3#link</handlerUri>
                </action>
            </reaction>
            <reaction>
                <situation>unmatched</situation>
                <synchronize>true</synchronize>
                <action>
                    <handlerUri>http://midpoint.evolveum.com/xml/ns/public/model/action-3#addFocus</handlerUri>
                </action>
            </reaction>
        </objectSynchronization>
    </synchronization>

</resource>
