<?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"
        xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
        oid="00000000-0000-0000-0000-000000000110">
    <name>Users in MidPoint</name>
    <description>Users listed in MidPoint.</description>
    <assignment id="1">
        <identifier>archetype</identifier>
        <targetRef oid="00000000-0000-0000-0000-000000000171" type="ArchetypeType"/>
    </assignment>
    <objectCollection>
        <collection>
            <filter>
                <q:text>
                    activation/administrativeStatus = yaml```
                            queryInterpretationOfNoValue: filterAll
                            path: "$activation"
                    ``` and assignment/targetRef = yaml```
                            queryInterpretationOfNoValue: filterAll
                            path: "$organizationRef"
                    ``` and assignment/targetRef = yaml```
                            queryInterpretationOfNoValue: filterAll
                            path: "$roleRef"
                    ``` and assignment/construction/resourceRef = yaml```
                            queryInterpretationOfNoValue: filterAll
                            path: "$resourceRef"
                    ```
                </q:text>
            </filter>
        </collection>
        <parameter id="2">
            <name>activation</name>
            <type>ActivationStatusType</type>
            <display>
                <label>
                    <orig>activation</orig>
                    <translation>
                        <key>ActivationType.administrativeStatus</key>
                    </translation>
                </label>
            </display>
        </parameter>
        <parameter id="3">
            <name>organizationRef</name>
            <type>c:ObjectReferenceType</type>
            <targetType>c:OrgType</targetType>
            <display>
                <label>
                    <orig>organization</orig>
                    <translation>
                        <key>ObjectTypeGuiDescriptor.org</key>
                    </translation>
                </label>
            </display>
        </parameter>
        <parameter id="4">
            <name>roleRef</name>
            <type>c:ObjectReferenceType</type>
            <targetType>c:RoleType</targetType>
            <display>
                <label>
                    <orig>role</orig>
                    <translation>
                        <key>ObjectTypeGuiDescriptor.role</key>
                    </translation>
                </label>
            </display>
        </parameter>
        <parameter id="5">
            <name>resourceRef</name>
            <type>c:ObjectReferenceType</type>
            <targetType>c:ResourceType</targetType>
            <display>
                <label>
                    <orig>resource</orig>
                    <translation>
                        <key>ObjectTypeGuiDescriptor.resource</key>
                    </translation>
                </label>
            </display>
        </parameter>
        <view>
            <column id="6">
                <name>nameColumn</name>
                <path>name</path>
            </column>
            <column id="7">
                <name>fullNameColumn</name>
                <path>fullName</path>
                <previousColumn>nameColumn</previousColumn>
            </column>
            <column id="8">
                <name>activationColumn</name>
                <path>activation/administrativeStatus</path>
                <previousColumn>fullNameColumn</previousColumn>
            </column>
            <column id="9">
                <name>roleColumn</name>
                <path>assignment</path>
                <display>
                    <label>
                        <orig>Role</orig>
                        <translation>
                            <key>reportUserList.roleColumn.label</key>
                        </translation>
                    </label>
                </display>
                <export>
                    <expression>
                        <script>
                            <code>
                                if (input != null){
                                    roles = report.resolveRoles(input);
                                    if (roles.isEmpty()) {
                                        return null;
                                    }
                                    list = new ArrayList();
                                    for (role in roles) {
                                        list.add(role.getName());
                                    }
                                    return list;
                                }
                            </code>
                        </script>
                    </expression>
                </export>
                <previousColumn>activationColumn</previousColumn>
            </column>
            <column id="10">
                <name>orgColumn</name>
                <path>assignment</path>
                <display>
                    <label>
                        <orig>Organization</orig>
                        <translation>
                            <key>reportUserList.orgColumn.label</key>
                        </translation>
                    </label>
                </display>
                <export>
                    <expression>
                        <script>
                            <code>
                                if (input != null){
                                    orgs = report.resolveOrgs(input);
                                    if (orgs.isEmpty()) {
                                        return null;
                                    }
                                    list = new ArrayList();
                                    for (org in orgs) {
                                        list.add(org.getName());
                                    }
                                    return list;
                                }
                            </code>
                        </script>
                    </expression>
                </export>
                <previousColumn>roleColumn</previousColumn>
            </column>
            <column id="11">
                <name>accountColumn</name>
                <path>linkRef</path>
                <display>
                    <label>
                        <orig>Account</orig>
                        <translation>
                            <key>reportUserList.accountColumn.label</key>
                        </translation>
                    </label>
                </display>
                <export>
                    <expression>
                        <script>
                            <code>
                                import com.evolveum.midpoint.schema.SelectorOptions;
                                import com.evolveum.midpoint.schema.GetOperationOptions;
                                import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;

                                if (input != null){
                                    list = new ArrayList();
                                    for (linkRef in input){
                                    shadow = midpoint.getObject(ShadowType.class, linkRef.getOid(),
                                    SelectorOptions.createCollection(GetOperationOptions.createNoFetch().resolveNames(true)));
                                    list.add(shadow.getName().getOrig() + "(Resource: " + shadow.getResourceRef().getTargetName()?.getOrig() + ")");
                                }
                                return list;
                                }
                            </code>
                        </script>
                    </expression>
                </export>
                <previousColumn>orgColumn</previousColumn>
            </column>
            <type>UserType</type>
        </view>
    </objectCollection>
</report>
