<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- $This file is distributed under the terms of the license in LICENSE$ -->

<!-- See guidelines at https://wiki.duraspace.org/x/eYXVAw -->

<list-view-config>
    <query-select>
        PREFIX rdfs: &lt;http://www.w3.org/2000/01/rdf-schema#&gt;
        PREFIX core: &lt;http://vivoweb.org/ontology/core#&gt;
        PREFIX foaf: &lt;http://xmlns.com/foaf/0.1/&gt;
        PREFIX vitro: &lt;http://vitro.mannlib.cornell.edu/ns/vitro/0.7#&gt;
        PREFIX obo:   &lt;http://purl.obolibrary.org/obo/&gt;

        SELECT DISTINCT <collated>?subclass</collated>
            ?position
            ?positionTitle
            ?hrJobTitle
            ?rank
            ?org ?orgName
            ?middleOrg ?middleOrgName
            ?outerOrg ?outerOrgName
            ?dateTimeStart ?dateTimeEnd
        WHERE
        {
            ?subject ?property ?position .
            ?position a core:Position .
            OPTIONAL {
                <precise-subquery>?subject ?property ?position .
                ?position a core:Position .</precise-subquery>
                ?position core:relates ?org .
                ?org a foaf:Organization .
                ?org rdfs:label ?orgName .
            }
            OPTIONAL {
                <precise-subquery>?subject ?property ?position .
                ?position a core:Position .</precise-subquery>
                ?position core:relates ?org .
                ?org a foaf:Organization .
                ?org rdfs:label ?orgName .
                ?org obo:BFO_0000050 ?middleOrg .
                ?middleOrg rdfs:label ?middleOrgName .
            }
            OPTIONAL {
                <precise-subquery>?subject ?property ?position .
                ?position a core:Position .</precise-subquery>
                ?position core:relates ?org .
                ?org a foaf:Organization .
                ?org rdfs:label ?orgName .
                ?org obo:BFO_0000050 ?middleOrg .
                ?middleOrg obo:BFO_0000050 ?outerOrg .
                ?outerOrg rdfs:label ?outerOrgName .
            }
            OPTIONAL {
                <precise-subquery>?subject ?property ?position .
                ?position a core:Position .</precise-subquery>
                ?position rdfs:label ?positionTitle .
            }
            OPTIONAL {
                <precise-subquery>?subject ?property ?position .
                ?position a core:Position .</precise-subquery>
                ?position core:hrJobTitle ?hrJobTitle .
            }
            OPTIONAL {
                <precise-subquery>?subject ?property ?position .
                ?position a core:Position .</precise-subquery>
                ?position core:rank ?rank .
            }
            OPTIONAL {
                <precise-subquery>?subject ?property ?position .
                ?position a core:Position .</precise-subquery>
                ?position core:dateTimeInterval ?dateTimeInterval .
                ?dateTimeInterval core:start ?dateTimeStartValue .
                ?dateTimeStartValue core:dateTime ?dateTimeStart .
            }
            OPTIONAL {
                <precise-subquery>?subject ?property ?position .
                ?position a core:Position .</precise-subquery>
                ?position core:dateTimeInterval ?dateTimeInterval .
                ?dateTimeInterval core:end ?dateTimeEndValue .
                ?dateTimeEndValue core:dateTime ?dateTimeEnd .
            }

            <collated>
            OPTIONAL {
                <precise-subquery>?subject ?property ?position .
                ?position a core:Position .</precise-subquery>
                ?position vitro:mostSpecificType ?subclass .
                ?subclass rdfs:subClassOf core:Position .
            }
            </collated>
            <critical-data-required>
            FILTER ( bound(?org) )
            </critical-data-required>
        } ORDER BY <collated>?subclass</collated> DESC(?dateTimeEnd) ?rank
    </query-select>

    <template>propStatement-personInPosition.ftl</template>
</list-view-config>
