diff --git a/source/RobotAPI/libraries/skills/core/error/FluxioErrorMessages.cpp b/source/RobotAPI/libraries/skills/core/error/FluxioErrorMessages.cpp index bb020804c311bfd85b86a384d2a471dd465d2d9e..e49dc59719f84ac5372c515633247436482fc4a9 100644 --- a/source/RobotAPI/libraries/skills/core/error/FluxioErrorMessages.cpp +++ b/source/RobotAPI/libraries/skills/core/error/FluxioErrorMessages.cpp @@ -60,6 +60,12 @@ namespace armarx::skills::error return formatString("This is a test Error with Argument: '%s'", args); case ErrorCode::ProviderAlreadyExists: return formatString("Provider with ID '%s' already exists.", args); + case ErrorCode::ProfileHasNoParent: + return formatString("Profile with name: '%s' could not be added because it has no " + "Parent Profile assigned.", + args); + case ErrorCode::ProfileAlreadyExists: + return formatString("Profile with name: '%s' already exists.", args); default: return "Unknown error."; } diff --git a/source/RobotAPI/libraries/skills/core/error/FluxioErrorMessages.h b/source/RobotAPI/libraries/skills/core/error/FluxioErrorMessages.h index 94663239de2da22b2bea1e703e11b6c8ec3b761f..9c8e64ebf3f214ce11f99230e95add483b54cb24 100644 --- a/source/RobotAPI/libraries/skills/core/error/FluxioErrorMessages.h +++ b/source/RobotAPI/libraries/skills/core/error/FluxioErrorMessages.h @@ -18,7 +18,9 @@ namespace armarx::skills::error AddSkillError, ProviderAlreadyExists, ConverterError, - TestError + TestError, + ProfileHasNoParent, + ProfileAlreadyExists }; std::string formatString(const std::string& format, const std::vector<std::string>& args); diff --git a/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPlugin.cpp b/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPlugin.cpp index 00744b11d81ffda9dbb9767d3f10d4f106353d40..a90d04e34ac89c3b420c3841a6d6043fb96e8060 100644 --- a/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPlugin.cpp +++ b/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPlugin.cpp @@ -13,6 +13,7 @@ #include <utility> #include <vector> +#include <boost/algorithm/string/case_conv.hpp> #include <boost/locale.hpp> #include <boost/uuid/name_generator.hpp> #include <boost/uuid/nil_generator.hpp> @@ -1331,9 +1332,54 @@ namespace armarx::plugins skills::Result<skills::FluxioProfile, skills::error::FluxioException> SkillManagerComponentPlugin::createProfile(const skills::FluxioProfile& profile) { - std::string id = IceUtil::generateUUID(); + if (profile.parentPtr == nullptr) + { + ARMARX_WARNING << "Profile with name '" << profile.name << "' has no parent."; + return {skills::error::FluxioException::create( + skills::error::createErrorMessage(skills::error::ErrorCode::ProfileHasNoParent, + {profile.name}), + skills::error::FluxioExceptionType::BAD_REQUEST, + "SkillManagerComponentPlugin", + __FUNCTION__, + __LINE__)}; + } + + const auto& parentId = profile.parentPtr->id; + const auto& nameLowerCase = boost::algorithm::to_lower_copy(profile.name); std::unique_lock l(fluxioDC.profilesMutex); + if (std::find_if(fluxioDC.profiles.begin(), + fluxioDC.profiles.end(), + [&profile, &parentId, &nameLowerCase](auto& p) + { + return nameLowerCase == "root" || + (p.parentPtr != nullptr && profile.parentPtr->id == parentId && + boost::algorithm::to_lower(p.second.name) == nameLowerCase); + }) != fluxioDC.profiles.end()) + { + ARMARX_WARNING << "Profile with name '" << profile.name << "' already exists."; + l.unlock(); + return {skills::error::FluxioException::create( + skills::error::createErrorMessage(skills::error::ErrorCode::ProfileAlreadyExists, + {profile.name}), + skills::error::FluxioExceptionType::BAD_REQUEST, + "SkillManagerComponentPlugin", + __FUNCTION__, + __LINE__)}; + } + + std::string id; + if (fluxioDC.profiles.find(profile.id) != fluxioDC.profiles.end()) + { + ARMARX_INFO << "The id '" << profile.id + << "' is already taken. A new uuid will be generated."; + id = IceUtil::generateUUID(); + } + else + { + id = profile.id; + } + fluxioDC.profiles[id] = profile; // a copy is created when the profile is added to the map fluxioDC.profiles[id].id = id; // this copy can then be modified const auto& ret = fluxioDC.profiles[id]; @@ -1501,6 +1547,10 @@ namespace armarx::plugins // its a new skill, its a new world, ... skill.id = IceUtil::generateUUID(); } + else + { + // TODO(me): check if a skill with the same id already exists + } boost::uuids::uuid uuid; try