From 7a98c9853726ed09abd35a447f9854c5459a855d Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 21 Mar 2017 13:09:46 +0100 Subject: Move type implementations in one place Having them separated is rather pointless (since we need one for every type, and all types are the interface of sink, as one), and caused quite a bit of friction when adding new types. This will also make it easier to change things for all types. --- common/CMakeLists.txt | 6 +- common/domain/addressbook.cpp | 54 ------- common/domain/addressbook.h | 51 ------- common/domain/contact.cpp | 60 -------- common/domain/contact.h | 58 -------- common/domain/domaintypes.h | 6 - common/domain/event.cpp | 57 -------- common/domain/event.h | 57 -------- common/domain/folder.cpp | 60 -------- common/domain/folder.h | 51 ------- common/domain/mail.cpp | 104 -------------- common/domain/mail.h | 52 ------- common/domain/typeimplementations.cpp | 218 +++++++++++++++++++++++++++++ common/domain/typeimplementations.h | 122 ++++++++++++++++ common/domainadaptor.h | 2 +- common/storage/entitystore.cpp | 3 +- examples/dummyresource/resourcefactory.cpp | 2 - sinksh/syntax_modules/sink_clear.cpp | 2 - sinksh/syntax_modules/sink_count.cpp | 2 - sinksh/syntax_modules/sink_inspect.cpp | 2 - sinksh/syntax_modules/sink_remove.cpp | 2 - sinksh/syntax_modules/sink_show.cpp | 2 - sinksh/syntax_modules/sink_stat.cpp | 2 - sinksh/syntax_modules/sink_sync.cpp | 2 - 24 files changed, 343 insertions(+), 634 deletions(-) delete mode 100644 common/domain/addressbook.cpp delete mode 100644 common/domain/addressbook.h delete mode 100644 common/domain/contact.cpp delete mode 100644 common/domain/contact.h delete mode 100644 common/domain/domaintypes.h delete mode 100644 common/domain/event.cpp delete mode 100644 common/domain/event.h delete mode 100644 common/domain/folder.cpp delete mode 100644 common/domain/folder.h delete mode 100644 common/domain/mail.cpp delete mode 100644 common/domain/mail.h create mode 100644 common/domain/typeimplementations.cpp create mode 100644 common/domain/typeimplementations.h diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index a10f84f..001a412 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -61,11 +61,7 @@ set(command_SRCS resultset.cpp domain/propertyregistry.cpp domain/applicationdomaintype.cpp - domain/contact.cpp - domain/addressbook.cpp - domain/event.cpp - domain/mail.cpp - domain/folder.cpp + domain/typeimplementations.cpp test.cpp query.cpp changereplay.cpp diff --git a/common/domain/addressbook.cpp b/common/domain/addressbook.cpp deleted file mode 100644 index d1a3eaf..0000000 --- a/common/domain/addressbook.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2017 Christian Mollekopf - * - * 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 "addressbook.h" - -#include -#include - -#include "../propertymapper.h" -#include "../typeindex.h" -#include "entitybuffer.h" -#include "entity_generated.h" - -#include "addressbook_generated.h" - -using namespace Sink::ApplicationDomain; - -void TypeImplementation::configure(TypeIndex &index) -{ - index.addProperty(Addressbook::Parent::name); - index.addProperty(Addressbook::Name::name); -} - -void TypeImplementation::configure(ReadPropertyMapper &propertyMapper) -{ - propertyMapper.addMapping(&Buffer::parent); - propertyMapper.addMapping(&Buffer::name); -} - -void TypeImplementation::configure(WritePropertyMapper &propertyMapper) -{ - propertyMapper.addMapping(&BufferBuilder::add_parent); - propertyMapper.addMapping(&BufferBuilder::add_name); -} - -void TypeImplementation::configure(IndexPropertyMapper &) -{ - -} diff --git a/common/domain/addressbook.h b/common/domain/addressbook.h deleted file mode 100644 index 6475073..0000000 --- a/common/domain/addressbook.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2017 Christian Mollekopf - * - * 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. - */ -#pragma once - -#include "applicationdomaintype.h" - -template -class ReadPropertyMapper; -template -class WritePropertyMapper; -class IndexPropertyMapper; - -class TypeIndex; - -namespace Sink { - -namespace ApplicationDomain { - namespace Buffer { - struct Addressbook; - struct AddressbookBuilder; - } - -template<> -class TypeImplementation { -public: - typedef Sink::ApplicationDomain::Buffer::Addressbook Buffer; - typedef Sink::ApplicationDomain::Buffer::AddressbookBuilder BufferBuilder; - static void configure(TypeIndex &); - static void configure(ReadPropertyMapper &); - static void configure(WritePropertyMapper &); - static void configure(IndexPropertyMapper &indexPropertyMapper); -}; - -} -} diff --git a/common/domain/contact.cpp b/common/domain/contact.cpp deleted file mode 100644 index 01f9144..0000000 --- a/common/domain/contact.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2017 Sandro Knauß - * Copyright (C) 2017 Christian Mollekopf - * - * 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 "contact.h" - -#include -#include -#include - -#include "../propertymapper.h" -#include "../typeindex.h" -#include "entity_generated.h" - -#include "contact_generated.h" - -using namespace Sink::ApplicationDomain; - -void TypeImplementation::configure(TypeIndex &index) -{ - index.addProperty(Contact::Uid::name); -} - -void TypeImplementation::configure(ReadPropertyMapper &propertyMapper) -{ - propertyMapper.addMapping(&Buffer::uid); - propertyMapper.addMapping(&Buffer::fn); - propertyMapper.addMapping(&Buffer::emails); - propertyMapper.addMapping(&Buffer::vcard); - propertyMapper.addMapping(&Buffer::addressbook); -} - -void TypeImplementation::configure(WritePropertyMapper &propertyMapper) -{ - propertyMapper.addMapping(&BufferBuilder::add_uid); - propertyMapper.addMapping(&BufferBuilder::add_fn); - propertyMapper.addMapping(&BufferBuilder::add_emails); - propertyMapper.addMapping(&BufferBuilder::add_vcard); - propertyMapper.addMapping(&BufferBuilder::add_addressbook); -} - -void TypeImplementation::configure(IndexPropertyMapper &) -{ - -} diff --git a/common/domain/contact.h b/common/domain/contact.h deleted file mode 100644 index 976f16e..0000000 --- a/common/domain/contact.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2017 Sandro Knauß - * Copyright (C) 2017 Christian Mollekopf - * - * 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. - */ -#pragma once - -#include "applicationdomaintype.h" - -class QByteArray; - -template -class ReadPropertyMapper; -template -class WritePropertyMapper; -class IndexPropertyMapper; - -class TypeIndex; - -namespace Sink { -namespace ApplicationDomain { - namespace Buffer { - struct Contact; - struct ContactBuilder; - } - -/** - * Implements all type-specific code such as updating and querying indexes. - * - * These are type specifiy default implementations. Theoretically a resource could implement it's own implementation. - */ -template<> -class TypeImplementation { -public: - typedef Sink::ApplicationDomain::Buffer::Contact Buffer; - typedef Sink::ApplicationDomain::Buffer::ContactBuilder BufferBuilder; - static void configure(TypeIndex &); - static void configure(ReadPropertyMapper &); - static void configure(WritePropertyMapper &); - static void configure(IndexPropertyMapper &indexPropertyMapper); -}; - -} -} diff --git a/common/domain/domaintypes.h b/common/domain/domaintypes.h deleted file mode 100644 index 8e31d48..0000000 --- a/common/domain/domaintypes.h +++ /dev/null @@ -1,6 +0,0 @@ - -#include "contact.h" -#include "addressbook.h" -#include "mail.h" -#include "folder.h" -#include "event.h" diff --git a/common/domain/event.cpp b/common/domain/event.cpp deleted file mode 100644 index 10c92bb..0000000 --- a/common/domain/event.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2014 Christian Mollekopf - * - * 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 "event.h" - -#include -#include -#include - -#include "../propertymapper.h" -#include "../typeindex.h" -#include "entity_generated.h" - -#include "event_generated.h" - -using namespace Sink::ApplicationDomain; - -void TypeImplementation::configure(TypeIndex &index) -{ - index.addProperty(Event::Uid::name); -} - -void TypeImplementation::configure(ReadPropertyMapper &propertyMapper) -{ - propertyMapper.addMapping(&Buffer::summary); - propertyMapper.addMapping(&Buffer::description); - propertyMapper.addMapping(&Buffer::uid); - propertyMapper.addMapping(&Buffer::attachment); -} - -void TypeImplementation::configure(WritePropertyMapper &propertyMapper) -{ - propertyMapper.addMapping(&BufferBuilder::add_summary); - propertyMapper.addMapping(&BufferBuilder::add_description); - propertyMapper.addMapping(&BufferBuilder::add_uid); - propertyMapper.addMapping(&BufferBuilder::add_attachment); -} - -void TypeImplementation::configure(IndexPropertyMapper &) -{ - -} diff --git a/common/domain/event.h b/common/domain/event.h deleted file mode 100644 index b683f5f..0000000 --- a/common/domain/event.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2014 Christian Mollekopf - * - * 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. - */ -#pragma once - -#include "applicationdomaintype.h" - -class QByteArray; - -template -class ReadPropertyMapper; -template -class WritePropertyMapper; -class IndexPropertyMapper; - -class TypeIndex; - -namespace Sink { -namespace ApplicationDomain { - namespace Buffer { - struct Event; - struct EventBuilder; - } - -/** - * Implements all type-specific code such as updating and querying indexes. - * - * These are type specifiy default implementations. Theoretically a resource could implement it's own implementation. - */ -template<> -class TypeImplementation { -public: - typedef Sink::ApplicationDomain::Buffer::Event Buffer; - typedef Sink::ApplicationDomain::Buffer::EventBuilder BufferBuilder; - static void configure(TypeIndex &); - static void configure(ReadPropertyMapper &); - static void configure(WritePropertyMapper &); - static void configure(IndexPropertyMapper &indexPropertyMapper); -}; - -} -} diff --git a/common/domain/folder.cpp b/common/domain/folder.cpp deleted file mode 100644 index 6717661..0000000 --- a/common/domain/folder.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2015 Christian Mollekopf - * - * 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 "folder.h" - -#include -#include - -#include "../propertymapper.h" -#include "../typeindex.h" -#include "entitybuffer.h" -#include "entity_generated.h" - -#include "folder_generated.h" - -using namespace Sink::ApplicationDomain; - -void TypeImplementation::configure(TypeIndex &index) -{ - index.addProperty(Folder::Parent::name); - index.addProperty(Folder::Name::name); -} - -void TypeImplementation::configure(ReadPropertyMapper &propertyMapper) -{ - propertyMapper.addMapping(&Buffer::parent); - propertyMapper.addMapping(&Buffer::name); - propertyMapper.addMapping(&Buffer::icon); - propertyMapper.addMapping(&Buffer::specialpurpose); - propertyMapper.addMapping(&Buffer::enabled); -} - -void TypeImplementation::configure(WritePropertyMapper &propertyMapper) -{ - propertyMapper.addMapping(&BufferBuilder::add_parent); - propertyMapper.addMapping(&BufferBuilder::add_name); - propertyMapper.addMapping(&BufferBuilder::add_icon); - propertyMapper.addMapping(&BufferBuilder::add_specialpurpose); - propertyMapper.addMapping(&BufferBuilder::add_enabled); -} - -void TypeImplementation::configure(IndexPropertyMapper &) -{ - -} diff --git a/common/domain/folder.h b/common/domain/folder.h deleted file mode 100644 index f232ab5..0000000 --- a/common/domain/folder.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2015 Christian Mollekopf - * - * 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. - */ -#pragma once - -#include "applicationdomaintype.h" - -template -class ReadPropertyMapper; -template -class WritePropertyMapper; -class IndexPropertyMapper; - -class TypeIndex; - -namespace Sink { - -namespace ApplicationDomain { - namespace Buffer { - struct Folder; - struct FolderBuilder; - } - -template<> -class TypeImplementation { -public: - typedef Sink::ApplicationDomain::Buffer::Folder Buffer; - typedef Sink::ApplicationDomain::Buffer::FolderBuilder BufferBuilder; - static void configure(TypeIndex &); - static void configure(ReadPropertyMapper &); - static void configure(WritePropertyMapper &); - static void configure(IndexPropertyMapper &indexPropertyMapper); -}; - -} -} diff --git a/common/domain/mail.cpp b/common/domain/mail.cpp deleted file mode 100644 index 8cbe61b..0000000 --- a/common/domain/mail.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (C) 2015 Christian Mollekopf - * - * 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 "mail.h" - -#include -#include -#include - -#include "../propertymapper.h" -#include "../typeindex.h" -#include "entitybuffer.h" -#include "entity_generated.h" -#include "mail/threadindexer.h" -#include "domainadaptor.h" - -#include "mail_generated.h" - -using namespace Sink; -using namespace Sink::ApplicationDomain; - -void TypeImplementation::configure(TypeIndex &index) -{ - // index.addProperty(); - /* index.addProperty(Mail::SenderName::name); */ - /* index->addProperty(Mail::Subject::name); */ - /* index->addFulltextProperty(Mail::Subject::name); */ - index.addProperty(); - index.addProperty(); - index.addPropertyWithSorting(); - index.addProperty(); - index.addProperty(); - - index.addSecondaryPropertyIndexer(); - index.addSecondaryProperty(); - index.addSecondaryProperty(); -} - -void TypeImplementation::configure(IndexPropertyMapper &indexPropertyMapper) -{ - indexPropertyMapper.addIndexLookupProperty([](TypeIndex &index, const ApplicationDomain::BufferAdaptor &entity) { - auto messageId = entity.getProperty(Mail::MessageId::name); - auto thread = index.secondaryLookup(messageId); - if (!thread.isEmpty()) { - return thread.first(); - } - return QByteArray{}; - }); -} - -void TypeImplementation::configure(ReadPropertyMapper &propertyMapper) -{ - propertyMapper.addMapping(&Buffer::sender); - propertyMapper.addMapping(&Buffer::to); - propertyMapper.addMapping(&Buffer::cc); - propertyMapper.addMapping(&Buffer::bcc); - propertyMapper.addMapping(&Buffer::subject); - propertyMapper.addMapping(&Buffer::date); - propertyMapper.addMapping(&Buffer::unread); - propertyMapper.addMapping(&Buffer::important); - propertyMapper.addMapping(&Buffer::folder); - propertyMapper.addMapping(&Buffer::mimeMessage); - propertyMapper.addMapping(&Buffer::fullPayloadAvailable); - propertyMapper.addMapping(&Buffer::draft); - propertyMapper.addMapping(&Buffer::trash); - propertyMapper.addMapping(&Buffer::sent); - propertyMapper.addMapping(&Buffer::messageId); - propertyMapper.addMapping(&Buffer::parentMessageId); -} - -void TypeImplementation::configure(WritePropertyMapper &propertyMapper) -{ - propertyMapper.addMapping(&BufferBuilder::add_sender); - propertyMapper.addMapping(&BufferBuilder::add_to); - propertyMapper.addMapping(&BufferBuilder::add_cc); - propertyMapper.addMapping(&BufferBuilder::add_bcc); - propertyMapper.addMapping(&BufferBuilder::add_subject); - propertyMapper.addMapping(&BufferBuilder::add_date); - propertyMapper.addMapping(&BufferBuilder::add_unread); - propertyMapper.addMapping(&BufferBuilder::add_important); - propertyMapper.addMapping(&BufferBuilder::add_folder); - propertyMapper.addMapping(&BufferBuilder::add_mimeMessage); - propertyMapper.addMapping(&BufferBuilder::add_fullPayloadAvailable); - propertyMapper.addMapping(&BufferBuilder::add_draft); - propertyMapper.addMapping(&BufferBuilder::add_trash); - propertyMapper.addMapping(&BufferBuilder::add_sent); - propertyMapper.addMapping(&BufferBuilder::add_messageId); - propertyMapper.addMapping(&BufferBuilder::add_parentMessageId); -} diff --git a/common/domain/mail.h b/common/domain/mail.h deleted file mode 100644 index e052448..0000000 --- a/common/domain/mail.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2015 Christian Mollekopf - * - * 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. - */ -#pragma once - -#include "applicationdomaintype.h" - -class QByteArray; - -template -class ReadPropertyMapper; -template -class WritePropertyMapper; -class IndexPropertyMapper; - -class TypeIndex; - -namespace Sink { -namespace ApplicationDomain { - namespace Buffer { - struct Mail; - struct MailBuilder; - } - -template<> -class TypeImplementation { -public: - typedef Sink::ApplicationDomain::Buffer::Mail Buffer; - typedef Sink::ApplicationDomain::Buffer::MailBuilder BufferBuilder; - static void configure(TypeIndex &index); - static void configure(ReadPropertyMapper &propertyMapper); - static void configure(WritePropertyMapper &propertyMapper); - static void configure(IndexPropertyMapper &indexPropertyMapper); -}; - -} -} diff --git a/common/domain/typeimplementations.cpp b/common/domain/typeimplementations.cpp new file mode 100644 index 0000000..38422f4 --- /dev/null +++ b/common/domain/typeimplementations.cpp @@ -0,0 +1,218 @@ +/* + * Copyright (C) 2015 Christian Mollekopf + * + * 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 "typeimplementations.h" + +#include +#include +#include + +#include "../propertymapper.h" +#include "../typeindex.h" +#include "entitybuffer.h" +#include "entity_generated.h" +#include "mail/threadindexer.h" +#include "domainadaptor.h" + +#include "mail_generated.h" +#include "folder_generated.h" +#include "event_generated.h" +#include "contact_generated.h" +#include "addressbook_generated.h" + +using namespace Sink; +using namespace Sink::ApplicationDomain; + +void TypeImplementation::configure(TypeIndex &index) +{ + // index.addProperty(); + /* index.addProperty(Mail::SenderName::name); */ + /* index->addProperty(Mail::Subject::name); */ + /* index->addFulltextProperty(Mail::Subject::name); */ + index.addProperty(); + index.addProperty(); + index.addPropertyWithSorting(); + index.addProperty(); + index.addProperty(); + + index.addSecondaryPropertyIndexer(); + index.addSecondaryProperty(); + index.addSecondaryProperty(); +} + +void TypeImplementation::configure(IndexPropertyMapper &indexPropertyMapper) +{ + indexPropertyMapper.addIndexLookupProperty([](TypeIndex &index, const ApplicationDomain::BufferAdaptor &entity) { + auto messageId = entity.getProperty(Mail::MessageId::name); + auto thread = index.secondaryLookup(messageId); + if (!thread.isEmpty()) { + return thread.first(); + } + return QByteArray{}; + }); +} + +void TypeImplementation::configure(ReadPropertyMapper &propertyMapper) +{ + propertyMapper.addMapping(&Buffer::sender); + propertyMapper.addMapping(&Buffer::to); + propertyMapper.addMapping(&Buffer::cc); + propertyMapper.addMapping(&Buffer::bcc); + propertyMapper.addMapping(&Buffer::subject); + propertyMapper.addMapping(&Buffer::date); + propertyMapper.addMapping(&Buffer::unread); + propertyMapper.addMapping(&Buffer::important); + propertyMapper.addMapping(&Buffer::folder); + propertyMapper.addMapping(&Buffer::mimeMessage); + propertyMapper.addMapping(&Buffer::fullPayloadAvailable); + propertyMapper.addMapping(&Buffer::draft); + propertyMapper.addMapping(&Buffer::trash); + propertyMapper.addMapping(&Buffer::sent); + propertyMapper.addMapping(&Buffer::messageId); + propertyMapper.addMapping(&Buffer::parentMessageId); +} + +void TypeImplementation::configure(WritePropertyMapper &propertyMapper) +{ + propertyMapper.addMapping(&BufferBuilder::add_sender); + propertyMapper.addMapping(&BufferBuilder::add_to); + propertyMapper.addMapping(&BufferBuilder::add_cc); + propertyMapper.addMapping(&BufferBuilder::add_bcc); + propertyMapper.addMapping(&BufferBuilder::add_subject); + propertyMapper.addMapping(&BufferBuilder::add_date); + propertyMapper.addMapping(&BufferBuilder::add_unread); + propertyMapper.addMapping(&BufferBuilder::add_important); + propertyMapper.addMapping(&BufferBuilder::add_folder); + propertyMapper.addMapping(&BufferBuilder::add_mimeMessage); + propertyMapper.addMapping(&BufferBuilder::add_fullPayloadAvailable); + propertyMapper.addMapping(&BufferBuilder::add_draft); + propertyMapper.addMapping(&BufferBuilder::add_trash); + propertyMapper.addMapping(&BufferBuilder::add_sent); + propertyMapper.addMapping(&BufferBuilder::add_messageId); + propertyMapper.addMapping(&BufferBuilder::add_parentMessageId); +} + + +void TypeImplementation::configure(TypeIndex &index) +{ + index.addProperty(Folder::Parent::name); + index.addProperty(Folder::Name::name); +} + +void TypeImplementation::configure(ReadPropertyMapper &propertyMapper) +{ + propertyMapper.addMapping(&Buffer::parent); + propertyMapper.addMapping(&Buffer::name); + propertyMapper.addMapping(&Buffer::icon); + propertyMapper.addMapping(&Buffer::specialpurpose); + propertyMapper.addMapping(&Buffer::enabled); +} + +void TypeImplementation::configure(WritePropertyMapper &propertyMapper) +{ + propertyMapper.addMapping(&BufferBuilder::add_parent); + propertyMapper.addMapping(&BufferBuilder::add_name); + propertyMapper.addMapping(&BufferBuilder::add_icon); + propertyMapper.addMapping(&BufferBuilder::add_specialpurpose); + propertyMapper.addMapping(&BufferBuilder::add_enabled); +} + +void TypeImplementation::configure(IndexPropertyMapper &) +{ + +} + + +void TypeImplementation::configure(TypeIndex &index) +{ + index.addProperty(Contact::Uid::name); +} + +void TypeImplementation::configure(ReadPropertyMapper &propertyMapper) +{ + propertyMapper.addMapping(&Buffer::uid); + propertyMapper.addMapping(&Buffer::fn); + propertyMapper.addMapping(&Buffer::emails); + propertyMapper.addMapping(&Buffer::vcard); + propertyMapper.addMapping(&Buffer::addressbook); +} + +void TypeImplementation::configure(WritePropertyMapper &propertyMapper) +{ + propertyMapper.addMapping(&BufferBuilder::add_uid); + propertyMapper.addMapping(&BufferBuilder::add_fn); + propertyMapper.addMapping(&BufferBuilder::add_emails); + propertyMapper.addMapping(&BufferBuilder::add_vcard); + propertyMapper.addMapping(&BufferBuilder::add_addressbook); +} + +void TypeImplementation::configure(IndexPropertyMapper &) +{ + +} + + +void TypeImplementation::configure(TypeIndex &index) +{ + index.addProperty(Addressbook::Parent::name); + index.addProperty(Addressbook::Name::name); +} + +void TypeImplementation::configure(ReadPropertyMapper &propertyMapper) +{ + propertyMapper.addMapping(&Buffer::parent); + propertyMapper.addMapping(&Buffer::name); +} + +void TypeImplementation::configure(WritePropertyMapper &propertyMapper) +{ + propertyMapper.addMapping(&BufferBuilder::add_parent); + propertyMapper.addMapping(&BufferBuilder::add_name); +} + +void TypeImplementation::configure(IndexPropertyMapper &) +{ + +} + + +void TypeImplementation::configure(TypeIndex &index) +{ + index.addProperty(Event::Uid::name); +} + +void TypeImplementation::configure(ReadPropertyMapper &propertyMapper) +{ + propertyMapper.addMapping(&Buffer::summary); + propertyMapper.addMapping(&Buffer::description); + propertyMapper.addMapping(&Buffer::uid); + propertyMapper.addMapping(&Buffer::attachment); +} + +void TypeImplementation::configure(WritePropertyMapper &propertyMapper) +{ + propertyMapper.addMapping(&BufferBuilder::add_summary); + propertyMapper.addMapping(&BufferBuilder::add_description); + propertyMapper.addMapping(&BufferBuilder::add_uid); + propertyMapper.addMapping(&BufferBuilder::add_attachment); +} + +void TypeImplementation::configure(IndexPropertyMapper &) +{ + +} diff --git a/common/domain/typeimplementations.h b/common/domain/typeimplementations.h new file mode 100644 index 0000000..cb63949 --- /dev/null +++ b/common/domain/typeimplementations.h @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2015 Christian Mollekopf + * + * 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. + */ +#pragma once + +#include "applicationdomaintype.h" + +class QByteArray; + +template +class ReadPropertyMapper; +template +class WritePropertyMapper; +class IndexPropertyMapper; + +class TypeIndex; + +/** + * Implements all type-specific code such as updating and querying indexes. + * + * These are type specifiy default implementations. Theoretically a resource could implement it's own implementation. + */ +namespace Sink { +namespace ApplicationDomain { + +namespace Buffer { + struct Mail; + struct MailBuilder; +} + +template<> +class TypeImplementation { +public: + typedef Sink::ApplicationDomain::Buffer::Mail Buffer; + typedef Sink::ApplicationDomain::Buffer::MailBuilder BufferBuilder; + static void configure(TypeIndex &index); + static void configure(ReadPropertyMapper &propertyMapper); + static void configure(WritePropertyMapper &propertyMapper); + static void configure(IndexPropertyMapper &indexPropertyMapper); +}; + +namespace Buffer { + struct Folder; + struct FolderBuilder; +} + +template<> +class TypeImplementation { +public: + typedef Sink::ApplicationDomain::Buffer::Folder Buffer; + typedef Sink::ApplicationDomain::Buffer::FolderBuilder BufferBuilder; + static void configure(TypeIndex &); + static void configure(ReadPropertyMapper &); + static void configure(WritePropertyMapper &); + static void configure(IndexPropertyMapper &indexPropertyMapper); +}; + +namespace Buffer { + struct Contact; + struct ContactBuilder; +} + +template<> +class TypeImplementation { +public: + typedef Sink::ApplicationDomain::Buffer::Contact Buffer; + typedef Sink::ApplicationDomain::Buffer::ContactBuilder BufferBuilder; + static void configure(TypeIndex &); + static void configure(ReadPropertyMapper &); + static void configure(WritePropertyMapper &); + static void configure(IndexPropertyMapper &indexPropertyMapper); +}; + +namespace Buffer { + struct Addressbook; + struct AddressbookBuilder; +} + +template<> +class TypeImplementation { +public: + typedef Sink::ApplicationDomain::Buffer::Addressbook Buffer; + typedef Sink::ApplicationDomain::Buffer::AddressbookBuilder BufferBuilder; + static void configure(TypeIndex &); + static void configure(ReadPropertyMapper &); + static void configure(WritePropertyMapper &); + static void configure(IndexPropertyMapper &indexPropertyMapper); +}; + +namespace Buffer { + struct Event; + struct EventBuilder; +} + +template<> +class TypeImplementation { +public: + typedef Sink::ApplicationDomain::Buffer::Event Buffer; + typedef Sink::ApplicationDomain::Buffer::EventBuilder BufferBuilder; + static void configure(TypeIndex &); + static void configure(ReadPropertyMapper &); + static void configure(WritePropertyMapper &); + static void configure(IndexPropertyMapper &indexPropertyMapper); +}; + +} +} diff --git a/common/domainadaptor.h b/common/domainadaptor.h index 66ffb88..54aa53e 100644 --- a/common/domainadaptor.h +++ b/common/domainadaptor.h @@ -26,7 +26,7 @@ #include "domaintypeadaptorfactoryinterface.h" #include "domain/applicationdomaintype.h" -#include "domain/domaintypes.h" +#include "domain/typeimplementations.h" #include "bufferadaptor.h" #include "entity_generated.h" #include "metadata_generated.h" diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index 909f1b2..7f065f9 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp @@ -31,8 +31,7 @@ #include "bufferutils.h" #include "entity_generated.h" #include "applicationdomaintype_p.h" - -#include "domaintypes.h" +#include "typeimplementations.h" using namespace Sink; using namespace Sink::Storage; diff --git a/examples/dummyresource/resourcefactory.cpp b/examples/dummyresource/resourcefactory.cpp index cf20633..e89edde 100644 --- a/examples/dummyresource/resourcefactory.cpp +++ b/examples/dummyresource/resourcefactory.cpp @@ -26,8 +26,6 @@ #include "mail_generated.h" #include "domainadaptor.h" #include "log.h" -#include "domain/event.h" -#include "domain/mail.h" #include "dummystore.h" #include "definitions.h" #include "facadefactory.h" diff --git a/sinksh/syntax_modules/sink_clear.cpp b/sinksh/syntax_modules/sink_clear.cpp index 1537ecd..0f0f296 100644 --- a/sinksh/syntax_modules/sink_clear.cpp +++ b/sinksh/syntax_modules/sink_clear.cpp @@ -23,8 +23,6 @@ #include "common/resource.h" #include "common/storage.h" -#include "common/domain/event.h" -#include "common/domain/folder.h" #include "common/resourceconfig.h" #include "common/log.h" #include "common/storage.h" diff --git a/sinksh/syntax_modules/sink_count.cpp b/sinksh/syntax_modules/sink_count.cpp index 5ab9ca5..9b6aa1e 100644 --- a/sinksh/syntax_modules/sink_count.cpp +++ b/sinksh/syntax_modules/sink_count.cpp @@ -25,8 +25,6 @@ #include "common/resource.h" #include "common/storage.h" -#include "common/domain/event.h" -#include "common/domain/folder.h" #include "common/resourceconfig.h" #include "common/log.h" #include "common/storage.h" diff --git a/sinksh/syntax_modules/sink_inspect.cpp b/sinksh/syntax_modules/sink_inspect.cpp index 0d2ea00..a8a3805 100644 --- a/sinksh/syntax_modules/sink_inspect.cpp +++ b/sinksh/syntax_modules/sink_inspect.cpp @@ -24,8 +24,6 @@ #include "common/resource.h" #include "common/storage.h" -#include "common/domain/event.h" -#include "common/domain/folder.h" #include "common/resourceconfig.h" #include "common/log.h" #include "common/storage.h" diff --git a/sinksh/syntax_modules/sink_remove.cpp b/sinksh/syntax_modules/sink_remove.cpp index 7e66ece..bbc1752 100644 --- a/sinksh/syntax_modules/sink_remove.cpp +++ b/sinksh/syntax_modules/sink_remove.cpp @@ -25,8 +25,6 @@ #include "common/resource.h" #include "common/storage.h" -#include "common/domain/event.h" -#include "common/domain/folder.h" #include "common/resourceconfig.h" #include "common/log.h" #include "common/storage.h" diff --git a/sinksh/syntax_modules/sink_show.cpp b/sinksh/syntax_modules/sink_show.cpp index 8e3f715..391505a 100644 --- a/sinksh/syntax_modules/sink_show.cpp +++ b/sinksh/syntax_modules/sink_show.cpp @@ -26,8 +26,6 @@ #include "common/resource.h" #include "common/storage.h" -#include "common/domain/event.h" -#include "common/domain/folder.h" #include "common/resourceconfig.h" #include "common/log.h" #include "common/storage.h" diff --git a/sinksh/syntax_modules/sink_stat.cpp b/sinksh/syntax_modules/sink_stat.cpp index 982d4cf..73b6ac4 100644 --- a/sinksh/syntax_modules/sink_stat.cpp +++ b/sinksh/syntax_modules/sink_stat.cpp @@ -24,8 +24,6 @@ #include "common/resource.h" #include "common/storage.h" -#include "common/domain/event.h" -#include "common/domain/folder.h" #include "common/resourceconfig.h" #include "common/log.h" #include "common/storage.h" diff --git a/sinksh/syntax_modules/sink_sync.cpp b/sinksh/syntax_modules/sink_sync.cpp index ed2912e..ef84734 100644 --- a/sinksh/syntax_modules/sink_sync.cpp +++ b/sinksh/syntax_modules/sink_sync.cpp @@ -24,8 +24,6 @@ #include "common/resource.h" #include "common/storage.h" #include "common/resourcecontrol.h" -#include "common/domain/event.h" -#include "common/domain/folder.h" #include "common/resourceconfig.h" #include "common/log.h" #include "common/storage.h" -- cgit v1.2.3