<?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:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
        xmlns:t="http://prism.evolveum.com/xml/ns/public/types-3"
        oid="00000000-0000-0000-0000-000000000150">
    <name>Certification cases report</name>
    <description>Cases within given certification campaign(s).</description>
    <assignment id="1">
        <identifier>archetype</identifier>
        <targetRef oid="00000000-0000-0000-0000-000000000171" type="ArchetypeType"/>
    </assignment>
    <objectCollection>
        <collection>
            <filter>
                <q:text>
                    . ownedByOid yaml```
                        queryInterpretationOfNoValue: filterAll
                        script:
                            objectVariableMode: prismReference
                            code: campaignRef?.oid
                    ```
                </q:text>
            </filter>
        </collection>
        <view>
            <!-- We do sorting on object name. Hence, it is the first column. The campaign name would be more logical as the
                 first one, but we currently cannot sort on both campaign name and object name. And perhaps the primary use
                 case will be reporting on a specific campaign. -->
            <column id="2">
                <name>object</name>
                <path>objectRef</path>
                <display>
                    <label>
                        <orig>Object</orig>
                        <translation>
                            <key>reportCertificationCases.objectColumn.label</key>
                        </translation>
                    </label>
                </display>
                <export>
                    <expression>
                        <script>
                            <objectVariableMode>prismReference</objectVariableMode>
                            <code>
                                import com.evolveum.midpoint.report.impl.ReportUtils

                                // Provides the type plus object name
                                ReportUtils.prettyPrintForReport(input)
                            </code>
                        </script>
                    </expression>
                </export>
            </column>
            <column id="3">
                <name>target</name>
                <path>targetRef</path>
                <display>
                    <label>
                        <orig>Target</orig>
                        <translation>
                            <key>reportCertificationCases.targetColumn.label</key>
                        </translation>
                    </label>
                </display>
                <previousColumn>object</previousColumn>
                <export>
                    <expression>
                        <script>
                            <objectVariableMode>prismReference</objectVariableMode>
                            <code>
                                import com.evolveum.midpoint.report.impl.ReportUtils

                                // Provides the type plus object name
                                ReportUtils.prettyPrintForReport(input)
                            </code>
                        </script>
                    </expression>
                </export>
            </column>
            <column id="4">
                <name>campaignName</name>
                <display>
                    <label>
                        <orig>Campaign</orig>
                        <translation>
                            <key>reportCertificationCases.campaignNameColumn.label</key>
                        </translation>
                    </label>
                </display>
                <previousColumn>target</previousColumn>
                <export>
                    <expression>
                        <script>
                            <code>
                                import com.evolveum.midpoint.schema.util.CertCampaignTypeUtil
                                import com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType

                                CertCampaignTypeUtil.getCampaign(object as AccessCertificationCaseType)?.name?.orig
                            </code>
                        </script>
                    </expression>
                </export>
            </column>
            <column id="5">
                <name>reviewers</name>
                <display>
                    <label>
                        <orig>Reviewers</orig>
                        <translation>
                            <key>reportCertificationCases.reviewersColumn.label</key>
                        </translation>
                    </label>
                </display>
                <previousColumn>campaignName</previousColumn>
                <export>
                    <expression>
                        <script>
                            <code>
                                import com.evolveum.midpoint.schema.util.CertCampaignTypeUtil
                                import com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType

                                return CertCampaignTypeUtil.getCurrentlyAssignedReviewers(object as AccessCertificationCaseType)
                            </code>
                        </script>
                    </expression>
                </export>
            </column>
            <column id="6">
                <name>lastReviewedOn</name>
                <display>
                    <label>
                        <orig>Last reviewed on</orig>
                        <translation>
                            <key>reportCertificationCases.lastReviewedOnColumn.label</key>
                        </translation>
                    </label>
                </display>
                <previousColumn>reviewers</previousColumn>
                <export>
                    <expression>
                        <script>
                            <code>
                                import com.evolveum.midpoint.schema.util.CertCampaignTypeUtil
                                import com.evolveum.midpoint.report.impl.ReportUtils

                                CertCampaignTypeUtil.getLastReviewedOn(object.asPrismContainerValue())
                            </code>
                        </script>
                    </expression>
                </export>
            </column>
            <column id="7">
                <name>reviewedBy</name>
                <display>
                    <label>
                        <orig>Reviewed by</orig>
                        <translation>
                            <key>reportCertificationCases.reviewedByColumn.label</key>
                        </translation>
                    </label>
                </display>
                <previousColumn>lastReviewedOn</previousColumn>
                <export>
                    <expression>
                        <script>
                            <code>
                                import com.evolveum.midpoint.schema.util.CertCampaignTypeUtil
                                import com.evolveum.midpoint.report.impl.ReportUtils

                                CertCampaignTypeUtil.getReviewedBy(object.asPrismContainerValue())
                            </code>
                        </script>
                    </expression>
                </export>
            </column>
            <column id="8">
                <name>iteration</name>
                <path>iteration</path>
                <display>
                    <label>
                        <orig>Iteration</orig>
                        <translation>
                            <key>reportCertificationCases.iterationColumn.label</key>
                        </translation>
                    </label>
                </display>
                <previousColumn>reviewedBy</previousColumn>
            </column>
            <column id="9">
                <name>inStageNumber</name>
                <path>stageNumber</path>
                <display>
                    <label>
                        <orig>In stage</orig>
                        <translation>
                            <key>reportCertificationCases.inStageNumberColumn.label</key>
                        </translation>
                    </label>
                </display>
                <previousColumn>iteration</previousColumn>
            </column>
            <column id="10">
                <name>outcome</name>
                <path>outcome</path>
                <display>
                    <label>
                        <orig>Outcome</orig>
                        <translation>
                            <key>reportCertificationCases.outcomeColumn.label</key>
                        </translation>
                    </label>
                </display>
                <previousColumn>inStageNumber</previousColumn>
                <export>
                    <expression>
                        <script>
                            <code>
                                import com.evolveum.midpoint.report.impl.ReportUtils

                                ReportUtils.prettyPrintCertOutcomeForReport(input as String, false)
                            </code>
                        </script>
                    </expression>
                </export>
            </column>
            <column id="11">
                <name>comments</name>
                <display>
                    <label>
                        <orig>Comments</orig>
                        <translation>
                            <key>reportCertificationCases.commentsColumn.label</key>
                        </translation>
                    </label>
                </display>
                <previousColumn>outcome</previousColumn>
                <export>
                    <expression>
                        <script>
                            <code>
                                import com.evolveum.midpoint.schema.util.CertCampaignTypeUtil
                                import com.evolveum.midpoint.report.impl.ReportUtils

                                CertCampaignTypeUtil.getComments(object.asPrismContainerValue())
                            </code>
                        </script>
                    </expression>
                </export>
            </column>
            <column id="12">
                <name>remediedTimestamp</name>
                <path>remediedTimestamp</path>
                <display>
                    <label>
                        <orig>Remedied on</orig>
                        <translation>
                            <key>reportCertificationCases.remediedTimestampColumn.label</key>
                        </translation>
                    </label>
                </display>
                <previousColumn>comments</previousColumn>
            </column>
            <paging>
                <q:orderBy>objectRef/@/name</q:orderBy>
            </paging>
            <type>AccessCertificationCaseType</type>
        </view>
        <parameter id="13">
            <name>campaignRef</name>
            <type>c:ObjectReferenceType</type>
            <targetType>c:AccessCertificationCampaignType</targetType>
            <display>
                <label>
                    <t:orig>campaignName</t:orig>
                    <t:translation>
                        <t:key>runReportPopupContent.param.name.campaignName</t:key>
                    </t:translation>
                </label>
            </display>
        </parameter>
    </objectCollection>
</report>
