From b9ce5cb1de8bfebc1e5ebe2bdfa18580792e0047 Mon Sep 17 00:00:00 2001
From: gakin <gakin>
Date: Wed, 7 Dec 2016 17:01:20 +0000
Subject: [PATCH] SSDM-4501 : Parse the timestamp sent by the data source in 
 <rs:md? "at" value in the XML

SVN: 37457
---
 .../synchronizer/ResourceListParser.java      | 23 +++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/datastore_server/source/java/ch/ethz/sis/openbis/generic/server/dss/plugins/harvester/synchronizer/ResourceListParser.java b/datastore_server/source/java/ch/ethz/sis/openbis/generic/server/dss/plugins/harvester/synchronizer/ResourceListParser.java
index 64af0041cef..00c132f124c 100644
--- a/datastore_server/source/java/ch/ethz/sis/openbis/generic/server/dss/plugins/harvester/synchronizer/ResourceListParser.java
+++ b/datastore_server/source/java/ch/ethz/sis/openbis/generic/server/dss/plugins/harvester/synchronizer/ResourceListParser.java
@@ -138,6 +138,7 @@ public class ResourceListParser
                     throw new UnsupportedOperationException("Not implemented!!!");
                 }
             });
+        Date resourceListTimestamp = getResourceListTimestamp(doc, xpath);
         List<String> uris = getResourceLocations(doc, xpath);
         for (String uri : uris)
         {
@@ -147,6 +148,23 @@ public class ResourceListParser
         return data;
     }
 
+    private Date getResourceListTimestamp(Document doc, XPath xpath) throws XPathExpressionException
+    {
+        XPathExpression expr = xpath.compile("/s:urlset/rs:md");
+        Object result = expr.evaluate(doc, XPathConstants.NODESET);
+        NodeList nodes = (NodeList) result;
+        for (int i = 0; i < nodes.getLength(); i++)
+        {
+            String capability = nodes.item(i).getAttributes().getNamedItem("capability").getTextContent();
+            if (capability.equals("resourcelist"))
+            {
+                String timestamp = nodes.item(i).getAttributes().getNamedItem("at").getTextContent();
+                return convertFromW3CDate(timestamp);
+            }
+        }
+        throw new XPathExpressionException("The master data resurce list should send a timestamp.");
+    }
+
     private List<String> getResourceLocations(Document doc, XPath xpath) throws XPathExpressionException
     {
         XPathExpression expr = xpath.compile("/s:urlset/s:url/s:loc");// "//*[local-name()='loc']/text()"); //"//s:loc/text()"
@@ -243,6 +261,11 @@ public class ResourceListParser
 
         String lastModDataStr = lastModNode.getTextContent().trim();
         // TODO data source servlet that generates the XML on the data source side MUST use the same format
+        return convertFromW3CDate(lastModDataStr);
+    }
+
+    private Date convertFromW3CDate(String lastModDataStr) throws XPathExpressionException
+    {
         DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.US);
         df1.setTimeZone(TimeZone.getTimeZone("GMT"));
         // DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
-- 
GitLab