~ubuntu-branches/ubuntu/quantal/kde-runtime/quantal

« back to all changes in this revision

Viewing changes to nepomuk/services/backupsync/lib/resourcemerger.h

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2012-06-03 21:50:00 UTC
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: package-import@ubuntu.com-20120603215000-vn7oarsq0ynrydj5
Tags: upstream-4.8.80
Import upstream version 4.8.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    This file is part of the Nepomuk KDE project.
3
 
    Copyright (C) 2010-11  Vishesh Handa <handa.vish@gmail.com>
4
 
 
5
 
   This library is free software; you can redistribute it and/or
6
 
   modify it under the terms of the GNU Lesser General Public
7
 
   License as published by the Free Software Foundation; either
8
 
   version 2.1 of the License, or (at your option) version 3, or any
9
 
   later version accepted by the membership of KDE e.V. (or its
10
 
   successor approved by the membership of KDE e.V.), which shall
11
 
   act as a proxy defined in Section 6 of version 3 of the license.
12
 
 
13
 
   This library is distributed in the hope that it will be useful,
14
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 
   Lesser General Public License for more details.
17
 
 
18
 
   You should have received a copy of the GNU Lesser General Public
19
 
   License along with this library.  If not, see <http://www.gnu.org/licenses/>.
20
 
*/
21
 
 
22
 
 
23
 
#ifndef NEPOMUK_RESOURCEMERGER_H
24
 
#define NEPOMUK_RESOURCEMERGER_H
25
 
 
26
 
#include <QtCore/QList>
27
 
#include <QtCore/QHash>
28
 
 
29
 
#include <KUrl>
30
 
 
31
 
#include "nepomuksync_export.h"
32
 
#include <Soprano/Error/ErrorCode>
33
 
 
34
 
namespace Soprano {
35
 
    class Statement;
36
 
    class Model;
37
 
    class Graph;
38
 
    class Node;
39
 
}
40
 
 
41
 
namespace Nepomuk {
42
 
 
43
 
    class Resource;
44
 
    class ResourceManager;
45
 
 
46
 
    namespace Types {
47
 
        class Class;
48
 
    }
49
 
 
50
 
    namespace Sync {
51
 
 
52
 
        /**
53
 
         * \class ResourceMerger resourcemerger.h
54
 
         *
55
 
         * This class can be used to push resources into repository after identification.
56
 
         * It's default behavior is to create all the resources that have not been
57
 
         * identified.
58
 
         *
59
 
         * By default, it pushes all the statements with a nrl:InstanceBase graph. If a
60
 
         * statement already exists in the repository then it is NOT overwritten.
61
 
         *
62
 
         * \author Vishesh Handa <handa.vish@gmail.com>
63
 
         */
64
 
        class NEPOMUKSYNC_EXPORT ResourceMerger : public Soprano::Error::ErrorCache
65
 
        {
66
 
        public:
67
 
            ResourceMerger( Soprano::Model * model =0, const QHash<KUrl, KUrl> & mappings = (QHash<KUrl, KUrl>()) );
68
 
            virtual ~ResourceMerger();
69
 
 
70
 
            void setModel( Soprano::Model * model );
71
 
            Soprano::Model * model() const;
72
 
 
73
 
            void setMappings( const QHash<KUrl, KUrl> & mappings );
74
 
            QHash<KUrl, KUrl> mappings() const;
75
 
 
76
 
            /**
77
 
             * Merges all the statements in \p graph into the model, by calling
78
 
             * mergeStatement
79
 
             *
80
 
             * It stops merging if any of the statements in \p graph fail to merge
81
 
             *
82
 
             * \sa mergeStatement
83
 
             * \return \c true if merging was successful
84
 
             */
85
 
            virtual bool merge( const Soprano::Graph & graph );
86
 
 
87
 
            /**
88
 
             * Merges the statement \p st into the model. If the statement
89
 
             * already exists then resolveDuplicate() is called.
90
 
             *
91
 
             * If any of the statements contains a graph, then that graph is used. Otherwise
92
 
             * createGraph() is called which returns a new graph.
93
 
             *
94
 
             * lastError() is set, if merging fails.
95
 
             *
96
 
             * \sa createGraph
97
 
             * \return \c true if the merging was sucessful.
98
 
             *         \c false if merging failed
99
 
             */
100
 
            virtual bool mergeStatement( const Soprano::Statement & st );
101
 
 
102
 
            /**
103
 
             * Sets the graph metadata which will be used to create a graph.
104
 
             *
105
 
             * \sa createGraph
106
 
             */
107
 
            void setAdditionalGraphMetadata( const QMultiHash<QUrl, Soprano::Node>& additionalMetadata );
108
 
 
109
 
            QMultiHash<QUrl, Soprano::Node> additionalMetadata() const;
110
 
 
111
 
        protected:
112
 
            /**
113
 
             * Called when trying to merge a statement which contains a Resource that
114
 
             * has not been identified.
115
 
             *
116
 
             * The default implementation of this creates the resource in the model.
117
 
             * The resourceUri is generated using createResourceUri.
118
 
             *
119
 
             * If the resolution is supposed to fail, this function returns KUrl().
120
 
             * The reason why resolution failed should also be set with setError()
121
 
             *
122
 
             * \sa createResourceUri
123
 
             */
124
 
            virtual KUrl resolveUnidentifiedResource( const KUrl & uri );
125
 
 
126
 
            /**
127
 
             * Creates a new graph with the additional metadata.
128
 
             * All graphs that are created should be a subtype of nrl:Graph
129
 
             *
130
 
             * \sa additionalMetadata
131
 
             */
132
 
            virtual KUrl createGraph();
133
 
 
134
 
            /**
135
 
             * Push the statement into the Nepomuk repository.
136
 
             * If a statement with the same subject, predicate and object already
137
 
             * exists in the model, then resolveDuplicate is called.
138
 
             *
139
 
             * \sa resolveDuplicate
140
 
             * \return \c true if pushing the statement was successful
141
 
             */
142
 
            bool push( const Soprano::Statement & st );
143
 
 
144
 
            /**
145
 
             * If the statement being pushed already exists this method is called.
146
 
             * By default it does nothing which means keeping the old statement
147
 
             *
148
 
             * \return \c true if resolution was successful
149
 
             *         \c false if resolution failed, and merging and should fail
150
 
             */
151
 
            virtual bool resolveDuplicate( const Soprano::Statement & newSt );
152
 
 
153
 
            /**
154
 
             * Creates a new resource uri. By default this creates it using the
155
 
             * ResourceManager::instace()->generateUniqueUri("res")
156
 
             */
157
 
            virtual QUrl createResourceUri();
158
 
 
159
 
            /**
160
 
             * Creates a new graph uri. By default this creates it using the
161
 
             * ResourceManager::instace()->generateUniqueUri("ctx")
162
 
             */
163
 
            virtual QUrl createGraphUri();
164
 
 
165
 
            /**
166
 
             * Returns the graph that is being used to add new statements.
167
 
             * If this graph does not exist it is created using createGraph
168
 
             *
169
 
             * \sa createGraph
170
 
             */
171
 
            KUrl graph();
172
 
 
173
 
            /**
174
 
             * Add the statement in the model. By default it just calls
175
 
             * Soprano::Model::addStatement()
176
 
             *
177
 
             * \return \c Soprano::Error::ErrorNone if added to model
178
 
             */
179
 
            virtual Soprano::Error::ErrorCode addStatement( const Soprano::Statement & st );
180
 
            Soprano::Error::ErrorCode addStatement( const Soprano::Node& subject, const Soprano::Node& property,
181
 
                                                    const Soprano::Node& object, const Soprano::Node& graph );
182
 
 
183
 
            /**
184
 
             * Resolves the subject and object and gets the object ready for pushing
185
 
             */
186
 
            bool resolveStatement( Soprano::Statement& st );
187
 
        private:
188
 
            class Private;
189
 
            Private * d;
190
 
        };
191
 
    }
192
 
}
193
 
#endif // NEPOMUK_RESOURCEMERGER_H