<?xml version="1.0"?>
<schema
  targetNamespace="http://extreme.indiana.edu/namespaces/2006/08/karma/xsd"
  xmlns:karma="http://extreme.indiana.edu/namespaces/2006/08/karma/xsd"
  xmlns:wft="http://lead.extreme.indiana.edu/namespaces/2006/06/workflow_tracking"
  xmlns="http://www.w3.org/2001/XMLSchema"
  elementFormDefault="qualified">

    <!-- ========================================================================================== -->
    <import namespace="http://lead.extreme.indiana.edu/namespaces/2006/06/workflow_tracking" 
	    schemaLocation="../workflow_tracking/config/notification_types.xsd" />

    <!-- ========================================================================================== -->

    <!-- A process consists of an invocation that uses (consumes) 0 or more -->
    <!-- data products and produces 0 or more data products. -->
    
    <!-- A workflow consists of 1 or more invocations, one of which is the -->
    <!-- invocation of the workflow itself: a workflow is considered to be a -->
    <!-- service too. -->
    
    <!-- Process provenance describes an invocation, the input data to -->
    <!-- (usingData) and output data from (producingData) it. -->
    
    <!-- Data provenance describes the creation of a data product: the process -->
    <!-- (invocation) that created this data (producedBy), and inputs to the -->
    <!-- process (usingData). It is similar to process provenance, but from the -->
    <!-- perspective of an output data product. -->
    
    <!-- Workflow trace describes the set of invocations (traceSteps) that took -->
    <!-- place as part of a workflow execution. It can be thought of as a list -->
    <!-- of process provenance records, one for each invocation, and one -->
    <!-- process provenance record for the invocation of the workflow itself. -->
    
    <!-- A workflow can recursively invoke other workflows. A workflow trace -->
    <!-- step can represent an invocation of a process or another workflow. In -->
    <!-- a full recursive workflow trace, the trace step representing another -->
    <!-- workflow's invocation contains the full workflow trace for that -->
    <!-- workflow. A partial recursive workflow trace can end the recursion at -->
    <!-- a certain depth. -->

    <!-- ========================================================================================== -->


    <!-- ========================================================================================== -->
    <!--                                     common types                                           -->
    <!-- ========================================================================================== -->
    <complexType name="InvocationType"> <!-- earlier known as processType in Karma v0.2 -->
	<sequence>
	    <!-- source of invocation -->
	    <element name="invoker" type="wft:BaseIDType" minOccurs="0" />
	    <!-- target of invocation -->
	    <element name="invokee">
		<complexType>
		    <complexContent>
			<extension base="wft:BaseIDType">
			    <!-- is the invokee a workflow (i.e. was a workflow invoked in this invocation) -->
			    <attribute name="isWorkflow" type="boolean" use="required" />
			</extension>
		    </complexContent>
		</complexType>
	    </element>

	    <!-- request message received by invokee -->
	    <element name="requestMessage" type="wft:MessageType" minOccurs="0" />
	    <!-- response message sent by invokee (OR) ... -->
	    <element name="responseResult" type="wft:MessageType" minOccurs="0" />
	    <!-- ... response fault sent by by invokee -->
	    <element name="responseFault" type="wft:MessageType" minOccurs="0" />
	</sequence>
	
	<!-- time at which invokee received request -->
	<attribute name="requestReceiveTime" type="dateTime" />
	<!-- time at which invokee sent response -->
	<attribute name="responseSendTime" type="dateTime" />
	<!-- list of status flags that apply to this invocation -->
	<attribute name="status" type="karma:StatusListType" use="required" />
    </complexType>

    <!-- list of status flags that apply to an invocation -->
    <simpleType name="StatusListType">
	<list itemType="karma:StatusType"/>
    </simpleType>

    <!-- set of status flags, one or more of which apply to an invocation -->
    <simpleType name="StatusType">
	<restriction base="NCName">
	    <enumeration value="InvokingService"/>
	    <!-- same as WorkflowInvoked...we don't make a distinction -->
	    <enumeration value="ServiceInvoked"/> 
	    <enumeration value="InvokingServiceSucceeded"/>
	    <enumeration value="InvokingServiceFailed"/>
	    <enumeration value="SendingResult"/>
	    <enumeration value="ReceivedResult"/>
	    <enumeration value="SendingFault"/>
	    <enumeration value="ReceivedFault"/>
	    <enumeration value="SendingResponseSucceeded"/>
	    <enumeration value="SendingResponseFailed"/>
	</restriction>
    </simpleType>
    
    <!-- ========================================================================================== -->

    <complexType name="DataProductType">
	<!-- Globally Unique ID to identify the data product -->
	<attribute name="dataProductID" type="anyURI" use="required" />
	<!-- optional list of locations at which this data products (replicas) may be present -->
	<attribute name="dataProductLocation" type="karma:LocationListType" />
	<!-- context sensitive. time at which data product was produced or consumed. -->
	<attribute name="timestamp" type="dateTime" use="required" />
    </complexType>

    <simpleType name="LocationListType">
	<list itemType="anyURI" />
    </simpleType>

    <!-- ========================================================================================== -->
    <!--                            process provenance types                                        -->
    <!-- ========================================================================================== -->

    <complexType name="ProcessProvenanceType">
	<complexContent>
	    <extension base="karma:InvocationType"> <!-- details about process invocation ... -->
		<sequence>
		    <element name="usingData" type="karma:DataProductType" minOccurs="0" maxOccurs="unbounded" />
		    <element name="producingData" type="karma:DataProductType" minOccurs="0" maxOccurs="unbounded" />
		</sequence>
	    </extension>
	</complexContent>
    </complexType>


    <!-- ========================================================================================== -->
    <!--                            data provenance types                                           -->
    <!-- ========================================================================================== -->
    <complexType name="DataProvenanceType">
	<complexContent>
	    <extension base="karma:DataProductType"> <!-- details about creation time... -->
		<sequence>
		    <!-- if provenance is unavailable, do not set -->
		    <element name="producedBy" type="karma:InvocationType" minOccurs="0" />  <!-- nillable="true" -->
		    <element name="usingData" type="karma:DataProductType" minOccurs="0" maxOccurs="unbounded" />
		</sequence>
		<!-- overriding to set optional if provenance absent -->
		<attribute name="timestamp" type="dateTime" use="optional" />
	    </extension>
	</complexContent>
    </complexType>


    <complexType name="AncestorDataProvenanceType">
	<complexContent>
	    <extension base="karma:DataProvenanceType"> <!-- data provenance of ancestor... -->
		<!-- parent:1,2,3; grand-parent: *.1,*.2 (1.1, 2.1, 2.2, 2.3); ... -->
		<attribute name="ancestorPath" type="token" use="required" />  
		<!-- set to true if this ancestor's provenance has already appeared in a child level -->
		<!-- can be used to differentiate between missing provenance and -->
		<!-- provenance skipped to optimize duplicates -->
		<attribute name="isDuplicate" type="boolean" use="required" />  
	    </extension>
	</complexContent>
    </complexType>

    <complexType name="RecursiveDataProvenanceType">
	<sequence>
	    <element ref="karma:dataProvenance" />
	    <element name="ancestorDataProvenance" type="karma:AncestorDataProvenanceType" 
		     minOccurs="0" maxOccurs="unbounded" />
	</sequence>
    </complexType>


    <!-- ========================================================================================== -->
    <!--                            data usage types                                                -->
    <!-- ========================================================================================== -->
    <complexType name="DataUsageEntryType">
	<complexContent>
	    <extension base="karma:DataProductType"> <!-- time and location of this data, when it was used -->
		<sequence>
		    <!-- invocation that used this data -->
		    <element name="usedBy" type="karma:InvocationType" />
		</sequence>
	    </extension>
	</complexContent>
    </complexType>

    <!-- ========================================================================================== -->

    <complexType name="DataUsageType">
	<complexContent>
	    <!-- data product that was consumed (provide creation info here, IF AVAILABLE) -->
	    <extension base="karma:DataProductType"> 
		<sequence>
		    <!-- usage information about this data -->
		    <element name="usageEntry" type="karma:DataUsageEntryType" minOccurs="0" maxOccurs="unbounded" />
		</sequence>
		<!-- override from dataprod and make optinal since creation info may not be available -->
		<attribute name="timestamp" type="dateTime" use="optional" /> 
	    </extension>
	</complexContent>
    </complexType>
    
  
    <!-- ========================================================================================== -->
    <!--                            workflow trace types                                            -->
    <!-- ========================================================================================== -->
    <complexType name="WorkflowTraceStepType">
	<choice>
	    <!-- each step in a workflow execution can be an invocation of a process (service) ... -->
	    <element name="process" type="karma:ProcessProvenanceType" />
	    <!-- ... or another workflow, recursively -->
	    <!-- NOTE: if recursion is disabled, this field may not have traceSteps enclosed within -->
	    <element name="workflow" type="karma:WorkflowTraceType" />
	</choice>
    </complexType>
    
    <!-- ========================================================================================== -->

    <complexType name="WorkflowTraceType">
	<complexContent>
	    <!-- the invocation of this workflow (as a service) -->
	    <!-- assert: /invocation/@isInvokeeWorkflow='true' -->
	    <extension base="karma:ProcessProvenanceType"> 
		<sequence>
		    <!-- set of steps that take place during the workflow's execution -->
		    <!-- optionally sorted by workflowTimestep (prefered) or by invocation start time -->
		    <element name="traceStep" type="karma:WorkflowTraceStepType" minOccurs="0" maxOccurs="unbounded" />
		</sequence>
		<!-- Whether this workflow trace is recursing into its immediate trace -->
		<!-- steps or terminating as a leaf at this level. This is especially -->
		<!-- relevant when there are no trace steps, which may indicate -->
		<!-- either that no invocations took place (isRecursing==true) or -->
		<!-- that the invocations are not being recursed into and hence not -->
		<!-- displayed (isRecursing==false). -->
		<attribute name="isRecursing" type="boolean" use="required" />
	    </extension>
	</complexContent>
    </complexType>

    
    <!-- ========================================================================================== -->
    <!--                            root elements                                                   -->
    <!-- ========================================================================================== -->
    <element name="processProvenance" type="karma:ProcessProvenanceType" />
    <element name="dataProvenance" type="karma:DataProvenanceType" />
    <element name="dataUsage" type="karma:DataUsageType" />
    <element name="workflowTrace" type="karma:WorkflowTraceType" />

    <element name="recursiveDataProvenance" type="karma:RecursiveDataProvenanceType" />


    
    <!-- ========================================================================================== -->
    <!--                            external types                                                  -->
    <!-- ========================================================================================== -->
    <element name="pasoaInteractionRecord" type="karma:pasoaRecordType" />
    <complexType name="pasoaRecordType">
	<sequence>
	    <element name="interactionPAssertion" minOccurs="0" maxOccurs="unbounded" type="string" />
	    <element name="actorStatePAssertion" minOccurs="0" maxOccurs="unbounded" type="string" />
	    <element name="relationshipPAssertion" minOccurs="0" maxOccurs="unbounded" type="string" />
	</sequence>
	<!-- Workflow instance ID. for now, the  notification topic serves this purpose. -->
	<attribute name="exportFormat" type="string" use="required" fixed="www.pasoa.org"/>
    </complexType>
    

</schema>