Skip to content
Snippets Groups Projects
Commit eb56dcac authored by David Fairbrother's avatar David Fairbrother
Browse files

Re #22901 Add option for getObjects to return hidden

Previously getObjects in the ADS returned hidden workspaces
conditionally depending on the config setting. This commit adds an
option building on previous work completed in getObjectNames().

Allowing callers to specify whether to include hidden workspaces is
required for project recovery. The hidden workspace history can then be
saved out
parent b1fa64f9
Branches 22661_correct_save_format_empty_issue
No related tags found
No related merge requests found
......@@ -482,15 +482,23 @@ public:
}
/// Get a vector of the pointers to the data objects stored by the service
std::vector<boost::shared_ptr<T>> getObjects() const {
std::vector<boost::shared_ptr<T>> getObjects(DataServiceHidden includeHidden = DataServiceHidden::Auto) const {
std::lock_guard<std::recursive_mutex> _lock(m_mutex);
const bool showingHidden = showingHiddenObjects();
if (includeHidden == DataServiceHidden::Include) {
// Return all elements including hidden ones
}
const bool alwaysIncludeHidden = includeHidden == DataServiceHidden::Include;
const bool usingAuto = includeHidden == DataServiceHidden::Auto && showingHiddenObjects();
const bool showingHidden = alwaysIncludeHidden || usingAuto;
std::vector<boost::shared_ptr<T>> objects;
objects.reserve(datamap.size());
for (auto it = datamap.begin(); it != datamap.end(); ++it) {
if (showingHidden || !isHiddenDataServiceObject(it->first)) {
objects.push_back(it->second);
for (const auto &it : datamap) {
if (showingHidden || !isHiddenDataServiceObject(it.first)) {
objects.push_back(it.second);
}
}
return objects;
......
......@@ -6,6 +6,9 @@
#include <cxxtest/TestSuite.h>
#include <Poco/NObserver.h>
#include <boost/make_shared.hpp>
#include <iostream>
#include <sstream>
#include <mutex>
using namespace Mantid;
......@@ -327,6 +330,84 @@ public:
TS_ASSERT_EQUALS(objects.at(std::distance(names.cbegin(), cit)), three);
}
void test_getObjectsReturnsConfigOption() {
svc.clear();
ConfigService::Instance().setString("MantidOptions.InvisibleWorkspaces",
"0");
auto one = boost::make_shared<int>(1);
auto two = boost::make_shared<int>(2);
auto three = boost::make_shared<int>(3);
svc.add("One", one);
svc.add("Two", two);
svc.add("TwoAgain",
two); // Same pointer again - should appear twice in getObjects()
svc.add("__Three", three);
auto objects = svc.getObjects(DataServiceHidden::Auto);
auto objectsDefaultCall = svc.getObjects();
TSM_ASSERT_EQUALS("Default parameter is not set to auto", objects, objectsDefaultCall);
TSM_ASSERT_EQUALS("Hidden entries should not be returned", objects.size(),
3);
// Check the hidden ws isn't present
TS_ASSERT_EQUALS(objects.at(0), one);
TS_ASSERT_EQUALS(objects.at(1), two);
TS_ASSERT_EQUALS(objects.at(2), two);
TSM_ASSERT_EQUALS("Hidden entries should not be returned", std::find(objects.cbegin(), objects.cend(), three),
objects.end());
ConfigService::Instance().setString("MantidOptions.InvisibleWorkspaces",
"1");
objects = svc.getObjects();
TS_ASSERT_EQUALS(objects.size(), 4);
}
void test_getObjectsReturnsNoHiddenOption() {
svc.clear();
ConfigService::Instance().setString("MantidOptions.InvisibleWorkspaces",
"1");
auto one = boost::make_shared<int>(1);
auto two = boost::make_shared<int>(2);
auto three = boost::make_shared<int>(3);
svc.add("One", one);
svc.add("Two", two);
svc.add("__Three", three);
auto objects = svc.getObjects(DataServiceHidden::Exclude);
TSM_ASSERT_EQUALS("Hidden entries should not be returned", objects.size(),
2);
// Check the hidden ws isn't present
TS_ASSERT_EQUALS(objects.at(0), one);
TS_ASSERT_EQUALS(objects.at(1), two);
TSM_ASSERT_EQUALS("Hidden entries should not be returned", std::find(objects.cbegin(), objects.cend(), three),
objects.end());
}
void test_getObjectsReturnsHiddenOption() {
svc.clear();
ConfigService::Instance().setString("MantidOptions.InvisibleWorkspaces",
"0");
auto one = boost::make_shared<int>(1);
auto two = boost::make_shared<int>(2);
auto three = boost::make_shared<int>(3);
svc.add("One", one);
svc.add("Two", two);
svc.add("__Three", three);
auto objects = svc.getObjects(DataServiceHidden::Include);
TSM_ASSERT_EQUALS("Hidden entries should be returned", objects.size(),
3);
// Check the hidden ws isn't present
TS_ASSERT_DIFFERS(std::find(objects.begin(), objects.end(), one), objects.end());
TS_ASSERT_DIFFERS(std::find(objects.begin(), objects.end(), two), objects.end());
TSM_ASSERT_DIFFERS("Hidden entries should be returned", std::find(objects.cbegin(), objects.cend(), three),
objects.end());
}
void test_sortedAndHiddenGetNames() {
auto one = boost::make_shared<int>(1);
auto two = boost::make_shared<int>(2);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment