summaryrefslogtreecommitdiffstats
path: root/common/domain/applicationdomaintype.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/domain/applicationdomaintype.cpp')
-rw-r--r--common/domain/applicationdomaintype.cpp45
1 files changed, 2 insertions, 43 deletions
diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp
index c1ac7e8..8bb74e3 100644
--- a/common/domain/applicationdomaintype.cpp
+++ b/common/domain/applicationdomaintype.cpp
@@ -58,12 +58,6 @@ QDebug Sink::ApplicationDomain::operator<< (QDebug d, const Sink::ApplicationDom
58 return d; 58 return d;
59} 59}
60 60
61QDebug Sink::ApplicationDomain::operator<< (QDebug d, const Sink::ApplicationDomain::BLOB &blob)
62{
63 d << blob.value << "external:" << blob.isExternal ;
64 return d;
65}
66
67template <typename DomainType, typename Property> 61template <typename DomainType, typename Property>
68int registerProperty() { 62int registerProperty() {
69 Sink::Private::PropertyRegistry::instance().registerProperty<Property>(Sink::ApplicationDomain::getTypeName<DomainType>()); 63 Sink::Private::PropertyRegistry::instance().registerProperty<Property>(Sink::ApplicationDomain::getTypeName<DomainType>());
@@ -130,13 +124,12 @@ static const int foo = [] {
130 QMetaType::registerEqualsComparator<Reference>(); 124 QMetaType::registerEqualsComparator<Reference>();
131 QMetaType::registerDebugStreamOperator<Reference>(); 125 QMetaType::registerDebugStreamOperator<Reference>();
132 QMetaType::registerConverter<Reference, QByteArray>(); 126 QMetaType::registerConverter<Reference, QByteArray>();
133 QMetaType::registerDebugStreamOperator<BLOB>();
134 QMetaType::registerDebugStreamOperator<Mail::Contact>(); 127 QMetaType::registerDebugStreamOperator<Mail::Contact>();
135 qRegisterMetaTypeStreamOperators<Sink::ApplicationDomain::Reference>(); 128 qRegisterMetaTypeStreamOperators<Sink::ApplicationDomain::Reference>();
136 return 0; 129 return 0;
137}(); 130}();
138 131
139void copyBuffer(Sink::ApplicationDomain::BufferAdaptor &buffer, Sink::ApplicationDomain::BufferAdaptor &memoryAdaptor, const QList<QByteArray> &properties, bool copyBlobs, bool pruneReferences) 132void copyBuffer(Sink::ApplicationDomain::BufferAdaptor &buffer, Sink::ApplicationDomain::BufferAdaptor &memoryAdaptor, const QList<QByteArray> &properties, bool pruneReferences)
140{ 133{
141 auto propertiesToCopy = properties; 134 auto propertiesToCopy = properties;
142 if (properties.isEmpty()) { 135 if (properties.isEmpty()) {
@@ -144,14 +137,7 @@ void copyBuffer(Sink::ApplicationDomain::BufferAdaptor &buffer, Sink::Applicatio
144 } 137 }
145 for (const auto &property : propertiesToCopy) { 138 for (const auto &property : propertiesToCopy) {
146 const auto value = buffer.getProperty(property); 139 const auto value = buffer.getProperty(property);
147 if (copyBlobs && value.canConvert<BLOB>()) { 140 if (pruneReferences && value.canConvert<Reference>()) {
148 const auto oldPath = value.value<BLOB>().value;
149 const auto newPath = Sink::temporaryFileLocation() + "/" + createUuid();
150 if (!QFile::copy(oldPath, newPath)) {
151 SinkWarning() << "Failed to copy file from: " << oldPath << "to: " << newPath;
152 }
153 memoryAdaptor.setProperty(property, QVariant::fromValue(BLOB{newPath}));
154 } else if (pruneReferences && value.canConvert<Reference>()) {
155 continue; 141 continue;
156 } else { 142 } else {
157 memoryAdaptor.setProperty(property, value); 143 memoryAdaptor.setProperty(property, value);
@@ -245,33 +231,6 @@ void ApplicationDomainType::setProperty(const QByteArray &key, const Application
245 setProperty(key, QVariant::fromValue(Reference{value.identifier()})); 231 setProperty(key, QVariant::fromValue(Reference{value.identifier()}));
246} 232}
247 233
248QByteArray ApplicationDomainType::getBlobProperty(const QByteArray &key) const
249{
250 const auto path = getProperty(key).value<BLOB>().value;
251 QFile file(path);
252 if (!file.open(QIODevice::ReadOnly)) {
253 SinkError() << "Failed to open the file for reading: " << file.errorString() << "Path:" << path << " For property:" << key;
254 return QByteArray();
255 }
256 return file.readAll();
257}
258
259void ApplicationDomainType::setBlobProperty(const QByteArray &key, const QByteArray &value)
260{
261 const auto path = Sink::temporaryFileLocation() + "/" + createUuid();
262 QFile file(path);
263 if (!file.open(QIODevice::WriteOnly)) {
264 SinkError() << "Failed to open the file for writing: " << file.errorString() << path << " For property " << key;
265 return;
266 }
267 if (file.write(value) < 0) {
268 SinkError() << "Failed to write to file: " << file.errorString() << path << " For property " << key;
269 }
270 //Ensure that the file is written to disk immediately
271 file.close();
272 setProperty(key, QVariant::fromValue(BLOB{path}));
273}
274
275void ApplicationDomainType::setChangedProperties(const QSet<QByteArray> &changeset) 234void ApplicationDomainType::setChangedProperties(const QSet<QByteArray> &changeset)
276{ 235{
277 *mChangeSet = changeset; 236 *mChangeSet = changeset;