|
@@ -21,9 +21,12 @@
|
|
|
|
|
|
#include "ctkXnatFile.h"
|
|
|
|
|
|
+#include "ctkXnatException.h"
|
|
|
#include "ctkXnatObjectPrivate.h"
|
|
|
#include "ctkXnatSession.h"
|
|
|
|
|
|
+#include <QFile>
|
|
|
+
|
|
|
const QString ctkXnatFile::FILE_NAME = "Name";
|
|
|
const QString ctkXnatFile::FILE_TAGS = "file_tags";
|
|
|
const QString ctkXnatFile::FILE_FORMAT = "file_format";
|
|
@@ -41,10 +44,9 @@ public:
|
|
|
|
|
|
void reset()
|
|
|
{
|
|
|
-// uri.clear();
|
|
|
}
|
|
|
|
|
|
-// QString uri;
|
|
|
+ QString localFilePath;
|
|
|
};
|
|
|
|
|
|
|
|
@@ -77,6 +79,7 @@ void ctkXnatFile::setFileFormat(const QString &fileFormat)
|
|
|
this->setProperty(FILE_FORMAT, fileFormat);
|
|
|
}
|
|
|
|
|
|
+//----------------------------------------------------------------------------
|
|
|
QString ctkXnatFile::fileFormat() const
|
|
|
{
|
|
|
return this->property(FILE_FORMAT);
|
|
@@ -88,6 +91,7 @@ void ctkXnatFile::setFileContent(const QString &fileContent)
|
|
|
this->setProperty(FILE_CONTENT, fileContent);
|
|
|
}
|
|
|
|
|
|
+//----------------------------------------------------------------------------
|
|
|
QString ctkXnatFile::fileContent() const
|
|
|
{
|
|
|
return this->property(FILE_CONTENT);
|
|
@@ -99,20 +103,30 @@ void ctkXnatFile::setFileTags(const QString &fileTags)
|
|
|
this->setProperty(FILE_TAGS, fileTags);
|
|
|
}
|
|
|
|
|
|
+//----------------------------------------------------------------------------
|
|
|
QString ctkXnatFile::fileTags() const
|
|
|
{
|
|
|
return this->property(FILE_TAGS);
|
|
|
}
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
-QString ctkXnatFile::resourceUri() const
|
|
|
+void ctkXnatFile::setLocalFilePath(const QString &filePath)
|
|
|
{
|
|
|
- return QString("%1/files/%2").arg(parent()->resourceUri(), this->name());
|
|
|
+ Q_D(ctkXnatFile);
|
|
|
+ d->localFilePath = filePath;
|
|
|
+}
|
|
|
+
|
|
|
+//----------------------------------------------------------------------------
|
|
|
+QString ctkXnatFile::localFilePath() const
|
|
|
+{
|
|
|
+ Q_D(const ctkXnatFile);
|
|
|
+ return d->localFilePath;
|
|
|
}
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
-void ctkXnatFile::upload(const QString& /*filename*/)
|
|
|
+QString ctkXnatFile::resourceUri() const
|
|
|
{
|
|
|
+ return QString("%1/files/%2").arg(parent()->resourceUri(), this->name());
|
|
|
}
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
@@ -132,3 +146,42 @@ void ctkXnatFile::downloadImpl(const QString& filename)
|
|
|
QString query = this->resourceUri();
|
|
|
this->session()->download(filename, query);
|
|
|
}
|
|
|
+
|
|
|
+//----------------------------------------------------------------------------
|
|
|
+void ctkXnatFile::saveImpl()
|
|
|
+{
|
|
|
+ QString query = this->resourceUri();
|
|
|
+ QString filename = this->localFilePath();
|
|
|
+
|
|
|
+ QFile file(filename);
|
|
|
+
|
|
|
+ if (!file.exists())
|
|
|
+ {
|
|
|
+ QString msg = "Error uploading file! ";
|
|
|
+ msg.append(QString("File \"%1\" does not exist!").arg(filename));
|
|
|
+ throw ctkXnatException(msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Creating the update query
|
|
|
+ query.append(QString("?%1=%2").arg("xsi:type", this->schemaType()));
|
|
|
+ const QMap<QString, QString>& properties = this->properties();
|
|
|
+ QMapIterator<QString, QString> itProperties(properties);
|
|
|
+ while (itProperties.hasNext())
|
|
|
+ {
|
|
|
+ itProperties.next();
|
|
|
+
|
|
|
+ // Do not append these file specific properties since they require a slightly
|
|
|
+ // different key for uploading a file (e.g. instead of "file_format" only "format")
|
|
|
+ if (itProperties.key() == FILE_TAGS || itProperties.key() == FILE_FORMAT ||
|
|
|
+ itProperties.key() == FILE_CONTENT)
|
|
|
+ continue;
|
|
|
+
|
|
|
+ query.append(QString("&%1=%2").arg(itProperties.key(), itProperties.value()));
|
|
|
+ }
|
|
|
+ query.append(QString("&%1=%2").arg("format", this->fileFormat()));
|
|
|
+ query.append(QString("&%1=%2").arg("content", this->fileContent()));
|
|
|
+ query.append(QString("&%1=%2").arg("tags", this->fileTags()));
|
|
|
+ query.append(QString("&%1=%2").arg("inbody", "true"));
|
|
|
+
|
|
|
+ this->session()->upload(filename, query);
|
|
|
+}
|