<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright (c) 2010-2020 Evolveum and contributors
  ~
  ~ Licensed under the EUPL-1.2 or later.
  -->

<report xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
        xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3"
        oid="00000000-0000-0000-0000-000000000130">
    <name>Certification definitions report</name>
    <description>All certification definitions with basic information on related campaigns.</description>
    <assignment id="1">
        <identifier>archetype</identifier>
        <targetRef oid="00000000-0000-0000-0000-000000000171" type="ArchetypeType" />
    </assignment>
    <objectCollection>
        <collection>
            <!-- Type is declared in the view element. -->
        </collection>
        <view>
            <column id="2">
                <name>name</name>
                <path>name</path>
            </column>
            <column id="3">
                <name>owner</name>
                <path>ownerRef</path>
                <display>
                    <label>
                        <orig>Owner</orig>
                        <translation>
                            <key>reportCertificationDefinitions.ownerColumn.label</key>
                        </translation>
                    </label>
                </display>
                <previousColumn>name</previousColumn>
            </column>
            <column id="4">
                <name>campaigns</name>
                <display>
                    <label>
                        <orig>Campaigns</orig>
                        <translation>
                            <key>reportCertificationDefinitions.campaignsColumn.label</key>
                        </translation>
                    </label>
                </display>
                <previousColumn>owner</previousColumn>
                <export>
                    <expression>
                        <script>
                            <code>campaigns</code>
                        </script>
                    </expression>
                </export>
                <displayValue>number</displayValue>
            </column>
            <column id="5">
                <name>openCampaigns</name>
                <display>
                    <label>
                        <orig>Open campaigns</orig>
                        <translation>
                            <key>reportCertificationDefinitions.openCampaignsColumn.label</key>
                        </translation>
                    </label>
                </display>
                <previousColumn>campaigns</previousColumn>
                <export>
                    <expression>
                        <script>
                            <code><![CDATA[
                                import com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType
                                import static com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignStateType.*

                                (campaigns as Collection<AccessCertificationCampaignType>)
                                        .count { it.state != CREATED && it.state != CLOSED }
                            ]]></code>
                        </script>
                    </expression>
                </export>
            </column>
            <column id="6">
                <name>lastStarted</name>
                <path>lastCampaignStartedTimestamp</path>
                <display>
                    <label>
                        <orig>Last started</orig>
                        <translation>
                            <key>reportCertificationDefinitions.lastStartedColumn.label</key>
                        </translation>
                    </label>
                </display>
                <previousColumn>openCampaigns</previousColumn>
            </column>
            <column id="7">
                <name>lastClosed</name>
                <path>lastCampaignClosedTimestamp</path>
                <display>
                    <label>
                        <orig>Last closed</orig>
                        <translation>
                            <key>reportCertificationDefinitions.lastClosedColumn.label</key>
                        </translation>
                    </label>
                </display>
                <previousColumn>lastStarted</previousColumn>
            </column>
            <paging>
                <q:orderBy>name</q:orderBy>
                <q:orderDirection>ascending</q:orderDirection>
            </paging>
            <type>AccessCertificationDefinitionType</type>
        </view>
        <useOnlyReportView>true</useOnlyReportView>
        <subreport id="8">
            <name>campaigns</name>
            <type>AccessCertificationCampaignType</type>
            <expression>
                <script>
                    <code>
                        import com.evolveum.midpoint.prism.query.ObjectQuery
                        import com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType

                        midpoint.searchObjects(
                            AccessCertificationCampaignType.class,
                            prismContext.queryFor(AccessCertificationCampaignType.class)
                                .item(AccessCertificationCampaignType.F_DEFINITION_REF)
                                .ref(object.oid)
                                .build() as ObjectQuery,
                            null)
                    </code>
                </script>
            </expression>
        </subreport>
    </objectCollection>
</report>
