summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--common/CMakeLists.txt2
-rw-r--r--common/domain/applicationdomaintype.h10
-rw-r--r--common/eventpreprocessor.cpp60
-rw-r--r--common/eventpreprocessor.h35
-rw-r--r--examples/caldavresource/caldavresource.cpp8
-rw-r--r--examples/dummyresource/resourcefactory.cpp7
-rw-r--r--tests/clientapitest.cpp6
8 files changed, 113 insertions, 17 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ba2c411..54ab9ea 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -39,7 +39,7 @@ ecm_setup_version(PROJECT
39 ) 39 )
40 40
41find_package(Qt5 COMPONENTS REQUIRED Core Concurrent Network Gui Test) 41find_package(Qt5 COMPONENTS REQUIRED Core Concurrent Network Gui Test)
42find_package(KF5 COMPONENTS REQUIRED Mime Contacts) 42find_package(KF5 COMPONENTS REQUIRED Mime Contacts CalendarCore)
43find_package(FlatBuffers REQUIRED 1.4.0) 43find_package(FlatBuffers REQUIRED 1.4.0)
44find_package(KAsync REQUIRED 0.1.2) 44find_package(KAsync REQUIRED 0.1.2)
45find_package(LMDB REQUIRED 0.9) 45find_package(LMDB REQUIRED 0.9)
diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt
index 9c4d4f1..51145fd 100644
--- a/common/CMakeLists.txt
+++ b/common/CMakeLists.txt
@@ -70,6 +70,7 @@ set(command_SRCS
70 synchronizerstore.cpp 70 synchronizerstore.cpp
71 contactpreprocessor.cpp 71 contactpreprocessor.cpp
72 mailpreprocessor.cpp 72 mailpreprocessor.cpp
73 eventpreprocessor.cpp
73 specialpurposepreprocessor.cpp 74 specialpurposepreprocessor.cpp
74 datastorequery.cpp 75 datastorequery.cpp
75 storage/entitystore.cpp 76 storage/entitystore.cpp
@@ -130,6 +131,7 @@ PRIVATE
130 Qt5::Gui 131 Qt5::Gui
131 KF5::Mime 132 KF5::Mime
132 KF5::Contacts 133 KF5::Contacts
134 KF5::CalendarCore
133 ${XAPIAN_LIBRARIES} 135 ${XAPIAN_LIBRARIES}
134) 136)
135install(TARGETS ${PROJECT_NAME} 137install(TARGETS ${PROJECT_NAME}
diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h
index 43d385c..f3c954a 100644
--- a/common/domain/applicationdomaintype.h
+++ b/common/domain/applicationdomaintype.h
@@ -396,11 +396,11 @@ struct SINK_EXPORT Calendar : public Entity {
396 396
397struct SINK_EXPORT Event : public Entity { 397struct SINK_EXPORT Event : public Entity {
398 SINK_ENTITY(Event, event); 398 SINK_ENTITY(Event, event);
399 SINK_PROPERTY(QString, Uid, uid); 399 SINK_EXTRACTED_PROPERTY(QString, Uid, uid);
400 SINK_PROPERTY(QString, Summary, summary); 400 SINK_EXTRACTED_PROPERTY(QString, Summary, summary);
401 SINK_PROPERTY(QString, Description, description); 401 SINK_EXTRACTED_PROPERTY(QString, Description, description);
402 SINK_PROPERTY(QDateTime, StartTime, startTime); 402 SINK_EXTRACTED_PROPERTY(QDateTime, StartTime, startTime);
403 SINK_PROPERTY(QDateTime, EndTime, endTime); 403 SINK_EXTRACTED_PROPERTY(QDateTime, EndTime, endTime);
404 SINK_PROPERTY(QByteArray, Ical, ical); 404 SINK_PROPERTY(QByteArray, Ical, ical);
405 SINK_REFERENCE_PROPERTY(Calendar, Calendar, calendar); 405 SINK_REFERENCE_PROPERTY(Calendar, Calendar, calendar);
406}; 406};
diff --git a/common/eventpreprocessor.cpp b/common/eventpreprocessor.cpp
new file mode 100644
index 0000000..e087563
--- /dev/null
+++ b/common/eventpreprocessor.cpp
@@ -0,0 +1,60 @@
1/*
2 * Copyright (C) 2018 Christian Mollekopf <chrigi_1@fastmail.fm>
3 * Copyright (C) 2018 Rémi Nicole <minijackson@riseup.net>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the
17 * Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#include "eventpreprocessor.h"
22
23#include <KCalCore/ICalFormat>
24
25void EventPropertyExtractor::updatedIndexedProperties(Event &event, const QByteArray &rawIcal)
26{
27 auto incidence = KCalCore::ICalFormat().readIncidence(rawIcal);
28
29 if(!incidence) {
30 SinkWarning() << "Invalid ICal to process, ignoring...";
31 return;
32 }
33
34 if(incidence->type() != KCalCore::IncidenceBase::IncidenceType::TypeEvent) {
35 SinkWarning() << "ICal to process is not of type `Event`, ignoring...";
36 return;
37 }
38
39 auto icalEvent = dynamic_cast<const KCalCore::Event *>(incidence.data());
40 // Should be guaranteed by the incidence->type() condition above.
41 Q_ASSERT(icalEvent);
42
43 SinkTrace() << "Extracting properties for event:" << icalEvent->summary();
44
45 event.setExtractedUid(icalEvent->uid());
46 event.setExtractedSummary(icalEvent->summary());
47 event.setExtractedDescription(icalEvent->description());
48 event.setExtractedStartTime(icalEvent->dtStart());
49 event.setExtractedEndTime(icalEvent->dtEnd());
50}
51
52void EventPropertyExtractor::newEntity(Event &event)
53{
54 updatedIndexedProperties(event, event.getIcal());
55}
56
57void EventPropertyExtractor::modifiedEntity(const Event &oldEvent, Event &newEvent)
58{
59 updatedIndexedProperties(newEvent, newEvent.getIcal());
60}
diff --git a/common/eventpreprocessor.h b/common/eventpreprocessor.h
new file mode 100644
index 0000000..3fde8b2
--- /dev/null
+++ b/common/eventpreprocessor.h
@@ -0,0 +1,35 @@
1/*
2 * Copyright (C) 2018 Christian Mollekopf <chrigi_1@fastmail.fm>
3 * Copyright (C) 2018 Rémi Nicole <minijackson@riseup.net>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the
17 * Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#include "pipeline.h"
22#include "sink_export.h"
23
24class SINK_EXPORT EventPropertyExtractor : public Sink::EntityPreprocessor<Sink::ApplicationDomain::Event>
25{
26 using Event = Sink::ApplicationDomain::Event;
27
28public:
29 virtual ~EventPropertyExtractor() {}
30 virtual void newEntity(Event &event) Q_DECL_OVERRIDE;
31 virtual void modifiedEntity(const Event &oldEvent, Event &newEvent) Q_DECL_OVERRIDE;
32
33private:
34 static void updatedIndexedProperties(Event &event, const QByteArray &rawIcal);
35};
diff --git a/examples/caldavresource/caldavresource.cpp b/examples/caldavresource/caldavresource.cpp
index 57f030b..6bf1a27 100644
--- a/examples/caldavresource/caldavresource.cpp
+++ b/examples/caldavresource/caldavresource.cpp
@@ -24,6 +24,7 @@
24#include "adaptorfactoryregistry.h" 24#include "adaptorfactoryregistry.h"
25#include "applicationdomaintype.h" 25#include "applicationdomaintype.h"
26#include "domainadaptor.h" 26#include "domainadaptor.h"
27#include "eventpreprocessor.h"
27#include "facade.h" 28#include "facade.h"
28#include "facadefactory.h" 29#include "facadefactory.h"
29 30
@@ -76,11 +77,6 @@ protected:
76 auto remoteEvent = dynamic_cast<const KCalCore::Event &>(*incidence); 77 auto remoteEvent = dynamic_cast<const KCalCore::Event &>(*incidence);
77 78
78 Event localEvent; 79 Event localEvent;
79 localEvent.setUid(remoteEvent.uid());
80 localEvent.setSummary(remoteEvent.summary());
81 localEvent.setDescription(remoteEvent.description());
82 localEvent.setStartTime(remoteEvent.dtStart());
83 localEvent.setEndTime(remoteEvent.dtEnd());
84 localEvent.setIcal(ical); 80 localEvent.setIcal(ical);
85 localEvent.setCalendar(calendarLocalId); 81 localEvent.setCalendar(calendarLocalId);
86 82
@@ -119,7 +115,7 @@ CalDavResource::CalDavResource(const Sink::ResourceContext &context)
119 auto synchronizer = QSharedPointer<EventSynchronizer>::create(context); 115 auto synchronizer = QSharedPointer<EventSynchronizer>::create(context);
120 setupSynchronizer(synchronizer); 116 setupSynchronizer(synchronizer);
121 117
122 // setupPreprocessors(ENTITY_TYPE_EVENT, QVector<Sink::Preprocessor*>() << new EventPropertyExtractor); 118 setupPreprocessors(ENTITY_TYPE_EVENT, QVector<Sink::Preprocessor*>() << new EventPropertyExtractor);
123} 119}
124 120
125CalDavResourceFactory::CalDavResourceFactory(QObject *parent) 121CalDavResourceFactory::CalDavResourceFactory(QObject *parent)
diff --git a/examples/dummyresource/resourcefactory.cpp b/examples/dummyresource/resourcefactory.cpp
index cfce6e4..597bd95 100644
--- a/examples/dummyresource/resourcefactory.cpp
+++ b/examples/dummyresource/resourcefactory.cpp
@@ -55,9 +55,12 @@ class DummySynchronizer : public Sink::Synchronizer {
55 Sink::ApplicationDomain::Event::Ptr createEvent(const QByteArray &ridBuffer, const QMap<QString, QVariant> &data) 55 Sink::ApplicationDomain::Event::Ptr createEvent(const QByteArray &ridBuffer, const QMap<QString, QVariant> &data)
56 { 56 {
57 auto event = Sink::ApplicationDomain::Event::Ptr::create(); 57 auto event = Sink::ApplicationDomain::Event::Ptr::create();
58 event->setSummary(data.value("summary").toString()); 58 event->setExtractedUid(data.value("uid").toString());
59 event->setExtractedSummary(data.value("summary").toString());
60 event->setExtractedDescription(data.value("description").toString());
61 event->setExtractedStartTime(data.value("starttime").toDateTime());
62 event->setExtractedEndTime(data.value("endtime").toDateTime());
59 event->setProperty("remoteId", ridBuffer); 63 event->setProperty("remoteId", ridBuffer);
60 event->setDescription(data.value("description").toString());
61 return event; 64 return event;
62 } 65 }
63 66
diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp
index e2f3543..aa03fc3 100644
--- a/tests/clientapitest.cpp
+++ b/tests/clientapitest.cpp
@@ -387,7 +387,7 @@ private slots:
387 Sink::Store::create(event).exec().waitForFinished(); 387 Sink::Store::create(event).exec().waitForFinished();
388 QCOMPARE(facade->creations.size(), 1); 388 QCOMPARE(facade->creations.size(), 1);
389 //Modify something so the mdofication won't be dropped 389 //Modify something so the mdofication won't be dropped
390 event.setSummary("foobar"); 390 event.setExtractedSummary("foobar");
391 Sink::Store::modify(event).exec().waitForFinished(); 391 Sink::Store::modify(event).exec().waitForFinished();
392 QCOMPARE(facade->modifications.size(), 1); 392 QCOMPARE(facade->modifications.size(), 1);
393 Sink::Store::remove(event).exec().waitForFinished(); 393 Sink::Store::remove(event).exec().waitForFinished();
@@ -404,7 +404,7 @@ private slots:
404 query.resourceFilter("dummyresource.instance1"); 404 query.resourceFilter("dummyresource.instance1");
405 405
406 auto event = Sink::ApplicationDomain::Event::createEntity<Sink::ApplicationDomain::Event>("dummyresource.instance1"); 406 auto event = Sink::ApplicationDomain::Event::createEntity<Sink::ApplicationDomain::Event>("dummyresource.instance1");
407 event.setUid("modifiedUid"); 407 event.setExtractedUid("modifiedUid");
408 Sink::Store::modify(query, event).exec().waitForFinished(); 408 Sink::Store::modify(query, event).exec().waitForFinished();
409 QCOMPARE(facade->modifications.size(), 2); 409 QCOMPARE(facade->modifications.size(), 2);
410 for (const auto &m : facade->modifications) { 410 for (const auto &m : facade->modifications) {
@@ -420,7 +420,7 @@ private slots:
420 420
421 Sink::ApplicationDomain::Event modification("dummyresource.instance1", "id1", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); 421 Sink::ApplicationDomain::Event modification("dummyresource.instance1", "id1", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create());
422 modification.aggregatedIds() << "id1" << "id2"; 422 modification.aggregatedIds() << "id1" << "id2";
423 modification.setUid("modifiedUid2"); 423 modification.setExtractedUid("modifiedUid2");
424 424
425 Sink::Store::modify(modification).exec().waitForFinished(); 425 Sink::Store::modify(modification).exec().waitForFinished();
426 QCOMPARE(facade->modifications.size(), 2); 426 QCOMPARE(facade->modifications.size(), 2);