Skip to content

Commit

Permalink
ISSUE #703 refactored header files, updated more types to be repo doc…
Browse files Browse the repository at this point in the history
…uments and removed all instances of cloneAndAddParent
  • Loading branch information
sebjf committed Oct 15, 2024
1 parent 894183b commit f241d3b
Show file tree
Hide file tree
Showing 62 changed files with 730 additions and 631 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#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;

Expand Down
5 changes: 3 additions & 2 deletions bouncer/src/repo/core/handler/fileservice/repo_data_ref.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@

#include <string>

#include "../../../core/model/bson/repo_bson_builder.h"

namespace repo {
namespace core {
namespace model {
class RepoBSON;
}
namespace handler {
namespace fileservice {
class DataRef {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
#include <unordered_map>
#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:
Expand Down Expand Up @@ -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
Expand Down
17 changes: 14 additions & 3 deletions bouncer/src/repo/core/handler/repo_database_handler_mongo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}
21 changes: 9 additions & 12 deletions bouncer/src/repo/core/handler/repo_database_handler_mongo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 --------------
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions bouncer/src/repo/core/model/bson/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 1 addition & 7 deletions bouncer/src/repo/core/model/bson/repo_bson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,18 +232,12 @@ std::vector<repo::lib::RepoUUID> RepoBSON::getUUIDFieldArray(const std::string &
if (hasField(label))
{
RepoBSON array = getObjectField(label);

if (!array.isEmpty())
{
std::set<std::string> fields = array.getFieldNames();

std::set<std::string>::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
}
}

Expand Down
14 changes: 7 additions & 7 deletions bouncer/src/repo/core/model/bson/repo_bson.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion bouncer/src/repo/core/model/bson/repo_bson_assets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
68 changes: 68 additions & 0 deletions bouncer/src/repo/core/model/bson/repo_bson_calibration.cpp
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

#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<repo::lib::RepoVector3D>& horizontal3d,
const std::vector<repo::lib::RepoVector2D>& 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<float> >(REPO_LABEL_MODEL, {
horizontal3d[0].toStdVector(),
horizontal3d[1].toStdVector()
});
horizontalBuilder.appendArray< std::vector<float> >(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();
}
30 changes: 25 additions & 5 deletions bouncer/src/repo/core/model/bson/repo_bson_calibration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <vector>

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<repo::lib::RepoVector3D>& horizontal3d,
const std::vector<repo::lib::RepoVector2D>& 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<repo::lib::RepoVector3D> horizontal3d;
std::vector<repo::lib::RepoVector2D> horizontal2d;
std::string units;
};
}// end namespace model
} // end namespace core
Expand Down
40 changes: 11 additions & 29 deletions bouncer/src/repo/core/model/bson/repo_bson_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

#include <boost/filesystem.hpp>

#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;

Expand All @@ -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;
}
Expand Down Expand Up @@ -228,32 +228,14 @@ RepoCalibration repo::core::model::RepoBSONFactory::makeRepoCalibration(
const std::vector<repo::lib::RepoVector2D>& 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<float> >(REPO_LABEL_MODEL, {
horizontal3d[0].toStdVector(),
horizontal3d[1].toStdVector()
});
horizontalBuilder.appendArray< std::vector<float> >(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(
Expand Down
Loading

0 comments on commit f241d3b

Please sign in to comment.