|
@@ -37,6 +37,7 @@
|
|
|
|
|
|
#include <QDateTime>
|
|
#include <QDateTime>
|
|
#include <QDebug>
|
|
#include <QDebug>
|
|
|
|
+#include <QDir>
|
|
#include <QScopedPointer>
|
|
#include <QScopedPointer>
|
|
#include <QStringBuilder>
|
|
#include <QStringBuilder>
|
|
#include <QNetworkCookie>
|
|
#include <QNetworkCookie>
|
|
@@ -61,6 +62,7 @@ public:
|
|
QScopedPointer<ctkXnatAPI> xnat;
|
|
QScopedPointer<ctkXnatAPI> xnat;
|
|
QScopedPointer<ctkXnatDataModel> dataModel;
|
|
QScopedPointer<ctkXnatDataModel> dataModel;
|
|
QString sessionId;
|
|
QString sessionId;
|
|
|
|
+ QString defaultFilePath;
|
|
|
|
|
|
QMap<QString, QString> sessionProperties;
|
|
QMap<QString, QString> sessionProperties;
|
|
|
|
|
|
@@ -87,6 +89,7 @@ ctkXnatSessionPrivate::ctkXnatSessionPrivate(const ctkXnatLoginProfile& loginPro
|
|
ctkXnatSession* q)
|
|
ctkXnatSession* q)
|
|
: loginProfile(loginProfile)
|
|
: loginProfile(loginProfile)
|
|
, xnat(new ctkXnatAPI())
|
|
, xnat(new ctkXnatAPI())
|
|
|
|
+ , defaultFilePath("")
|
|
, q(q)
|
|
, q(q)
|
|
{
|
|
{
|
|
// TODO This is a workaround for connecting to sites with self-signed
|
|
// TODO This is a workaround for connecting to sites with self-signed
|
|
@@ -329,6 +332,12 @@ ctkXnatSession::ctkXnatSession(const ctkXnatLoginProfile& loginProfile)
|
|
QString url = d->loginProfile.serverUrl().toString();
|
|
QString url = d->loginProfile.serverUrl().toString();
|
|
d->xnat->setServerUrl(url);
|
|
d->xnat->setServerUrl(url);
|
|
|
|
|
|
|
|
+ QObject::connect(d->xnat.data(), SIGNAL(uploadFinished()), this, SIGNAL(uploadFinished()));
|
|
|
|
+ QObject::connect(d->xnat.data(), SIGNAL(progress(QUuid,double)),
|
|
|
|
+ this, SIGNAL(progress(QUuid,double)));
|
|
|
|
+// QObject::connect(d->xnat.data(), SIGNAL(progress(QUuid,double)),
|
|
|
|
+// this, SLOT(onProgress(QUuid,double)));
|
|
|
|
+
|
|
d->setDefaultHttpHeaders();
|
|
d->setDefaultHttpHeaders();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -432,7 +441,7 @@ ctkXnatLoginProfile ctkXnatSession::loginProfile() const
|
|
}
|
|
}
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
//----------------------------------------------------------------------------
|
|
-void ctkXnatSession::progress(QUuid /*queryId*/, double /*progress*/)
|
|
|
|
|
|
+void ctkXnatSession::onProgress(QUuid /*queryId*/, double /*progress*/)
|
|
{
|
|
{
|
|
// qDebug() << "ctkXnatSession::progress(QUuid queryId, double progress)";
|
|
// qDebug() << "ctkXnatSession::progress(QUuid queryId, double progress)";
|
|
// qDebug() << "query id:" << queryId;
|
|
// qDebug() << "query id:" << queryId;
|
|
@@ -468,6 +477,30 @@ QString ctkXnatSession::sessionId() const
|
|
}
|
|
}
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
//----------------------------------------------------------------------------
|
|
|
|
+void ctkXnatSession::setDefaultFilePath(const QString &path)
|
|
|
|
+{
|
|
|
|
+ Q_D(ctkXnatSession);
|
|
|
|
+
|
|
|
|
+ QDir directory(path);
|
|
|
|
+ if (directory.exists() && path.size() != 0)
|
|
|
|
+ {
|
|
|
|
+ d->defaultFilePath = path;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ d->defaultFilePath = QDir::currentPath();
|
|
|
|
+ qWarning() << "Specified directory: ["<<path<<"] does not exists! Setting default filepath to :"<<d->defaultFilePath;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//----------------------------------------------------------------------------
|
|
|
|
+QString ctkXnatSession::defaultFilePath() const
|
|
|
|
+{
|
|
|
|
+ Q_D(const ctkXnatSession);
|
|
|
|
+ return d->defaultFilePath;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//----------------------------------------------------------------------------
|
|
ctkXnatDataModel* ctkXnatSession::dataModel() const
|
|
ctkXnatDataModel* ctkXnatSession::dataModel() const
|
|
{
|
|
{
|
|
Q_D(const ctkXnatSession);
|
|
Q_D(const ctkXnatSession);
|
|
@@ -497,6 +530,13 @@ QList<ctkXnatObject*> ctkXnatSession::httpResults(const QUuid& uuid, const QStri
|
|
return d->results(restResult.data(), schemaType);
|
|
return d->results(restResult.data(), schemaType);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+QUuid ctkXnatSession::httpPut(const QString& resource, const ctkXnatSession::UrlParameters& parameters, const ctkXnatSession::HttpRawHeaders& rawHeaders)
|
|
|
|
+{
|
|
|
|
+ Q_D(ctkXnatSession);
|
|
|
|
+ d->checkSession();
|
|
|
|
+ return d->xnat->put(resource);
|
|
|
|
+}
|
|
|
|
+
|
|
//----------------------------------------------------------------------------
|
|
//----------------------------------------------------------------------------
|
|
QList<QVariantMap> ctkXnatSession::httpSync(const QUuid& uuid)
|
|
QList<QVariantMap> ctkXnatSession::httpSync(const QUuid& uuid)
|
|
{
|
|
{
|
|
@@ -518,17 +558,6 @@ QList<QVariantMap> ctkXnatSession::httpSync(const QUuid& uuid)
|
|
}
|
|
}
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
//----------------------------------------------------------------------------
|
|
-bool ctkXnatSession::exists(const ctkXnatObject* object)
|
|
|
|
-{
|
|
|
|
- Q_D(ctkXnatSession);
|
|
|
|
-
|
|
|
|
- QString query = object->resourceUri();
|
|
|
|
- bool success = d->xnat->sync(d->xnat->get(query));
|
|
|
|
-
|
|
|
|
- return success;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-//----------------------------------------------------------------------------
|
|
|
|
const QMap<QByteArray, QByteArray> ctkXnatSession::httpHeadSync(const QUuid &uuid)
|
|
const QMap<QByteArray, QByteArray> ctkXnatSession::httpHeadSync(const QUuid &uuid)
|
|
{
|
|
{
|
|
Q_D(ctkXnatSession);
|
|
Q_D(ctkXnatSession);
|
|
@@ -549,38 +578,14 @@ QUuid ctkXnatSession::httpHead(const QString& resourceUri)
|
|
}
|
|
}
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
//----------------------------------------------------------------------------
|
|
-void ctkXnatSession::save(ctkXnatObject* object)
|
|
|
|
|
|
+bool ctkXnatSession::exists(const ctkXnatObject* object)
|
|
{
|
|
{
|
|
Q_D(ctkXnatSession);
|
|
Q_D(ctkXnatSession);
|
|
|
|
|
|
QString query = object->resourceUri();
|
|
QString query = object->resourceUri();
|
|
- query.append(QString("?%1=%2").arg("xsi:type", object->schemaType()));
|
|
|
|
- const QMap<QString, QString>& properties = object->properties();
|
|
|
|
- QMapIterator<QString, QString> itProperties(properties);
|
|
|
|
- while (itProperties.hasNext())
|
|
|
|
- {
|
|
|
|
- itProperties.next();
|
|
|
|
- query.append(QString("&%1=%2").arg(itProperties.key(), itProperties.value()));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- qDebug() << "ctkXnatSession::save() query:" << query;
|
|
|
|
- QUuid queryId = d->xnat->put(query);
|
|
|
|
- qRestResult* result = d->xnat->takeResult(queryId);
|
|
|
|
-
|
|
|
|
- if (!result || !result->error().isNull())
|
|
|
|
- {
|
|
|
|
- d->throwXnatException("Error occurred while creating the data.");
|
|
|
|
- }
|
|
|
|
|
|
+ bool success = d->xnat->sync(d->xnat->get(query));
|
|
|
|
|
|
- const QList<QVariantMap>& maps = result->results();
|
|
|
|
- if (maps.size() == 1 && maps[0].size() == 1)
|
|
|
|
- {
|
|
|
|
- QVariant id = maps[0][ctkXnatObject::ID];
|
|
|
|
- if (!id.isNull())
|
|
|
|
- {
|
|
|
|
- object->setId(id.toString());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ return success;
|
|
}
|
|
}
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
//----------------------------------------------------------------------------
|
|
@@ -610,6 +615,17 @@ void ctkXnatSession::download(const QString& fileName,
|
|
}
|
|
}
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
//----------------------------------------------------------------------------
|
|
|
|
+void ctkXnatSession::upload(const QString &fileName,
|
|
|
|
+ const QString &resource,
|
|
|
|
+ const UrlParameters ¶meters,
|
|
|
|
+ const HttpRawHeaders &rawHeaders)
|
|
|
|
+{
|
|
|
|
+ Q_D(ctkXnatSession);
|
|
|
|
+ QUuid queryId = d->xnat->upload(fileName, resource, parameters);
|
|
|
|
+ d->xnat->sync(queryId);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//----------------------------------------------------------------------------
|
|
void ctkXnatSession::processResult(QUuid queryId, QList<QVariantMap> parameters)
|
|
void ctkXnatSession::processResult(QUuid queryId, QList<QVariantMap> parameters)
|
|
{
|
|
{
|
|
Q_UNUSED(queryId)
|
|
Q_UNUSED(queryId)
|