<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright (c) 2010-2019 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"
        xmlns:t="http://prism.evolveum.com/xml/ns/public/types-3"
        oid="00000000-0000-0000-0000-000000000140">
    <name>Certification campaigns report</name>
    <description>All certification campaigns along with their state.</description>
    <assignment id="1">
        <identifier>archetype</identifier>
        <targetRef oid="00000000-0000-0000-0000-000000000171" type="ArchetypeType" />
    </assignment>
    <objectCollection>
        <collection>
            <filter>
                <q:text>
                    state = yaml```
                        queryInterpretationOfNoValue: filterAll
                        script:
                            code: |
                                import com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignStateType
                                // If \"alsoClosedCampaigns\" is true, we return null that causes all campaigns to be considered
                                return alsoClosedCampaigns ? null : AccessCertificationCampaignStateType.CREATED
                    ``` or state = 'inReviewStage' or state = 'reviewStageDone' or state = 'inRemediation'
                </q:text>
            </filter>
            <baseCollectionRef>
                <collectionRef oid="00000000-0000-0000-0001-000000000280" type="ObjectCollectionType"/>
            </baseCollectionRef>
        </collection>
        <view>
            <column id="2">
                <name>name</name>
                <path>name</path>
                <display>
                    <label>
                        <orig>Name</orig>
                        <translation>
                            <key>reportCertificationCampaigns.nameColumn.label</key>
                        </translation>
                    </label>
                </display>
            </column>
            <column id="3">
                <name>owner</name>
                <path>ownerRef</path>
                <display>
                    <label>
                        <orig>Owner</orig>
                        <translation>
                            <key>reportCertificationCampaigns.ownerColumn.label</key>
                        </translation>
                    </label>
                </display>
                <previousColumn>name</previousColumn>
            </column>
            <column id="4">
                <name>startTimestamp</name>
                <path>startTimestamp</path>
                <display>
                    <label>
                        <orig>Start</orig>
                        <translation>
                            <key>reportCertificationCampaigns.startTimestampColumn.label</key>
                        </translation>
                    </label>
                </display>
                <previousColumn>owner</previousColumn>
            </column>
            <column id="5">
                <name>endTimestamp</name>
                <path>endTimestamp</path>
                <display>
                    <label>
                        <orig>Finish</orig>
                        <translation>
                            <key>reportCertificationCampaigns.endTimestampColumn.label</key>
                        </translation>
                    </label>
                </display>
                <previousColumn>startTimestamp</previousColumn>
            </column>
            <column id="6">
                <name>cases</name>
                <path>case</path>
                <display>
                    <label>
                        <orig>Cases</orig>
                        <translation>
                            <key>reportCertificationCampaigns.casesColumn.label</key>
                        </translation>
                    </label>
                </display>
                <previousColumn>endTimestamp</previousColumn>
                <displayValue>number</displayValue>
            </column>
            <column id="7">
                <name>state</name>
                <path>state</path>
                <display>
                    <label>
                        <orig>State</orig>
                        <translation>
                            <key>reportCertificationCampaigns.stateColumn.label</key>
                        </translation>
                    </label>
                </display>
                <previousColumn>cases</previousColumn>
            </column>
            <column id="8">
                <name>stageNumber</name>
                <path>stageNumber</path>
                <display>
                    <label>
                        <orig>Actual stage</orig>
                        <translation>
                            <key>reportCertificationCampaigns.stageNumberColumn.label</key>
                        </translation>
                    </label>
                </display>
                <previousColumn>state</previousColumn>
            </column>
            <column id="9">
                <name>stageCases</name>
                <display>
                    <label>
                        <orig>Stage cases</orig>
                        <translation>
                            <key>reportCertificationCampaigns.stageCasesColumn.label</key>
                        </translation>
                    </label>
                </display>
                <previousColumn>stageNumber</previousColumn>
                <export>
                    <expression>
                        <script>
                            <code>
                                import com.evolveum.midpoint.schema.util.CertCampaignTypeUtil
                                import com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType

                                def campaign = object as AccessCertificationCampaignType
                                CertCampaignTypeUtil.getActiveCases(campaign.case, campaign.stageNumber, campaign.state)
                            </code>
                        </script>
                    </expression>
                </export>
            </column>
            <column id="10">
                <name>percentComplete</name>
                <display>
                    <label>
                        <orig>% complete</orig>
                        <translation>
                            <key>reportCertificationCampaigns.percentCompleteColumn.label</key>
                        </translation>
                    </label>
                </display>
                <previousColumn>stageCases</previousColumn>
                <export>
                    <expression>
                        <script>
                            <code>
                                import com.evolveum.midpoint.schema.util.CertCampaignTypeUtil
                                import com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType

                                def campaign = object as AccessCertificationCampaignType
                                CertCampaignTypeUtil.getCasesDecidedPercentageAllStagesAllIterations(campaign) + " %"
                            </code>
                        </script>
                    </expression>
                </export>
            </column>
            <paging>
                <q:orderBy>name</q:orderBy>
                <q:orderDirection>ascending</q:orderDirection>
            </paging>
            <type>AccessCertificationCampaignType</type>
        </view>
        <useOnlyReportView>true</useOnlyReportView>
        <parameter id="11">
            <name>alsoClosedCampaigns</name>
            <type>boolean</type>
            <display>
                <label>
                    <t:orig>alsoClosedCampaigns</t:orig>
                    <t:translation>
                        <t:key>runReportPopupContent.param.name.alsoClosedCampaigns</t:key>
                    </t:translation>
                </label>
            </display>
        </parameter>
    </objectCollection>
</report>
