From f241d3bebacbe3cd7496dafa8e57eeef9e5f778f Mon Sep 17 00:00:00 2001 From: Sebastian Friston Date: Tue, 15 Oct 2024 16:44:46 +0100 Subject: [PATCH] ISSUE #703 refactored header files, updated more types to be repo documents and removed all instances of cloneAndAddParent --- .../handler/fileservice/repo_data_ref.cpp | 2 +- .../core/handler/fileservice/repo_data_ref.h | 5 +- .../handler/repo_database_handler_abstract.h | 7 +- .../handler/repo_database_handler_mongo.cpp | 17 +- .../handler/repo_database_handler_mongo.h | 21 +-- .../src/repo/core/model/bson/CMakeLists.txt | 3 + .../src/repo/core/model/bson/repo_bson.cpp | 8 +- bouncer/src/repo/core/model/bson/repo_bson.h | 14 +- .../repo/core/model/bson/repo_bson_assets.cpp | 2 +- .../core/model/bson/repo_bson_calibration.cpp | 68 ++++++++ .../core/model/bson/repo_bson_calibration.h | 30 +++- .../core/model/bson/repo_bson_factory.cpp | 40 ++--- .../model/bson/repo_bson_project_settings.cpp | 64 +++---- .../model/bson/repo_bson_project_settings.h | 139 +++------------ .../src/repo/core/model/bson/repo_bson_ref.h | 1 - .../repo/core/model/bson/repo_bson_sequence.h | 9 +- .../repo/core/model/bson/repo_bson_task.cpp | 2 +- .../src/repo/core/model/bson/repo_bson_task.h | 8 +- .../core/model/bson/repo_bson_teamspace.cpp | 46 +++++ .../core/model/bson/repo_bson_teamspace.h | 53 ++++++ .../src/repo/core/model/bson/repo_node.cpp | 79 ++------- bouncer/src/repo/core/model/bson/repo_node.h | 57 ++----- .../model/bson/repo_node_drawing_revision.h | 1 + .../repo/core/model/bson/repo_node_material.h | 4 +- .../repo/core/model/bson/repo_node_mesh.cpp | 9 +- .../src/repo/core/model/bson/repo_node_mesh.h | 10 +- .../core/model/bson/repo_node_metadata.cpp | 5 +- .../repo/core/model/bson/repo_node_metadata.h | 10 +- .../core/model/bson/repo_node_reference.h | 3 +- .../repo/core/model/bson/repo_node_revision.h | 1 + .../core/model/bson/repo_node_supermesh.cpp | 7 +- .../core/model/bson/repo_node_supermesh.h | 3 +- .../core/model/bson/repo_node_texture.cpp | 6 +- .../repo/core/model/bson/repo_node_texture.h | 4 +- .../model/bson/repo_node_transformation.cpp | 4 +- .../model/bson/repo_node_transformation.h | 1 + .../repo/core/model/collection/repo_scene.cpp | 14 +- .../src/repo/lib/datastructure/repo_structs.h | 5 +- .../import/odaHelper/data_processor_rvt.h | 3 +- .../import/odaHelper/geometry_collector.cpp | 7 +- .../import/repo_model_import_3drepo.cpp | 17 +- .../import/repo_model_import_3drepo.h | 1 - .../import/repo_model_import_assimp.cpp | 29 ++-- .../import/repo_model_import_assimp.h | 2 +- .../import/repo_model_import_synchro.cpp | 15 +- .../repo_optimizer_multipart.cpp | 3 +- .../modelutility/repo_drawing_manager.cpp | 11 +- .../repo_mesh_map_reorganiser.cpp | 1 - .../modelutility/repo_scene_manager.cpp | 24 +-- .../src/repo/manipulator/repo_manipulator.cpp | 24 +-- .../src/repo/manipulator/repo_manipulator.h | 3 +- bouncer/src/repo/repo_controller.cpp.inl | 1 - .../src/repo/repo_controller_internal.cpp.inl | 5 +- submodules/asset_generator | 2 +- .../unit/repo/core/model/bson/CMakeLists.txt | 2 + .../repo/core/model/bson/ut_repo_bson.cpp | 78 ++------- .../bson/ut_repo_bson_project_settings.cpp | 97 +++++++++++ .../model/bson/ut_repo_bson_teamspace.cpp | 81 +++++++++ .../repo/core/model/bson/ut_repo_node.cpp | 161 ++++++------------ .../core/model/bson/ut_repo_node_material.cpp | 18 ++ .../core/model/bson/ut_repo_node_mesh.cpp | 12 ++ test/src/unit/repo_test_mesh_utils.cpp | 2 + 62 files changed, 730 insertions(+), 631 deletions(-) create mode 100644 bouncer/src/repo/core/model/bson/repo_bson_calibration.cpp create mode 100644 bouncer/src/repo/core/model/bson/repo_bson_teamspace.cpp create mode 100644 bouncer/src/repo/core/model/bson/repo_bson_teamspace.h create mode 100644 test/src/unit/repo/core/model/bson/ut_repo_bson_project_settings.cpp create mode 100644 test/src/unit/repo/core/model/bson/ut_repo_bson_teamspace.cpp diff --git a/bouncer/src/repo/core/handler/fileservice/repo_data_ref.cpp b/bouncer/src/repo/core/handler/fileservice/repo_data_ref.cpp index 9a229daa8..c2c178578 100644 --- a/bouncer/src/repo/core/handler/fileservice/repo_data_ref.cpp +++ b/bouncer/src/repo/core/handler/fileservice/repo_data_ref.cpp @@ -15,7 +15,7 @@ * along with this program. If not, see . */ #include "repo_data_ref.h" -#include "../../../lib/datastructure/repo_uuid.h" +#include "repo/core/model/bson/repo_bson_builder.h" using namespace repo::core::handler::fileservice; diff --git a/bouncer/src/repo/core/handler/fileservice/repo_data_ref.h b/bouncer/src/repo/core/handler/fileservice/repo_data_ref.h index 2fcbf5151..ae596231e 100644 --- a/bouncer/src/repo/core/handler/fileservice/repo_data_ref.h +++ b/bouncer/src/repo/core/handler/fileservice/repo_data_ref.h @@ -19,10 +19,11 @@ #include -#include "../../../core/model/bson/repo_bson_builder.h" - namespace repo { namespace core { + namespace model { + class RepoBSON; + } namespace handler { namespace fileservice { class DataRef { diff --git a/bouncer/src/repo/core/handler/repo_database_handler_abstract.h b/bouncer/src/repo/core/handler/repo_database_handler_abstract.h index 7e1ba316a..3f2e9e566 100644 --- a/bouncer/src/repo/core/handler/repo_database_handler_abstract.h +++ b/bouncer/src/repo/core/handler/repo_database_handler_abstract.h @@ -28,10 +28,11 @@ #include #include "repo/lib/datastructure/repo_variant.h" -#include "../model/bson/repo_bson.h" - namespace repo { namespace core { + namespace model { + class RepoBSON; + } namespace handler { class AbstractDatabaseHandler { public: @@ -97,7 +98,7 @@ namespace repo { * @param name name of the collection * @param index BSONObj specifying the index */ - virtual void createIndex(const std::string &database, const std::string &collection, const mongo::BSONObj & obj) = 0; + virtual void createIndex(const std::string &database, const std::string &collection, const repo::core::model::RepoBSON& obj) = 0; /** * Insert a single document in database.collection diff --git a/bouncer/src/repo/core/handler/repo_database_handler_mongo.cpp b/bouncer/src/repo/core/handler/repo_database_handler_mongo.cpp index b62e6700b..31b5204d2 100644 --- a/bouncer/src/repo/core/handler/repo_database_handler_mongo.cpp +++ b/bouncer/src/repo/core/handler/repo_database_handler_mongo.cpp @@ -25,7 +25,8 @@ #include "repo_database_handler_mongo.h" #include "fileservice/repo_file_manager.h" #include "fileservice/repo_blob_files_handler.h" -#include "../../lib/repo_log.h" +#include "repo/core/model/bson/repo_bson_builder.h" +#include "repo/lib/repo_log.h" using namespace repo::core::handler; @@ -177,11 +178,11 @@ void MongoDatabaseHandler::createCollection(const std::string &database, const s } } -void MongoDatabaseHandler::createIndex(const std::string &database, const std::string &collection, const mongo::BSONObj & obj) +void MongoDatabaseHandler::createIndex(const std::string &database, const std::string &collection, const repo::core::model::RepoBSON& obj) { if (!(database.empty() || collection.empty())) { - repoInfo << "Creating index for :" << database << "." << collection << " : index: " << obj; + repoInfo << "Creating index for :" << database << "." << collection << " : index: " << obj.toString(); try { worker->createIndex(database + "." + collection, obj); } @@ -841,4 +842,14 @@ bool MongoDatabaseHandler::upsertDocument( } return success; +} + +repo::core::model::RepoBSON* MongoDatabaseHandler::createBSONCredentials( + const std::string& dbName, + const std::string& username, + const std::string& password, + const bool& pwDigested) +{ + mongo::BSONObj* mongoBSON = createAuthBSON(dbName, username, password, pwDigested); + return mongoBSON ? new repo::core::model::RepoBSON(*mongoBSON) : nullptr; } \ No newline at end of file diff --git a/bouncer/src/repo/core/handler/repo_database_handler_mongo.h b/bouncer/src/repo/core/handler/repo_database_handler_mongo.h index c67375fe1..b5ba1be03 100644 --- a/bouncer/src/repo/core/handler/repo_database_handler_mongo.h +++ b/bouncer/src/repo/core/handler/repo_database_handler_mongo.h @@ -36,12 +36,13 @@ #include "repo_database_handler_abstract.h" #include "connectionpool/repo_connection_pool_mongo.h" -#include "../model/bson/repo_bson.h" -#include "../model/bson/repo_bson_builder.h" -#include "../../lib/repo_stack.h" +#include "repo/lib/repo_stack.h" namespace repo { namespace core { + namespace model { + class RepoBSON; // Forward declaration for document type + } namespace handler { namespace fileservice{ class Metadata; // Forward declaration for alias @@ -160,14 +161,10 @@ namespace repo { * @return returns the constructed BSON object, or 0 nullptr username is empty */ static repo::core::model::RepoBSON* createBSONCredentials( - const std::string &dbName, - const std::string &username, - const std::string &password, - const bool &pwDigested = false) - { - mongo::BSONObj *mongoBSON = createAuthBSON(dbName, username, password, pwDigested); - return mongoBSON ? new repo::core::model::RepoBSON(*mongoBSON) : nullptr; - } + const std::string& dbName, + const std::string& username, + const std::string& password, + const bool& pwDigested = false); /* * ------------- Database info lookup -------------- @@ -230,7 +227,7 @@ namespace repo { * @param name name of the collection * @param index BSONObj specifying the index */ - virtual void createIndex(const std::string &database, const std::string &collection, const mongo::BSONObj & obj); + virtual void createIndex(const std::string &database, const std::string &collection, const repo::core::model::RepoBSON& obj); /** * Remove a collection from the database diff --git a/bouncer/src/repo/core/model/bson/CMakeLists.txt b/bouncer/src/repo/core/model/bson/CMakeLists.txt index 81277d775..dfdd116ca 100644 --- a/bouncer/src/repo/core/model/bson/CMakeLists.txt +++ b/bouncer/src/repo/core/model/bson/CMakeLists.txt @@ -9,12 +9,14 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/repo_bson.cpp ${CMAKE_CURRENT_SOURCE_DIR}/repo_bson_assets.cpp ${CMAKE_CURRENT_SOURCE_DIR}/repo_bson_builder.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/repo_bson_calibration.cpp ${CMAKE_CURRENT_SOURCE_DIR}/repo_bson_element.cpp ${CMAKE_CURRENT_SOURCE_DIR}/repo_bson_factory.cpp ${CMAKE_CURRENT_SOURCE_DIR}/repo_bson_project_settings.cpp ${CMAKE_CURRENT_SOURCE_DIR}/repo_bson_ref.cpp ${CMAKE_CURRENT_SOURCE_DIR}/repo_bson_sequence.cpp ${CMAKE_CURRENT_SOURCE_DIR}/repo_bson_task.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/repo_bson_teamspace.cpp ${CMAKE_CURRENT_SOURCE_DIR}/repo_node.cpp ${CMAKE_CURRENT_SOURCE_DIR}/repo_node_drawing_revision.cpp ${CMAKE_CURRENT_SOURCE_DIR}/repo_node_material.cpp @@ -40,6 +42,7 @@ set(HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/repo_bson_ref.h ${CMAKE_CURRENT_SOURCE_DIR}/repo_bson_sequence.h ${CMAKE_CURRENT_SOURCE_DIR}/repo_bson_task.h + ${CMAKE_CURRENT_SOURCE_DIR}/repo_bson_teamspace.h ${CMAKE_CURRENT_SOURCE_DIR}/repo_node.h ${CMAKE_CURRENT_SOURCE_DIR}/repo_node_drawing_revision.h ${CMAKE_CURRENT_SOURCE_DIR}/repo_node_material.h diff --git a/bouncer/src/repo/core/model/bson/repo_bson.cpp b/bouncer/src/repo/core/model/bson/repo_bson.cpp index dcc0fade5..9513e60c8 100644 --- a/bouncer/src/repo/core/model/bson/repo_bson.cpp +++ b/bouncer/src/repo/core/model/bson/repo_bson.cpp @@ -232,18 +232,12 @@ std::vector RepoBSON::getUUIDFieldArray(const std::string & if (hasField(label)) { RepoBSON array = getObjectField(label); - if (!array.isEmpty()) { std::set fields = array.getFieldNames(); - std::set::iterator it; for (it = fields.begin(); it != fields.end(); ++it) - results.push_back(array.getUUIDField(*it)); - } - else - { - repoDebug << "getUUIDFieldArray: field " << label << " is an empty bson or wrong type!"; + results.push_back(array.getUUIDField(*it)); // If the item is the wrong type an exception will be thrown to the caller } } diff --git a/bouncer/src/repo/core/model/bson/repo_bson.h b/bouncer/src/repo/core/model/bson/repo_bson.h index 7e25290c7..fc06ef170 100644 --- a/bouncer/src/repo/core/model/bson/repo_bson.h +++ b/bouncer/src/repo/core/model/bson/repo_bson.h @@ -246,8 +246,7 @@ namespace repo { } else { - repoError << "Trying to retrieve binary from a field that doesn't exist(" << field << ")"; - return false; + throw repo::lib::RepoFieldNotFoundException(field); } } else { @@ -263,13 +262,14 @@ namespace repo { memcpy(vec.data(), binData, length); success = true; } - else { - repoError << "RepoBSON::getBinaryFieldAsVector : " - << "size of binary data (" << length << ") Unable to copy 0 bytes!"; + else + { + throw repo::lib::RepoFieldTypeException(field + "; has a length of zero bytes"); } } - else { - repoError << "RepoBSON::getBinaryFieldAsVector : bson element type is not BinDataGeneral!"; + else + { + throw repo::lib::RepoFieldTypeException(field); } } diff --git a/bouncer/src/repo/core/model/bson/repo_bson_assets.cpp b/bouncer/src/repo/core/model/bson/repo_bson_assets.cpp index 15086e13b..c05a197f6 100644 --- a/bouncer/src/repo/core/model/bson/repo_bson_assets.cpp +++ b/bouncer/src/repo/core/model/bson/repo_bson_assets.cpp @@ -17,7 +17,7 @@ #include "repo_bson_assets.h" #include "repo_bson_builder.h" -#include "../../../lib/datastructure/repo_uuid.h" +#include "repo/lib/datastructure/repo_uuid.h" using namespace repo::core::model; diff --git a/bouncer/src/repo/core/model/bson/repo_bson_calibration.cpp b/bouncer/src/repo/core/model/bson/repo_bson_calibration.cpp new file mode 100644 index 000000000..2483f342f --- /dev/null +++ b/bouncer/src/repo/core/model/bson/repo_bson_calibration.cpp @@ -0,0 +1,68 @@ +/** +* Copyright (C) 2024 3D Repo Ltd +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as +* published by the Free Software Foundation, either version 3 of the +* License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see . +*/ + +#include "repo_bson_calibration.h" +#include "repo_bson_builder.h" + +using namespace repo::core::model; + +RepoCalibration::RepoCalibration( + const repo::lib::RepoUUID& projectId, + const repo::lib::RepoUUID& drawingId, + const repo::lib::RepoUUID& revisionId, + const std::vector& horizontal3d, + const std::vector& horizontal2d, + const std::string& units +) + :projectId(projectId), + drawingId(drawingId), + revisionId(revisionId), + horizontal3d(horizontal3d), + horizontal2d(horizontal2d), + units(units), + id(repo::lib::RepoUUID::createUUID()) +{ + if (horizontal2d.size() != 2 || horizontal3d.size() != 2) + { + throw repo::lib::RepoException("Incomplete calibration vectors supplied to makeRepoCalibration"); + } +} + +RepoCalibration::operator RepoBSON() const +{ + RepoBSONBuilder builder; + builder.append(REPO_LABEL_ID, id); + builder.append(REPO_LABEL_PROJECT, projectId); + builder.append(REPO_LABEL_DRAWING, drawingId.toString()); // By convention drawing ids must be strings + builder.append(REPO_LABEL_REVISION, revisionId); + builder.appendTimeStamp(REPO_LABEL_CREATEDAT); + + RepoBSONBuilder horizontalBuilder; + horizontalBuilder.appendArray< std::vector >(REPO_LABEL_MODEL, { + horizontal3d[0].toStdVector(), + horizontal3d[1].toStdVector() + }); + horizontalBuilder.appendArray< std::vector >(REPO_LABEL_DRAWING, { + horizontal2d[0].toStdVector(), + horizontal2d[1].toStdVector() + }); + builder.append(REPO_LABEL_HORIZONTAL, horizontalBuilder.obj()); + + builder.append(REPO_LABEL_UNITS, units); + + return builder.obj(); +} \ No newline at end of file diff --git a/bouncer/src/repo/core/model/bson/repo_bson_calibration.h b/bouncer/src/repo/core/model/bson/repo_bson_calibration.h index 8194945e1..ba2d79585 100644 --- a/bouncer/src/repo/core/model/bson/repo_bson_calibration.h +++ b/bouncer/src/repo/core/model/bson/repo_bson_calibration.h @@ -17,21 +17,41 @@ #pragma once -#include "repo_bson.h" +#include "repo/repo_bouncer_global.h" +#include "repo/lib/datastructure/repo_uuid.h" +#include "repo/lib/datastructure/repo_vector.h" +#include namespace repo { namespace core { namespace model { - class REPO_API_EXPORT RepoCalibration : public RepoBSON + class RepoBSON; + + class REPO_API_EXPORT RepoCalibration { public: + RepoCalibration( + const repo::lib::RepoUUID& projectId, + const repo::lib::RepoUUID& drawingId, + const repo::lib::RepoUUID& revisionId, + const std::vector& horizontal3d, + const std::vector& horizontal2d, + const std::string& units + ); - RepoCalibration() : RepoBSON() {} - - RepoCalibration(RepoBSON bson) : RepoBSON(bson) {} + operator RepoBSON() const; ~RepoCalibration() {} + + private: + repo::lib::RepoUUID id; + repo::lib::RepoUUID projectId; + repo::lib::RepoUUID drawingId; + repo::lib::RepoUUID revisionId; + std::vector horizontal3d; + std::vector horizontal2d; + std::string units; }; }// end namespace model } // end namespace core diff --git a/bouncer/src/repo/core/model/bson/repo_bson_factory.cpp b/bouncer/src/repo/core/model/bson/repo_bson_factory.cpp index 516b83689..71f08fe15 100644 --- a/bouncer/src/repo/core/model/bson/repo_bson_factory.cpp +++ b/bouncer/src/repo/core/model/bson/repo_bson_factory.cpp @@ -19,8 +19,8 @@ #include -#include "../../../lib/repo_log.h" -#include "../../../lib/repo_exception.h" +#include "repo/lib/repo_log.h" +#include "repo/lib/repo_exception.h" using namespace repo::core::model; @@ -32,7 +32,7 @@ MaterialNode RepoBSONFactory::makeMaterialNode( { MaterialNode node; node.setMaterialStruct(material); - node.changeName(name); + node.changeName(name, true); // Always give new material nodes a unique Id, as more than likely even identical materials should have different instances in a RepoNodeList node.addParents(parents); return node; } @@ -228,32 +228,14 @@ RepoCalibration repo::core::model::RepoBSONFactory::makeRepoCalibration( const std::vector& horizontal2d, const std::string& units) { - RepoBSONBuilder bsonBuilder; - bsonBuilder.append(REPO_LABEL_ID, repo::lib::RepoUUID::createUUID()); - bsonBuilder.append(REPO_LABEL_PROJECT, projectId); - bsonBuilder.append(REPO_LABEL_DRAWING, drawingId.toString()); - bsonBuilder.append(REPO_LABEL_REVISION, revisionId); - bsonBuilder.appendTimeStamp(REPO_LABEL_CREATEDAT); - - if (horizontal2d.size() != 2 || horizontal3d.size() != 2) - { - throw repo::lib::RepoException("Incomplete calibration vectors supplied to makeRepoCalibration"); - } - - RepoBSONBuilder horizontalBuilder; - horizontalBuilder.appendArray< std::vector >(REPO_LABEL_MODEL, { - horizontal3d[0].toStdVector(), - horizontal3d[1].toStdVector() - }); - horizontalBuilder.appendArray< std::vector >(REPO_LABEL_DRAWING, { - horizontal2d[0].toStdVector(), - horizontal2d[1].toStdVector() - }); - bsonBuilder.append(REPO_LABEL_HORIZONTAL, horizontalBuilder.obj()); - - bsonBuilder.append(REPO_LABEL_UNITS, units); - - return RepoCalibration(bsonBuilder.obj()); + return RepoCalibration( + projectId, + drawingId, + revisionId, + horizontal3d, + horizontal2d, + units + ); } ReferenceNode RepoBSONFactory::makeReferenceNode( diff --git a/bouncer/src/repo/core/model/bson/repo_bson_project_settings.cpp b/bouncer/src/repo/core/model/bson/repo_bson_project_settings.cpp index 2e4e39f77..b31826c94 100644 --- a/bouncer/src/repo/core/model/bson/repo_bson_project_settings.cpp +++ b/bouncer/src/repo/core/model/bson/repo_bson_project_settings.cpp @@ -19,54 +19,42 @@ * Project setting BSON */ -#include "repo_bson_builder.h" #include "repo_bson_project_settings.h" -#include "../../../lib/repo_log.h" +#include "repo_bson_builder.h" +#include "repo/lib/repo_log.h" using namespace repo::core::model; -RepoProjectSettings RepoProjectSettings::cloneAndClearStatus() const +const std::string STATUS_OK = "ok"; +const std::string STATUS_ERROR = "error"; + +RepoProjectSettings::RepoProjectSettings(RepoBSON bson) { - RepoBSONBuilder builder; - builder.appendTimeStamp(REPO_PROJECT_SETTINGS_LABEL_TIMESTAMP); - builder.append(REPO_PROJECT_SETTINGS_LABEL_STATUS, "ok"); - builder.appendElementsUnique(*this); - return builder.obj(); + id = bson.getStringField(REPO_LABEL_ID); + status = STATUS_OK; + if (bson.hasField(REPO_PROJECT_SETTINGS_LABEL_STATUS)) + { + status = bson.getStringField(REPO_PROJECT_SETTINGS_LABEL_STATUS); + } } - -RepoProjectSettings RepoProjectSettings::cloneAndAddErrorStatus() const +void RepoProjectSettings::setErrorStatus() { - RepoBSONBuilder builder; - builder.append(REPO_PROJECT_SETTINGS_LABEL_STATUS, "error"); - builder.appendElementsUnique(*this); - return builder.obj(); + status = STATUS_ERROR; } -RepoProjectSettings RepoProjectSettings::cloneAndMergeProjectSettings -(const RepoProjectSettings &proj) const +void RepoProjectSettings::clearErrorStatus() { - RepoBSONBuilder newProjBuilder, propertiesBuilder; - - auto currentProperties = getObjectField(REPO_LABEL_PROPERTIES); - propertiesBuilder.appendElements(proj.getObjectField(REPO_LABEL_PROPERTIES)); - - currentProperties = currentProperties.removeField(REPO_LABEL_PIN_SIZE); - currentProperties = currentProperties.removeField(REPO_LABEL_AVATAR_HEIGHT); - currentProperties = currentProperties.removeField(REPO_LABEL_VISIBILITY_LIMIT); - currentProperties = currentProperties.removeField(REPO_LABEL_SPEED); - currentProperties = currentProperties.removeField(REPO_LABEL_ZNEAR); - currentProperties = currentProperties.removeField(REPO_LABEL_ZFAR); - - propertiesBuilder.appendElementsUnique(currentProperties); - newProjBuilder.append(REPO_LABEL_PROPERTIES, propertiesBuilder.obj()); - - newProjBuilder.appendElementsUnique(proj); - - auto currentProjectSettings = removeField(REPO_LABEL_OWNER); - currentProjectSettings = currentProjectSettings.removeField(REPO_LABEL_TYPE); - currentProjectSettings = currentProjectSettings.removeField(REPO_LABEL_DESCRIPTION); - newProjBuilder.appendElementsUnique(currentProjectSettings); + status = STATUS_OK; +} - return newProjBuilder.obj(); +RepoProjectSettings::operator RepoBSON() const +{ + RepoBSONBuilder builder; + builder.append(REPO_PROJECT_SETTINGS_LABEL_STATUS, status); + builder.append(REPO_LABEL_ID, id); + if (status == STATUS_OK) { + builder.appendTimeStamp(REPO_PROJECT_SETTINGS_LABEL_TIMESTAMP); + } + return builder.obj(); } \ No newline at end of file diff --git a/bouncer/src/repo/core/model/bson/repo_bson_project_settings.h b/bouncer/src/repo/core/model/bson/repo_bson_project_settings.h index e31c78ae7..3c5db6b30 100644 --- a/bouncer/src/repo/core/model/bson/repo_bson_project_settings.h +++ b/bouncer/src/repo/core/model/bson/repo_bson_project_settings.h @@ -20,143 +20,50 @@ */ #pragma once -#include "repo_bson.h" + +#include "repo/repo_bouncer_global.h" +#include +#include namespace repo { namespace core { namespace model { - // TODO: make into header only + + class RepoBSON; - #define REPO_PROJECT_SETTINGS_LABEL_IS_FEDERATION "federate" - #define REPO_PROJECT_SETTINGS_LABEL_TIMESTAMP "timestamp" #define REPO_PROJECT_SETTINGS_LABEL_STATUS "status" - class REPO_API_EXPORT RepoProjectSettings : public RepoBSON + #define REPO_PROJECT_SETTINGS_LABEL_TIMESTAMP "timestamp" + + class REPO_API_EXPORT RepoProjectSettings { public: - RepoProjectSettings() : RepoBSON() {} - - RepoProjectSettings(RepoBSON bson) : RepoBSON(bson){} + // RepoProjectSettings can only be initialised from an existing + // document, and should only be used with upsert + + RepoProjectSettings(RepoBSON bson); ~RepoProjectSettings() {} - /** - * Clone and merge new project settings into the existing info - * @proj new info that needs ot be added/updated - * @return returns a new project settings with fields updated - */ - RepoProjectSettings cloneAndClearStatus() const; - - RepoProjectSettings cloneAndAddErrorStatus() const; - - - /** - * Clone and merge new project settings into the existing info - * @proj new info that needs ot be added/updated - * @return returns a new project settings with fields updated - */ - RepoProjectSettings cloneAndMergeProjectSettings(const RepoProjectSettings &proj) const; - - /** - * Get the avatar height if present or default value if not. - * @brief getAvatarHeight - * @return returns avatar height as double. - */ - double getAvatarHeight() const - { - return getEmbeddedDouble( - REPO_LABEL_PROPERTIES, - REPO_LABEL_AVATAR_HEIGHT, - (double)REPO_DEFAULT_PROJECT_AVATAR_HEIGHT); - } + operator RepoBSON() const; - /** - * Get the description of the project for this settings - * @return returns project description as string - */ - std::string getDescription() const - { - return getStringField(REPO_LABEL_DESCRIPTION); - } + void setErrorStatus(); - /** - * @return returns true if the project setting is for a federated project - */ - bool isFederate() const - { - return getBoolField(REPO_PROJECT_SETTINGS_LABEL_IS_FEDERATION); - } + void clearErrorStatus(); - /** - * Get the owner of the project for this settings - * @return returns owner name as string - */ - std::string getOwner() const + const std::string& getProjectId() const { - return getStringField(REPO_LABEL_OWNER); + return id; } - double getPinSize() const + const std::string& getStatus() const { - return getEmbeddedDouble( - REPO_LABEL_PROPERTIES, - REPO_LABEL_PIN_SIZE, - REPO_DEFAULT_PROJECT_PIN_SIZE); + return status; } - /** - * Get the name of the project for this settings - * @return returns project name as string - */ - std::string getProjectName() const - { - return getStringField(REPO_LABEL_ID); - } - - double getSpeed() const - { - return getEmbeddedDouble( - REPO_LABEL_PROPERTIES, - REPO_LABEL_SPEED, - REPO_DEFAULT_PROJECT_SPEED); - } - - /** - * Get the type of the project for this settings - * @return returns project type as string - */ - std::string getType() const - { - return getStringField(REPO_LABEL_TYPE); - } - - double getVisibilityLimit() const - { - return getEmbeddedDouble( - REPO_LABEL_PROPERTIES, - REPO_LABEL_VISIBILITY_LIMIT, - REPO_DEFAULT_PROJECT_VISIBILITY_LIMIT); - } - - double getZFar() const - { - return getEmbeddedDouble( - REPO_LABEL_PROPERTIES, - REPO_LABEL_ZFAR, - REPO_DEFAULT_PROJECT_ZFAR); - } - - /** - * Get the zNear of the project for this settings - * @return returns project zNear as double - */ - double getZNear() const - { - return getEmbeddedDouble( - REPO_LABEL_PROPERTIES, - REPO_LABEL_ZNEAR, - REPO_DEFAULT_PROJECT_ZNEAR); - } + private: + std::string id; + std::string status; }; }// end namespace model } // end namespace core diff --git a/bouncer/src/repo/core/model/bson/repo_bson_ref.h b/bouncer/src/repo/core/model/bson/repo_bson_ref.h index 339eea92f..52cce8672 100644 --- a/bouncer/src/repo/core/model/bson/repo_bson_ref.h +++ b/bouncer/src/repo/core/model/bson/repo_bson_ref.h @@ -23,7 +23,6 @@ #include "repo/repo_bouncer_global.h" #include "repo/lib/datastructure/repo_variant.h" - #include namespace repo { diff --git a/bouncer/src/repo/core/model/bson/repo_bson_sequence.h b/bouncer/src/repo/core/model/bson/repo_bson_sequence.h index e085736da..40da5eb72 100644 --- a/bouncer/src/repo/core/model/bson/repo_bson_sequence.h +++ b/bouncer/src/repo/core/model/bson/repo_bson_sequence.h @@ -16,8 +16,13 @@ */ #pragma once + +#include "repo/repo_bouncer_global.h" +#include "repo/lib/datastructure/repo_structs.h" +#include "repo/lib/datastructure/repo_uuid.h" #include -#include "repo_bson.h" +#include +#include namespace repo { namespace core { @@ -35,6 +40,8 @@ namespace repo { #define REPO_SEQUENCE_LABEL_END_DATE "endDate" #define REPO_SEQUENCE_LABEL_STATE "state" + class RepoBSON; + class REPO_API_EXPORT RepoSequence { public: diff --git a/bouncer/src/repo/core/model/bson/repo_bson_task.cpp b/bouncer/src/repo/core/model/bson/repo_bson_task.cpp index e7e7e7ead..a6fcbcb4f 100644 --- a/bouncer/src/repo/core/model/bson/repo_bson_task.cpp +++ b/bouncer/src/repo/core/model/bson/repo_bson_task.cpp @@ -17,7 +17,7 @@ #include "repo_bson_task.h" #include "repo_bson_builder.h" -#include "../../../lib/datastructure/repo_uuid.h" +#include "repo/lib/datastructure/repo_uuid.h" #include diff --git a/bouncer/src/repo/core/model/bson/repo_bson_task.h b/bouncer/src/repo/core/model/bson/repo_bson_task.h index e47482df9..de24101c5 100644 --- a/bouncer/src/repo/core/model/bson/repo_bson_task.h +++ b/bouncer/src/repo/core/model/bson/repo_bson_task.h @@ -16,7 +16,11 @@ */ #pragma once -#include "repo_bson.h" + +#include "repo/repo_bouncer_global.h" +#include "repo/lib/datastructure/repo_uuid.h" +#include +#include namespace repo { namespace core { @@ -37,6 +41,8 @@ namespace repo { #define REPO_TASK_META_KEY "key" #define REPO_TASK_META_VALUE "value" + class RepoBSON; + class REPO_API_EXPORT RepoTask { public: diff --git a/bouncer/src/repo/core/model/bson/repo_bson_teamspace.cpp b/bouncer/src/repo/core/model/bson/repo_bson_teamspace.cpp new file mode 100644 index 000000000..e7db756be --- /dev/null +++ b/bouncer/src/repo/core/model/bson/repo_bson_teamspace.cpp @@ -0,0 +1,46 @@ +/** +* Copyright (C) 2015 3D Repo Ltd +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as +* published by the Free Software Foundation, either version 3 of the +* License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see . +*/ + +#include "repo_bson_teamspace.h" +#include "repo/core/model/bson/repo_bson.h" +#include "repo/lib/repo_log.h" + +using namespace repo::core::model; + +#define REPO_USER_LABEL_ADDONS "addOns" + +RepoTeamspace::RepoTeamspace(RepoBSON bson) +{ + if (bson.hasField(REPO_USER_LABEL_ADDONS)) + { + auto addons = bson.getObjectField(REPO_USER_LABEL_ADDONS); + for (const auto& name : addons.getFieldNames()) + { + auto addon = addons.getField(name); + if (addon.type() == repo::core::model::ElementType::BOOL) { + if (addon.Bool()) { + addOns.insert(name); + } + } + } + } +} + +bool RepoTeamspace::isAddOnEnabled(const std::string& addOnName) +{ + return addOns.find(addOnName) != addOns.end(); +} \ No newline at end of file diff --git a/bouncer/src/repo/core/model/bson/repo_bson_teamspace.h b/bouncer/src/repo/core/model/bson/repo_bson_teamspace.h new file mode 100644 index 000000000..df1997070 --- /dev/null +++ b/bouncer/src/repo/core/model/bson/repo_bson_teamspace.h @@ -0,0 +1,53 @@ +/** +* Copyright (C) 2015 3D Repo Ltd +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as +* published by the Free Software Foundation, either version 3 of the +* License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see . +*/ + +#pragma once + +#include "repo/repo_bouncer_global.h" +#include +#include + +namespace repo { + namespace core { + namespace model { + + class RepoBSON; + + #define REPO_USER_LABEL_VR_ENABLED "vrEnabled" + #define REPO_USER_LABEL_SRC_ENABLED "srcEnabled" + + class REPO_API_EXPORT RepoTeamspace + { + public: + + // RepoTeamspace provides access to the teamspace settings + // document. This is a read-only object. + + RepoTeamspace(RepoBSON bson); + + ~RepoTeamspace() {} + + // Currently the only supported member is the addons + + bool isAddOnEnabled(const std::string& addOnName); + + private: + std::set addOns; + }; + }// end namespace model + } // end namespace core +} // end namespace repo diff --git a/bouncer/src/repo/core/model/bson/repo_node.cpp b/bouncer/src/repo/core/model/bson/repo_node.cpp index a224d8601..d5734e13b 100644 --- a/bouncer/src/repo/core/model/bson/repo_node.cpp +++ b/bouncer/src/repo/core/model/bson/repo_node.cpp @@ -24,12 +24,10 @@ using namespace repo::core::model; -RepoNode::RepoNode(RepoBSON bson, - const std::unordered_map>> &binMapping) { +RepoNode::RepoNode(RepoBSON bson) { uniqueId = repo::lib::RepoUUID::createUUID(); sharedId = repo::lib::RepoUUID::defaultValue; revId = repo::lib::RepoUUID::defaultValue; - bigFiles = binMapping; deserialise(bson); } @@ -40,6 +38,11 @@ RepoNode::RepoNode() revId = repo::lib::RepoUUID::defaultValue; } +RepoNode::operator RepoBSON() const +{ + return getBSON(); +} + RepoBSON RepoNode::getBSON() const { RepoBSONBuilder builder; serialise(builder); @@ -47,8 +50,14 @@ RepoBSON RepoNode::getBSON() const { } void RepoNode::deserialise(RepoBSON& bson) { - uniqueId = bson.getUUIDField(REPO_NODE_LABEL_ID); - name = bson.getStringField(REPO_NODE_LABEL_NAME); + if (bson.hasField(REPO_NODE_LABEL_ID)) + { + uniqueId = bson.getUUIDField(REPO_NODE_LABEL_ID); + } + if (bson.hasField(REPO_NODE_LABEL_NAME)) + { + name = bson.getStringField(REPO_NODE_LABEL_NAME); + } if (bson.hasField(REPO_NODE_LABEL_SHARED_ID)) { sharedId = bson.getUUIDField(REPO_NODE_LABEL_SHARED_ID); @@ -80,72 +89,12 @@ void RepoNode::serialise(repo::core::model::RepoBSONBuilder& builder) const if (!revId.isDefaultValue()) { builder.append(REPO_NODE_REVISION_ID, revId); } - for (auto& pair : bigFiles) { - builder.appendLargeArray(pair.first, pair.second.second); - } } RepoNode::~RepoNode() { } -RepoNode RepoNode::cloneAndAddParent( - const repo::lib::RepoUUID &parentID, - const bool &newUniqueID, - const bool &newSharedID, - const bool &overwrite) const -{ - RepoBSONBuilder builder; - - std::vector currentParents; - if (!overwrite) - { - currentParents = getParentIDs(); - } - - if (std::find(currentParents.begin(), currentParents.end(), parentID) == currentParents.end()) - currentParents.push_back(parentID); - builder.appendArray(REPO_NODE_LABEL_PARENTS, currentParents); - - if (newUniqueID) - builder.append(REPO_NODE_LABEL_ID, repo::lib::RepoUUID::createUUID()); - - if (newSharedID) - builder.append(REPO_NODE_LABEL_SHARED_ID, repo::lib::RepoUUID::createUUID()); - - builder.appendElementsUnique(getBSON()); - - return RepoNode(builder.obj(), bigFiles); -} - -RepoNode RepoNode::cloneAndAddParent( - const std::vector &parentIDs) const -{ - if (!parentIDs.size()) return RepoNode(getBSON(), bigFiles); - - RepoBSONBuilder builder; - RepoBSONBuilder arrayBuilder; - std::set currentParents; - for (const auto &parent : getParentIDs()) { - currentParents.insert(parent.toString()); - } - - for (const auto &parent : parentIDs) { - currentParents.insert(parent.toString()); - } - - std::vector newParents; - for (const auto &parent : currentParents) { - newParents.push_back(repo::lib::RepoUUID(parent)); - } - - builder.appendArray(REPO_NODE_LABEL_PARENTS, newParents); - - builder.appendElementsUnique(getBSON()); - - return RepoNode(builder.obj(), bigFiles); -} - NodeType RepoNode::getTypeAsEnum() const // todo: get rid of this in favour of RTTI { std::string type = getType(); diff --git a/bouncer/src/repo/core/model/bson/repo_node.h b/bouncer/src/repo/core/model/bson/repo_node.h index f2c47b85c..c41f77b30 100644 --- a/bouncer/src/repo/core/model/bson/repo_node.h +++ b/bouncer/src/repo/core/model/bson/repo_node.h @@ -17,12 +17,18 @@ #pragma once -#include "repo_bson.h" -#include "../../../lib/datastructure/repo_matrix.h" +#include "repo/repo_bouncer_global.h" +#include "repo/lib/datastructure/repo_matrix.h" +#include "repo/lib/datastructure/repo_uuid.h" +#include +#include namespace repo { namespace core { namespace model { + + class RepoBSON; + enum class NodeType { MATERIAL, MESH, @@ -52,9 +58,7 @@ namespace repo { * not be called directly, because RepoNodes should always be * initialised to their most specific subtype from RepoBSONs. */ - RepoNode(RepoBSON bson, - const std::unordered_map>> &binMapping = - std::unordered_map>>()); + RepoNode(RepoBSON bson); /** * Empty Constructor @@ -66,11 +70,9 @@ namespace repo { */ virtual ~RepoNode(); - std::unordered_map>> bigFiles; - RepoBSON getBSON() const; - operator RepoBSON() const { return getBSON(); } + operator RepoBSON() const; protected: virtual void deserialise(RepoBSON&); @@ -92,38 +94,6 @@ namespace repo { return false; } - /* - * ------------- Delusional modifiers -------------- - * These are like "setters" but not. We are actually - * creating a new bson object with the changed field - */ - - /** - * Create a new object with this object's values, - * and add another parent into this new object - * NOTE: this object is unchanged! - * @param parentID the shared uuid of the parent - * @param newUniqueID assign a new unique ID - * @param newSharedID assign a new shared ID - * @param overwrite overwrite the current parenting information - * @return new object with the field updated - */ - RepoNode cloneAndAddParent( - const repo::lib::RepoUUID &parent, - const bool &newUniqueID = false, - const bool &newSharedID = false, - const bool &overwrite = false) const; - - /** - * Create a new object with this object's values, - * and add other parents into this new object - * NOTE: this object is unchanged! - * @param parentID the shared uuid of the parent - * @return new object with the field updated - */ - RepoNode cloneAndAddParent( - const std::vector &parents) const; - void addParent( const repo::lib::RepoUUID& parent ) @@ -136,10 +106,15 @@ namespace repo { { for (auto id : parents) { parentIds.insert(id); - } } + void setParents(const std::vector& parents) + { + parentIds.clear(); + addParents(parents); + } + void removeParent( const repo::lib::RepoUUID& parent ) diff --git a/bouncer/src/repo/core/model/bson/repo_node_drawing_revision.h b/bouncer/src/repo/core/model/bson/repo_node_drawing_revision.h index 95c21588a..4eb4b61af 100644 --- a/bouncer/src/repo/core/model/bson/repo_node_drawing_revision.h +++ b/bouncer/src/repo/core/model/bson/repo_node_drawing_revision.h @@ -21,6 +21,7 @@ #pragma once #include "repo_node_revision.h" +#include "repo/core/model/repo_model_global.h" //------------------------------------------------------------------------------ // diff --git a/bouncer/src/repo/core/model/bson/repo_node_material.h b/bouncer/src/repo/core/model/bson/repo_node_material.h index e91f954b8..fdfecc662 100644 --- a/bouncer/src/repo/core/model/bson/repo_node_material.h +++ b/bouncer/src/repo/core/model/bson/repo_node_material.h @@ -20,7 +20,7 @@ #pragma once #include "repo_node.h" -#include "../../../lib/datastructure/repo_structs.h" +#include "repo/lib/datastructure/repo_structs.h" namespace repo { namespace core { @@ -43,7 +43,7 @@ namespace repo { //------------------------------------------------------------------------------ - class REPO_API_EXPORT MaterialNode :public RepoNode + class REPO_API_EXPORT MaterialNode : public RepoNode { public: diff --git a/bouncer/src/repo/core/model/bson/repo_node_mesh.cpp b/bouncer/src/repo/core/model/bson/repo_node_mesh.cpp index c5f057636..d1fdf0a2c 100644 --- a/bouncer/src/repo/core/model/bson/repo_node_mesh.cpp +++ b/bouncer/src/repo/core/model/bson/repo_node_mesh.cpp @@ -19,9 +19,11 @@ * Mesh node */ +#define NOMINMAX + #include "repo_node_mesh.h" -#include "../../../lib/repo_log.h" +#include "repo/lib/repo_log.h" #include "repo_bson_builder.h" using namespace repo::core::model; @@ -37,9 +39,8 @@ MeshNode::MeshNode() : }); } -MeshNode::MeshNode(RepoBSON bson, - const std::unordered_map>>&binMapping) : - RepoNode(bson, binMapping) +MeshNode::MeshNode(RepoBSON bson) : + RepoNode(bson) { deserialise(bson); } diff --git a/bouncer/src/repo/core/model/bson/repo_node_mesh.h b/bouncer/src/repo/core/model/bson/repo_node_mesh.h index c31d73dd5..f76b66af4 100644 --- a/bouncer/src/repo/core/model/bson/repo_node_mesh.h +++ b/bouncer/src/repo/core/model/bson/repo_node_mesh.h @@ -20,9 +20,8 @@ #pragma once #include "repo_node.h" - -#include "../../../repo_bouncer_global.h" -#include "../../../lib/datastructure/repo_structs.h" +#include "repo/repo_bouncer_global.h" +#include "repo/lib/datastructure/repo_structs.h" namespace repo { namespace core { @@ -85,10 +84,7 @@ namespace repo { * @param RepoBSON object * @param binMapping binary mapping of fields that are too big to fit within the bson */ - MeshNode(RepoBSON bson, - const std::unordered_map>> &binMapping = - std::unordered_map>>() - ); + MeshNode(RepoBSON bson); /** * Default deconstructor diff --git a/bouncer/src/repo/core/model/bson/repo_node_metadata.cpp b/bouncer/src/repo/core/model/bson/repo_node_metadata.cpp index bb44280bd..fb28f0057 100644 --- a/bouncer/src/repo/core/model/bson/repo_node_metadata.cpp +++ b/bouncer/src/repo/core/model/bson/repo_node_metadata.cpp @@ -29,9 +29,8 @@ RepoNode() { } -MetadataNode::MetadataNode(RepoBSON bson, - const std::unordered_map>> &binMapping) : - RepoNode(bson, binMapping) +MetadataNode::MetadataNode(RepoBSON bson) : + RepoNode(bson) { deserialise(bson); } diff --git a/bouncer/src/repo/core/model/bson/repo_node_metadata.h b/bouncer/src/repo/core/model/bson/repo_node_metadata.h index 6279df429..6158df245 100644 --- a/bouncer/src/repo/core/model/bson/repo_node_metadata.h +++ b/bouncer/src/repo/core/model/bson/repo_node_metadata.h @@ -20,7 +20,9 @@ #pragma once #include "repo_node.h" -#include "../../../lib/datastructure/repo_variant.h" +#include "repo/lib/datastructure/repo_variant.h" +#include "repo/core/model/repo_model_global.h" +#include namespace repo { namespace core { @@ -35,7 +37,7 @@ namespace repo { #define REPO_NODE_LABEL_META_VALUE "value" //------------------------------------------------------------------------------ - class REPO_API_EXPORT MetadataNode :public RepoNode + class REPO_API_EXPORT MetadataNode : public RepoNode { public: @@ -48,9 +50,7 @@ namespace repo { * Construct a MetadataNode from a RepoBSON object * @param RepoBSON object */ - MetadataNode(RepoBSON bson, - const std::unordered_map>> &binMapping = - std::unordered_map>>()); + MetadataNode(RepoBSON bson); /** * Default deconstructor diff --git a/bouncer/src/repo/core/model/bson/repo_node_reference.h b/bouncer/src/repo/core/model/bson/repo_node_reference.h index 7cf5dfc58..1a1024c8e 100644 --- a/bouncer/src/repo/core/model/bson/repo_node_reference.h +++ b/bouncer/src/repo/core/model/bson/repo_node_reference.h @@ -20,6 +20,7 @@ #pragma once #include "repo_node.h" +#include "repo/core/model/repo_model_global.h" //------------------------------------------------------------------------------ // @@ -35,7 +36,7 @@ namespace repo { namespace core { namespace model { - class REPO_API_EXPORT ReferenceNode :public RepoNode + class REPO_API_EXPORT ReferenceNode : public RepoNode { public: diff --git a/bouncer/src/repo/core/model/bson/repo_node_revision.h b/bouncer/src/repo/core/model/bson/repo_node_revision.h index da92cd7e7..0612f194c 100644 --- a/bouncer/src/repo/core/model/bson/repo_node_revision.h +++ b/bouncer/src/repo/core/model/bson/repo_node_revision.h @@ -21,6 +21,7 @@ #pragma once #include "repo_node.h" +#include "repo/core/model/repo_model_global.h" //------------------------------------------------------------------------------ // diff --git a/bouncer/src/repo/core/model/bson/repo_node_supermesh.cpp b/bouncer/src/repo/core/model/bson/repo_node_supermesh.cpp index 82070f4b7..44599c9af 100644 --- a/bouncer/src/repo/core/model/bson/repo_node_supermesh.cpp +++ b/bouncer/src/repo/core/model/bson/repo_node_supermesh.cpp @@ -17,13 +17,12 @@ #include "repo_node_supermesh.h" #include "repo_bson_builder.h" -#include "../../../lib/repo_exception.h" +#include "repo/lib/repo_exception.h" using namespace repo::core::model; -SupermeshNode::SupermeshNode(RepoBSON bson, - const std::unordered_map>>& binMapping) - : MeshNode(bson, binMapping) +SupermeshNode::SupermeshNode(RepoBSON bson) + : MeshNode(bson) { deserialise(bson); } diff --git a/bouncer/src/repo/core/model/bson/repo_node_supermesh.h b/bouncer/src/repo/core/model/bson/repo_node_supermesh.h index 3e1e6bb28..755ec3210 100644 --- a/bouncer/src/repo/core/model/bson/repo_node_supermesh.h +++ b/bouncer/src/repo/core/model/bson/repo_node_supermesh.h @@ -26,8 +26,7 @@ namespace repo { public: SupermeshNode(); - SupermeshNode(RepoBSON bson, - const std::unordered_map>>& binMapping); + SupermeshNode(RepoBSON bson); protected: std::vector mappings; diff --git a/bouncer/src/repo/core/model/bson/repo_node_texture.cpp b/bouncer/src/repo/core/model/bson/repo_node_texture.cpp index c8aff58f5..06994d547 100644 --- a/bouncer/src/repo/core/model/bson/repo_node_texture.cpp +++ b/bouncer/src/repo/core/model/bson/repo_node_texture.cpp @@ -20,7 +20,7 @@ */ #include "repo_node_texture.h" -#include "../../../lib/repo_log.h" +#include "repo/lib/repo_log.h" #include #include "repo_bson_builder.h" @@ -33,8 +33,8 @@ TextureNode::TextureNode() : height = 0; } -TextureNode::TextureNode(RepoBSON bson, const std::unordered_map>>&binMapping) : - RepoNode(bson, binMapping) +TextureNode::TextureNode(RepoBSON bson) : + RepoNode(bson) { width = 0; height = 0; diff --git a/bouncer/src/repo/core/model/bson/repo_node_texture.h b/bouncer/src/repo/core/model/bson/repo_node_texture.h index 751c81fb6..68f53bd9b 100644 --- a/bouncer/src/repo/core/model/bson/repo_node_texture.h +++ b/bouncer/src/repo/core/model/bson/repo_node_texture.h @@ -20,6 +20,7 @@ #pragma once #include "repo_node.h" +#include "repo/core/model/repo_model_global.h" namespace repo { namespace core { @@ -45,8 +46,7 @@ namespace repo { * Construct a TextureNode from a RepoBSON object * @param RepoBSON object */ - TextureNode(RepoBSON bson, - const std::unordered_map>>&binMapping = std::unordered_map>>()); + TextureNode(RepoBSON bson); /** * Default deconstructor diff --git a/bouncer/src/repo/core/model/bson/repo_node_transformation.cpp b/bouncer/src/repo/core/model/bson/repo_node_transformation.cpp index c1c847a37..5d9e76ed3 100644 --- a/bouncer/src/repo/core/model/bson/repo_node_transformation.cpp +++ b/bouncer/src/repo/core/model/bson/repo_node_transformation.cpp @@ -25,13 +25,13 @@ using namespace repo::core::model; TransformationNode::TransformationNode() : -RepoNode() + RepoNode() { // (The default matrix constructor initialises itself to identity) } TransformationNode::TransformationNode(RepoBSON bson) : -RepoNode(bson) + RepoNode(bson) { deserialise(bson); } diff --git a/bouncer/src/repo/core/model/bson/repo_node_transformation.h b/bouncer/src/repo/core/model/bson/repo_node_transformation.h index 641acb362..e6033ca93 100644 --- a/bouncer/src/repo/core/model/bson/repo_node_transformation.h +++ b/bouncer/src/repo/core/model/bson/repo_node_transformation.h @@ -20,6 +20,7 @@ #pragma once #include "repo_node.h" +#include "repo/core/model/repo_model_global.h" namespace repo { namespace core { diff --git a/bouncer/src/repo/core/model/collection/repo_scene.cpp b/bouncer/src/repo/core/model/collection/repo_scene.cpp index e3e262a8a..4b47bc8c8 100644 --- a/bouncer/src/repo/core/model/collection/repo_scene.cpp +++ b/bouncer/src/repo/core/model/collection/repo_scene.cpp @@ -366,7 +366,7 @@ void RepoScene::addMetadata( } } - *meta = meta->cloneAndAddParent(parents); + meta->addParents(parents); graph.nodesByUniqueID[metaUniqueID] = meta; graph.sharedIDtoUniqueID[metaSharedID] = metaUniqueID; @@ -667,10 +667,10 @@ void RepoScene::addErrorStatusToProjectSettings( ) { RepoBSON criteria = BSON(REPO_LABEL_ID << projectName); - auto doc = RepoProjectSettings(handler->findOneByCriteria(databaseName, REPO_COLLECTION_SETTINGS, criteria)); - auto updatedProjectsettings = doc.cloneAndAddErrorStatus(); + auto projectsettings = RepoProjectSettings(handler->findOneByCriteria(databaseName, REPO_COLLECTION_SETTINGS, criteria)); + projectsettings.setErrorStatus(); std::string errorMsg; - if (!handler->upsertDocument(databaseName, REPO_COLLECTION_SETTINGS, updatedProjectsettings, true, errorMsg)) + if (!handler->upsertDocument(databaseName, REPO_COLLECTION_SETTINGS, projectsettings, false, errorMsg)) { repoError << "Failed to update project settings: " << errorMsg; } @@ -681,10 +681,10 @@ void RepoScene::addTimestampToProjectSettings( ) { RepoBSON criteria = BSON(REPO_LABEL_ID << projectName); - auto doc = RepoProjectSettings(handler->findOneByCriteria(databaseName, REPO_COLLECTION_SETTINGS, criteria)); - auto updatedProjectsettings = doc.cloneAndClearStatus(); + auto projectsettings = RepoProjectSettings(handler->findOneByCriteria(databaseName, REPO_COLLECTION_SETTINGS, criteria)); + projectsettings.clearErrorStatus(); std::string errorMsg; - if (!handler->upsertDocument(databaseName, REPO_COLLECTION_SETTINGS, updatedProjectsettings, true, errorMsg)) + if (!handler->upsertDocument(databaseName, REPO_COLLECTION_SETTINGS, projectsettings, false, errorMsg)) { repoError << "Failed to update project settings: " << errorMsg; } diff --git a/bouncer/src/repo/lib/datastructure/repo_structs.h b/bouncer/src/repo/lib/datastructure/repo_structs.h index cbf2c2cb7..d03de107d 100644 --- a/bouncer/src/repo/lib/datastructure/repo_structs.h +++ b/bouncer/src/repo/lib/datastructure/repo_structs.h @@ -19,8 +19,9 @@ #include #include -#include "../../repo_bouncer_global.h" -#include "../../core/model/bson/repo_bson_assets.h" +#include +#include "repo/repo_bouncer_global.h" +#include "repo/core/model/bson/repo_bson_assets.h" #include "repo_uuid.h" #include "repo_vector.h" #include diff --git a/bouncer/src/repo/manipulator/modelconvertor/import/odaHelper/data_processor_rvt.h b/bouncer/src/repo/manipulator/modelconvertor/import/odaHelper/data_processor_rvt.h index d4be477d2..494778137 100644 --- a/bouncer/src/repo/manipulator/modelconvertor/import/odaHelper/data_processor_rvt.h +++ b/bouncer/src/repo/manipulator/modelconvertor/import/odaHelper/data_processor_rvt.h @@ -55,8 +55,7 @@ #include -#include "../../../../lib/datastructure/repo_structs.h" -#include "../../../../core/model/bson/repo_bson_builder.h" +#include "repo/lib/datastructure/repo_structs.h" #include "geometry_collector.h" #include "data_processor.h" diff --git a/bouncer/src/repo/manipulator/modelconvertor/import/odaHelper/geometry_collector.cpp b/bouncer/src/repo/manipulator/modelconvertor/import/odaHelper/geometry_collector.cpp index ec33d4c28..ed1086e6f 100644 --- a/bouncer/src/repo/manipulator/modelconvertor/import/odaHelper/geometry_collector.cpp +++ b/bouncer/src/repo/manipulator/modelconvertor/import/odaHelper/geometry_collector.cpp @@ -396,13 +396,16 @@ void GeometryCollector::getMaterialAndTextureNodes(repo::core::model::RepoNodeSe auto& materialNode = matPair.second.first; auto& textureNode = matPair.second.second; - auto matNode = new repo::core::model::MaterialNode(materialNode.cloneAndAddParent(matToMeshes[matIdx])); + auto matNode = new repo::core::model::MaterialNode(materialNode); + matNode->addParents(matToMeshes[matIdx]); materials.insert(matNode); //FIXME: Mat shared ID is known at the point of creating texture node. We shouldn't be cloning here. // SJF: the clone is also to get a pointer if (!textureNode.isEmpty()) { - auto texNode = new repo::core::model::TextureNode(textureNode.cloneAndAddParent(matNode->getSharedID())); + + auto texNode = new repo::core::model::TextureNode(textureNode); + texNode->addParent(matNode->getSharedID()); textures.insert(texNode); } } diff --git a/bouncer/src/repo/manipulator/modelconvertor/import/repo_model_import_3drepo.cpp b/bouncer/src/repo/manipulator/modelconvertor/import/repo_model_import_3drepo.cpp index 95b6dfc63..f57984582 100644 --- a/bouncer/src/repo/manipulator/modelconvertor/import/repo_model_import_3drepo.cpp +++ b/bouncer/src/repo/manipulator/modelconvertor/import/repo_model_import_3drepo.cpp @@ -22,10 +22,9 @@ #include #include #include -#include "../../../core/model/bson/repo_bson_builder.h" -#include "../../../core/model/bson/repo_bson_factory.h" -#include "../../../lib/repo_log.h" -#include "../../../error_codes.h" +#include "repo/core/model/bson/repo_bson_factory.h" +#include "repo/lib/repo_log.h" +#include "repo/error_codes.h" using namespace repo::core::model; using namespace repo::manipulator::modelconvertor; @@ -361,7 +360,7 @@ RepoModelImport::mesh_data_t RepoModelImport::createMeshRecord( if (materialID >= 0) { - matParents[materialID].push_back(sharedID); + matNodeList[materialID]->addParent(sharedID); } mesh_data_t result = { vertices, normals, uvChannels, faces, boundingBox, parentID, sharedID }; @@ -515,7 +514,6 @@ bool RepoModelImport::importModel(std::string filePath, uint8_t& err) { parseMaterial(element.second); } - matParents.resize(materials.size()); repoInfo << "Loaded: " << materials.size() << " materials"; } else @@ -642,13 +640,12 @@ repo::core::model::RepoScene* RepoModelImport::generateRepoScene(uint8_t& errCod createObject(jsonTree); } - // Attach all the parents to the materials - repoInfo << "Attaching materials to parents"; + // Change the container type of the materials for RepoScene's constructor + repoInfo << "Building materials list"; materials.clear(); for (int i = 0; i < matNodeList.size(); i++) { - //TODO SJF: check if we actually need to clone here... - materials.insert(new repo::core::model::MaterialNode(matNodeList[i]->cloneAndAddParent(matParents[i]))); + materials.insert(matNodeList[i]); } // Preparing reference files diff --git a/bouncer/src/repo/manipulator/modelconvertor/import/repo_model_import_3drepo.h b/bouncer/src/repo/manipulator/modelconvertor/import/repo_model_import_3drepo.h index d3fd27d9c..6e31f9946 100644 --- a/bouncer/src/repo/manipulator/modelconvertor/import/repo_model_import_3drepo.h +++ b/bouncer/src/repo/manipulator/modelconvertor/import/repo_model_import_3drepo.h @@ -146,7 +146,6 @@ namespace repo { std::vector node_map; //!< List of all transform nodes in order of decoding std::vector trans_matrix_map; //!< List of all transformation matrices in same order as node_map std::vector matNodeList; //!< Stores a list of materials - std::vector> matParents; //!< Stores the UUIDs of all parents of a given material node in the same order matNodeList std::map> textureIdToParents; //!< Maps a texture to the UUID of all the parents that reference it std::vector meshEntries; diff --git a/bouncer/src/repo/manipulator/modelconvertor/import/repo_model_import_assimp.cpp b/bouncer/src/repo/manipulator/modelconvertor/import/repo_model_import_assimp.cpp index bdf58b9d2..f951f6669 100644 --- a/bouncer/src/repo/manipulator/modelconvertor/import/repo_model_import_assimp.cpp +++ b/bouncer/src/repo/manipulator/modelconvertor/import/repo_model_import_assimp.cpp @@ -29,7 +29,6 @@ #include #include "../../../core/model/bson/repo_node_mesh.h" -#include "../../../core/model/bson/repo_bson_builder.h" #include "../../../core/model/bson/repo_bson_factory.h" #include "../../../lib/repo_utils.h" #include "../../../error_codes.h" @@ -580,14 +579,10 @@ repo::core::model::MetadataNode* AssimpModelImport::createMetadataRepoNode( const std::string &metadataName, const std::vector &parents) { - repo::core::model::MetadataNode *metaNode; - std::unordered_map metaEntries; - std::string val; + repo::core::model::MetadataNode *metaNode = 0; if (assimpMeta) { - //build the metadata as a bson - repo::core::model::RepoBSONBuilder builder; - + std::unordered_map metaEntries; for (uint32_t i = 0; i < assimpMeta->mNumProperties; i++) { std::string key(assimpMeta->mKeys[i].C_Str()); @@ -611,7 +606,7 @@ repo::core::model::MetadataNode* AssimpModelImport::createMetadataRepoNode( } else if (currentValue.mType == AI_AISTRING) { // We do additional checks with the string, so we have to handle this separately from the rest - val = (static_cast(currentValue.mData))->C_Str(); + std::string val = (static_cast(currentValue.mData))->C_Str(); if (val.compare(key)) { metaEntries[key] = val; } @@ -916,14 +911,10 @@ repo::core::model::RepoScene* AssimpModelImport::convertAiSceneToRepoScene() //Update material parents for (const auto &matPair : matParents) { - /*if (matPair.second.size() > 0) - { - repo::core::model::RepoNode updatedMat = matPair.first->cloneAndAddParent(matPair.second); - matPair.first->swap(updatedMat); - }*/ - - for (const auto meshId : matPair.second) + for (const auto meshId : matPair.second) { + matPair.first->addParents(matPair.second); meshToMat[meshId] = matPair.first; + } } matParents.clear(); } @@ -992,11 +983,15 @@ repo::core::model::RepoScene* AssimpModelImport::convertAiSceneToRepoScene() repo::core::model::RepoNode* AssimpModelImport::duplicateMesh( repo::lib::RepoUUID &newParent, - repo::core::model::RepoNode &mesh, + repo::core::model::MeshNode &mesh, const std::unordered_map &meshToMat, std::unordered_map> &matParents) { - auto newMesh = new repo::core::model::MeshNode(mesh.cloneAndAddParent(newParent, true, true, true)); + auto newMesh = new repo::core::model::MeshNode(mesh); + newMesh->setUniqueId(repo::lib::RepoUUID::createUUID()); + newMesh->setSharedID(repo::lib::RepoUUID::createUUID()); + newMesh->setParents({ newParent }); + auto it = meshToMat.find(mesh.getSharedID()); if (it != meshToMat.end() && it->second) { diff --git a/bouncer/src/repo/manipulator/modelconvertor/import/repo_model_import_assimp.h b/bouncer/src/repo/manipulator/modelconvertor/import/repo_model_import_assimp.h index 65016ae64..08db26e78 100644 --- a/bouncer/src/repo/manipulator/modelconvertor/import/repo_model_import_assimp.h +++ b/bouncer/src/repo/manipulator/modelconvertor/import/repo_model_import_assimp.h @@ -166,7 +166,7 @@ namespace repo { */ repo::core::model::RepoNode* duplicateMesh( repo::lib::RepoUUID &newParent, - repo::core::model::RepoNode &mesh, + repo::core::model::MeshNode &mesh, const std::unordered_map &meshToMat, std::unordered_map> &matParents); diff --git a/bouncer/src/repo/manipulator/modelconvertor/import/repo_model_import_synchro.cpp b/bouncer/src/repo/manipulator/modelconvertor/import/repo_model_import_synchro.cpp index a5b3b7ea8..484774393 100644 --- a/bouncer/src/repo/manipulator/modelconvertor/import/repo_model_import_synchro.cpp +++ b/bouncer/src/repo/manipulator/modelconvertor/import/repo_model_import_synchro.cpp @@ -19,11 +19,10 @@ #include #include "repo_model_import_synchro.h" -#include "../../../core/model/bson/repo_bson_builder.h" -#include "../../../core/model/bson/repo_bson_factory.h" -#include "../../../lib/repo_log.h" -#include "../../../lib/datastructure/repo_matrix.h" -#include "../../../error_codes.h" +#include "repo/core/model/bson/repo_bson_factory.h" +#include "repo/lib/repo_log.h" +#include "repo/lib/datastructure/repo_matrix.h" +#include "repo/error_codes.h" using namespace repo::manipulator::modelconvertor; @@ -107,7 +106,7 @@ std::pair Synchr auto textBuff = mat.texture.texture; if (textBuff.size()) { auto textNode = new repo::core::model::TextureNode(repo::core::model::RepoBSONFactory::makeTextureNode("texture", (char*)textBuff.data(), - textBuff.size(), matEntry.second.texture.width, matEntry.second.texture.height).cloneAndAddParent(matNode->getSharedID())); + textBuff.size(), matEntry.second.texture.width, matEntry.second.texture.height, { matNode->getSharedID() })); textNodes.insert(textNode); repoIDToNode[textNode->getUniqueID()] = textNode; } @@ -393,13 +392,13 @@ repo::core::model::RepoScene* SynchroModelImport::constructScene( if (synchroIDToRepoID.find(synchroParent) != synchroIDToRepoID.end()) { parentSharedID = repoIDToNode[synchroIDToRepoID[synchroParent]]->getSharedID(); } - *repoIDToNode[nodeID] = repoIDToNode[nodeID]->cloneAndAddParent(parentSharedID); + repoIDToNode[nodeID]->addParent(parentSharedID); } for (auto entry : nodeToParents) { auto nodeID = entry.first; auto parents = entry.second; - *repoIDToNode[nodeID] = repoIDToNode[nodeID]->cloneAndAddParent(parents); + repoIDToNode[nodeID]->addParents(parents); } repo::core::model::RepoNodeSet dummy; diff --git a/bouncer/src/repo/manipulator/modeloptimizer/repo_optimizer_multipart.cpp b/bouncer/src/repo/manipulator/modeloptimizer/repo_optimizer_multipart.cpp index d2abbb962..c01e61ba5 100644 --- a/bouncer/src/repo/manipulator/modeloptimizer/repo_optimizer_multipart.cpp +++ b/bouncer/src/repo/manipulator/modeloptimizer/repo_optimizer_multipart.cpp @@ -25,8 +25,7 @@ #include "bvh/sweep_sah_builder.hpp" #include "repo_optimizer_multipart.h" -#include "../../core/model/bson/repo_bson_factory.h" -#include "../../core/model/bson/repo_bson_builder.h" +#include "repo/core/model/bson/repo_bson_factory.h" #include #include diff --git a/bouncer/src/repo/manipulator/modelutility/repo_drawing_manager.cpp b/bouncer/src/repo/manipulator/modelutility/repo_drawing_manager.cpp index 821a4036e..14d63f6a4 100644 --- a/bouncer/src/repo/manipulator/modelutility/repo_drawing_manager.cpp +++ b/bouncer/src/repo/manipulator/modelutility/repo_drawing_manager.cpp @@ -16,10 +16,10 @@ */ #include "repo_drawing_manager.h" -#include "../../core/model/bson/repo_bson_builder.h" -#include "../../core/model/bson/repo_bson_ref.h" -#include "../../core/model/bson/repo_bson_factory.h" -#include "../../error_codes.h" +#include "repo/core/model/bson/repo_bson_ref.h" +#include "repo/core/model/bson/repo_bson_factory.h" +#include "repo/core/model/bson/repo_bson.h" +#include "repo/error_codes.h" using namespace repo::manipulator::modelutility; @@ -46,11 +46,12 @@ uint8_t DrawingManager::commitImage( auto name = drawing.name.substr(0, drawing.name.size() - 3) + "svg"; // The name should be the drawing's original name with an updated extension repo::core::handler::AbstractDatabaseHandler::Metadata metadata; + auto revId = revision.getUniqueID(); metadata[REPO_NODE_LABEL_NAME] = name; metadata[REPO_LABEL_MEDIA_TYPE] = std::string(REPO_MEDIA_TYPE_SVG); metadata[REPO_LABEL_MEDIA_TYPE] = revision.getProject(); metadata[REPO_LABEL_MODEL] = revision.getModel(); - metadata[REPO_NODE_REVISION_ID] = revision.getUniqueID(); + metadata[REPO_NODE_REVISION_ID] = revId; fileManager->uploadFileAndCommit( teamspace, diff --git a/bouncer/src/repo/manipulator/modelutility/repo_mesh_map_reorganiser.cpp b/bouncer/src/repo/manipulator/modelutility/repo_mesh_map_reorganiser.cpp index b46484280..7526450ae 100644 --- a/bouncer/src/repo/manipulator/modelutility/repo_mesh_map_reorganiser.cpp +++ b/bouncer/src/repo/manipulator/modelutility/repo_mesh_map_reorganiser.cpp @@ -15,7 +15,6 @@ * along with this program. If not, see . */ #include "repo_mesh_map_reorganiser.h" -#include "../../core/model/bson/repo_bson_builder.h" #include "../../core/model/bson/repo_bson_factory.h" using namespace repo::manipulator::modelutility; diff --git a/bouncer/src/repo/manipulator/modelutility/repo_scene_manager.cpp b/bouncer/src/repo/manipulator/modelutility/repo_scene_manager.cpp index ed31b0e8d..db43f9aff 100644 --- a/bouncer/src/repo/manipulator/modelutility/repo_scene_manager.cpp +++ b/bouncer/src/repo/manipulator/modelutility/repo_scene_manager.cpp @@ -15,9 +15,9 @@ * along with this program. If not, see . */ #include "repo_scene_manager.h" - -#include "../../core/model/bson/repo_bson_builder.h" -#include "../../core/model/bson/repo_bson_ref.h" +#include "repo/core/model/bson/repo_bson_builder.h" +#include "repo/core/model/bson/repo_bson_ref.h" +#include "repo/core/model/bson/repo_bson_teamspace.h" #include "../../error_codes.h" #include "../modeloptimizer/repo_optimizer_multipart.h" #include "../modelconvertor/export/repo_model_export_src.h" @@ -28,9 +28,6 @@ #include #endif -#define REPO_USER_LABEL_VR_ENABLED "vrEnabled" -#define REPO_USER_LABEL_SRC_ENABLED "srcEnabled" - using namespace repo::manipulator::modelutility; bool SceneManager::commitWebBuffers( @@ -79,8 +76,7 @@ bool SceneManager::commitWebBuffers( if (!resultBuffers.repoAssets.isEmpty()) { - if (success &= handler->upsertDocument(databaseName, projectName + "." + repoAssetsStashExt, resultBuffers.repoAssets, - true, errMsg)) + if (success &= handler->upsertDocument(databaseName, projectName + "." + repoAssetsStashExt, resultBuffers.repoAssets, true, errMsg)) { repoInfo << "Assets list added successfully."; } @@ -457,15 +453,9 @@ repo_web_buffers_t SceneManager::generateRepoBundleBuffer( } bool isAddOnEnabled(repo::core::handler::AbstractDatabaseHandler *handler, const std::string &database, const std::string addOn) { - auto teamspaceSetting = handler->findOneByCriteria(database, "teamspace", BSON("_id" << database)); - if (teamspaceSetting.hasField("addOns")) { - auto addOns = teamspaceSetting.getObjectField("addOns"); - if (addOns.hasField(addOn)) { - return addOns.getBoolField(addOn); - } - } - - return false; + + auto teamspace = repo::core::model::RepoTeamspace(handler->findOneByCriteria(database, "teamspace", BSON("_id" << database))); + return teamspace.isAddOnEnabled(addOn); } bool SceneManager::isVrEnabled( diff --git a/bouncer/src/repo/manipulator/repo_manipulator.cpp b/bouncer/src/repo/manipulator/repo_manipulator.cpp index a058ee9b7..e4f2418b0 100644 --- a/bouncer/src/repo/manipulator/repo_manipulator.cpp +++ b/bouncer/src/repo/manipulator/repo_manipulator.cpp @@ -23,12 +23,13 @@ #include #include -#include "../core/handler/repo_database_handler_mongo.h" -#include "../core/handler/fileservice/repo_file_manager.h" -#include "../core/model/bson/repo_bson_factory.h" -#include "../error_codes.h" -#include "../lib/repo_log.h" -#include "../lib/repo_config.h" +#include "repo/core/handler/repo_database_handler_mongo.h" +#include "repo/core/handler/fileservice/repo_file_manager.h" +#include "repo/core/model/bson/repo_bson_factory.h" +#include "repo/core/model/bson/repo_bson.h" +#include "repo/error_codes.h" +#include "repo/lib/repo_log.h" +#include "repo/lib/repo_config.h" #include "modelconvertor/import/repo_drawing_import_manager.h" #include "modelconvertor/import/repo_model_import_manager.h" #include "modelconvertor/import/repo_metadata_import_csv.h" @@ -127,9 +128,9 @@ repo::core::model::RepoScene* RepoManipulator::createFederatedScene( parentNode = groupNameToNode[pair.second]; } - refNodes.insert(new repo::core::model::ReferenceNode( - pair.first.cloneAndAddParent(parentNode->getSharedID()) - )); + auto copy = new repo::core::model::ReferenceNode(pair.first); + copy->addParent(parentNode->getSharedID()); + refNodes.insert(copy); } //federate scene has no referenced files std::vector empty; @@ -141,7 +142,7 @@ repo::core::model::RepoScene* RepoManipulator::createFederatedScene( uint8_t RepoManipulator::commitScene( const std::string& databaseAd, - const repo::core::model::RepoBSON* cred, + const std::string& user, const std::string& bucketName, const std::string& bucketRegion, repo::core::model::RepoScene* scene, @@ -154,7 +155,7 @@ uint8_t RepoManipulator::commitScene( repo::core::handler::AbstractDatabaseHandler* handler = repo::core::handler::MongoDatabaseHandler::getHandler(databaseAd); auto manager = repo::core::handler::fileservice::FileManager::getManager(); - std::string projOwner = owner.empty() ? cred->getStringField("user") : owner; + std::string projOwner = owner.empty() ? user : owner; //Check if database exists std::string dbName = scene->getDatabaseName(); @@ -285,7 +286,6 @@ repo_web_buffers_t RepoManipulator::generateSRCBuffer( std::vector RepoManipulator::getAllFromCollectionTailable( const std::string& databaseAd, - const repo::core::model::RepoBSON* cred, const std::string& database, const std::string& collection, const uint64_t& skip, diff --git a/bouncer/src/repo/manipulator/repo_manipulator.h b/bouncer/src/repo/manipulator/repo_manipulator.h index d590a7e80..ffa8fb902 100644 --- a/bouncer/src/repo/manipulator/repo_manipulator.h +++ b/bouncer/src/repo/manipulator/repo_manipulator.h @@ -49,7 +49,7 @@ namespace repo { */ uint8_t commitScene( const std::string &databaseAd, - const repo::core::model::RepoBSON *cred, + const std::string &user, const std::string &bucketName, const std::string &bucketRegion, repo::core::model::RepoScene *scene, @@ -224,7 +224,6 @@ namespace repo { std::vector getAllFromCollectionTailable( const std::string &databaseAd, - const repo::core::model::RepoBSON *cred, const std::string &database, const std::string &collection, const uint64_t &skip = 0, diff --git a/bouncer/src/repo/repo_controller.cpp.inl b/bouncer/src/repo/repo_controller.cpp.inl index 8106fba66..87ac3786b 100644 --- a/bouncer/src/repo/repo_controller.cpp.inl +++ b/bouncer/src/repo/repo_controller.cpp.inl @@ -18,7 +18,6 @@ #include "lib/repo_license.h" #include "manipulator/repo_manipulator.h" #include "repo_controller.h" -#include "core/model/bson/repo_bson_builder.h" #include "core/handler/repo_database_handler_mongo.h" using namespace repo; diff --git a/bouncer/src/repo/repo_controller_internal.cpp.inl b/bouncer/src/repo/repo_controller_internal.cpp.inl index 4d06f382d..7a063cc42 100644 --- a/bouncer/src/repo/repo_controller_internal.cpp.inl +++ b/bouncer/src/repo/repo_controller_internal.cpp.inl @@ -18,6 +18,7 @@ #pragma once #include "repo_controller.cpp.inl" #include "error_codes.h" +#include "repo/core/model/bson/repo_bson.h" #include "manipulator/modelconvertor/import/repo_model_import_assimp.h" @@ -104,7 +105,7 @@ uint8_t RepoController::_RepoControllerImpl::commitScene( { manipulator::RepoManipulator* worker = workerPool.pop(); errCode = worker->commitScene(token->databaseAd, - token->getCredentials(), + token->getCredentials()->getStringField("user"), token->bucketName, token->bucketRegion, scene, @@ -216,7 +217,7 @@ RepoController::_RepoControllerImpl::getAllFromCollectionContinuous( { manipulator::RepoManipulator* worker = workerPool.pop(); - vector = worker->getAllFromCollectionTailable(token->databaseAd, token->getCredentials(), + vector = worker->getAllFromCollectionTailable(token->databaseAd, database, collection, skip, limit); workerPool.push(worker); diff --git a/submodules/asset_generator b/submodules/asset_generator index 789b0c3e2..4d32cc242 160000 --- a/submodules/asset_generator +++ b/submodules/asset_generator @@ -1 +1 @@ -Subproject commit 789b0c3e2fa5ae4931a9154e2f2ef149262014b1 +Subproject commit 4d32cc2426974c7638ec1efa2963eeedfc2f7d0c diff --git a/test/src/unit/repo/core/model/bson/CMakeLists.txt b/test/src/unit/repo/core/model/bson/CMakeLists.txt index 3692600cc..bdae91d26 100644 --- a/test/src/unit/repo/core/model/bson/CMakeLists.txt +++ b/test/src/unit/repo/core/model/bson/CMakeLists.txt @@ -11,9 +11,11 @@ set(TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/ut_repo_bson_builder.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ut_repo_bson_element.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ut_repo_bson_factory.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ut_repo_bson_project_settings.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ut_repo_bson_ref.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ut_repo_bson_sequence.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ut_repo_bson_task.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ut_repo_bson_teamspace.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ut_repo_node.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ut_repo_node_drawing_revision.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ut_repo_node_material.cpp diff --git a/test/src/unit/repo/core/model/bson/ut_repo_bson.cpp b/test/src/unit/repo/core/model/bson/ut_repo_bson.cpp index 0ba568d00..11dd664b0 100644 --- a/test/src/unit/repo/core/model/bson/ut_repo_bson.cpp +++ b/test/src/unit/repo/core/model/bson/ut_repo_bson.cpp @@ -18,12 +18,15 @@ #include #include +#include +#include #include #include #include using namespace repo::core::model; +using namespace testing; static auto mongoTestBSON = BSON("ice" << "lolly" << "amount" << 100.0); static const RepoBSON testBson = RepoBSON(BSON("ice" << "lolly" << "amount" << 100)); @@ -72,8 +75,12 @@ TEST(RepoBSONTest, GetField) EXPECT_TRUE(emptyBson.getField("hello").eoo()); } -TEST(RepoBSONTest, GetBinaryAsVectorEmbedded) +TEST(RepoBSONTest, GetBinDataGeneralAsVectorEmbedded) { + // RepoBSONBuilder no longer supports adding BinDataGeneral fields, however + // legacy documents may still have them, therefore RepoBSON should be able + // to return these fields if they exist. + mongo::BSONObjBuilder builder; std::vector < uint8_t > in, out; @@ -91,16 +98,11 @@ TEST(RepoBSONTest, GetBinaryAsVectorEmbedded) EXPECT_TRUE(bson.getBinaryFieldAsVector("binDataTest", out)); - EXPECT_EQ(in.size(), out.size()); - for (size_t i = 0; i < size; ++i) - { - EXPECT_EQ(in[i], out[i]); - } + EXPECT_THAT(in, Eq(out)); - //Invalid retrieval, but they shouldn't throw exception - EXPECT_FALSE(bson.getBinaryFieldAsVector("numTest", out)); - EXPECT_FALSE(bson.getBinaryFieldAsVector("stringTest", out)); - EXPECT_FALSE(bson.getBinaryFieldAsVector("doesn'tExist", out)); + EXPECT_THROW({ bson.getBinaryFieldAsVector("numTest", out); }, repo::lib::RepoFieldTypeException); + EXPECT_THROW({ bson.getBinaryFieldAsVector("stringTest", out); }, repo::lib::RepoFieldTypeException); + EXPECT_THROW({ bson.getBinaryFieldAsVector("doesn'tExist", out); }, repo::lib::RepoFieldNotFoundException); } TEST(RepoBSONTest, GetBinaryAsVectorReferenced) @@ -126,20 +128,12 @@ TEST(RepoBSONTest, GetBinaryAsVectorReferenced) EXPECT_TRUE(bson.getBinaryFieldAsVector("binDataTest", out)); EXPECT_FALSE(bson.getBinaryFieldAsVector(fname, out)); //make sure fieldname/filename are not mixed up. - ASSERT_EQ(out.size(), in.size()); - for (size_t i = 0; i < size; ++i) - { - EXPECT_EQ(in[i], out[i]); - } + EXPECT_THAT(in, Eq(out)); EXPECT_TRUE(bson2.getBinaryFieldAsVector("binDataTest", out)); EXPECT_FALSE(bson2.getBinaryFieldAsVector(fname, out)); //make sure fieldname/filename are not mixed up. - ASSERT_EQ(out.size(), in.size()); - for (size_t i = 0; i < size; ++i) - { - EXPECT_EQ(in[i], out[i]); - } + EXPECT_THAT(in, Eq(out)); } TEST(RepoBSONTest, AssignOperator) @@ -533,48 +527,4 @@ TEST(RepoBSONTest, HasEmbeddedFieldTest) RepoBSON expectTrue(BSON("field" << mongoTestBSON)); EXPECT_TRUE(expectTrue.hasEmbeddedField("field", "ice")); EXPECT_FALSE(expectTrue.hasEmbeddedField("field", "NonExistent")); -} - -TEST(RepoBSONTest, ProjectSettingsTest) -{ - // Project Settings can be read from an existing BSON, but not created anew - - std::string projectName = "project"; - std::string owner = "repo"; - std::string type = "Structural"; - std::string description = "testing project"; - - { - RepoBSONBuilder builder; - builder.append(REPO_LABEL_ID, projectName); - builder.append(REPO_LABEL_DESCRIPTION, description); - builder.append(REPO_LABEL_OWNER, owner); - builder.append(REPO_LABEL_TYPE, type); - builder.append(REPO_PROJECT_SETTINGS_LABEL_IS_FEDERATION, false); - - RepoProjectSettings settings(builder.obj()); - - EXPECT_EQ(projectName, settings.getProjectName()); - EXPECT_EQ(description, settings.getDescription()); - EXPECT_EQ(owner, settings.getOwner()); - EXPECT_EQ(type, settings.getType()); - EXPECT_FALSE(settings.isFederate()); - } - - { - RepoBSONBuilder builder; - builder.append(REPO_LABEL_ID, projectName); - builder.append(REPO_LABEL_DESCRIPTION, description); - builder.append(REPO_LABEL_OWNER, owner); - builder.append(REPO_LABEL_TYPE, type); - builder.append(REPO_PROJECT_SETTINGS_LABEL_IS_FEDERATION, true); - - RepoProjectSettings settings2(builder.obj()); - - EXPECT_EQ(projectName, settings2.getProjectName()); - EXPECT_EQ(description, settings2.getDescription()); - EXPECT_EQ(owner, settings2.getOwner()); - EXPECT_EQ(type, settings2.getType()); - EXPECT_TRUE(settings2.isFederate()); - } } \ No newline at end of file diff --git a/test/src/unit/repo/core/model/bson/ut_repo_bson_project_settings.cpp b/test/src/unit/repo/core/model/bson/ut_repo_bson_project_settings.cpp new file mode 100644 index 000000000..2d96c31f5 --- /dev/null +++ b/test/src/unit/repo/core/model/bson/ut_repo_bson_project_settings.cpp @@ -0,0 +1,97 @@ +/** +* Copyright (C) 2024 3D Repo Ltd +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as +* published by the Free Software Foundation, either version 3 of the +* License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see . +*/ + +#include +#include +#include + +#include "repo/core/model/bson/repo_bson_project_settings.h" +#include "repo/core/model/bson/repo_bson_builder.h" +#include "../../../../repo_test_utils.h" +#include "../../../../repo_test_matchers.h" + +using namespace repo::core::model; +using namespace testing; + +// The following tests are written expecting a schema used with upsert and overwrite +// false; that is, the id is expected to be set to identify the document, and only +// the fields that are to be overwritten should be set. + +TEST(RepoProjectSettingsTest, Deserialise) +{ + std::string projectId = "project"; // Project Settings Ids are in string format, even though nowadays they are all UUIDs + + { + RepoBSONBuilder builder; + builder.append(REPO_LABEL_ID, projectId); + RepoProjectSettings settings(builder.obj()); + EXPECT_THAT(settings.getProjectId(), Eq(projectId)); + } + + { + RepoBSONBuilder builder; + builder.append(REPO_LABEL_ID, projectId); + RepoProjectSettings settings(builder.obj()); + EXPECT_EQ(settings.getStatus(), "ok"); + } + + { + RepoBSONBuilder builder; + builder.append(REPO_LABEL_ID, projectId); + builder.append(REPO_PROJECT_SETTINGS_LABEL_STATUS, "ok"); + RepoProjectSettings settings(builder.obj()); + EXPECT_EQ(settings.getStatus(), "ok"); + } + + { + RepoBSONBuilder builder; + builder.append(REPO_LABEL_ID, projectId); + builder.append(REPO_PROJECT_SETTINGS_LABEL_STATUS, "error"); + RepoProjectSettings settings(builder.obj()); + EXPECT_EQ(settings.getStatus(), "error"); + } +} + +TEST(RepoProjectSettingsTest, Serialise) +{ + auto id = repo::lib::RepoUUID::createUUID().toString(); + RepoBSONBuilder builder; + builder.append(REPO_LABEL_ID, id); + RepoProjectSettings settings(builder.obj()); + + // Re-serialising with status OK should update the timestamp + + EXPECT_THAT(((RepoBSON)settings).getStringField(REPO_LABEL_ID), Eq(id)); + EXPECT_THAT(((RepoBSON)settings).getStringField(REPO_PROJECT_SETTINGS_LABEL_STATUS), Eq("ok")); + EXPECT_THAT(((RepoBSON)settings).getTimeStampField(REPO_PROJECT_SETTINGS_LABEL_TIMESTAMP), IsNow()); + + // Serialising with error set should not change the timestamp + + settings.setErrorStatus(); + + EXPECT_THAT(((RepoBSON)settings).getStringField(REPO_LABEL_ID), Eq(id)); + EXPECT_THAT(((RepoBSON)settings).getStringField(REPO_PROJECT_SETTINGS_LABEL_STATUS), Eq("error")); + EXPECT_THAT(((RepoBSON)settings).hasField(REPO_PROJECT_SETTINGS_LABEL_TIMESTAMP), IsFalse()); + + // Clearing the status should go back to as if it were deserialised with OK + + settings.clearErrorStatus(); + + EXPECT_THAT(((RepoBSON)settings).getStringField(REPO_LABEL_ID), Eq(id)); + EXPECT_THAT(((RepoBSON)settings).getStringField(REPO_PROJECT_SETTINGS_LABEL_STATUS), Eq("ok")); + EXPECT_THAT(((RepoBSON)settings).getTimeStampField(REPO_PROJECT_SETTINGS_LABEL_TIMESTAMP), IsNow()); +} \ No newline at end of file diff --git a/test/src/unit/repo/core/model/bson/ut_repo_bson_teamspace.cpp b/test/src/unit/repo/core/model/bson/ut_repo_bson_teamspace.cpp new file mode 100644 index 000000000..598f71674 --- /dev/null +++ b/test/src/unit/repo/core/model/bson/ut_repo_bson_teamspace.cpp @@ -0,0 +1,81 @@ +/** +* Copyright (C) 2024 3D Repo Ltd +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as +* published by the Free Software Foundation, either version 3 of the +* License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see . +*/ + +#include +#include +#include + +#include "repo/core/model/bson/repo_bson_teamspace.h" +#include "repo/core/model/bson/repo_bson_builder.h" +#include "../../../../repo_test_utils.h" +#include "../../../../repo_test_matchers.h" + +using namespace repo::core::model; +using namespace testing; + +TEST(RepoTeamspaceTest, Deserialise) +{ + { + RepoBSONBuilder builder; + RepoBSONBuilder addOnsBuilder; + builder.append("addOns", addOnsBuilder.obj()); + + RepoTeamspace teamspace(builder.obj()); + + EXPECT_THAT(teamspace.isAddOnEnabled(REPO_USER_LABEL_VR_ENABLED), IsFalse()); + EXPECT_THAT(teamspace.isAddOnEnabled(REPO_USER_LABEL_SRC_ENABLED), IsFalse()); + } + + { + RepoBSONBuilder builder; + RepoBSONBuilder addOnsBuilder; + addOnsBuilder.append("srcEnabled", false); + addOnsBuilder.append("vrEnabled", false); + builder.append("addOns", addOnsBuilder.obj()); + + RepoTeamspace teamspace(builder.obj()); + + EXPECT_THAT(teamspace.isAddOnEnabled(REPO_USER_LABEL_SRC_ENABLED), IsFalse()); + EXPECT_THAT(teamspace.isAddOnEnabled(REPO_USER_LABEL_VR_ENABLED), IsFalse()); + } + + { + RepoBSONBuilder builder; + RepoBSONBuilder addOnsBuilder; + addOnsBuilder.append("srcEnabled", false); + addOnsBuilder.append("vrEnabled", true); + builder.append("addOns", addOnsBuilder.obj()); + + RepoTeamspace teamspace(builder.obj()); + + EXPECT_THAT(teamspace.isAddOnEnabled(REPO_USER_LABEL_SRC_ENABLED), IsFalse()); + EXPECT_THAT(teamspace.isAddOnEnabled(REPO_USER_LABEL_VR_ENABLED), IsTrue()); + } + + { + RepoBSONBuilder builder; + RepoBSONBuilder addOnsBuilder; + addOnsBuilder.append("srcEnabled", true); + addOnsBuilder.append("vrEnabled", true); + builder.append("addOns", addOnsBuilder.obj()); + + RepoTeamspace teamspace(builder.obj()); + + EXPECT_THAT(teamspace.isAddOnEnabled(REPO_USER_LABEL_SRC_ENABLED), IsTrue()); + EXPECT_THAT(teamspace.isAddOnEnabled(REPO_USER_LABEL_VR_ENABLED), IsTrue()); + } +} \ No newline at end of file diff --git a/test/src/unit/repo/core/model/bson/ut_repo_node.cpp b/test/src/unit/repo/core/model/bson/ut_repo_node.cpp index c15ce8bf8..e96e9a796 100644 --- a/test/src/unit/repo/core/model/bson/ut_repo_node.cpp +++ b/test/src/unit/repo/core/model/bson/ut_repo_node.cpp @@ -103,7 +103,7 @@ TEST(RepoNodeTest, Deserialise) builder.append(REPO_NODE_REVISION_ID, revisionId); builder.appendArray(REPO_NODE_LABEL_PARENTS, parentIds); - auto node = RepoNode(builder.obj(), {}); + auto node = RepoNode(builder.obj()); EXPECT_EQ(node.getName(), name); EXPECT_EQ(node.getSharedID(), sharedId); @@ -125,7 +125,7 @@ TEST(RepoNodeTest, DeserialiseNoSharedIDOrParents) builder.append(REPO_NODE_LABEL_NAME, name); builder.append(REPO_NODE_LABEL_ID, uniqueId); - auto node = RepoNode(builder.obj(), {}); + auto node = RepoNode(builder.obj()); EXPECT_EQ(node.getName(), name); EXPECT_EQ(node.getUniqueID(), uniqueId); @@ -144,7 +144,7 @@ TEST(RepoNodeTest, DeserialiseNoName) RepoBSONBuilder builder; builder.append(REPO_NODE_LABEL_ID, uniqueId); - auto node = RepoNode(builder.obj(), {}); + auto node = RepoNode(builder.obj()); EXPECT_TRUE(node.getName().empty()); EXPECT_EQ(node.getUniqueID(), uniqueId); @@ -271,114 +271,26 @@ TEST(RepoNodeTest, AddParentsTest) EXPECT_THAT(node.getParentIDs(), UnorderedElementsAreArray(parentIds)); } -TEST(RepoNodeTest, CloneAndAddParentTest) +TEST(RepoNodeTest, SetParentsTest) { RepoNode node; - EXPECT_FALSE(node.getParentIDs().size()); - - repo::lib::RepoUUID parent = repo::lib::RepoUUID::createUUID(); - RepoNode nodeWithParent = node.cloneAndAddParent(parent); - - ASSERT_TRUE(nodeWithParent.getParentIDs().size()); - EXPECT_NE(node, nodeWithParent); - - std::vector parentsOut = nodeWithParent.getParentIDs(); - - EXPECT_EQ(1, parentsOut.size()); - EXPECT_EQ(parent, parentsOut[0]); - - //Ensure same parent isn't added - RepoNode sameParentTest = nodeWithParent.cloneAndAddParent(parent); - - parentsOut = sameParentTest.getParentIDs(); - - ASSERT_EQ(1, parentsOut.size()); - EXPECT_EQ(parent, parentsOut[0]); - - //Try to add a parent when there's already a vector - repo::lib::RepoUUID parent2 = repo::lib::RepoUUID::createUUID(); - - RepoNode secondParentNode = nodeWithParent.cloneAndAddParent(parent2); - EXPECT_THAT(secondParentNode.getParentIDs(), UnorderedElementsAre(parent, parent2)); - - //ensure extref files are retained - std::vector file1; - std::vector file2; - - size_t fileSize = 32876; - file1.resize(fileSize); - file2.resize(fileSize); - - std::unordered_map< std::string, std::pair>> files; - files["field1"] = std::pair>("file1", file1); - files["field2"] = std::pair>("file2", file2); - - RepoNode nodeWithFiles = RepoNode(node, files); - - EXPECT_TRUE(((RepoBSON)nodeWithFiles).hasOversizeFiles()); - - RepoNode clonedNodeWithFiles = nodeWithFiles.cloneAndAddParent(parent); - - auto bson = (RepoBSON)clonedNodeWithFiles; - - EXPECT_TRUE(bson.hasOversizeFiles()); - auto mappingOut = bson.getFilesMapping(); - EXPECT_EQ(2, mappingOut.size()); -} - -TEST(RepoNodeTest, CloneAndAddParentsTest) -{ - RepoNode node; - - EXPECT_FALSE(node.getParentIDs().size()); - - std::vector parentsIn; - size_t nParents = 10; - for (size_t i = 0; i < nParents; ++i) - { - parentsIn.push_back(repo::lib::RepoUUID::createUUID()); - } - RepoNode nodeWithParent = node.cloneAndAddParent(parentsIn); - EXPECT_NE(node, nodeWithParent); - EXPECT_THAT(nodeWithParent.getParentIDs(), UnorderedElementsAreArray(parentsIn)); - - //Ensure same parent isn't added - - RepoNode sameParentTest = nodeWithParent.cloneAndAddParent(parentsIn); - EXPECT_THAT(sameParentTest.getParentIDs(), UnorderedElementsAreArray(parentsIn)); - - //Try to add a parent when there's already a vector - std::vector parent2; - for (size_t i = 0; i < nParents; ++i) - { - auto parent = repo::lib::RepoUUID::createUUID(); - parent2.push_back(parent); - parentsIn.push_back(parent); - } - RepoNode existingParentTest = sameParentTest.cloneAndAddParent(parent2); - EXPECT_THAT(existingParentTest.getParentIDs(), UnorderedElementsAreArray(parentsIn)); - - //ensure extref files are retained - std::vector file1; - std::vector file2; - - size_t fileSize = 32876; - file1.resize(fileSize); - file2.resize(fileSize); - - std::unordered_map< std::string, std::pair>> files; - files["field1"] = std::pair>("file1", file1); - files["field2"] = std::pair>("file2", file2); + auto parentIds1 = std::vector({ + repo::lib::RepoUUID::createUUID(), + repo::lib::RepoUUID::createUUID(), + }); - RepoNode nodeWithFiles = RepoNode(node, files); - RepoNode clonedNodeWithFiles = nodeWithFiles.cloneAndAddParent(parentsIn); + node.addParents(parentIds1); + EXPECT_THAT(node.getParentIDs(), UnorderedElementsAreArray(parentIds1)); - auto bson = (RepoBSON)clonedNodeWithFiles; + auto parentIds2 = std::vector({ + repo::lib::RepoUUID::createUUID(), + repo::lib::RepoUUID::createUUID(), + }); - EXPECT_TRUE(bson.hasOversizeFiles()); - auto mappingOut = bson.getFilesMapping(); - EXPECT_EQ(2, mappingOut.size()); + node.setParents(parentIds2); + + EXPECT_THAT(node.getParentIDs(), UnorderedElementsAreArray(parentIds2)); } TEST(RepoNodeTest, SetSharedIDTest) @@ -463,4 +375,43 @@ TEST(RepoNodeTest, OperatorCompareTest) EXPECT_EQ(uniqueID < uniqueID2, makeNode(uniqueID, sharedID, "14") < makeNode(uniqueID2, sharedID, "14")); EXPECT_EQ(uniqueID < uniqueID2, makeNode(uniqueID, sharedID, "15") < makeNode(uniqueID2, sharedID, "15")); EXPECT_EQ(uniqueID < uniqueID2, makeNode(uniqueID, sharedID, "16") < makeNode(uniqueID2, sharedID, "16")); +} + +TEST(RepoNodeTest, RepoNodeSetTest) +{ + // Does the MaterialNode behave correctly when added to a RepoNodeSet? + + auto node1 = new RepoNode(); + auto node2 = new RepoNode(); + + node2->setUniqueId(node1->getUniqueID()); + + // Nodes have identical unique and sharedIds + + repo::core::model::RepoNodeSet nodes; + nodes.insert(node1); + nodes.insert(node2); + + EXPECT_THAT(nodes.size(), Eq(1)); + + // Changing the unique Id of node2 makes it different from node1 + + node2->setUniqueId(repo::lib::RepoUUID::createUUID()); + nodes.insert(node2); + EXPECT_THAT(nodes.size(), Eq(2)); + + // A new node that is identical to node1 and should not be added + + auto node3 = new RepoNode(); + node3->setUniqueId(node1->getUniqueID()); + nodes.insert(node3); + EXPECT_THAT(nodes.size(), Eq(2)); + + // But giving it a sharedId will allow it to be added + node3->setSharedID(repo::lib::RepoUUID::createUUID()); + nodes.insert(node3); + EXPECT_THAT(nodes.size(), Eq(3)); + + // The current version of RepoNodeSet only considers the shared and uniqueIds, + // not the sEqual response. } \ No newline at end of file diff --git a/test/src/unit/repo/core/model/bson/ut_repo_node_material.cpp b/test/src/unit/repo/core/model/bson/ut_repo_node_material.cpp index ce4ab91f3..68e365465 100644 --- a/test/src/unit/repo/core/model/bson/ut_repo_node_material.cpp +++ b/test/src/unit/repo/core/model/bson/ut_repo_node_material.cpp @@ -40,6 +40,24 @@ std::vector makeColour() }); } +static repo_material_t makeRandomMaterialStruct() +{ + repo_material_t matProp; + for (int i = 0; i < 3; ++i) + { + matProp.ambient.push_back(rand() / 100.f); + matProp.diffuse.push_back(rand() / 100.f); + matProp.specular.push_back(rand() / 100.f); + matProp.emissive.push_back(rand() / 100.f); + matProp.opacity = rand() / 100.f; + matProp.shininess = rand() / 100.f; + matProp.shininessStrength = rand() / 100.f; + matProp.isWireframe = rand() % 2; + matProp.isTwoSided = rand() % 2; + } + return matProp; +} + static MaterialNode makeRandomMaterial( repo_material_t &matProp) { diff --git a/test/src/unit/repo/core/model/bson/ut_repo_node_mesh.cpp b/test/src/unit/repo/core/model/bson/ut_repo_node_mesh.cpp index 258c490b3..b3883151a 100644 --- a/test/src/unit/repo/core/model/bson/ut_repo_node_mesh.cpp +++ b/test/src/unit/repo/core/model/bson/ut_repo_node_mesh.cpp @@ -564,12 +564,18 @@ TEST(MeshNodeTest, CopyConstructor) auto b = a; EXPECT_THAT(a.sEqual(b), IsTrue()); + EXPECT_THAT(a.getParentIDs(), UnorderedElementsAreArray(b.getParentIDs())); + EXPECT_THAT(a.getSharedID(), b.getSharedID()); + EXPECT_THAT(a.getUniqueID(), b.getUniqueID()); b.setFaces(makeFaces(MeshNode::Primitive::TRIANGLES)); EXPECT_THAT(a.sEqual(b), IsFalse()); auto c = new MeshNode(a); EXPECT_THAT(a.sEqual(*c), IsTrue()); + EXPECT_THAT(a.getParentIDs(), UnorderedElementsAreArray(c->getParentIDs())); + EXPECT_THAT(a.getSharedID(), c->getSharedID()); + EXPECT_THAT(a.getUniqueID(), c->getUniqueID()); c->setFaces(makeFaces(MeshNode::Primitive::TRIANGLES)); EXPECT_THAT(a.sEqual(*c), IsFalse()); @@ -578,6 +584,9 @@ TEST(MeshNodeTest, CopyConstructor) auto d = makeNewMeshNode(); EXPECT_THAT(a.sEqual(*d), IsTrue()); + EXPECT_THAT(a.getParentIDs(), UnorderedElementsAreArray(d->getParentIDs())); + EXPECT_THAT(a.getSharedID(), d->getSharedID()); + EXPECT_THAT(a.getUniqueID(), d->getUniqueID()); d->setFaces(makeFaces(MeshNode::Primitive::TRIANGLES)); EXPECT_THAT(a.sEqual(*d), IsFalse()); @@ -586,6 +595,9 @@ TEST(MeshNodeTest, CopyConstructor) auto e = makeRefMeshNode(); EXPECT_THAT(a.sEqual(e), IsTrue()); + EXPECT_THAT(a.getParentIDs(), UnorderedElementsAreArray(e.getParentIDs())); + EXPECT_THAT(a.getSharedID(), e.getSharedID()); + EXPECT_THAT(a.getUniqueID(), e.getUniqueID()); e.setFaces(makeFaces(MeshNode::Primitive::TRIANGLES)); EXPECT_THAT(a.sEqual(e), IsFalse()); diff --git a/test/src/unit/repo_test_mesh_utils.cpp b/test/src/unit/repo_test_mesh_utils.cpp index ed6175696..8b7ec6411 100644 --- a/test/src/unit/repo_test_mesh_utils.cpp +++ b/test/src/unit/repo_test_mesh_utils.cpp @@ -15,6 +15,8 @@ * along with this program. If not, see . */ +#define NOMINMAX + #include #include #include