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


<resource oid="1ba5d182-c4da-4de1-927e-c5e0b27cd2e3"
            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:ext="http://midpoint.evolveum.com/xml/ns/story/orgsync/ext"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:icfc="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/connector-schema-3">

    <name>Enterprise Architecture Catalog</name>

    <description>
        Definition of Enterprise Architecture Catalog as a source resource for information about applications.
    </description>

    <connectorRef type="ConnectorType">
        <filter>
            <q:text>connectorType = "com.evolveum.polygon.connector.csv.CsvConnector"</q:text>
        </filter>
    </connectorRef>

    <connectorConfiguration>
        <!-- Configuration specific for the CSV connector -->
        <icfc:configurationProperties
                xmlns:icfccsvfile="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/bundle/com.evolveum.polygon.connector-csv/com.evolveum.polygon.connector.csv.CsvConnector">
            <icfccsvfile:filePath>/opt/midpoint/var/resources/architecture.csv</icfccsvfile:filePath>
            <icfccsvfile:encoding>utf-8</icfccsvfile:encoding>
            <icfccsvfile:fieldDelimiter>,</icfccsvfile:fieldDelimiter>
            <icfccsvfile:multivalueDelimiter>;</icfccsvfile:multivalueDelimiter>
            <icfccsvfile:uniqueAttribute>appid</icfccsvfile:uniqueAttribute>
        </icfc:configurationProperties>
    </connectorConfiguration>

    <schemaHandling>

        <objectType>
            <displayName>Application</displayName>
            <kind>generic</kind>
            <intent>application</intent>
            <default>true</default>
            <delineation>
                <objectClass>AccountObjectClass</objectClass>
            </delineation>
            <focus>
                <type>ServiceType</type>
                <archetypeRef oid="00000000-0000-0000-0000-000000000329"/>
            </focus>
            <attribute>
                <ref>appid</ref>
                <displayName>Application ID</displayName>
                <inbound>
                    <target>
                        <path>identifier</path>
                    </target>
                </inbound>
            </attribute>
            <attribute>
                <ref>name</ref>
                <displayName>Name</displayName>
                <inbound>
                    <strength>weak</strength>
                    <target>
                        <path>name</path>
                    </target>
                </inbound>
            </attribute>
            <attribute>
                <ref>description</ref>
                <displayName>Description</displayName>
                <inbound>
                    <strength>weak</strength>
                    <target>
                        <path>description</path>
                    </target>
                </inbound>
            </attribute>
            <attribute>
                <ref>status</ref>
                <displayName>Status</displayName>
                <inbound>
                    <target>
                        <path>extension/appStatus</path>
                    </target>
                </inbound>
                <inbound>
                    <target>
                        <path>lifecycleState</path>
                    </target>
                    <expression>
                        <script>
                            <code>
                                switch (input) {
                                    case 'production' -> 'active'
                                    case 'pilot' -> 'active'
                                    case 'planned' -> 'draft'
                                    case 'deprecated' -> 'deprecated'
                                    case 'decommissioned' -> 'archived'
                                    default -> 'failed'
                                }
                            </code>
                        </script>
                    </expression>
                </inbound>
            </attribute>
            <attribute>
                <ref>deployment</ref>
            </attribute>

            <correlation>
                <correlators>
                    <items>
                        <item>
                            <ref>identifier</ref>
                        </item>
                    </items>
                </correlators>
            </correlation>

            <synchronization>
                <reaction>
                    <situation>linked</situation>
                    <actions>
                        <synchronize/>
                    </actions>
                </reaction>
                <reaction>
                    <situation>deleted</situation>
                    <actions>
                        <synchronize/>
                    </actions>
                </reaction>
                <reaction>
                    <situation>unlinked</situation>
                    <actions>
                        <link/>
                    </actions>
                </reaction>
                <reaction>
                    <situation>unmatched</situation>
<!--                    <channel>http://midpoint.evolveum.com/xml/ns/public/common/channels-3#import</channel>-->
                    <actions>
                        <addFocus/>
                    </actions>
                </reaction>
            </synchronization>

        </objectType>

    </schemaHandling>

    <projection>
        <assignmentPolicyEnforcement>none</assignmentPolicyEnforcement>
    </projection>

</resource>
