<?xml version="1.0" encoding="UTF-8"?>
<!--
    R Service Bus
    
    Copyright (c) Copyright of OpenAnalytics BVBA, 2010-2014
 
    ===========================================================================
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.
 
    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>
        
    @author rsb.development@openanalytics.eu
-->
<xsd:schema xmlns="http://rest.rsb.openanalytics.eu/types"
            targetNamespace="http://rest.rsb.openanalytics.eu/types"
            xmlns:common="http://rsb.openanalytics.eu/types"
            attributeFormDefault="unqualified"
            elementFormDefault="qualified" version="1.0"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
            jaxb:version="2.0" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
            jaxb:extensionBindingPrefixes="xjc">
            
    <xsd:import namespace="http://rsb.openanalytics.eu/types" schemaLocation="common.xsd" />

    <xsd:annotation>
        <xsd:documentation>
            Definition of the data structure for the application/vnd.rsb+xml and
            application/vnd.rsb+json media types.
        </xsd:documentation>
        <xsd:appinfo>
            <jaxb:globalBindings>
                <xjc:simple />
            </jaxb:globalBindings>
            <jaxb:schemaBindings>
                <jaxb:package name="eu.openanalytics.rsb.rest.types" />
            </jaxb:schemaBindings>
        </xsd:appinfo>
    </xsd:annotation>
    
    <!--
      Job Definitions 
      -->
    <xsd:element name="jobToken" type="jobTokenType" />
    <xsd:complexType name="jobTokenType">
        <xsd:attribute name="jobId" type="xsd:string" use="required" />
        <xsd:attribute name="applicationName" type="common:applicationNameType" use="required" />
        <xsd:attribute name="submissionTime" type="xsd:dateTime" use="required" />
        <xsd:attribute name="applicationResultsUri" type="xsd:anyURI" use="required" />
        <xsd:attribute name="resultUri" type="xsd:anyURI" use="required" />
    </xsd:complexType>

    <xsd:element name="errorResult" type="errorResultType" />
    <xsd:complexType name="errorResultType">
        <xsd:sequence>
            <xsd:element name="errorMessage" type="xsd:string" />
        </xsd:sequence>
        <xsd:attribute name="jobId" type="xsd:string" use="required" />
        <xsd:attribute name="applicationName" type="xsd:string" use="required" />
        <xsd:attribute name="submissionTime" type="xsd:dateTime" use="required" />
    </xsd:complexType>
    
    <!--
      Result Definitions 
      -->
    <xsd:element name="results" type="resultsType" />
    <xsd:complexType name="resultsType">
        <xsd:sequence>
            <xsd:element name="result" type="resultType" minOccurs="0"
                maxOccurs="unbounded">
                <xsd:annotation>
                    <xsd:appinfo>
                        <jaxb:property name="Contents" />
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:element name="result" type="resultType" />
    <xsd:complexType name="resultType">
        <xsd:attribute name="jobId" type="xsd:string" use="required" />
        <xsd:attribute name="applicationName" type="common:applicationNameType" use="required" />
        <xsd:attribute name="resultTime" type="xsd:dateTime" use="required" />
        <xsd:attribute name="success" type="xsd:boolean" use="required" />
        <xsd:attribute name="type" type="xsd:string" use="required" />
        <xsd:attribute name="selfUri" type="xsd:anyURI" use="required" />
        <xsd:attribute name="dataUri" type="xsd:anyURI" use="required" />
    </xsd:complexType>
    
    <!--
      File & Directory Definitions 
      -->
    <xsd:element name="directory" type="directoryType" />
    <xsd:complexType name="directoryType">
        <xsd:sequence>
            <xsd:element name="directory" type="directoryType" minOccurs="0" maxOccurs="unbounded" />
            <xsd:element name="file" type="fileType" minOccurs="0" maxOccurs="unbounded" />
        </xsd:sequence>
        <xsd:attribute name="path" type="xsd:string" use="required" />
        <xsd:attribute name="name" type="xsd:string" use="required" />
        <xsd:attribute name="uri" type="xsd:anyURI" use="required" />
        <xsd:attribute name="empty" type="xsd:boolean" use="required" />
    </xsd:complexType>
    
    <xsd:complexType name="fileType">
        <xsd:attribute name="path" type="xsd:string" use="required" />
        <xsd:attribute name="name" type="xsd:string" use="required" />
    </xsd:complexType>
    
    <!--
      Catalog
    -->
    <xsd:element name="catalog" type="catalogType" />
    <xsd:complexType name="catalogType">
        <xsd:sequence>
            <xsd:element name="directory" type="catalogDirectory" minOccurs="4" maxOccurs="4" />
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="catalogDirectory">
        <xsd:sequence>
            <xsd:element name="file" type="catalogFileType" minOccurs="0" maxOccurs="unbounded" />
        </xsd:sequence>
        <xsd:attribute name="type" use="required">
            <xsd:simpleType>
                <xsd:restriction base="xsd:NMTOKEN">
                    <xsd:enumeration value="EMAIL_REPLIES"/>
                    <xsd:enumeration value="JOB_CONFIGURATIONS"/>
                    <xsd:enumeration value="R_SCRIPTS"/>
                    <xsd:enumeration value="SWEAVE_FILES"/>
                </xsd:restriction>
            </xsd:simpleType>
        </xsd:attribute>
        <xsd:attribute name="path" type="xsd:string" use="required" />
    </xsd:complexType>
    
    <xsd:complexType name="catalogFileType">
        <xsd:attribute name="name" type="xsd:string" use="required" />
        <xsd:attribute name="dataUri" type="xsd:anyURI" use="required" />
    </xsd:complexType>
    
    <!--
      RServi Pools 
    -->
    <xsd:element name="rServiPools" type="rServiPoolsType" />
    <xsd:complexType name="rServiPoolsType">
        <xsd:sequence>
            <xsd:element name="rServiPool" type="rServiPoolType" minOccurs="1" maxOccurs="unbounded">
                <xsd:annotation>
                    <xsd:appinfo>
                        <jaxb:property name="Contents" />
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="rServiPoolType">
        <xsd:attribute name="poolUri" type="xsd:anyURI" use="required" />
        <xsd:attribute name="applicationNames" type="xsd:string" use="required" />
        <xsd:attribute name="default" type="xsd:boolean" use="required" />
    </xsd:complexType>
    
    <!--
      Node Information 
    -->
    <xsd:element name="nodeInformation" type="nodeInformationType" />
    <xsd:complexType name="nodeInformationType">
        <xsd:attribute name="name" type="xsd:string" use="required" />
        <xsd:attribute name="healthy" type="xsd:boolean" use="required" />
        <xsd:attribute name="uptime" type="xsd:long" use="required" />
        <xsd:attribute name="uptimeText" type="xsd:string" use="required" />
        <xsd:attribute name="servletContainerInfo" type="xsd:string" use="required" />
        <xsd:attribute name="rsbVersion" type="xsd:string" use="required" />
        <xsd:attribute name="jvmMaxMemory" type="xsd:long" use="required" />
        <xsd:attribute name="jvmFreeMemory" type="xsd:long" use="required" />
        <xsd:attribute name="osLoadAverage" type="xsd:double" use="required" />
    </xsd:complexType>
</xsd:schema>