MICO Platform
 All Classes Namespaces Functions Variables Friends
ContentItem.hpp
1 #ifndef HAVE_CONTENTITEM_H
2 #define HAVE_CONTENTITEM_H 1
3 
4 #include <iterator>
5 #include <string>
6 
7 #include <boost/uuid/uuid.hpp>
8 #include <boost/uuid/uuid_io.hpp>
9 #include <boost/iterator/iterator_facade.hpp>
10 
11 #include "Content.hpp"
12 #include "Metadata.hpp"
13 
14 #include "rdf_model.hpp"
15 #include "rdf_query.hpp"
16 
17 namespace mico {
18  namespace persistence {
19 
20 
25  class ContentItemMetadata : public Metadata {
26 
27  friend class ContentItem;
28 
29  protected:
30  ContentItemMetadata(std::string baseUrl, std::string context) : Metadata(baseUrl, context) {};
31 
32  };
33 
34 
39  class ExecutionMetadata : public Metadata {
40 
41  friend class ContentItem;
42 
43  protected:
44  ExecutionMetadata(std::string baseUrl, std::string context) : Metadata(baseUrl, context) {};
45 
46  };
47 
48 
53  class ResultMetadata : public Metadata {
54 
55  friend class ContentItem;
56 
57  protected:
58  ResultMetadata(std::string baseUrl, std::string context) : Metadata(baseUrl, context) {};
59 
60  };
61 
62 
63  class content_part_iterator;
64 
65  // suffixes for named graph URIs of a content item
66  const std::string SUFFIX_METADATA = "-metadata";
67  const std::string SUFFIX_EXECUTION = "-execution";
68  const std::string SUFFIX_RESULT = "-result";
69 
76  class ContentItem {
77 
78  friend bool operator==(const ContentItem& ci1, const ContentItem& ci2);
79 
80  protected:
81  const std::string& baseUrl;
82  const std::string& contentDirectory;
83  boost::uuids::uuid id;
84 
85  ContentItemMetadata metadata;
86  ExecutionMetadata execution;
87  ResultMetadata result;
88 
89  public:
97  ContentItem(const std::string& baseUrl, const std::string& contentDirectory, const boost::uuids::uuid& id);
98 
106  ContentItem(const std::string& baseUrl, const std::string& contentDirectory, const mico::rdf::model::URI& uri);
107 
113  inline std::string getBaseUrl() const { return baseUrl; }
114 
115 
121  inline const mico::rdf::model::URI getURI() const { return mico::rdf::model::URI(baseUrl + "/" + boost::uuids::to_string(id)); }
122 
131  ContentItemMetadata& getMetadata() { return metadata; }
132 
141  ExecutionMetadata& getExecution() { return execution; }
142 
149  ResultMetadata& getResult() { return result; }
150 
151 
159 
168 
177 
178 
186 
187 
193 
194 
200  content_part_iterator begin();
201 
202 
206  content_part_iterator end();
207 
208 
209 
210  };
211 
212 #ifndef DOXYGEN_SHOULD_SKIP_THIS
213 
217  class content_part_iterator : public boost::iterator_facade<content_part_iterator, Content*, boost::forward_traversal_tag, Content*> {
218  private:
219  int pos;
220  ContentItem& item;
221  const std::string& baseUrl;
222  const std::string& contentDirectory;
223  const mico::rdf::query::TupleResult* result;
224 
225  public:
226  content_part_iterator(ContentItem& item, const std::string& baseUrl, const std::string& contentDirectory)
227  : pos(-1), item(item), baseUrl(baseUrl), contentDirectory(contentDirectory), result(NULL) {}
228 
229  content_part_iterator(ContentItem& item, const std::string& baseUrl, const std::string& contentDirectory, const mico::rdf::query::TupleResult* r)
230  : pos(0), item(item), baseUrl(baseUrl), contentDirectory(contentDirectory), result(r) {}
231 
232  ~content_part_iterator() { if(result) { delete result; } }
233 
234 
235  private:
236 
237  friend class boost::iterator_core_access;
238 
239  void increment();
240  bool equal(content_part_iterator const& other) const;
241  Content* dereference() const;
242 
243  };
244 #endif
245 
246  inline bool operator==(const ContentItem& ci1, const ContentItem& ci2) {
247  return ci1.baseUrl == ci2.baseUrl && ci1.id == ci2.id;
248  }
249  }
250 }
251 #endif
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in c...
Definition: http_client.cpp:23
Content * createContentPart()
Create a new content part with a random URI and return a handle.
Definition: ContentItem.cpp:76
ContentItemMetadata & getMetadata()
Return (read-only) content item metadata part of the initial content item, e.g.
Definition: ContentItem.hpp:131
ExecutionMetadata & getExecution()
Return execution plan and metadata (e.g.
Definition: ContentItem.hpp:141
Specialised support for execution metadata of content item processing.
Definition: ContentItem.hpp:39
const mico::rdf::model::URI getURI() const
Return the identifier (a unique URI) for this content item.
Definition: ContentItem.hpp:121
content_part_iterator end()
Return the end iterator for content parts.
Definition: ContentItem.cpp:188
std::string getBaseUrl() const
Return the (base URL) used by this content item.
Definition: ContentItem.hpp:113
Specialised support for result metadata of content item processing.
Definition: ContentItem.hpp:53
A class offering access to RDF metadata through SPARQL.
Definition: Metadata.hpp:28
Definition: Content.hpp:20
std::string baseUrl
the base URL of the server
Definition: Metadata.hpp:31
Content * operator[](const mico::rdf::model::URI &id)
Convenient C++ style operator for accessing and constructing content parts.
Definition: ContentItem.cpp:158
Representation of a ContentItem.
Definition: ContentItem.hpp:76
ContentItem(const std::string &baseUrl, const std::string &contentDirectory, const boost::uuids::uuid &id)
Create a new content item using the given server base URL and a unique UUID as content item identifie...
Content * getContentPart(const mico::rdf::model::URI &id)
Return a handle to the ContentPart with the given URI, or null in case the content item does not have...
Definition: ContentItem.cpp:118
A URI.
Definition: rdf_model.hpp:74
The result of a SPARQL SELECT query.
Definition: rdf_query.hpp:89
void deleteContentPart(const mico::rdf::model::URI &id)
Remove the content part with the given URI in case it exists and is a part of this content item...
Definition: ContentItem.cpp:138
Metadata(std::string baseUrl)
Create a new metadata object for the given server using the global SPARQL endpoint.
Definition: Metadata.cpp:39
content_part_iterator begin()
Return an iterator over all content parts contained in this content item.
Definition: ContentItem.cpp:173
Specialised support for content item metadata of content item processing.
Definition: ContentItem.hpp:25
ResultMetadata & getResult()
Return the current state of the analysis result (as RDF metadata).
Definition: ContentItem.hpp:149