3D Repo Bouncer  1.4
repo_controller.h
1 
24 #pragma once
25 
26 #include <map>
27 #include <memory>
28 #include <string>
29 
30 #include "core/model/bson/repo_bson_project_settings.h"
31 #include "core/model/bson/repo_bson_role.h"
32 #include "core/model/bson/repo_bson_role_settings.h"
33 #include "core/model/bson/repo_bson_user.h"
34 #include "core/model/bson/repo_node_transformation.h"
35 #include "core/model/bson/repo_node_reference.h"
36 #include "core/model/bson/repo_node_map.h"
37 #include "core/model/collection/repo_scene.h"
38 #include "lib/datastructure/repo_structs.h"
39 #include "lib/repo_listener_abstract.h"
40 #include "manipulator/modelconvertor/import/repo_model_import_config.h"
41 #include "repo_bouncer_global.h"
42 
43 namespace repo{
44  class REPO_API_EXPORT RepoController
45  {
46  public:
47 
48  class RepoToken;
49 
57  std::vector<lib::RepoAbstractListener*> listeners = std::vector<lib::RepoAbstractListener *>(),
58  const uint32_t &numConcurrentOps = 1,
59  const uint32_t &numDbConn = 1);
60 
64  ~RepoController();
65 
66  /*
67  * ------------- Database Connection & Authentication --------------
68  */
69 
81  RepoToken* authenticateMongo(
82  std::string &errMsg,
83  const std::string &address,
84  const uint32_t &port,
85  const std::string &dbName,
86  const std::string &username,
87  const std::string &password,
88  const bool &pwDigested = false
89  );
90 
96  bool authenticateMongo(
97  std::string &errMsg,
98  const RepoToken *token
99  );
100 
111  RepoToken* authenticateToAdminDatabaseMongo(
112  std::string &errMsg,
113  const std::string &address,
114  const int &port,
115  const std::string &username,
116  const std::string &password,
117  const bool &pwDigested = false
118  );
119 
126  void disconnectFromDatabase(const RepoToken* token);
127 
134  bool testConnection(const RepoToken *token);
135 
136  /*
137  * ------------- Token operations --------------
138  */
139 
145  void addAlias(
146  RepoToken *token,
147  const std::string &alias);
148 
152  RepoToken* createToken(
153  const std::string &alias,
154  const std::string &address,
155  const int &port,
156  const std::string &dbName,
157  const std::string &username,
158  const std::string &password
159  );
160 
161  RepoToken* createToken(
162  const std::string &alias,
163  const std::string &address,
164  const int &port,
165  const std::string &dbName,
166  const RepoController::RepoToken *token
167  );
168 
174  RepoToken* createTokenFromSerialised(
175  const std::string &data) const;
176 
181  void destroyToken(RepoToken* token);
182 
183  void getInfoFromToken(
184  const RepoToken *token,
185  std::string &alias,
186  std::string &host,
187  uint32_t &port,
188  std::string &username,
189  std::string &authDB
190  ) const;
191 
197  std::string serialiseToken(
198  const RepoToken* token) const;
199 
200  /*
201  * ------------- Database info lookup --------------
202  */
203 
211  uint64_t countItemsInCollection(
212  const RepoToken *token,
213  const std::string &database,
214  const std::string &collection);
215 
228  std::vector < repo::core::model::RepoBSON >
229  getAllFromCollectionContinuous(
230  const RepoToken *token,
231  const std::string &database,
232  const std::string &collection,
233  const uint64_t &skip = 0,
234  const uint32_t &limit = 0);
235 
251  std::vector < repo::core::model::RepoBSON >
252  getAllFromCollectionContinuous(
253  const RepoToken *token,
254  const std::string &database,
255  const std::string &collection,
256  const std::list<std::string> &fields,
257  const std::string &sortField,
258  const int &sortOrder = -1,
259  const uint64_t &skip = 0,
260  const uint32_t &limit = 0);
261 
273  std::vector < repo::core::model::RepoRole >
274  getRolesFromDatabase(
275  const RepoToken *token,
276  const std::string &database,
277  const uint64_t &skip = 0,
278  const uint32_t &limit = 0);
279 
287  std::vector < repo::core::model::RepoRoleSettings >
288  getRoleSettingsFromDatabase(
289  const RepoToken *token,
290  const std::string &database,
291  const uint64_t &skip = 0,
292  const uint32_t &limit = 0);
293 
294  repo::core::model::RepoRoleSettings getRoleSettings(
295  const RepoToken *token,
296  const repo::core::model::RepoRole &role);
297 
304  repo::core::model::RepoRoleSettings getRoleSettings(
305  const RepoToken *token,
306  const std::string &database,
307  const std::string &uniqueRoleName
308  );
309 
316  std::list<std::string> getCollections(
317  const RepoToken *token,
318  const std::string &databaseName
319  );
320 
329  repo::core::model::CollectionStats getCollectionStats(
330  const RepoToken *token,
331  const std::string &database,
332  const std::string &collection);
333 
339  std::list<std::string> getDatabases(
340  const RepoToken *token);
341  //FIXME: vectors are much better than list for traversal efficiency...
342  // (but they also require large continuos memory allocation should they be massive)
343 
350  std::map<std::string, std::list<std::string>>
351  getDatabasesWithProjects(
352  const RepoToken *token,
353  const std::list<std::string> &databases);
354 
361  std::string getHostAndPort(const RepoToken *token);
367  std::list<std::string> getAdminDatabaseRoles(const RepoToken *token);
368 
374  std::string getNameOfAdminDatabase(const RepoToken *token);
375 
381  std::list<std::string> getStandardDatabaseRoles(const RepoToken *token);
382 
383  /*
384  * ---------------- Database Retrieval -----------------------
385  */
386 
393  void cleanUp(
394  const RepoToken *token,
395  const std::string &dbName,
396  const std::string &projectName
397  );
398 
411  repo::core::model::RepoScene* fetchScene(
412  const RepoToken *token,
413  const std::string &database,
414  const std::string &project,
415  const std::string &uuid = REPO_HISTORY_MASTER_BRANCH,
416  const bool &headRevision = true,
417  const bool &lightFetch = false);
418 
425  void saveOriginalFiles(
426  const RepoToken *token,
427  const repo::core::model::RepoScene *scene,
428  const std::string &directory);
429 
437  void saveOriginalFiles(
438  const RepoToken *token,
439  const std::string &database,
440  const std::string &project,
441  const std::string &directory);
442 
443  /*
444  * ------- Database Operations (insert/delete/update) ---------
445  */
446 
453  bool commitScene(
454  const RepoToken *token,
456  const std::string &owner = "",
457  const std::string &tag = "",
458  const std::string &desc = "");
459 
468  void insertBinaryFileToDatabase(
469  const RepoToken *token,
470  const std::string &database,
471  const std::string &collection,
472  const std::string &name,
473  const std::vector<uint8_t> &rawData,
474  const std::string &mimeType = "");
480  void insertRole(
481  const RepoToken *token,
482  const repo::core::model::RepoRole &role);
483 
489  void insertUser(
490  const RepoToken *token,
491  const repo::core::model::RepoUser &user);
492 
501  bool removeCollection(
502  const RepoToken *token,
503  const std::string &databaseName,
504  const std::string &collectionName,
505  std::string &errMsg
506  );
507 
515  bool removeDatabase(
516  const RepoToken *token,
517  const std::string &databaseName,
518  std::string &errMsg
519  );
520 
530  void removeDocument(
531  const RepoToken *token,
532  const std::string &databaseName,
533  const std::string &collectionName,
534  const repo::core::model::RepoBSON &bson);
535 
548  bool removeProject(
549  const RepoToken *token,
550  const std::string &databaseName,
551  const std::string &projectName,
552  std::string &errMsg);
553 
554  void removeProjectSettings(
555  const RepoToken *token,
556  const std::string &database,
557  const repo::core::model::RepoProjectSettings &projectSettings)
558  {
559  removeDocument(token, database, REPO_COLLECTION_SETTINGS_PROJECTS, projectSettings);
560  }
561 
562  void removeRoleSettings(
563  const RepoToken *token,
564  const std::string &database,
565  const repo::core::model::RepoRoleSettings &roleSettings)
566  {
567  removeDocument(token, database, REPO_COLLECTION_SETTINGS_ROLES, roleSettings);
568  }
569 
570  void removeRoleSettings(
571  const RepoToken *token,
572  const repo::core::model::RepoRole &role,
573  const repo::core::model::RepoRoleSettings &settings)
574  {
575  removeRoleSettings(token, role.getDatabase(), settings);
576  }
577 
583  void removeRole(
584  const RepoToken *token,
585  const repo::core::model::RepoRole &role);
586 
592  void removeUser(
593  const RepoToken *token,
594  const repo::core::model::RepoUser &user);
595 
601  void updateRole(
602  const RepoToken *token,
603  const repo::core::model::RepoRole &role);
604 
610  void updateUser(
611  const RepoToken *token,
612  const repo::core::model::RepoUser &user);
613 
623  void upsertDocument(
624  const RepoToken *token,
625  const std::string &databaseName,
626  const std::string &collectionName,
627  const repo::core::model::RepoBSON &bson);
628 
629  void upsertRoleSettings(
630  const RepoToken *token,
631  const std::string &database,
632  const repo::core::model::RepoRoleSettings &roleSettings)
633  {
634  upsertDocument(token, database, REPO_COLLECTION_SETTINGS_ROLES, roleSettings);
635  }
636 
637  void upsertRoleSettings(
638  const RepoToken *token,
639  const repo::core::model::RepoRole &role,
640  const repo::core::model::RepoRoleSettings &settings)
641  {
642  upsertRoleSettings(token, role.getDatabase(), settings);
643  }
644 
645  void upsertProjectSettings(
646  const RepoToken *token,
647  const std::string &database,
648  const repo::core::model::RepoProjectSettings &projectSettings)
649  {
650  upsertDocument(token, database, REPO_COLLECTION_SETTINGS, projectSettings);
651  }
652 
653  /*
654  * ------------- Logging --------------
655  */
656 
669  void setLoggingLevel(const repo::lib::RepoLog::RepoLogLevel &level);
670 
675  void logToFile(const std::string &filePath);
676 
677  /*
678  * ------------- Import/ Export --------------
679  */
680 
686  repo::core::model::RepoScene* createFederatedScene(
687  const std::map<repo::core::model::TransformationNode, repo::core::model::ReferenceNode> &fedMap);
688 
695  repo::core::model::RepoScene* createMapScene(
696  const repo::core::model::MapNode &mapNode);
697 
705  bool generateAndCommitGLTFBuffer(
706  const RepoToken *token,
708 
716  bool generateAndCommitSRCBuffer(
717  const RepoToken *token,
719 
726  repo_web_buffers_t generateGLTFBuffer(
728 
735  bool generateAndCommitSelectionTree(
736  const RepoToken *token,
738 
745  repo_web_buffers_t generateSRCBuffer(
747 
752  std::string getSupportedExportFormats();
753 
758  std::string getSupportedImportFormats();
759 
768  repo::core::model::RepoScene* loadSceneFromFile(
769  const std::string &filePath,
770  const bool &applyReduction = true,
771  const bool &rotateModel = false,
773  = nullptr);
774 
780  repo::core::model::RepoNodeSet loadMetadataFromFile(
781  const std::string &filePath,
782  const char &delimiter = ',');
783 
790  bool saveSceneToFile(
791  const std::string &filePath,
792  const repo::core::model::RepoScene* scene);
793 
794  /*
795  * ------------- Optimizations --------------
796  */
797 
806  bool generateAndCommitStashGraph(
807  const RepoToken *token,
809  );
810 
816  std::shared_ptr<repo_partitioning_tree_t>
817  getScenePartitioning(
818  const repo::core::model::RepoScene *scene,
819  const uint32_t &maxDepth = 8
820  );
821 
829  void reduceTransformations(
830  const RepoToken *token,
832 
833  /*
834  * ------------- 3D Diff --------------
835  */
836 
847  void compareScenes(
848  const RepoToken *token,
851  repo_diff_result_t &baseResults,
852  repo_diff_result_t &compResults,
853  const repo::DiffMode &diffMode
854  );
855 
866  const RepoToken *token,
869  repo_diff_result_t &baseResults,
870  repo_diff_result_t &compResults
871  )
872  {
873  compareScenes(token, base, compare, baseResults, compResults, repo::DiffMode::DIFF_BY_ID);
874  }
875 
886  const RepoToken *token,
889  repo_diff_result_t &baseResults,
890  repo_diff_result_t &compResults
891  )
892  {
893  compareScenes(token, base, compare, baseResults, compResults, repo::DiffMode::DIFF_BY_NAME);
894  }
895 
896  /*
897  * ------------- Versioning --------------
898  */
902  std::string getVersion();
903 
904  private:
905  class _RepoControllerImpl;
906  _RepoControllerImpl *impl;
907  };
908 }
Definition: repo_bson_collection_stats.h:30
Definition: repo_node_map.h:27
Definition: repo_controller.h:44
Definition: repo_connection_pool_mongo.h:32
RepoLogLevel
Definition: repo_log.h:56
Definition: repo_scene.h:44
Definition: repo_structs.h:77
Definition: repo_bson_project_settings.h:30
void compareScenesByNames(const RepoToken *token, repo::core::model::RepoScene *base, repo::core::model::RepoScene *compare, repo_diff_result_t &baseResults, repo_diff_result_t &compResults)
Definition: repo_controller.h:885
void compareScenesByIDs(const RepoToken *token, repo::core::model::RepoScene *base, repo::core::model::RepoScene *compare, repo_diff_result_t &baseResults, repo_diff_result_t &compResults)
Definition: repo_controller.h:865
Definition: repo_bson_role_settings.h:30
Definition: repo_bson.h:53
std::string getDatabase() const
Definition: repo_bson_role.h:161
Definition: repo_bson_role.h:45
Definition: repo_model_import_config.h:33
Definition: repo_controller.cpp.inl:31
Definition: repo_structs.h:25
Definition: repo_bson_user.h:69