|
@@ -329,6 +329,12 @@ ctkXnatSession::ctkXnatSession(const ctkXnatLoginProfile& loginProfile)
|
|
|
QString url = d->loginProfile.serverUrl().toString();
|
|
|
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();
|
|
|
}
|
|
|
|
|
@@ -430,7 +436,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() << "query id:" << queryId;
|
|
@@ -488,6 +494,13 @@ QList<ctkXnatObject*> ctkXnatSession::httpResults(const QUuid& uuid, const QStri
|
|
|
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)
|
|
|
{
|
|
@@ -509,17 +522,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)
|
|
|
{
|
|
|
Q_D(ctkXnatSession);
|
|
@@ -540,38 +542,14 @@ QUuid ctkXnatSession::httpHead(const QString& resourceUri)
|
|
|
}
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
-void ctkXnatSession::save(ctkXnatObject* object)
|
|
|
+bool ctkXnatSession::exists(const ctkXnatObject* object)
|
|
|
{
|
|
|
Q_D(ctkXnatSession);
|
|
|
|
|
|
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]["ID"];
|
|
|
- if (!id.isNull())
|
|
|
- {
|
|
|
- object->setId(id.toString());
|
|
|
- }
|
|
|
- }
|
|
|
+ return success;
|
|
|
}
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
@@ -610,6 +588,19 @@ void ctkXnatSession::download(ctkXnatResource* resource, const QString& fileName
|
|
|
d->xnat->sync(queryId);
|
|
|
}
|
|
|
|
|
|
+void ctkXnatSession::upload(ctkXnatFile *file)
|
|
|
+{
|
|
|
+ Q_D(ctkXnatSession);
|
|
|
+
|
|
|
+ QString query = file->resourceUri();
|
|
|
+ QString filename = file->property("filename");
|
|
|
+ qRestAPI::Parameters parameters;
|
|
|
+ parameters["inbody"] = "true";
|
|
|
+ parameters["tags"] = file->property("tags");
|
|
|
+ QUuid queryId = d->xnat->upload(filename, query, parameters);
|
|
|
+ d->xnat->sync(queryId);
|
|
|
+}
|
|
|
+
|
|
|
//----------------------------------------------------------------------------
|
|
|
void ctkXnatSession::processResult(QUuid queryId, QList<QVariantMap> parameters)
|
|
|
{
|