Browse Source

Adaptions to changes in qRestAPI

Andreas Fetzer 11 years ago
parent
commit
8039265f44

+ 1 - 1
CMakeExternals/qRestAPI.cmake

@@ -24,7 +24,7 @@ endif()
 
 if(NOT DEFINED ${proj}_DIR)
 
-  set(revision_tag "836c87dbbc")
+  set(revision_tag "5f3a03b15d")
   if(${proj}_REVISION_TAG)
     set(revision_tag ${${proj}_REVISION_TAG})
   endif()

+ 28 - 1
Libs/XNAT/Core/ctkXnatObject.cpp

@@ -27,6 +27,7 @@
 
 #include <QDateTime>
 #include <QDebug>
+#include <QStringList>
 #include <QVariant>
 
 
@@ -106,7 +107,33 @@ QString ctkXnatObject::childDataType() const
 
 QDateTime ctkXnatObject::lastModifiedTime() const
 {
-  return this->session()->lastModified(this->resourceUri());
+  QUuid queryId = this->session()->httpHead(this->resourceUri());
+  QMap<QByteArray, QByteArray> header = this->session()->httpHeadSync(queryId);
+  QVariant lastModifiedHeader = header.value("Last-Modified");
+  QDateTime lastModifiedTime;
+  if (lastModifiedHeader.isValid())
+  {
+    QStringList dateformates;
+    // In case http date formate RFC 822 ( "Sun, 06 Nov 1994 08:49:37 GMT" )
+    dateformates<<"ddd, dd MMM yyyy HH:mm:ss";
+    // In case http date formate ANSI ( "Sun Nov  6 08:49:37 1994" )
+    dateformates<<"ddd MMM  d HH:mm:ss yyyy";
+    // In case http date formate RFC 850 ( "Sunday, 06-Nov-94 08:49:37 GMT" )
+    dateformates<<"dddd, dd-MMM-yy HH:mm:ss";
+
+    QString dateText = lastModifiedHeader.toString();
+    // Remove "GMT" addition at the end of the http timestamp
+    if (dateText.indexOf("GMT") != -1)
+      dateText = dateText.left(dateText.length()-4);
+
+    foreach (QString format, dateformates)
+    {
+      lastModifiedTime = QDateTime::fromString(dateText, format);
+      if (lastModifiedTime.isValid())
+        break;
+    }
+  }
+  return lastModifiedTime;
 }
 
 void ctkXnatObject::setLastModifiedTime(const QDateTime &lastModifiedTime)

+ 20 - 6
Libs/XNAT/Core/ctkXnatSession.cpp

@@ -512,6 +512,26 @@ bool ctkXnatSession::exists(const ctkXnatObject* object)
 }
 
 //----------------------------------------------------------------------------
+const QMap<QByteArray, QByteArray> ctkXnatSession::httpHeadSync(const QUuid &uuid)
+{
+  Q_D(ctkXnatSession);
+  QScopedPointer<qRestResult> result (d->xnat->takeResult(uuid));
+  if (result == NULL)
+  {
+    d->throwXnatException("Sending HEAD request failed.");
+  }
+  return result->rawHeaders();
+}
+
+//----------------------------------------------------------------------------
+QUuid ctkXnatSession::httpHead(const QString& resourceUri)
+{
+  Q_D(ctkXnatSession);
+  QUuid queryId = d->xnat->head(resourceUri);
+  return queryId;
+}
+
+//----------------------------------------------------------------------------
 void ctkXnatSession::save(ctkXnatObject* object)
 {
   Q_D(ctkXnatSession);
@@ -560,12 +580,6 @@ void ctkXnatSession::remove(ctkXnatObject* object)
   }
 }
 
-const QDateTime ctkXnatSession::lastModified(const QString& resourceUri)
-{
-  Q_D(ctkXnatSession);
-  return d->xnat->head(resourceUri, QNetworkRequest::LastModifiedHeader).toDateTime();
-}
-
 //----------------------------------------------------------------------------
 //void ctkXnatSession::create(ctkXnatSubject* subject)
 //{

+ 15 - 1
Libs/XNAT/Core/ctkXnatSession.h

@@ -174,6 +174,15 @@ public:
    */
   QList<QVariantMap> httpSync(const QUuid& uuid);
 
+  /**
+   * @brief Reads the result of a head request
+   * @param uuid the uid of the related query
+   *
+   * @throws ctkXnatInvalidSessionException if the session is closed.
+   * @return a QMap containing the retrieved header information
+   */
+  const QMap<QByteArray, QByteArray> httpHeadSync(const QUuid& uuid);
+
   bool exists(const ctkXnatObject* object);
 
   void save(ctkXnatObject* object);
@@ -189,7 +198,12 @@ public:
   void download(ctkXnatScanResource* scanResource, const QString& zipFileName);
   void download(ctkXnatReconstructionResource* reconstructionResource, const QString& zipFileName);
 
-  const QDateTime lastModified(const QString& resourceUri);
+  /**
+   * @brief Sends a http HEAD request to the xnat instance
+   * @param resourceUri the URL to the server
+   * @return the query uid
+   */
+  QUuid httpHead(const QString& resourceUri);
 
 //  void downloadReconstruction(ctkXnatReconstruction* reconstruction, const QString& zipFilename);