<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://ns.dataone.org/debian/conf/types/v1"
    xmlns:dpc="http://ns.dataone.org/debian/conf/types/v1"
    version="1.0.0"
    elementFormDefault="unqualified" attributeFormDefault="unqualified">
 
 <!-- 

About this document:

  This XML Schema document defines a structure that is used to configure
  the installation of debian packages of the  DataONE Coordinating Node
  infrastructure.
  
License:

  This work was created by participants in the DataONE project, and is
  jointly copyrighted by participating institutions in DataONE. For
  more information on DataONE, see our web site at http://dataone.org.
  
    Copyright 2013
    
  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.
  
Formatting: 

  - This document should be saved as a UTF-8 encoded file.
  
    -->
    

    <xs:simpleType name="keyType">
        <xs:annotation>
            <xs:documentation>Template names are made up of components separated by the character `/' (slash). Each component is limited to alphanumerics and `+' `-' `.' `_' (plus, minus, full stop, underscore).</xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string">
            <xs:minLength value="1"/>
            <xs:pattern value="[a-zA-Z0-9_\+\-\./]*"/>
        </xs:restriction>
    </xs:simpleType>
    

    <xs:simpleType name="fieldTypeType">
        <xs:restriction base="xs:NMTOKEN">
            <xs:enumeration value="string"/>
            <xs:enumeration value="password"/>
            <xs:enumeration value=" boolean"/>
            <xs:enumeration value="select"/>
            <xs:enumeration value="multiselect"/>
            <xs:enumeration value="note"/>
            <xs:enumeration value="error"/>
            <xs:enumeration value=" title"/>
            <xs:enumeration value=" text"/>
        </xs:restriction>
    </xs:simpleType>
    
    <xs:simpleType name="phaseType">
        <xs:annotation>
            <xs:documentation>The controlled list of phases that may describe an envrionment's use in product lifecycle
            CUSTOM indicates that all the properties are to be set by prompting the user.  This field will never  have any machine level properties, but may have some environment wide properties
            LOCALHOST provides setting up a single instance of a CN on one's localhost development environment.
            LOCALNET provides an environment for setting a local virtual network for development testing. It is assumed that developers have personal resources to set up their own CN/MN environment, including setting up a localized  CA
            DEV    a development environment on public facing machines in a 'testing' subnet
            SANDBOX    a type of testing environment on public facing machines  in a 'testing' subnet
            STAGE    another type of testing environment on public facing machines that simulates the production environment  in a 'testing' subnet
            STAGE2    another type of testing environment on public facing machines that simulates the production environment  in a 'testing' subnet
            PRODUCTION the public facing and accessible servers</xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string">
            <xs:minLength value="1"/>
        </xs:restriction>
    </xs:simpleType>

    <xs:complexType name="choicesType">
        <xs:annotation>
            <xs:documentation>
                Holds all  the possible values of a select or multiselect template type
            </xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="choice" type="xs:string" minOccurs="1" maxOccurs="unbounded" />
        </xs:sequence>
    </xs:complexType>
    
    <xs:complexType name="debConfType">
        <xs:annotation>
            <xs:documentation>
               Root element type that will contain all the various environment configurations
            </xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="templates" type="dpc:templatesType" minOccurs="1" maxOccurs="1" />
            <xs:element name="environment" type="dpc:environmentType" minOccurs="1" maxOccurs="unbounded" />
        </xs:sequence>
    </xs:complexType>
    
    <xs:complexType name="environmentType">
        <xs:annotation>
            <xs:documentation>
                The Environment describes a series of machines that play a specific role in product lifecycle phases. Developmet, Testing, Validating, Simulation and Production rollout All have attributes or properties  that may have different configuration values.
            </xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="machine" type="dpc:machineType" minOccurs="1" maxOccurs="unbounded" />
            <xs:element name="question" type="dpc:templateQuestionType" minOccurs="1" maxOccurs="unbounded" />
        </xs:sequence>
        <xs:attribute name="context" type="dpc:phaseType"  use="required"/>
    </xs:complexType>
    
    <xs:complexType name="flagType">
        <xs:annotation>
            <xs:documentation>
                The key and value of thie property type will be used to fill in debian template values in the debian backend database. The key must match the Template value in the templates file of the dataone_cn_os_core buildout package.
            </xs:documentation>
        </xs:annotation>
        
        <xs:simpleContent >
            <xs:extension base="xs:boolean">
                <xs:attribute name="name" type="dpc:keyType"  use="required"/>
            </xs:extension>
        </xs:simpleContent> 
    </xs:complexType>
    
    <xs:complexType name="machineType">
        <xs:annotation>
            <xs:documentation>
                Provides configuration values for a particular machine in an environment. NodeId is based from the node list. Ldap Server Id is an ordinal value from 1 to X  indicating the replication id of an ldap server. Must be increasing sequentially and unique unqiue among environment machines.
            </xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="question" type="dpc:templateQuestionType" minOccurs="1" maxOccurs="unbounded" />
        </xs:sequence>
        <xs:attribute name="ip"  use="required"/>
    </xs:complexType>
    <xs:simpleType name="attributeType">
        <xs:restriction base="xs:string" />
    </xs:simpleType>
    
    <xs:complexType name="templateType" abstract="true">
        <xs:annotation>
            <xs:documentation>
                extends the template type to add in attribute fields.  The name of the fields must be restricted to the valid types that are acceptable for fields to have.  
                excluding template field and  including the a flag field. as a question a flag field must have a the key field filled in, otherwise there is no way to distingush one 
                flag from another.
            </xs:documentation>
        </xs:annotation>
    </xs:complexType>
    
    <xs:complexType  name="templateFieldsType">
        <xs:annotation>
            <xs:documentation>
                extends the templateType to add in an attribute and element fields.  The name of the fields must be restricted to the valid types that are acceptable for the fields of templates to have.  
                this is a 'class' or abstract data structure to which the questions are instantiated from.  The answers to the questions are stored in the DB as are the flags. 
                There are for different flags that are tracked currently.  
                'seen' informs the configuration management system that the question has been asked already.  It prevents questions from being asked twice 
                during the same installation.
                'configured-value' indicates that the value of the template question is found in the xml configuration file, the instance file of this schema.
                'derived-value' indicates that the value of the template question has been derived from the configured values of other questions.
                'user-entered-value' indicates that the user must be prompted for the input value, or that the user overrode the configured value at installation time.
            </xs:documentation>
        </xs:annotation>
        <xs:complexContent>
            <xs:extension base="dpc:templateType">
                <xs:sequence>  
                    
                    <xs:element minOccurs="1"  maxOccurs="1"  name="description" type="xs:string" />
                    <xs:element minOccurs="1"  maxOccurs="1"  name="type" type="dpc:fieldTypeType" />
                    <xs:element minOccurs="0" maxOccurs="1" name="choices" type="dpc:choicesType" />
                    <xs:element minOccurs="0"  maxOccurs="1"  name="default" type="xs:string" />
                    <xs:element minOccurs="0"  maxOccurs="unbounded"  name="flag"  type="dpc:flagType" />
                        
                </xs:sequence>
                <xs:attribute name="key" type="dpc:keyType" />
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    
    <xs:complexType  name="templateQuestionType" mixed="true">
        <xs:annotation>
            <xs:documentation>
                extends the templateType to add in an attribute keyref.  It is derived from templateType to show the relationship between key and keyref. The templateQuestionType is the instantiation for an environment of a template.  
                The templateQuestionType is not derived from the templateFieldsType since the key attribute and  fields of the template should be excluded in the instantiation.
                The question may contain a value that is considered the default configuration for a machine/environment. Or it may be empty. If it is empty, then the flags of the templateFieldsType should be checked in order to determine
                if the value of the question is derived or user entered.
            </xs:documentation>
        </xs:annotation>
        <xs:complexContent>
            <xs:extension base="dpc:templateType" >
                <xs:attribute name="keyref" type="dpc:keyType" />
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <xs:complexType name="templatesType">
        <xs:annotation>
            <xs:documentation>
                The templates file lists the templates for variables that a package uses. Each variable in the configuration space is associated with some meta-data. The minimum meta-data associated with a variable is: long and short description, type, and default value.
                See http://www.debian.org/doc/packaging-manuals/debconf_specification.html
                Each property is a template variable that contains the metadata about the template variable.
            </xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="template"  minOccurs="1" type="dpc:templateFieldsType" maxOccurs="unbounded" />
        </xs:sequence>
    </xs:complexType>

    <xs:element name="debconf" type="dpc:debConfType" />
        
</xs:schema>
