<!--
  ~ Copyright (c) 2020 Evolveum and contributors
  ~
  ~ Licensed under the EUPL-1.2 or later.
  -->

<archetype oid="00000000-0000-0000-0000-000000000505"
        xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
        xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
        xmlns:mext="http://midpoint.evolveum.com/xml/ns/public/model/extension-3">
    <name>Asynchronous update task</name>
    <archetypePolicy>
        <display>
            <label>
                <orig>Asynchronous update task</orig>
                <translation>
                    <key>AsynchronousUpdateTask.label</key>
                </translation>
            </label>
            <pluralLabel>
                <orig>Asynchronous update tasks</orig>
                <translation>
                    <key>AsynchronousUpdateTasks.title</key>
                </translation>
            </pluralLabel>
            <icon>
                <cssClass>fa fa-bolt</cssClass>
                <color>green</color>
            </icon>
        </display>
        <itemConstraint id="1">
            <path>extension</path>
            <visibility>vacant</visibility>
        </itemConstraint>
        <itemConstraint id="2">
            <path xmlns:mext="http://midpoint.evolveum.com/xml/ns/public/model/extension-3">extension/mext:workerThreads</path>
            <visibility>visible</visibility>
        </itemConstraint>
        <adminGuiConfiguration>
            <objectDetails>
                <type>TaskType</type>
                <panel id="3">
                    <identifier>activity</identifier>
                    <panel id="5">
                        <identifier>work</identifier>
                        <container id="6">
                            <identifier>work-asynchronous-update</identifier>
                            <path>activity/work/asynchronousUpdate</path>
                        </container>
                    </panel>
                </panel>
                <panel id="4">
                    <identifier>taskBasic</identifier>
                    <container id="7">
                        <identifier>async-options</identifier>
                        <display>
                            <label>
                                <orig>Options</orig>
                                <translation>
                                    <key>AsynchronousUpdateTask.options</key>
                                </translation>
                            </label>
                        </display>
                        <item id="8">
                            <path>objectRef</path>
                        </item>
                        <item id="9">
                            <c:path>extension/mext:workerThreads</c:path>
                        </item>
                    </container>
                </panel>
            </objectDetails>
        </adminGuiConfiguration>
    </archetypePolicy>
    <assignment id="10">
        <identifier>holderType</identifier>
        <assignmentRelation id="11">
            <holderType>TaskType</holderType>
        </assignmentRelation>
    </assignment>
    <inducement id="12">
        <identifier>nameMapping</identifier>
        <focusMappings>
            <mapping id="13">
                <strength>weak</strength>
                <expression>
                    <script>
                        <code>
                            import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType
                            import org.apache.commons.lang3.StringUtils

                            def task = focus as TaskType

                            String name = source.name

                            String description = midpoint.describeResourceObjectSet(task?.activity?.work?.asynchronousUpdate?.resourceObjects)
                            if(StringUtils.isNotEmpty(description)) {
                                return name + ': ' + description
                            }

                            return name
                        </code>
                    </script>
                </expression>
                <target>
                    <path>name</path>
                </target>
            </mapping>
        </focusMappings>
    </inducement>
</archetype>
