<?xml version="1.0" encoding="UTF-8" standalone="no"?><!--
  ~ Copyright (C) 2010-2023 Evolveum and contributors
  ~
  ~ Licensed under the EUPL-1.2 or later.
  --><!--suppress XmlUnusedNamespaceDeclaration --><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:a="http://prism.evolveum.com/xml/ns/public/annotation-3" xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb" xmlns:t="http://prism.evolveum.com/xml/ns/public/types-3" xmlns:tns="http://prism.evolveum.com/xml/ns/public/query-3" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" elementFormDefault="qualified" jaxb:extensionBindingPrefixes="xjc" jaxb:version="3.0" targetNamespace="http://prism.evolveum.com/xml/ns/public/query-3">

    <xsd:annotation>
        <xsd:documentation>
            MidPoint works with objects of various types, which can be part
            of the running process (in memory), stored persistently in midPoint Repository,
            or can represent objects on the Resources.

            MidPoint query allows us to select only the objects that match specified criteria.
            These criteria are formulated as a filter and are part of the query.
            Both query and filter are part of the midPoint Query API described in this document.

            For more see: https://docs.evolveum.com/midpoint/reference/concepts/query/query-api/

            Version: 4.6
            Recommended namespace prefix: q
        </xsd:documentation>
        <xsd:appinfo>
            <a:defaultPrefix>q</a:defaultPrefix>
        </xsd:appinfo>
    </xsd:annotation>

    <xsd:import namespace="http://prism.evolveum.com/xml/ns/public/annotation-3" schemaLocation="annotation-3.xsd">
        <xsd:annotation>
            <xsd:documentation>
                Common prism annotations used in various XSD schemas.
            </xsd:documentation>
        </xsd:annotation>
    </xsd:import>

    <xsd:import namespace="http://prism.evolveum.com/xml/ns/public/types-3" schemaLocation="types-3.xsd">
        <xsd:annotation>
            <xsd:documentation>
                Common prism types.
            </xsd:documentation>
        </xsd:annotation>
    </xsd:import>

    <!-- Filters & queries -->

    <xsd:complexType name="QueryType">
        <xsd:annotation>
            <xsd:documentation>
                TODO
            </xsd:documentation>
        </xsd:annotation>
        <xsd:sequence>
            <xsd:element maxOccurs="1" minOccurs="0" name="description" type="xsd:string"/>
            <xsd:element minOccurs="0" name="filter" type="tns:SearchFilterType"/>
            <xsd:element minOccurs="0" name="paging" type="tns:PagingType"/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="query" type="tns:QueryType"/>

    <xsd:complexType name="PagingType">
        <xsd:annotation>
            <xsd:documentation>
                Parameters limiting the number of returned
                entries, offset, etc.
                Used in the web service operations
                such as list or search
            </xsd:documentation>
        </xsd:annotation>
        <xsd:sequence>
            <xsd:element minOccurs="0" name="orderBy" type="t:ItemPathType">
                <xsd:annotation>
                    <xsd:documentation>
                        Property by which the results should be sorted.
                        Reference to a property (XPath).
                        Just one property for now.
                        Maybe we will change this to a list later.
                        If not specified, the ordering is arbitrary.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element default="ascending" minOccurs="0" name="orderDirection" type="tns:OrderDirectionType">
                <xsd:annotation>
                    <xsd:documentation>
                        Direction of ordering (ascending or descending).
                        Only valid if "orderBy" element is specified.
                        If not specified, the ordering order is ascending.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element default="0" minOccurs="0" name="offset" type="xsd:int">
                <xsd:annotation>
                    <xsd:documentation>
                        The index of the first returned entry, starting
                        with zero. Therefore if 0 is specified, the resulting list
                        will start with first entry. If 1 is specified, the resulting set will
                        start with second entry. If not specified, value of zero (0) is assumed.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element default="2147483647" minOccurs="0" name="maxSize" type="xsd:int">
                <xsd:annotation>
                    <xsd:documentation>
                        The maximum number of entries returned.
                        The operation may return specified number of entries or less.
                        If not specified, unlimited maximum size is assumed.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:simpleType name="OrderDirectionType">
        <xsd:annotation>
            <xsd:documentation>
                Direction of an ordering.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="ascending">
                <xsd:annotation>
                    <xsd:appinfo>
                        <jaxb:typesafeEnumMember name="ASCENDING"/>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:enumeration>
            <xsd:enumeration value="descending">
                <xsd:annotation>
                    <xsd:appinfo>
                        <jaxb:typesafeEnumMember name="DESCENDING"/>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:enumeration>
        </xsd:restriction>
    </xsd:simpleType>

    <xsd:complexType name="SearchFilterType">
        <xsd:sequence>
            <xsd:element maxOccurs="1" minOccurs="0" name="description" type="xsd:string"/>
            <xsd:element maxOccurs="1" minOccurs="0" name="text" type="xsd:string"/>
            <xsd:element maxOccurs="1" minOccurs="0" ref="tns:filterClause">
                <xsd:annotation>
                    <xsd:appinfo>
                        <jaxb:dom/> <!-- this is necessary for the model-client -->
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="filter" type="tns:SearchFilterType"/>

    <xsd:complexType name="FilterClauseType">
        <xsd:annotation>
            <xsd:appinfo>
                <jaxb:dom/> <!-- this is necessary for the model-client -->
            </xsd:appinfo>
        </xsd:annotation>
        <xsd:sequence>
            <!-- TODO move only to relevant clauses (not all support matching) -->
            <xsd:element minOccurs="0" name="matching" type="xsd:string">
                <xsd:annotation>
                    <xsd:documentation>
                        Property which specifies matching rules. E.g. for polyString,
                        matching rules can be: norm, orig, strict etc.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="RefFilterClauseType">
        <xsd:complexContent>
            <xsd:extension base="tns:PropertySimpleValueFilterClauseType">
                <xsd:sequence>
                    <xsd:element minOccurs="0" ref="tns:filter"/>
                </xsd:sequence>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>

    <xsd:element name="filterClause" type="tns:FilterClauseType"/>

    <!-- individual clauses -->

    <!-- A: primitive filters -->
    <!-- A1: trivial filters -->
    <xsd:element name="all" substitutionGroup="tns:filterClause" type="tns:FilterClauseType"/>
    <xsd:element name="none" substitutionGroup="tns:filterClause" type="tns:FilterClauseType"/>
    <xsd:element name="undefined" substitutionGroup="tns:filterClause" type="tns:FilterClauseType"/>

    <!-- A2: value filters -->
    <xsd:element name="equal" substitutionGroup="tns:filterClause" type="tns:PropertyComplexValueFilterClauseType"/>
    <xsd:element name="anyIn" substitutionGroup="tns:filterClause" type="tns:PropertyComplexValueFilterClauseType"/>
    <xsd:element name="greater" substitutionGroup="tns:filterClause" type="tns:PropertySimpleValueFilterClauseType"/>
    <xsd:element name="greaterOrEqual" substitutionGroup="tns:filterClause" type="tns:PropertySimpleValueFilterClauseType"/>
    <xsd:element name="less" substitutionGroup="tns:filterClause" type="tns:PropertySimpleValueFilterClauseType"/>
    <xsd:element name="lessOrEqual" substitutionGroup="tns:filterClause" type="tns:PropertySimpleValueFilterClauseType"/>
    <xsd:element name="substring" substitutionGroup="tns:filterClause" type="tns:SubstringFilterClauseType"/>
    <xsd:element name="fuzzyStringMatch" substitutionGroup="tns:filterClause" type="tns:FuzzyStringMatchClauseType"/>

    <xsd:element name="ref" substitutionGroup="tns:filterClause" type="tns:RefFilterClauseType"/>
    <xsd:element name="ownedBy" substitutionGroup="tns:filterClause" type="tns:OwnedByFilterClauseType"/>

    <xsd:element name="org" substitutionGroup="tns:filterClause" type="tns:OrgFilterClauseType"/>
    <xsd:element name="inOid" substitutionGroup="tns:filterClause" type="tns:InOidFilterClauseType"/>
    <xsd:element name="fullText" substitutionGroup="tns:filterClause" type="tns:FullTextFilterClauseType"/>

    <!-- B: complex filters -->
    <!-- B1: logical filters -->
    <xsd:element name="and" substitutionGroup="tns:filterClause" type="tns:NAryLogicalOperatorFilterClauseType"/>
    <xsd:element name="or" substitutionGroup="tns:filterClause" type="tns:NAryLogicalOperatorFilterClauseType"/>
    <xsd:element name="not" substitutionGroup="tns:filterClause" type="tns:UnaryLogicalOperatorFilterClauseType"/>

    <!-- B2: other filters -->
    <xsd:element name="type" substitutionGroup="tns:filterClause" type="tns:TypeFilterClauseType"/>
    <xsd:element name="exists" substitutionGroup="tns:filterClause" type="tns:ExistsFilterClauseType"/>

    <!-- Common types. TODO refactor these e.g. to be compatible with classes in
         com.evolveum.midpoint.prism.query package (although these should be cleaned-up as well.
         However, this would be an incompatible change, so it needs to wait for midPoint 4.0 -->

    <!-- TODO what's the difference between PropertyComplexValueFilterClauseType and PropertySimpleValueFilterClauseType?
         There doesn't seem to be any. (med) -->
    <xsd:complexType name="PropertyComplexValueFilterClauseType">
        <xsd:complexContent>
            <xsd:extension base="tns:FilterClauseType">
                <xsd:sequence>
                    <xsd:element maxOccurs="1" minOccurs="0" ref="tns:path"/>
                    <xsd:choice>
                        <xsd:element maxOccurs="unbounded" minOccurs="0" ref="tns:value"/>
                        <xsd:element name="rightHandSidePath" type="t:ItemPathType">
                            <xsd:annotation>
                                <xsd:documentation>
                                    An item that is to be related to the left-hand-side one.
                                </xsd:documentation>
                            </xsd:annotation>
                        </xsd:element>
                        <xsd:any namespace="##other" processContents="strict">
                            <xsd:annotation>
                                <xsd:documentation>
                                    Extensibility point for various expression languages and other
                                    "value derivation" mechanisms.
                                </xsd:documentation>
                            </xsd:annotation>
                        </xsd:any>
                    </xsd:choice>
                </xsd:sequence>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="PropertySimpleValueFilterClauseType">
        <xsd:complexContent>
            <xsd:extension base="tns:FilterClauseType">
                <xsd:sequence>
                    <xsd:element name="path" type="t:ItemPathType">
                        <xsd:annotation>
                            <xsd:documentation>
                                XPath to the property being queried.
                                It is mandatory, as there is no reasonable
                                default as in the case of path.
                            </xsd:documentation>
                        </xsd:annotation>
                    </xsd:element>
                    <xsd:choice>
                        <xsd:element maxOccurs="unbounded" minOccurs="0" name="value" type="xsd:anyType">
                            <xsd:annotation>
                                <xsd:documentation>
                                    The elements and values of queried properties.
                                </xsd:documentation>
                            </xsd:annotation>
                        </xsd:element>
                        <xsd:element minOccurs="0" name="rightHandSidePath" type="t:ItemPathType">
                            <xsd:annotation>
                                <xsd:documentation>
                                    An item that is to be related to the left-hand-side one.
                                </xsd:documentation>
                            </xsd:annotation>
                        </xsd:element>
                        <xsd:any namespace="##other" processContents="strict">
                            <xsd:annotation>
                                <xsd:documentation>
                                    Extensibility point for various expression languages and other
                                    "value derivation" mechanisms.
                                </xsd:documentation>
                            </xsd:annotation>
                        </xsd:any>
                    </xsd:choice>
                </xsd:sequence>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>

    <!-- Following element should be constrained a bit more, because their value
    is always string respectively and it is exactly one. But we don't know how to constrain it now
    and we do not have the time to find out. Therefore it should be OK for now. -->
    <xsd:complexType name="SubstringFilterClauseType">
        <xsd:complexContent>
            <xsd:extension base="tns:PropertySimpleValueFilterClauseType">
                <xsd:sequence>
                    <xsd:element default="false" minOccurs="0" name="anchorStart" type="xsd:boolean"/>
                    <xsd:element default="false" minOccurs="0" name="anchorEnd" type="xsd:boolean"/>
                </xsd:sequence>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="InOidFilterClauseType">
        <xsd:complexContent>
            <xsd:extension base="tns:FilterClauseType">
                <xsd:sequence>
                    <xsd:choice>
                        <xsd:element maxOccurs="unbounded" minOccurs="0" name="value" type="xsd:anyType">
                            <xsd:annotation>
                                <xsd:documentation>
                                    Values of queried properties.
                                </xsd:documentation>
                            </xsd:annotation>
                        </xsd:element>
                        <xsd:any namespace="##other" processContents="strict">
                            <xsd:annotation>
                                <xsd:documentation>
                                    Extensibility point for various expression languages and other
                                    "value derivation" mechanisms.
                                </xsd:documentation>
                            </xsd:annotation>
                        </xsd:any>
                    </xsd:choice>
                    <xsd:element minOccurs="0" name="considerOwner" type="xsd:boolean">
                        <xsd:annotation>
                            <xsd:documentation>
                                If true, queries not objects with a given OID/ID, but objects that have an owner with given OID/ID.
                            </xsd:documentation>
                        </xsd:annotation>
                    </xsd:element>
                </xsd:sequence>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="FullTextFilterClauseType">
        <xsd:complexContent>
            <xsd:extension base="tns:FilterClauseType">
                <xsd:sequence>
                    <xsd:choice>
                        <xsd:element maxOccurs="unbounded" minOccurs="0" name="value" type="xsd:string">
                            <xsd:annotation>
                                <xsd:documentation>
                                    Values to be found.
                                </xsd:documentation>
                            </xsd:annotation>
                        </xsd:element>
                        <xsd:any namespace="##other" processContents="strict">
                            <xsd:annotation>
                                <xsd:documentation>
                                    Extensibility point for various expression languages and other
                                    "value derivation" mechanisms.
                                </xsd:documentation>
                            </xsd:annotation>
                        </xsd:any>
                    </xsd:choice>
                </xsd:sequence>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="PropertyNoValueFilterClauseType">
        <xsd:complexContent>
            <xsd:extension base="tns:FilterClauseType">
                <xsd:sequence>
                    <xsd:element name="property" type="t:ItemPathType"/>
                </xsd:sequence>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="OrgFilterClauseType">
        <xsd:complexContent>
            <xsd:extension base="tns:FilterClauseType">
                <xsd:choice>
                    <xsd:element name="isRoot" type="xsd:boolean"/>
                    <xsd:sequence>
                        <xsd:element name="orgRef" type="tns:OrgFilterRefType"/>
                        <xsd:element minOccurs="0" name="scope" type="tns:OrgFilterScopeType"/>
                    </xsd:sequence>
                </xsd:choice>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="OrgFilterRefType">
        <xsd:sequence>
            <xsd:element name="oid" type="xsd:string"/>
            <xsd:element minOccurs="0" name="scope" type="tns:OrgFilterScopeType"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:simpleType name="OrgFilterScopeType">
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="SUBTREE">
                <xsd:annotation>
                    <xsd:documentation>
                        Object being considered can reside anywhere in the subtree rooted at base org.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:enumeration>
            <xsd:enumeration value="ONE_LEVEL">
                <xsd:annotation>
                    <xsd:documentation>
                        Object being considered has to reside one level below base org.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:enumeration>
        </xsd:restriction>
    </xsd:simpleType>

    <xsd:complexType name="TypeFilterClauseType">
        <xsd:complexContent>
            <xsd:extension base="tns:FilterClauseType">
                <xsd:sequence>
                    <xsd:element name="type" type="xsd:QName"/>
                    <xsd:element ref="tns:filter"/>
                </xsd:sequence>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="OwnedByFilterClauseType">
        <xsd:complexContent>
            <xsd:extension base="tns:FilterClauseType">
                <xsd:sequence>
                    <xsd:element name="type" type="xsd:QName"/>
                    <xsd:element name="path" type="t:ItemPathType"/>
                    <xsd:element minOccurs="0" ref="tns:filter"/>
                </xsd:sequence>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="FuzzyStringMatchClauseType">
        <xsd:complexContent>
            <xsd:extension base="tns:PropertySimpleValueFilterClauseType">
                <xsd:sequence>
                    <xsd:element maxOccurs="1" minOccurs="1" name="method" type="tns:FuzzyStringMatchMethodClauseType"/>
                </xsd:sequence>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="FuzzyStringMatchMethodClauseType">
        <xsd:sequence>
            <xsd:any maxOccurs="unbounded" minOccurs="0" processContents="lax">
            </xsd:any>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="ReferencedByFilterClauseType">
        <xsd:complexContent>
            <xsd:extension base="tns:FilterClauseType">
                <xsd:sequence>
                    <xsd:element name="type" type="xsd:QName"/>
                    <xsd:element name="path" type="t:ItemPathType"/>
                    <xsd:element minOccurs="0" name="relation" type="xsd:QName"/>
                    <xsd:element minOccurs="0" ref="tns:filter"/>
                </xsd:sequence>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="ExistsFilterClauseType">
        <xsd:complexContent>
            <xsd:extension base="tns:FilterClauseType">
                <xsd:sequence>
                    <xsd:element name="path" type="t:ItemPathType"/>
                    <xsd:element ref="tns:filter"/>
                </xsd:sequence>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>

    <xsd:element name="path" type="t:ItemPathType">
        <xsd:annotation>
            <xsd:documentation>
                XPath to the XML element for the queried property.
            </xsd:documentation>
        </xsd:annotation>
    </xsd:element>

    <!-- parsed as RawType; anyType is here for schema compliance when using xsi:type attribute -->
    <xsd:element name="value" type="xsd:anyType"/>

    <xsd:complexType abstract="true" name="LogicalOperatorFilterClauseType">
        <xsd:complexContent>
            <xsd:extension base="tns:FilterClauseType">
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="UnaryLogicalOperatorFilterClauseType">
        <xsd:complexContent>
            <xsd:extension base="tns:LogicalOperatorFilterClauseType">
                <xsd:sequence>
                    <xsd:element ref="tns:filterClause"/>
                </xsd:sequence>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="NAryLogicalOperatorFilterClauseType">
        <xsd:complexContent>
            <xsd:extension base="tns:LogicalOperatorFilterClauseType">
                <xsd:sequence>
                    <xsd:element maxOccurs="unbounded" minOccurs="0" ref="tns:filterClause"/>
                </xsd:sequence>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>

    <!-- currently not used -->
    <xsd:complexType name="UriFilterClauseType">
        <xsd:complexContent>
            <xsd:extension base="tns:FilterClauseType">
                <xsd:attribute name="uri" type="xsd:anyURI"/>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>

</xsd:schema>