1 #include "otsdaq/ConfigurationInterface/ConfigurationManager.h"
2 #include "otsdaq/Macros/TablePluginMacros.h"
3 #include "otsdaq/TablePlugins/DesktopIconTable.h"
4 #include "otsdaq/TablePlugins/XDAQContextTable/XDAQContextTable.h"
6 #include "otsdaq/WebUsersUtilities/WebUsers.h"
13 #define DESKTOP_ICONS_FILE \
14 std::string(__ENV__("SERVICE_DATA_PATH")) + "/OtsWizardData/iconList.dat"
19 const std::string DesktopIconTable::COL_STATUS = TableViewColumnInfo::COL_NAME_STATUS;
20 const std::string DesktopIconTable::COL_CAPTION =
"Caption";
21 const std::string DesktopIconTable::COL_ALTERNATE_TEXT =
"AlternateText";
22 const std::string DesktopIconTable::COL_FORCE_ONLY_ONE_INSTANCE =
"ForceOnlyOneInstance";
23 const std::string DesktopIconTable::COL_PERMISSIONS =
"RequiredPermissionLevel";
24 const std::string DesktopIconTable::COL_IMAGE_URL =
"ImageURL";
25 const std::string DesktopIconTable::COL_WINDOW_CONTENT_URL =
"WindowContentURL";
26 const std::string DesktopIconTable::COL_APP_LINK =
"LinkToApplicationTable";
27 const std::string DesktopIconTable::COL_APP_LINK_UID =
"LinkToApplicationUID";
29 const std::string DesktopIconTable::COL_PARAMETER_LINK =
"LinkToParameterTable";
30 const std::string DesktopIconTable::COL_PARAMETER_LINK_GID =
"LinkToParameterGroupID";
31 const std::string DesktopIconTable::COL_FOLDER_PATH =
"FolderPath";
33 const std::string DesktopIconTable::COL_PARAMETER_GID =
"windowParameterGroupID";
34 const std::string DesktopIconTable::COL_PARAMETER_KEY =
"windowParameterKey";
35 const std::string DesktopIconTable::COL_PARAMETER_VALUE =
"windowParameterValue";
37 const std::string DesktopIconTable::ICON_TABLE =
38 ConfigurationManager::DESKTOP_ICON_TABLE_NAME;
39 const std::string DesktopIconTable::PARAMETER_TABLE =
"DesktopWindowParameterTable";
68 DesktopIconTable::~DesktopIconTable(
void) {}
78 auto childrenMap = configManager->__SELF_NODE__.
getChildren();
81 configManager->
getNode(ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME);
83 ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME);
88 activeDesktopIcons_.clear();
94 for(
auto& child : childrenMap)
96 if(!child.second.getNode(COL_STATUS).getValue<
bool>())
101 icon = &(activeDesktopIcons_.back());
103 icon->recordUID_ = child.first;
104 icon->caption_ = child.second.getNode(COL_CAPTION).getValue<std::string>();
105 icon->alternateText_ =
106 child.second.getNode(COL_ALTERNATE_TEXT).getValue<std::string>();
107 icon->enforceOneWindowInstance_ =
108 child.second.getNode(COL_FORCE_ONLY_ONE_INSTANCE).getValue<
bool>();
110 child.second.getNode(COL_PERMISSIONS).getValueWithDefault<std::string>(
"1");
111 icon->imageURL_ = child.second.getNode(COL_IMAGE_URL).getValue<std::string>();
112 icon->windowContentURL_ =
113 child.second.getNode(COL_WINDOW_CONTENT_URL).getValue<std::string>();
115 child.second.getNode(COL_FOLDER_PATH).getValueWithDefault<std::string>(
"");
117 if(icon->windowContentURL_.size() == 0)
119 __SS__ <<
"Illegal empty URL in Desktop Icon '" << child.first <<
"'"
140 icon->caption_ = removeCommas(
141 icon->caption_,
false ,
true );
142 icon->alternateText_ = removeCommas(
143 icon->alternateText_,
false ,
true );
144 icon->imageURL_ = removeCommas(icon->imageURL_,
true );
145 icon->windowContentURL_ =
146 removeCommas(icon->windowContentURL_,
true );
147 icon->folderPath_ = removeCommas(
148 icon->folderPath_,
false ,
true );
156 if(icon->windowContentURL_.size() && icon->windowContentURL_[0] ==
'/')
172 <<
"' is disabled, which will likely break the behavior of "
174 << child.first <<
".' To fix, reenable the target app."
178 if(contextUID != gatewayContextUID)
182 contextTableNode.
getNode(contextUID);
187 <<
"Warning! The parent context '" << contextUID
189 <<
"' is disabled, which will likely break the behavior "
190 "of the Desktop Icon '"
192 <<
".' To fix, reenable the target app's parent context."
195 std::string contextAddress =
196 contextNode.
getNode(XDAQContextTable::colContext_.colAddress_)
198 unsigned int contextPort =
199 contextNode.
getNode(XDAQContextTable::colContext_.colPort_)
203 icon->windowContentURL_ = contextAddress +
":" +
204 std::to_string(contextPort) +
205 icon->windowContentURL_;
209 catch(
const std::runtime_error& e)
211 __SS__ <<
"Error finding XDAQ Application origin which was linked to "
213 << child.first <<
"': " << e.what() << __E__;
214 ss <<
"\n\nPlease fix by disabling the Icon, enabling the App or "
215 "fixing the link in the Configurate Tree."
223 if(icon->windowContentURL_[icon->windowContentURL_.size() - 1] !=
'=')
225 if(icon->windowContentURL_.find(
'?') ==
227 icon->windowContentURL_ +=
"?urn=";
229 icon->windowContentURL_ +=
"&urn=";
234 icon->windowContentURL_ += std::to_string(intVal);
242 if(!child.second.getNode(COL_PARAMETER_LINK).isDisconnected())
246 if(icon->windowContentURL_.find(
'?') == std::string::npos)
247 icon->windowContentURL_ +=
'?';
248 else if(addedAppId ||
249 icon->windowContentURL_[icon->windowContentURL_.size() - 1] !=
251 icon->windowContentURL_ +=
'&';
254 auto paramGroupMap = child.second.getNode(COL_PARAMETER_LINK).getChildren();
255 bool notFirst =
false;
256 for(
const auto& param : paramGroupMap)
258 if(!param.second.isEnabled())
262 icon->windowContentURL_ +=
'&';
265 icon->windowContentURL_ +=
266 StringMacros::encodeURIComponent(
267 param.second.getNode(COL_PARAMETER_KEY).getValue<std::string>()) +
269 StringMacros::encodeURIComponent(
270 param.second.getNode(COL_PARAMETER_VALUE)
271 .getValue<std::string>());
281 const std::string& localURL,
282 bool doForWizMode )
const
284 std::string contextAddress;
287 configManager->
getNode(ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME);
289 ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME);
294 contextAddress = contextNode.
getNode(XDAQContextTable::colContext_.colAddress_)
296 unsigned int contextPort =
297 contextNode.
getNode(XDAQContextTable::colContext_.colPort_)
303 "OTS_REMOTE_ICONS_NO_PORT_FOWARDING"))
304 contextAddress +=
":" + std::to_string(contextPort);
306 contextAddress = std::string(
"http://") +
"localhost" +
":" +
307 std::to_string(contextPort);
311 __COUTT__ <<
"Ignoring missing environment variable "
312 "OTS_REMOTE_ICONS_NO_PORT_FOWARDING, and assuming localhost "
313 "port forwarding to web browser."
316 std::string(
"http://") +
"localhost" +
":" + std::to_string(contextPort);
322 __COUTTV__(localURL);
323 if(localURL.size() && localURL[0] ==
'/')
324 retURL = contextAddress + localURL;
333 if(retURL.find(
'?') == std::string::npos)
335 else if(retURL[retURL.size() - 1] !=
'?')
338 "remoteServerOrigin=" + StringMacros::encodeURIComponent(contextAddress) +
339 "&remoteServerUrnLid=" +
340 std::to_string(doForWizMode ? XDAQContextTable::XDAQApplication::WIZMODE_APP_ID
341 : XDAQContextTable::XDAQApplication::GATEWAY_APP_ID);
344 retURL +=
"&forcedWizMode=1";
351 std::string DesktopIconTable::removeCommas(
const std::string& str,
355 std::string retStr =
"";
356 retStr.reserve(str.length());
358 for(
unsigned int i = 0; i < str.length(); ++i)
361 else if(andHexReplace)
363 else if(andHTMLReplace)
371 const std::vector<DesktopIconTable::DesktopIcon>& newIcons)
373 activeDesktopIcons_.clear();
374 for(
const auto& newIcon : newIcons)
375 activeDesktopIcons_.push_back(newIcon);
ConfigurationTree getNode(const std::string &nodeString, bool doNotThrowOnBrokenUIDLinks=false) const
"root/parent/parent/"
const T * getTable(const std::string &tableName) const
std::vector< std::pair< std::string, ConfigurationTree > > getChildren(std::map< std::string, TableVersion > *memberMap=0, std::string *accumulatedTreeErrors=0) const
bool isDisconnected(void) const
ConfigurationTree getNode(const std::string &nodeName, bool doNotThrowOnBrokenUIDLinks=false) const
navigating between nodes
const std::string & getValueAsString(bool returnLinkTableValue=false) const
void getValue(T &value) const
std::string getRemoteURL(ConfigurationManager *configManager, const std::string &localURL, bool doForWizMode=false) const
Convert to remote URL assuming port forwarding to primary Gateway Port.
void init(ConfigurationManager *configManager)
Methods.
void setAllDesktopIcons(const std::vector< DesktopIconTable::DesktopIcon > &newIcons)
overwrite dynamically the init result
static const std::string COL_APP_ID
XDAQ App Column names.
static const std::string COL_NAME
std::string getContextOfApplication(ConfigurationManager *configManager, const std::string &appUID, bool allowOffContexts=false) const
only considers ON contexts and applications, unless off contexts allows
std::string getContextOfGateway(ConfigurationManager *configManager) const
only considers ON contexts and applications
defines used also by OtsConfigurationWizardSupervisor
std::string permissionThresholdString_