diff --git a/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPlugin.cpp b/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPlugin.cpp index 00744b11d81ffda9dbb9767d3f10d4f106353d40..595f68609f18eecf0939709561e80cdd56bdf738 100644 --- a/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPlugin.cpp +++ b/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPlugin.cpp @@ -1331,12 +1331,41 @@ 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__)}; + } + + // create idempotent id with parent id as namespace + const auto& parentId = createUuidWithString(profile.parentPtr->id); + const auto& id = createUuidWithString(profile.name, parentId); + const auto& idStr = boost::uuids::to_string(id); std::unique_lock l(fluxioDC.profilesMutex); - 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]; + if (fluxioDC.profiles.find(idStr) != 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__)}; + } + + fluxioDC.profiles[idStr] = + profile; // a copy is created when the profile is added to the map + fluxioDC.profiles[idStr].id = idStr; // this copy can then be modified + const auto& ret = fluxioDC.profiles[idStr]; l.unlock(); return {ret};