diff --git a/src/terrama2/core/data-model/DataManager.cpp b/src/terrama2/core/data-model/DataManager.cpp index 4042d6e90..11ed9da74 100644 --- a/src/terrama2/core/data-model/DataManager.cpp +++ b/src/terrama2/core/data-model/DataManager.cpp @@ -395,6 +395,14 @@ terrama2::core::DataProviderPtr terrama2::core::DataManager::findDataProvider(co return it->second; } +bool terrama2::core::DataManager::hasProject(ProjectId id) const +{ + std::lock_guard lock(mtx_); + + const auto& it = projects_.find(id); + return it != projects_.cend(); +} + bool terrama2::core::DataManager::hasDataProvider(DataProviderId id) const { std::lock_guard lock(mtx_); @@ -470,7 +478,7 @@ void terrama2::core::DataManager::addJSon(const QJsonObject& obj) for(auto json : projects) { auto dataPtr = terrama2::core::fromProjectJson(json.toObject()); - if(hasDataProvider(dataPtr->id)) + if(hasProject(dataPtr->id)) update(dataPtr); else add(dataPtr); diff --git a/src/terrama2/core/data-model/DataManager.hpp b/src/terrama2/core/data-model/DataManager.hpp index b2d315d5e..618ab4202 100644 --- a/src/terrama2/core/data-model/DataManager.hpp +++ b/src/terrama2/core/data-model/DataManager.hpp @@ -394,6 +394,17 @@ namespace terrama2 */ virtual DataProviderPtr findDataProvider(const DataProviderId id) const; + /*! + \brief Verify if a given DataProvider exist + + \param id ID of the DataProvider + + \pre The DataProvider must not have a terrama2::core::InvalidId. + + \note Thread-safe. + */ + virtual bool hasProject(ProjectId id) const; + /*! \brief Verify if a given DataProvider exist