18#include <Poco/ActiveResult.h>
24std::vector<std::string> namesOfFacilitiesWithICAT() {
25 const auto &config = Kernel::ConfigService::Instance();
27 const auto facilityDoesNotHaveICAT = [&](
const std::string &
name) {
28 return config.getFacility(
name).catalogInfo().soapEndPoint().empty();
31 auto result = Kernel::ConfigService::Instance().getFacilityNames();
32 result.erase(std::remove_if(result.begin(), result.end(), facilityDoesNotHaveICAT), result.end());
37std::string defaultFacility() {
42 const auto facility = Kernel::ConfigService::Instance().getFacility().name();
43 const auto facilitiesWithICAT = namesOfFacilitiesWithICAT();
44 if (std::find(facilitiesWithICAT.begin(), facilitiesWithICAT.end(), facility) != facilitiesWithICAT.end()) {
48 if (facilitiesWithICAT.size() > 0) {
49 return facilitiesWithICAT[0];
58 auto requireValue = std::make_shared<Kernel::MandatoryValidator<std::string>>();
59 declareProperty(
"Username",
"", requireValue,
"The username to log into the catalog.");
61 "The password of the related username to use.");
63 std::make_shared<Kernel::StringListValidator>(namesOfFacilitiesWithICAT()),
64 "Select a facility to log in to.");
65 declareProperty(
"KeepSessionAlive",
true,
"Keeps the session of the catalog alive if login was successful.");
66 declareProperty(std::make_unique<API::AlgorithmProperty>(
"KeepAlive", std::make_shared<Kernel::NullValidator>(),
68 "A handle to the KeepAlive algorithm instance that continues "
69 "to keep the catalog alive after this algorithm completes.");
74 auto catalogInfo = Kernel::ConfigService::Instance().getFacility(
getProperty(
"FacilityName")).catalogInfo();
75 if (catalogInfo.soapEndPoint().empty())
76 throw std::runtime_error(
"There is no soap end-point for the facility you have selected.");
78 g_log.
notice() <<
"Attempting to verify user credentials against " << catalogInfo.catalogName() <<
'\n';
79 progress(0.5,
"Verifying user credentials...");
86 catalogInfo.soapEndPoint(),
getProperty(
"FacilityName"));
88 progress(0,
"Keeping current sessions alive.");
91 auto keepAliveAlgorithm = API::AlgorithmManager::Instance().create(
"CatalogKeepAlive");
92 keepAliveAlgorithm->initialize();
93 keepAliveAlgorithm->setPropertyValue(
"Session", session->getSessionId());
94 keepAliveAlgorithm->executeAsync();
#define DECLARE_ALGORITHM(classname)
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
void exec() override
Overwrites Algorithm method.
void init() override
Overwrites Algorithm method.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void notice(const std::string &msg)
Logs at notice level.
A property class for masking the properties.
@ Output
An output workspace.