<resource 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" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:icfc="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/connector-schema-3"
          oid="e1b34373-f61e-4a5a-9fb1-81f931fcfc05" version="0">
    <name>dms</name>

    <connectorRef>
        <filter>
            <q:text>connectorType = "com.evolveum.polygon.connector.scripted.sql.ScriptedSQLConnector"</q:text>
        </filter>
    </connectorRef>

    <c:connectorConfiguration>
        <!-- Configuration specific for the ScriptedSQL connector -->
        <icfc:configurationProperties
                xmlns:icscscriptedsql="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/bundle/com.evolveum.polygon.connector-scripted-sql/com.evolveum.polygon.connector.scripted.sql.ScriptedSQLConnector">
            <icscscriptedsql:createScriptFileName>CreateScript.groovy</icscscriptedsql:createScriptFileName>
            <icscscriptedsql:updateScriptFileName>UpdateScript.groovy</icscscriptedsql:updateScriptFileName>
            <icscscriptedsql:deleteScriptFileName>DeleteScript.groovy</icscscriptedsql:deleteScriptFileName>
            <icscscriptedsql:schemaScriptFileName>SchemaScript.groovy</icscscriptedsql:schemaScriptFileName>
            <icscscriptedsql:searchScriptFileName>SearchScript.groovy</icscscriptedsql:searchScriptFileName>
            <icscscriptedsql:testScriptFileName>TestScript.groovy</icscscriptedsql:testScriptFileName>
            <icscscriptedsql:scriptRoots>D:/mp-projects/issues/testing/associations-49-m5/dms/scripts</icscscriptedsql:scriptRoots>
            <icscscriptedsql:classpath>.</icscscriptedsql:classpath>
            <icscscriptedsql:scriptBaseClass>BaseScript</icscscriptedsql:scriptBaseClass>

            <icscscriptedsql:recompileGroovySource>true</icscscriptedsql:recompileGroovySource>

            <icscscriptedsql:user>midpoint</icscscriptedsql:user>
            <icscscriptedsql:password>password</icscscriptedsql:password>
            <icscscriptedsql:jdbcDriver>org.postgresql.Driver</icscscriptedsql:jdbcDriver>
            <icscscriptedsql:jdbcUrlTemplate>jdbc:postgresql://localhost:5432/dms</icscscriptedsql:jdbcUrlTemplate>
        </icfc:configurationProperties>
    </c:connectorConfiguration>

    <capabilities xmlns:cap="http://midpoint.evolveum.com/xml/ns/public/resource/capabilities-3">
        <configured>
<!--            <cap:pagedSearch/>-->
<!--            <cap:countObjects/>-->
            <cap:create>
                <cap:enabled>true</cap:enabled>
            </cap:create>
            <cap:update>
                <cap:enabled>true</cap:enabled>
            </cap:update>
            <cap:delete>
                <cap:enabled>true</cap:enabled>
            </cap:delete>
        </configured>
    </capabilities>

    <schemaHandling>
        <objectType>
            <kind>account</kind>
            <intent>default</intent>
            <default>true</default>
            <delineation>
                <objectClass>ri:user</objectClass>
            </delineation>
            <focus>
                <type>UserType</type>
            </focus>
            <attribute>
                <ref>icfs:name</ref>
                <correlator/>
                <inbound>
                    <strength>strong</strength>
                    <target>
                        <path>name</path>
                    </target>
                </inbound>
                <outbound>
                    <strength>strong</strength>
                    <source>
                        <path>name</path>
                    </source>
                </outbound>
            </attribute>
            <attribute>
                <ref>ri:fullname</ref>
                <inbound>
                    <strength>strong</strength>
                    <target>
                        <path>fullName</path>
                    </target>
                </inbound>
                <outbound>
                    <strength>strong</strength>
                    <source>
                        <path>fullName</path>
                    </source>
                </outbound>
            </attribute>
            <attribute>
                <ref>ri:email</ref>
                <inbound>
                    <strength>strong</strength>
                    <target>
                        <path>emailAddress</path>
                    </target>
                </inbound>
                <outbound>
                    <strength>strong</strength>
                    <source>
                        <path>emailAddress</path>
                    </source>
                </outbound>
            </attribute>
            <synchronization>
                <reaction>
                    <situation>unmatched</situation>
                    <actions>
                        <addFocus/>
                    </actions>
                </reaction>
                <reaction>
                    <situation>unlinked</situation>
                    <actions>
                        <link/>
                    </actions>
                </reaction>
                <reaction>
                    <situation>linked</situation>
                    <actions>
                        <synchronize/>
                    </actions>
                </reaction>
            </synchronization>
        </objectType>
        <objectType>
            <kind>generic</kind>
            <intent>documentStore</intent>
            <delineation>
                <objectClass>ri:documentStore</objectClass>
            </delineation>
            <focus>
                <type>ServiceType</type>
                <archetypeRef oid="8c0b32f9-fadc-42cb-bc05-878ecfe001e8"/>
            </focus>
            <attribute>
                <ref>icfs:name</ref>
                <correlator/>
                <inbound>
                    <strength>strong</strength>
                    <target>
                        <path>name</path>
                    </target>
                </inbound>
            </attribute>
            <attribute>
                <ref>ri:description</ref>
                <inbound>
                    <strength>strong</strength>
                    <target>
                        <path>displayName</path>
                    </target>
                </inbound>
            </attribute>
            <synchronization>
                <reaction>
                    <situation>unmatched</situation>
                    <actions>
                        <addFocus/>
                    </actions>
                </reaction>
                <reaction>
                    <situation>unlinked</situation>
                    <actions>
                        <link/>
                    </actions>
                </reaction>
                <reaction>
                    <situation>linked</situation>
                    <actions>
                        <synchronize/>
                    </actions>
                </reaction>
            </synchronization>
        </objectType>
        <associationType>
            <name>userDocumentStoreAccess</name>
            <subject>
                <objectType>
                    <kind>account</kind>
                    <intent>default</intent>
                </objectType>
                <association>
                    <ref>ri:access</ref>
                    <outbound>
                        <name>association-outbound</name>
                        <expression>
                            <associationConstruction>
                                <attribute>
                                    <ref>ri:level</ref>
                                    <mapping>
                                        <source>
                                            <path>targetRef</path>
                                        </source>
                                        <expression>
                                            <script>
                                                <code>targetRef?.relation?.localPart</code>
                                            </script>
                                        </expression>
                                    </mapping>
                                </attribute>
                                <objectRef>
                                    <ref>ri:documentStore</ref>
                                    <mapping>
                                        <expression>
                                            <associationFromLink/>
                                        </expression>
                                    </mapping>
                                </objectRef>
                            </associationConstruction>
                        </expression>
                    </outbound>
                    <inbound>
                        <name>association-inbound</name>
                        <expression>
                            <associationSynchronization>
                                <objectRef>
                                    <ref>ri:documentStore</ref>
                                    <mapping>
                                        <source>
                                            <path>$shadow/attributes/ri:level</path>
                                        </source>
                                        <expression>
                                            <shadowOwnerReferenceSearch>
                                                <relationExpression>
                                                    <path>$level</path>
                                                </relationExpression>
                                            </shadowOwnerReferenceSearch>
                                        </expression>
                                        <target>
                                            <path>targetRef</path>
                                        </target>
                                    </mapping>
                                </objectRef>
                                <correlation>
                                    <correlators>
                                        <items>
                                            <item>
                                                <ref>targetRef</ref>
                                            </item>
                                        </items>
                                    </correlators>
                                </correlation>
                                <synchronization>
                                    <reaction>
                                        <situation>unmatched</situation>
                                        <actions>
                                            <addFocusValue/>
                                        </actions>
                                    </reaction>
                                    <reaction>
                                        <situation>matched</situation>
                                        <actions>
                                            <synchronize/>
                                        </actions>
                                    </reaction>
                                </synchronization>
                            </associationSynchronization>
                        </expression>
                    </inbound>
                </association>
            </subject>
        </associationType>
    </schemaHandling>
</resource>
