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

<report xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
        xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
        xmlns:org="http://midpoint.evolveum.com/xml/ns/public/common/org-3"
        xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3">
    <name>Work items report</name>
    <description>Currently open work items.</description>
    <assignment>
        <targetRef oid="00000000-0000-0000-0000-000000000171" relation="org:default" type="c:ArchetypeType"/>
    </assignment>
    <objectCollection>
        <collection>
            <collectionRef oid="c00c56e0-3dc4-4eef-bb1f-e5d71635b675" relation="org:default" type="c:ObjectCollectionType"/>
        </collection>
        <view>
            <column>
                <name>nameColumn</name>
                <path>name</path>
                <display>
                    <label>Name</label>
                </display>
                <export>
                    <expression>
                        <script>
                            <code>
                                import com.evolveum.midpoint.report.impl.ReportUtils;

                                if (object != null) {
                                return ReportUtils.prettyPrintForReport(object.asPrismContainerValue().getParent().getParent().asContainerable().getName());
                                }
                            </code>
                        </script>
                    </expression>
                </export>
            </column>
            <column>
                <name>createTimestampColumn</name>
                <display>
                    <label>Requested on</label>
                </display>
                <previousColumn>nameColumn</previousColumn>
                <export>
                    <expression>
                        <script>
                            <code>
                                import com.evolveum.midpoint.report.impl.ReportUtils;

                                if (object != null) {
                                return ReportUtils.prettyPrintForReport(object.asPrismContainerValue().getParent().getParent().asContainerable().getMetadata().getCreateTimestamp());
                                }
                            </code>
                        </script>
                    </expression>
                </export>
            </column>
            <column>
                <name>assigneeRefColumn</name>
                <path>assigneeRef</path>
                <previousColumn>createTimestampColumn</previousColumn>
            </column>
            <column>
                <name>objectColumn</name>
                <display>
                    <label>Requestee</label>
                </display>
                <previousColumn>assigneeRefColumn</previousColumn>
                <export>
                    <expression>
                        <script>
                            <code>
                                import com.evolveum.midpoint.report.impl.ReportUtils;

                                if (object != null) {
                                return ReportUtils.prettyPrintForReport(object.asPrismContainerValue().getParent().getParent().asContainerable().getObjectRef());
                                }
                            </code>
                        </script>
                    </expression>
                </export>
            </column>
            <column>
                <name>targetColumn</name>
                <display>
                    <label>Target</label>
                </display>
                <previousColumn>objectColumn</previousColumn>
                <export>
                    <expression>
                        <script>
                            <code>
                                import com.evolveum.midpoint.report.impl.ReportUtils;

                                if (object != null) {
                                return ReportUtils.prettyPrintForReport(object.asPrismContainerValue().getParent().getParent().asContainerable().getTargetRef());
                                }
                            </code>
                        </script>
                    </expression>
                </export>
            </column>
            <column>
                <name>requesterColumn</name>
                <display>
                    <label>Requester</label>
                </display>
                <previousColumn>targetColumn</previousColumn>
                <export>
                    <expression>
                        <script>
                            <code>
                                import com.evolveum.midpoint.report.impl.ReportUtils;

                                if (object != null) {
                                return ReportUtils.prettyPrintForReport(object.asPrismContainerValue().getParent().getParent().asContainerable().getRequestorRef());
                                }
                            </code>
                        </script>
                    </expression>
                </export>
            </column>
            <column>
                <name>waitingSinceColumn</name>
                <path>createTimestamp</path>
                <display>
                    <label>Waiting since</label>
                </display>
                <previousColumn>requesterColumn</previousColumn>
            </column>
            <column>
                <name>deadlineColumn</name>
                <path>deadline</path>
                <previousColumn>waitingSinceColumn</previousColumn>
            </column>
            <column>
                <name>workItemIDColumn</name>
                <display>
                    <label>Work item ID</label>
                </display>
                <previousColumn>deadlineColumn</previousColumn>
                <export>
                    <expression>
                        <script>
                            <code>
                                import com.evolveum.midpoint.schema.util.WorkItemId;

                                if (object != null) {
                                return WorkItemId.create(object.asPrismContainerValue().getParent().getParent().getOid(), object.getId()).asString();
                                }
                            </code>
                        </script>
                    </expression>
                </export>
            </column>
            <paging>
                <q:orderBy>../name</q:orderBy>
            </paging>
            <type>CaseWorkItemType</type>
        </view>
    </objectCollection>
    <fileFormat>
        <type>csv</type>
        <csv>
            <multivalueDelimiter>,</multivalueDelimiter>
            <fieldDelimiter>;</fieldDelimiter>
            <quote>'</quote>
            <quoteMode>all</quoteMode>
            <header>true</header>
        </csv>
    </fileFormat>
</report>
