From cd81aed814286887911d99648d62bbb3c63e404c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Nicole?= Date: Fri, 13 Apr 2018 11:51:18 +0200 Subject: Change most of Event's properties to extracted properties Summary: Fix T8485 Reviewers: cmollekopf Reviewed By: cmollekopf Tags: #sink Maniphest Tasks: T8485 Differential Revision: https://phabricator.kde.org/D12106 --- CMakeLists.txt | 2 +- common/CMakeLists.txt | 2 + common/domain/applicationdomaintype.h | 10 ++--- common/eventpreprocessor.cpp | 60 ++++++++++++++++++++++++++++++ common/eventpreprocessor.h | 35 +++++++++++++++++ examples/caldavresource/caldavresource.cpp | 8 +--- examples/dummyresource/resourcefactory.cpp | 7 +++- tests/clientapitest.cpp | 6 +-- 8 files changed, 113 insertions(+), 17 deletions(-) create mode 100644 common/eventpreprocessor.cpp create mode 100644 common/eventpreprocessor.h 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 ) find_package(Qt5 COMPONENTS REQUIRED Core Concurrent Network Gui Test) -find_package(KF5 COMPONENTS REQUIRED Mime Contacts) +find_package(KF5 COMPONENTS REQUIRED Mime Contacts CalendarCore) find_package(FlatBuffers REQUIRED 1.4.0) find_package(KAsync REQUIRED 0.1.2) find_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 synchronizerstore.cpp contactpreprocessor.cpp mailpreprocessor.cpp + eventpreprocessor.cpp specialpurposepreprocessor.cpp datastorequery.cpp storage/entitystore.cpp @@ -130,6 +131,7 @@ PRIVATE Qt5::Gui KF5::Mime KF5::Contacts + KF5::CalendarCore ${XAPIAN_LIBRARIES} ) install(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 { struct SINK_EXPORT Event : public Entity { SINK_ENTITY(Event, event); - SINK_PROPERTY(QString, Uid, uid); - SINK_PROPERTY(QString, Summary, summary); - SINK_PROPERTY(QString, Description, description); - SINK_PROPERTY(QDateTime, StartTime, startTime); - SINK_PROPERTY(QDateTime, EndTime, endTime); + SINK_EXTRACTED_PROPERTY(QString, Uid, uid); + SINK_EXTRACTED_PROPERTY(QString, Summary, summary); + SINK_EXTRACTED_PROPERTY(QString, Description, description); + SINK_EXTRACTED_PROPERTY(QDateTime, StartTime, startTime); + SINK_EXTRACTED_PROPERTY(QDateTime, EndTime, endTime); SINK_PROPERTY(QByteArray, Ical, ical); SINK_REFERENCE_PROPERTY(Calendar, Calendar, calendar); }; 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 @@ +/* + * Copyright (C) 2018 Christian Mollekopf + * Copyright (C) 2018 Rémi Nicole + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "eventpreprocessor.h" + +#include + +void EventPropertyExtractor::updatedIndexedProperties(Event &event, const QByteArray &rawIcal) +{ + auto incidence = KCalCore::ICalFormat().readIncidence(rawIcal); + + if(!incidence) { + SinkWarning() << "Invalid ICal to process, ignoring..."; + return; + } + + if(incidence->type() != KCalCore::IncidenceBase::IncidenceType::TypeEvent) { + SinkWarning() << "ICal to process is not of type `Event`, ignoring..."; + return; + } + + auto icalEvent = dynamic_cast(incidence.data()); + // Should be guaranteed by the incidence->type() condition above. + Q_ASSERT(icalEvent); + + SinkTrace() << "Extracting properties for event:" << icalEvent->summary(); + + event.setExtractedUid(icalEvent->uid()); + event.setExtractedSummary(icalEvent->summary()); + event.setExtractedDescription(icalEvent->description()); + event.setExtractedStartTime(icalEvent->dtStart()); + event.setExtractedEndTime(icalEvent->dtEnd()); +} + +void EventPropertyExtractor::newEntity(Event &event) +{ + updatedIndexedProperties(event, event.getIcal()); +} + +void EventPropertyExtractor::modifiedEntity(const Event &oldEvent, Event &newEvent) +{ + updatedIndexedProperties(newEvent, newEvent.getIcal()); +} 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 @@ +/* + * Copyright (C) 2018 Christian Mollekopf + * Copyright (C) 2018 Rémi Nicole + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "pipeline.h" +#include "sink_export.h" + +class SINK_EXPORT EventPropertyExtractor : public Sink::EntityPreprocessor +{ + using Event = Sink::ApplicationDomain::Event; + +public: + virtual ~EventPropertyExtractor() {} + virtual void newEntity(Event &event) Q_DECL_OVERRIDE; + virtual void modifiedEntity(const Event &oldEvent, Event &newEvent) Q_DECL_OVERRIDE; + +private: + static void updatedIndexedProperties(Event &event, const QByteArray &rawIcal); +}; 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 @@ #include "adaptorfactoryregistry.h" #include "applicationdomaintype.h" #include "domainadaptor.h" +#include "eventpreprocessor.h" #include "facade.h" #include "facadefactory.h" @@ -76,11 +77,6 @@ protected: auto remoteEvent = dynamic_cast(*incidence); Event localEvent; - localEvent.setUid(remoteEvent.uid()); - localEvent.setSummary(remoteEvent.summary()); - localEvent.setDescription(remoteEvent.description()); - localEvent.setStartTime(remoteEvent.dtStart()); - localEvent.setEndTime(remoteEvent.dtEnd()); localEvent.setIcal(ical); localEvent.setCalendar(calendarLocalId); @@ -119,7 +115,7 @@ CalDavResource::CalDavResource(const Sink::ResourceContext &context) auto synchronizer = QSharedPointer::create(context); setupSynchronizer(synchronizer); - // setupPreprocessors(ENTITY_TYPE_EVENT, QVector() << new EventPropertyExtractor); + setupPreprocessors(ENTITY_TYPE_EVENT, QVector() << new EventPropertyExtractor); } CalDavResourceFactory::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 { Sink::ApplicationDomain::Event::Ptr createEvent(const QByteArray &ridBuffer, const QMap &data) { auto event = Sink::ApplicationDomain::Event::Ptr::create(); - event->setSummary(data.value("summary").toString()); + event->setExtractedUid(data.value("uid").toString()); + event->setExtractedSummary(data.value("summary").toString()); + event->setExtractedDescription(data.value("description").toString()); + event->setExtractedStartTime(data.value("starttime").toDateTime()); + event->setExtractedEndTime(data.value("endtime").toDateTime()); event->setProperty("remoteId", ridBuffer); - event->setDescription(data.value("description").toString()); return event; } 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: Sink::Store::create(event).exec().waitForFinished(); QCOMPARE(facade->creations.size(), 1); //Modify something so the mdofication won't be dropped - event.setSummary("foobar"); + event.setExtractedSummary("foobar"); Sink::Store::modify(event).exec().waitForFinished(); QCOMPARE(facade->modifications.size(), 1); Sink::Store::remove(event).exec().waitForFinished(); @@ -404,7 +404,7 @@ private slots: query.resourceFilter("dummyresource.instance1"); auto event = Sink::ApplicationDomain::Event::createEntity("dummyresource.instance1"); - event.setUid("modifiedUid"); + event.setExtractedUid("modifiedUid"); Sink::Store::modify(query, event).exec().waitForFinished(); QCOMPARE(facade->modifications.size(), 2); for (const auto &m : facade->modifications) { @@ -420,7 +420,7 @@ private slots: Sink::ApplicationDomain::Event modification("dummyresource.instance1", "id1", 0, QSharedPointer::create()); modification.aggregatedIds() << "id1" << "id2"; - modification.setUid("modifiedUid2"); + modification.setExtractedUid("modifiedUid2"); Sink::Store::modify(modification).exec().waitForFinished(); QCOMPARE(facade->modifications.size(), 2); -- cgit v1.2.3