<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
	targetNamespace="http://www.escidoc.de/schemas/aggregationdefinition/0.3" 
	xmlns:aggregation-definition="http://www.escidoc.de/schemas/aggregationdefinition/0.3" 
	xmlns:common-types="http://www.escidoc.de/schemas/commontypes/0.3"
	elementFormDefault="qualified" 
	attributeFormDefault="unqualified">
	<xs:import namespace="http://www.escidoc.de/schemas/commontypes/0.3"
	schemaLocation="../../soap/common/0.3/common-types.xsd" />
	<xs:element name="aggregation-definition">
		<xs:annotation>
			<xs:documentation>
				<para>
					The name and the database fields of the aggregation-table 
					and what to write into each field is defined by the aggregation-definition. 
					Also indexes for one or more fields of the table can be defined.
				</para>
				<para>
					Note: When creating an aggregation-definition, 
					the name of the database table can be defined. 
					Additionally the aggregation-definition gets a unique identifier 
					in the database. To avoid duplicate table-names in the system, 
					the given name of the aggregation-table internally gets extended 
					by the schema-name and the unique identifier. 
					Example: When creating an aggregation-definition with database table-name 
					page_statistics, the name of the table after creation will be eg sm._1_page_statistics. 
					This name also will be provided in the xml that gets returned by the interface call.
					The same will happen with index-names, also to avoid duplicate names.
				</para>
			</xs:documentation>
		</xs:annotation>
		<xs:complexType>
			<xs:sequence>
				<xs:element name="name" type="xs:string">
					<xs:annotation>
						<xs:documentation>
							<create>
								<input>required</input>
								<output>kept</output>
							</create>
							<comment>
								Name of the aggregation-definition.
							</comment>
						</xs:documentation>
					</xs:annotation>
				</xs:element>
        		<xs:element name="scope"
                    type="common-types:linkRequired">
          			<xs:annotation>
            			<xs:documentation>
							<create>
								<input>required</input>
								<output>kept</output>
							</create>
							<comment>
								objid of the scope.
							</comment>
						</xs:documentation>
          			</xs:annotation>
        		</xs:element>
				<xs:element name="aggregation-table" type="aggregation-definition:AggregationTableType" maxOccurs="unbounded">
					<xs:annotation>
						<xs:documentation>
							<create>
								<input>required</input>
								<output>kept</output>
							</create>
							<comment>
								Defines the fields of the aggregation-database-table, 
								their field-types and where to get the data from.
							</comment>
						</xs:documentation>
					</xs:annotation>
				</xs:element>
				<xs:element name="statistic-data" type="aggregation-definition:StatisticDataType">
					<xs:annotation>
						<xs:documentation>
							<create>
								<input>required</input>
								<output>kept</output>
							</create>
							<comment>
								Holds information about where to get the data from, 
								that has to get aggregated for this aggregation.
							</comment>
						</xs:documentation>
					</xs:annotation>
				</xs:element>
			</xs:sequence>
      		<xs:attributeGroup ref="common-types:eSciDocResourceIndentityAttributes"/>
		</xs:complexType>
	</xs:element>
	<!--*******************************
    AggregationTableType
    ********************************-->
	<xs:complexType name="AggregationTableType">
		<xs:sequence>
			<xs:element name="name" type="xs:string">
				<xs:annotation>
					<xs:documentation>
						<create>
							<input>required</input>
							<output>updated</output>
						</create>
						<comment>
					Name of the aggregation-database-table.
					Gets updated on create. 
					Tablename gets prefixed with _&lt;aggregation-definition-id&gt;_
				</comment>
					</xs:documentation>
				</xs:annotation>
			</xs:element>
			<xs:element name="field" type="aggregation-definition:FieldType" maxOccurs="unbounded">
				<xs:annotation>
					<xs:documentation>
						<create>
							<input>required</input>
							<output>kept</output>
						</create>
						<comment>
					Description of one database-field of the aggregation-table.
				</comment>
					</xs:documentation>
				</xs:annotation>
			</xs:element>
			<xs:element name="index" type="aggregation-definition:IndexType" minOccurs="0" maxOccurs="unbounded">
				<xs:annotation>
					<xs:documentation>
						<create>
							<input>optional</input>
							<output>kept</output>
						</create>
						<comment>
					Within the index-element, an index for the table can be defined.
				</comment>
					</xs:documentation>
				</xs:annotation>
			</xs:element>
		</xs:sequence>
	</xs:complexType>
	<!--*******************************
    StatisticDataType
    ********************************-->
	<xs:complexType name="StatisticDataType">
		<xs:sequence>
			<xs:element name="statistic-table">
				<xs:annotation>
					<xs:documentation>
						<create>
							<input>required</input>
							<output>kept</output>
						</create>
						<comment>
					Holds information which statistic-records to extract 
					out of the statistic-record-table for this aggregation.
				</comment>
					</xs:documentation>
				</xs:annotation>
				<xs:complexType>
					<xs:sequence>
						<xs:element name="xpath" type="xs:string" minOccurs="0">
							<xs:annotation>
								<xs:documentation>
									<create>
										<input>optional</input>
										<output>kept</output>
									</create>
									<comment>
								xpath-query for the statistic-data-table.
								Only these statistic-records are selected out of the 
								statistic-record-table that match this expression.
							</comment>
								</xs:documentation>
							</xs:annotation>
						</xs:element>
					</xs:sequence>
				</xs:complexType>
			</xs:element>
		</xs:sequence>
	</xs:complexType>
	<!--*******************************
    FieldType
    ********************************-->
	<xs:complexType name="FieldType">
		<xs:sequence>
			<xs:choice>
				<xs:element name="info-field" type="aggregation-definition:InfoFieldType">
					<xs:annotation>
						<xs:documentation>
							<create>
								<input>choice</input>
								<output>kept</output>
							</create>
							<comment>
							field that holds a value (string, date or numeric) 
							that comes from a parameter-value of one statistic-record-xml. 
							Attribute feed=statistics-data is for the 
							first release the only supported attribute. 
							In later releases feed could be eg xml-result if additional 
							data shall be aggregated from other sources than the statistic-record-xml.
						</comment>
						</xs:documentation>
					</xs:annotation>
				</xs:element>
				<xs:element name="time-reduction-field" type="aggregation-definition:TimeReductionFieldType">
					<xs:annotation>
						<xs:documentation>
							<create>
								<input>choice</input>
								<output>kept</output>
							</create>
							<comment>
							field that holds part of a date (can be year,month,day,weekday). 
							If a xpath-element is defined, use this parameter from the 
							statistic-record-xml. Child of this parameter must be &lt;datevalue&gt;. 
							If no xpath-element is defined, use the timestamp when the 
							statistics-record was written. Time-reduction-fields 
							are always numeric database-fields.
						</comment>
						</xs:documentation>
					</xs:annotation>
				</xs:element>
				<xs:element name="count-cumulation-field" type="aggregation-definition:CountCumulationFieldType">
					<xs:annotation>
						<xs:documentation>
							<create>
								<input>choice</input>
								<output>kept</output>
							</create>
							<comment>
							holds the count of aggregation-table-records with same 
							values in all other fields of type info-field and 
							time-reduction-field. Count-cumulation-fields 
							are always numeric database-fields.
						</comment>
						</xs:documentation>
					</xs:annotation>
				</xs:element>
				<xs:element name="difference-cumulation-field" type="aggregation-definition:DifferenceCumulationFieldType">
					<xs:annotation>
						<xs:documentation>
							<create>
								<input>choice</input>
								<output>kept</output>
							</create>
							<comment>
							holds the count of statistic-record-xmls with different 
							values in given statistics-parameter and same values 
							in all other fields of type info-field and time-reduction-field. 
							Eg used for a aggregation-table-field that holds 
							the number of sessions. Difference-cumulation-fields 
							are always numeric database-fields.
						</comment>
						</xs:documentation>
					</xs:annotation>
				</xs:element>
			</xs:choice>
		</xs:sequence>
	</xs:complexType>
	<!--*******************************
    InfoFieldType
    ********************************-->
	<xs:complexType name="InfoFieldType">
		<xs:sequence>
			<xs:element name="name" type="xs:string">
				<xs:annotation>
					<xs:documentation>
						<create>
							<input>required</input>
							<output>kept</output>
						</create>
						<comment>
					name of the table-field in the database.
				</comment>
					</xs:documentation>
				</xs:annotation>
			</xs:element>
			<xs:element name="type" type="aggregation-definition:field-types">
				<xs:annotation>
					<xs:documentation>
						<create>
							<input>required</input>
							<output>kept</output>
						</create>
						<comment>
					type of the field in the database. Can be text, numeric or date.
				</comment>
					</xs:documentation>
				</xs:annotation>
			</xs:element>
			<xs:element name="xpath" type="xs:string">
				<xs:annotation>
					<xs:documentation>
						<create>
							<input>required</input>
							<output>kept</output>
						</create>
						<comment>
					xpath to the required value in the statistic-record.xml.
				</comment>
					</xs:documentation>
				</xs:annotation>
			</xs:element>
		</xs:sequence>
		<xs:attribute name="feed" type="xs:string" use="required">
			<xs:annotation>
				<xs:documentation>
					<create>
						<input>required</input>
						<output>kept</output>
					</create>
					<comment>
					Attribute feed=statistics-data is for the first release the 
					only supported attribute. In later releases feed could be eg 
					xml-result if additional data shall be aggregated from other sources 
					than the statistic-record-xml.
				</comment>
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
	</xs:complexType>
	<!--*******************************
    TimeReductionFieldType
    ********************************-->
	<xs:complexType name="TimeReductionFieldType">
		<xs:sequence>
			<xs:element name="name" type="xs:string">
				<xs:annotation>
					<xs:documentation>
						<create>
							<input>required</input>
							<output>kept</output>
						</create>
						<comment>
					name of the table-field in the database.
				</comment>
					</xs:documentation>
				</xs:annotation>
			</xs:element>
			<xs:element name="reduce-to" type="xs:string">
				<xs:annotation>
					<xs:documentation>
						<create>
							<input>required</input>
							<output>kept</output>
						</create>
						<comment>
					part of date that has to be written in this field (year,month,day,weekday).
				</comment>
					</xs:documentation>
				</xs:annotation>
			</xs:element>
			<xs:element name="xpath" type="xs:string" minOccurs="0">
				<xs:annotation>
					<xs:documentation>
						<create>
							<input>optional</input>
							<output>kept</output>
						</create>
						<comment>
					xpath to the required value in the statistic-record.xml.
				</comment>
					</xs:documentation>
				</xs:annotation>
			</xs:element>
		</xs:sequence>
		<xs:attribute name="feed" type="xs:string" use="required">
			<xs:annotation>
				<xs:documentation>
					<create>
						<input>required</input>
						<output>kept</output>
					</create>
					<comment>
					Attribute feed=statistics-data is for the first release the 
					only supported attribute. In later releases feed could be eg 
					xml-result if additional data shall be aggregated from other sources 
					than the statistic-record-xml.
				</comment>
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
	</xs:complexType>
	<!--*******************************
    CountCumulationFieldType
    ********************************-->
	<xs:complexType name="CountCumulationFieldType">
		<xs:sequence>
			<xs:element name="name" type="xs:string">
				<xs:annotation>
					<xs:documentation>
						<create>
							<input>required</input>
							<output>kept</output>
						</create>
						<comment>
					name of the table-field in the database.
				</comment>
					</xs:documentation>
				</xs:annotation>
			</xs:element>
		</xs:sequence>
	</xs:complexType>
	<!--*******************************
    DifferenceCumulationFieldType
    ********************************-->
	<xs:complexType name="DifferenceCumulationFieldType">
		<xs:sequence>
			<xs:element name="name" type="xs:string">
				<xs:annotation>
					<xs:documentation>
						<create>
							<input>required</input>
							<output>kept</output>
						</create>
						<comment>
					name of the table-field in the database.
				</comment>
					</xs:documentation>
				</xs:annotation>
			</xs:element>
			<xs:element name="xpath" type="xs:string">
				<xs:annotation>
					<xs:documentation>
						<create>
							<input>required</input>
							<output>kept</output>
						</create>
						<comment>
					xpath to the required value in the statistic-record.xml.
				</comment>
					</xs:documentation>
				</xs:annotation>
			</xs:element>
		</xs:sequence>
		<xs:attribute name="feed" type="xs:string" use="required">
			<xs:annotation>
				<xs:documentation>
					<create>
						<input>required</input>
						<output>kept</output>
					</create>
					<comment>
					Attribute feed=statistics-data is for the first release the 
					only supported attribute. In later releases feed could be eg 
					xml-result if additional data shall be aggregated from other sources 
					than the statistic-record-xml.
				</comment>
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
	</xs:complexType>
	<!--*******************************
    IndexType
    ********************************-->
	<xs:complexType name="IndexType">
		<xs:sequence>
			<xs:element name="name" type="xs:string">
				<xs:annotation>
					<xs:documentation>
						<create>
							<input>required</input>
							<output>updated</output>
						</create>
						<comment>
					name of the index in the database.
					Indexname gets prefixed with _&lt;aggregation-definition-id&gt;_
				</comment>
					</xs:documentation>
				</xs:annotation>
			</xs:element>
			<xs:element name="field" type="xs:string" maxOccurs="unbounded">
				<xs:annotation>
					<xs:documentation>
						<create>
							<input>required</input>
							<output>updated</output>
						</create>
						<comment>
					field(s) of the database-table the index shall be created on.
				</comment>
					</xs:documentation>
				</xs:annotation>
			</xs:element>
		</xs:sequence>
	</xs:complexType>
	<!--*******************************
    Field-types
    ********************************-->
	<xs:simpleType name="field-types">
		<xs:restriction base="xs:token">
			<xs:enumeration value="numeric"/>
			<xs:enumeration value="text"/>
			<xs:enumeration value="date"/>
		</xs:restriction>
	</xs:simpleType>
	<!--*******************************
    Date-Reduction-types
    ********************************-->
	<xs:simpleType name="date-reduction-types">
		<xs:restriction base="xs:token">
			<xs:enumeration value="year"/>
			<xs:enumeration value="month"/>
			<xs:enumeration value="day"/>
			<xs:enumeration value="weekday"/>
		</xs:restriction>
	</xs:simpleType>
</xs:schema>