Hi there,

Hoping for some help with a SPARQL challenge I am facing...

We have an instance of Jena Fuseki to which we POST SPARQL update queries
to update the status of a thing called a transferAsset. A transferAsset is
actually a bNode which is referenced by a thing called a transfer. These
transferAssets have a subject, which is another resource, a status and a
modified date.

While there is a specific order in which status updates should be applied
(e.g SENDING, SENT, COMPLETED) there is no guarantee of the order in which
the updates will be received by Fuseki. In other words a COMPLETED status
may inadvertently be received before a SENDING status. To check that we
only apply the most recent status we check the modified date of the
transferAsset. If the new modified date is later than the existitng
modified date we delete the transferAsset at the same time as inserting a
new one.

The problem however is that although the deletion is conditional on there
being a transferAsset older than the new transferAsset, the insert is not,
and I am struggling to see how to make the insert conditional. This means
that if the updates are received out of order we end up inserting another
transferAsset with the same subject, i.e without deleting the old
transferAsset - not what we want.

The SPARQL code is shown below...

DELETE {
  ?transfer <http://nationalarchives.gov.uk/terms/dri#transferAsset>
?transferAsset .
}
INSERT {
  ?transfer <http://nationalarchives.gov.uk/terms/dri#transferAsset> _:b0 .
  _:b0 <http://purl.org/dc/terms/subject> ?subject .
  _:b0 <http://nationalarchives.gov.uk/terms/dri#transferAssetStatus> <
http://nationalarchives.gov.uk/dri/catalogue/transferAssetStatus#SENT> .
  _:b0 <http://purl.org/dc/terms/modified> "2013-06-13T11:58:23.468Z"^^<
http://www.w3.org/2001/XMLSchema#dateTime> .
}
WHERE
  { ?transfer <http://purl.org/dc/terms/identifier> "201305241200"^^<
http://www.w3.org/2001/XMLSchema#string> .
    ?subject <http://purl.org/dc/terms/identifier>
"dff82497-f161-4afd-8e38-f31a8b475b43"^^<
http://www.w3.org/2001/XMLSchema#string>
    OPTIONAL
      { ?transfer <http://nationalarchives.gov.uk/terms/dri#transferAsset>
?transferAsset .
        ?transferAsset <http://purl.org/dc/terms/subject> ?subject .
        ?transferAsset <http://purl.org/dc/terms/modified>
?transferAssetModified
        FILTER ( ?transferAssetModified < "2013-06-13T11:58:23.468Z"^^<
http://www.w3.org/2001/XMLSchema#dateTime> )
      }
  }

And a sample transfer showing the duplication problem...

<http://nationalarchives.gov.uk/dri/catalogue/transfer/201305241200>
      rdf:type      dri:Transfer ;
      dri:transferAsset
                    [ dri:transferAssetStatus
                                    <
http://nationalarchives.gov.uk/dri/catalogue/transferAssetStatus#SENDING> ;
                      dcterms:modified
 "2013-06-13T11:58:23.463Z"^^xsd:dateTime ;
                      dcterms:subject  <
http://nationalarchives.gov.uk/dri/catalogue/item/dff82497-f161-4afd-8e38-f31a8b475b43
>
                    ] ;
      dri:transferAsset
                    [ dri:transferAssetStatus
                                    <
http://nationalarchives.gov.uk/dri/catalogue/transferAssetStatus#SENT> ;
                      dcterms:modified
 "2013-06-13T11:58:23.468Z"^^xsd:dateTime ;
                      dcterms:subject  <
http://nationalarchives.gov.uk/dri/catalogue/item/dff82497-f161-4afd-8e38-f31a8b475b43
>
                    ] ;
      dri:transferStatus  <
http://nationalarchives.gov.uk/dri/catalogue/transferStatus#COMPLETED> ;
      dcterms:identifier  "201305241200"^^xsd:string ;
      dcterms:modified  "2013-06-13T11:58:27.999Z"^^xsd:dateTime .

Many thanks

-- 

Rob Walpole
Email [email protected]
Tel. +44 (0)7969 869881
Skype: RobertWalpolehttp://www.linkedin.com/in/robwalpole

Reply via email to