MICO Platform  1.0.0
 All Classes Namespaces Functions Variables Friends
PersistenceService.hpp
1 #ifndef HAVE_PERSISTENCE_SERVICE_H
2 #define HAVE_PERSISTENCE_SERVICE_H 1
3 
4 #include <string>
5 #include <iterator>
6 
7 #include <boost/iterator/iterator_facade.hpp>
8 
9 
10 #include "Metadata.hpp"
11 #include "ContentItem.hpp"
12 
13 #include "rdf_model.hpp"
14 #include "rdf_query.hpp"
15 
16 namespace mico {
17  namespace persistence {
18 
19  using namespace mico::rdf::query;
20 
21  class content_item_iterator;
22 
27  class PersistenceMetadata : public Metadata {
28  friend class PersistenceService;
29 
30  protected:
31  PersistenceMetadata(std::string baseUrl) : Metadata(baseUrl) {};
32 
33  };
34 
35 
42 
43  private:
44 
45  std::string marmottaServerUrl;
46  std::string contentDirectory;
47  PersistenceMetadata metadata;
48 
49  public:
50 
56  PersistenceService(std::string serverAddress)
57  : marmottaServerUrl("http://" + serverAddress + ":8080/marmotta")
58  , contentDirectory("ftp://mico:mico@" + serverAddress)
59  , metadata("http://" + serverAddress + ":8080/marmotta") {};
60 
61 
67  PersistenceService(std::string serverAddress, int marmottaPort, std::string user, std::string password)
68  : marmottaServerUrl("http://" + serverAddress + ":" + std::to_string(marmottaPort) + "/marmotta")
69  , contentDirectory("ftp://" + user + ":" + password + "@" + serverAddress)
70  , metadata("http://" + serverAddress + ":" + std::to_string(marmottaPort) + "/marmotta") {};
71 
72 
79  PersistenceService(std::string marmottaServerUrl, std::string contentDirectory)
80  : marmottaServerUrl(marmottaServerUrl), contentDirectory(contentDirectory), metadata(marmottaServerUrl) {};
81 
82 
89  PersistenceMetadata& getMetadata() { return metadata; };
90 
97  ContentItem* createContentItem();
98 
105  ContentItem* createContentItem(const mico::rdf::model::URI& id);
106 
107 
114  ContentItem* getContentItem(const mico::rdf::model::URI& id);
115 
119  void deleteContentItem(const mico::rdf::model::URI& id);
120 
126  content_item_iterator begin();
127 
128 
132  content_item_iterator end();
133 
134 
135 
136  };
137 
138 
139 #ifndef DOXYGEN_SHOULD_SKIP_THIS
140 
143  class content_item_iterator : public boost::iterator_facade<content_item_iterator, ContentItem*, boost::forward_traversal_tag, ContentItem*> {
144  private:
145  int pos;
146  const std::string& baseUrl;
147  const std::string& contentDirectory;
148  const mico::rdf::query::TupleResult* result;
149 
150  public:
151  content_item_iterator(const std::string& baseUrl, const std::string& contentDirectory)
152  : pos(-1), baseUrl(baseUrl), contentDirectory(contentDirectory), result(NULL) {};
153 
154  content_item_iterator(const std::string& baseUrl, const std::string& contentDirectory, const mico::rdf::query::TupleResult* r)
155  : pos(0), baseUrl(baseUrl), contentDirectory(contentDirectory), result(r) {};
156 
157  ~content_item_iterator() { if(result) { delete result; } };
158 
159 
160  private:
161 
162  friend class boost::iterator_core_access;
163 
164  void increment();
165  bool equal(content_item_iterator const& other) const;
166  ContentItem* dereference() const;
167 
168  };
169 #endif
170  }
171 }
172 
173 #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
PersistenceService(std::string serverAddress)
Initialise persistence service with the address of a server running the standard installation of the ...
Definition: PersistenceService.hpp:56
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in c...
Main service for accessing the MICO persistence API.
Definition: PersistenceService.hpp:41
PersistenceMetadata & getMetadata()
Get a handle on the overall metadata storage of the persistence service.
Definition: PersistenceService.hpp:89
PersistenceService(std::string marmottaServerUrl, std::string contentDirectory)
Initialise an instance of the PersistenceService using the Marmotta server with the given URL as back...
Definition: PersistenceService.hpp:79
A class offering access to RDF metadata through SPARQL.
Definition: Metadata.hpp:28
Specialised support for persistence service metadata.
Definition: PersistenceService.hpp:27
Representation of a ContentItem.
Definition: ContentItem.hpp:76
Definition: rdf_query.hpp:17
PersistenceService(std::string serverAddress, int marmottaPort, std::string user, std::string password)
Initialise persistence service with the address of a server running the standard installation of the ...
Definition: PersistenceService.hpp:67
A URI.
Definition: rdf_model.hpp:74
The result of a SPARQL SELECT query.
Definition: rdf_query.hpp:89