Requirement16Soln

From Filtered Push Wiki
Jump to: navigation, search


Requirement

Report:_FP_Requirements#16 Messages require identifiers.
See also Talk:Report_on_FP_Requirements#16

Solution

Carrying FPMessages in the network as XML compliant with FPMessageSchema.xsd (see Notes below) provides a MessageID.

Competency Question

Provide the IDs of all FP QUERY Messages sent on 2011-07-27 by Sender with identity http://applepie.net/nodes/HUH

Solutions

Assume the following:

  1. An XML FPMessage store (e.g. cache, log, etc) that supports XQuery queries.

For purposes of this solution, assume its contents contains five messages:

<?xml version="1.0" encoding="UTF-8"?>
<FPMessages xmlns="http://filteredpush.org/FPMessageSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://filteredpush.org/FPMessageSchema FPMessageSchema.xsd" >
    <!-- $Id$ -->
    
    <!-- Message 1 -->
    <FPMessage MessageType="QUERY" MessageID="xFVNjJOs6_z0VtvwEFnYOQJx" DateTimeCreated="2011-06-27T10:27:55">
        <Content>SELECT * FROM collection372 WHERE collectorName= 'James Macklin'</Content>
        <Sender>http://applepie.org/nodes/HUH</Sender>
        <Scheme>http:filteredpush.org/schemes/SQL</Scheme>
    </FPMessage>
    
    <!-- Message 2 -->
    <FPMessage MessageType="QUERY" MessageID="xFVNjJOs6_z0VtvwEFnYOQJy" DateTimeCreated="2011-07-27T10:27:55">
        <Content>SELECT * FROM collection372 WHERE collectorName= 'James Macklin'</Content>
        <Sender>http://applepie.org/nodes/HUH</Sender>
        <Scheme>http:filteredpush.org/schemes/SQL</Scheme>
    </FPMessage>
     
    <!-- Message 3 -->
    <FPMessage MessageType="NOTIFICATION" MessageID="PAGwDupRmG2AV.X" DateTimeCreated="2011-07-20T09:27:10">
        <Content>Offline for maintenance 2011-12-25</Content>
        <Sender>http://applepie.org/nodes/HUH</Sender>
        <Scheme>http:filteredpush.org/schemes/STRING</Scheme>
    </FPMessage>
    
    <!-- Message 4 -->
    <FPMessage MessageType="QUERY" MessageID="xFVNjJOs6_z0VtvwABCDLmn" DateTimeCreated="2011-07-27T10:37:55">
        <Content>SELECT * FROM collection852 WHERE collectorName= 'James Macklin'</Content> 
        <Sender>http://applepie.org/nodes/HUH</Sender>
        <Scheme>http:filteredpush.org/schemes/SQL</Scheme>
    </FPMessage>
    
    <!-- Message 5 -->
    <FPMessage MessageType="QUERY" MessageID="PQROs6_z0VtvwABCDLmn" DateTimeCreated="2011-07-27T10:37:55">
        <Content>SELECT * FROM collectionLaSelva WHERE collectorName= 'James Macklin'</Content> 
        <Sender>http://applepie.org/nodes/BBG</Sender>
        <Scheme>http:filteredpush.org/schemes/SQL</Scheme>
    </FPMessage>  
</FPMessages>


The following XPath expression will extract the desired messages.

(: The URI of the document that is to be queried :)
declare variable $cache-uri as xs:string := "messageCache.xml";

(: The XML document :)
declare variable $document as document-node() := doc($cache-uri);
<FPMessages xmlns="http://filteredpush.org/FPMessageSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://filteredpush.org/FPMessageSchema FPMessageSchema.xsd">
{
let $newline := "
"
for $a in $document/FPMessages/FPMessage 
where ( $a/@MessageType = 'QUERY' and 
   data($a/Sender)="http://applepie.org/nodes/HUH" and
   matches( $a/@DateTimeCreated, '2011-07-27.*' )
   )
return 
($a, $newline,$newline)
}
</FPMessages>

The output is below. To meet the exact competency question, and return only the id's, make the return in the XQuery be "$s/@MessageID" and don't wrap in an FPMessages element.

<?xml version="1.0" encoding="UTF-8"?>
<FPMessages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns="http://filteredpush.org/FPMessageSchema"
            xsi:schemaLocation="http://filteredpush.org/FPMessageSchema FPMessageSchema.xsd">
   <FPMessage MessageType="QUERY" MessageID="xFVNjJOs6_z0VtvwEFnYOQJy"
              DateTimeCreated="2011-07-27T10:27:55">
        <Content>SELECT * FROM collection372 WHERE collectorName= 'James Macklin'</Content>
        <Sender>http://applepie.org/nodes/HUH</Sender>
        <Scheme>http:filteredpush.org/schemes/SQL</Scheme>
    </FPMessage>
 
   <FPMessage MessageType="QUERY" MessageID="xFVNjJOs6_z0VtvwABCDLmn"
              DateTimeCreated="2011-07-27T10:37:55">
        <Content>SELECT * FROM collection852 WHERE collectorName= 'James Macklin'</Content> 
        <Sender>http://applepie.org/nodes/HUH</Sender>
        <Scheme>http:filteredpush.org/schemes/SQL</Scheme>
    </FPMessage>
 
</FPMessages>

Notes

At this writing, the UML class message.FPMessage needs a little work to be brought into better coherence with FPMessage.xsd. In this solution, we use the latter:

<?xml version="1.0" encoding="UTF-8"?>
<!-- $Id: FPMessageSchema.xsd 783 2011-11-28 17:06:06Z ramorrismorris $ -->
<!-- This lacks structure for Sender as a ClientIdenty object, per UML for <<interface>>Identity at rev 779 ...ram 11/26/2011 -->
<schema xmlns="http://www.w3.org/2001/XMLSchema"
	targetNamespace="http://filteredpush.org/FPMessageSchema"
	xmlns:fpm="http://filteredpush.org/FPMessageSchema" elementFormDefault="qualified">

	
	<element name="FPMessages" type="fpm:TMessages"></element>
	<element name="FPMessage" type="fpm:TMessage"></element>

	<complexType name="TMessage">
		<sequence>
			<element name="Content" type="string" maxOccurs="1" minOccurs="1"> </element>
			<element name="Sender" type="anySimpleType"/>
			<element name="Scheme" type="anyURI" maxOccurs="1" minOccurs="0"/>
		</sequence>
		<attribute name="MessageType" type="fpm:TMessageType"/>
		<attribute name="MessageID" type="string"/>
		<attribute name="DateTimeCreated" type="dateTime"/>
	</complexType>


	<simpleType name="TMessageType">
		<restriction base="string">
			<enumeration value="QUERY"/>
			<enumeration value="ANNOTATION"/>
			<enumeration value="NOTIFICATION"/>
			<enumeration value="FP_FIND_SETS"/>
		</restriction>
	</simpleType>
	<complexType name="TMessages">
		<sequence>
			<element maxOccurs="unbounded" name="FPMessage" type="fpm:TMessage"/>
		</sequence>
	</complexType>
</schema>