MICO Platform  1.0.0
 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 
108 
114  inline const mico::rdf::model::URI getURI() const { return mico::rdf::model::URI(baseUrl + "/" + boost::uuids::to_string(id)); };
115 
124  ContentItemMetadata& getMetadata() { return metadata; };
125 
134  ExecutionMetadata& getExecution() { return execution; }
135 
142  ResultMetadata& getResult() { return result; }
143 
144 
152 
161 
170 
171 
179 
180 
186 
187 
193  content_part_iterator begin();
194 
195 
199  content_part_iterator end();
200 
201 
202 
203  };
204 
205 #ifndef DOXYGEN_SHOULD_SKIP_THIS
206 
210  class content_part_iterator : public boost::iterator_facade<content_part_iterator, Content*, boost::forward_traversal_tag, Content*> {
211  private:
212  int pos;
213  ContentItem& item;
214  const std::string& baseUrl;
215  const std::string& contentDirectory;
216  const mico::rdf::query::TupleResult* result;
217 
218  public:
219  content_part_iterator(ContentItem& item, const std::string& baseUrl, const std::string& contentDirectory)
220  : pos(-1), item(item), baseUrl(baseUrl), contentDirectory(contentDirectory), result(NULL) {};
221 
222  content_part_iterator(ContentItem& item, const std::string& baseUrl, const std::string& contentDirectory, const mico::rdf::query::TupleResult* r)
223  : pos(0), item(item), baseUrl(baseUrl), contentDirectory(contentDirectory), result(r) {};
224 
225  ~content_part_iterator() { if(result) { delete result; } };
226 
227 
228  private:
229 
230  friend class boost::iterator_core_access;
231 
232  void increment();
233  bool equal(content_part_iterator const& other) const;
234  Content* dereference() const;
235 
236  };
237 #endif
238 
239  inline bool operator==(const ContentItem& ci1, const ContentItem& ci2) {
240  return ci1.baseUrl == ci2.baseUrl && ci1.id == ci2.id;
241  }
242  }
243 }
244 #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:124
ExecutionMetadata & getExecution()
Return execution plan and metadata (e.g.
Definition: ContentItem.hpp:134
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:114
content_part_iterator end()
Return the end iterator for content parts.
Definition: ContentItem.cpp:188
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:142