1 #include "otsdaq/ConfigurationInterface/ConfigurationManager.h"
2 #include "otsdaq/Macros/TablePluginMacros.h"
3 #include "otsdaq/TablePlugins/DesktopIconTable.h"
4 #include "otsdaq/TablePlugins/XDAQContextTable.h"
6 #include "otsdaq/WebUsersUtilities/WebUsers.h"
13 #define DESKTOP_ICONS_FILE std::string(__ENV__("SERVICE_DATA_PATH")) + "/OtsWizardData/iconList.dat"
17 const std::string DesktopIconTable::COL_NAME =
"IconName";
18 const std::string DesktopIconTable::COL_STATUS = TableViewColumnInfo::COL_NAME_STATUS;
19 const std::string DesktopIconTable::COL_CAPTION =
"Caption";
20 const std::string DesktopIconTable::COL_ALTERNATE_TEXT =
"AlternateText";
21 const std::string DesktopIconTable::COL_FORCE_ONLY_ONE_INSTANCE =
"ForceOnlyOneInstance";
22 const std::string DesktopIconTable::COL_PERMISSIONS =
"RequiredPermissionLevel";
23 const std::string DesktopIconTable::COL_IMAGE_URL =
"ImageURL";
24 const std::string DesktopIconTable::COL_WINDOW_CONTENT_URL =
"WindowContentURL";
25 const std::string DesktopIconTable::COL_APP_LINK =
"LinkToApplicationTable";
26 const std::string DesktopIconTable::COL_APP_LINK_UID =
"LinkToApplicationUID";
28 const std::string DesktopIconTable::COL_PARAMETER_LINK =
"LinkToParameterTable";
29 const std::string DesktopIconTable::COL_PARAMETER_LINK_GID =
"LinkToParameterGroupID";
30 const std::string DesktopIconTable::COL_FOLDER_PATH =
"FolderPath";
32 const std::string DesktopIconTable::COL_PARAMETER_GID =
"windowParameterGroupID";
33 const std::string DesktopIconTable::COL_PARAMETER_KEY =
"windowParameterKey";
34 const std::string DesktopIconTable::COL_PARAMETER_VALUE =
"windowParameterValue";
36 const std::string DesktopIconTable::ICON_TABLE =
"DesktopIconTable";
37 const std::string DesktopIconTable::PARAMETER_TABLE =
"DesktopWindowParameterTable";
54 const std::string DesktopIconTable::COL_APP_ID =
"Id";
61 std::system((
"rm -rf " + (std::string)DESKTOP_ICONS_FILE).c_str());
69 DesktopIconTable::~DesktopIconTable(
void) {}
79 auto childrenMap = configManager->__SELF_NODE__.getChildren();
81 ConfigurationTree contextTableNode = configManager->getNode(ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME);
83 configManager->getTable<
XDAQContextTable>(ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME);
86 std::string gatewayContextUID = contextTable->getContextOfGateway(configManager);
90 activeDesktopIcons_.clear();
96 for(
auto& child : childrenMap)
98 if(!child.second.getNode(COL_STATUS).getValue<
bool>())
103 icon = &(activeDesktopIcons_.back());
105 icon->caption_ = child.second.getNode(COL_CAPTION).getValue<std::string>();
106 icon->alternateText_ = child.second.getNode(COL_ALTERNATE_TEXT).getValue<std::string>();
107 icon->enforceOneWindowInstance_ = child.second.getNode(COL_FORCE_ONLY_ONE_INSTANCE).getValue<
bool>();
108 icon->permissionThresholdString_ = child.second.getNode(COL_PERMISSIONS).getValue<std::string>();
109 icon->imageURL_ = child.second.getNode(COL_IMAGE_URL).getValue<std::string>();
110 icon->windowContentURL_ = child.second.getNode(COL_WINDOW_CONTENT_URL).getValue<std::string>();
111 icon->folderPath_ = child.second.getNode(COL_FOLDER_PATH).getValue<std::string>();
113 if(icon->folderPath_ == TableViewColumnInfo::DATATYPE_STRING_DEFAULT)
114 icon->folderPath_ =
"";
116 if(icon->permissionThresholdString_ == TableViewColumnInfo::DATATYPE_STRING_DEFAULT)
117 icon->permissionThresholdString_ =
"1";
120 for(i = 0; i < icon->permissionThresholdString_.size(); ++i)
121 if(!(icon->permissionThresholdString_[i] >=
'0' && icon->permissionThresholdString_[i] <=
'9'))
129 icon->permissionThresholdString_ = WebUsers::DEFAULT_USER_GROUP +
":" + icon->permissionThresholdString_;
133 icon->caption_ = removeCommas(icon->caption_,
false ,
true );
134 icon->alternateText_ = removeCommas(icon->alternateText_,
false ,
true );
135 icon->imageURL_ = removeCommas(icon->imageURL_,
true );
136 icon->windowContentURL_ = removeCommas(icon->windowContentURL_,
true );
137 icon->folderPath_ = removeCommas(icon->folderPath_,
false ,
true );
142 if(!appLink.isDisconnected())
146 if(icon->windowContentURL_.size() && icon->windowContentURL_[0] ==
'/')
152 std::string contextUID = contextTable->getContextOfApplication(configManager,
153 appLink.getValueAsString());
157 if(contextUID != gatewayContextUID)
163 contextTableNode.getNode(contextUID);
165 std::string contextAddress = contextNode.getNode(
166 XDAQContextTable::colContext_.colAddress_).getValue<std::string>();
167 unsigned int contextPort = contextNode.getNode(
168 XDAQContextTable::colContext_.colPort_).getValue<
unsigned int>();
171 icon->windowContentURL_ = contextAddress +
":" +
172 std::to_string(contextPort) +
173 icon->windowContentURL_;
176 catch(
const std::runtime_error& e)
178 __SS__ <<
"Error finding App origin which was linked to Desktop Icon '" <<
180 "': " << e.what() << __E__;
181 ss <<
"\n\nPlease fix by disabling the Icon, enabling the App or fixing the link in the Configurate Tree." << __E__;
190 if(icon->windowContentURL_[icon->windowContentURL_.size() - 1] !=
'=')
191 icon->windowContentURL_ +=
"?urn=";
194 appLink.getNode(COL_APP_ID).getValue(intVal);
195 icon->windowContentURL_ += std::to_string(intVal);
203 if(!child.second.getNode(COL_PARAMETER_LINK).isDisconnected())
207 if(icon->windowContentURL_.find(
'?') == std::string::npos)
208 icon->windowContentURL_ +=
'?';
209 else if(addedAppId || icon->windowContentURL_[icon->windowContentURL_.size() - 1] !=
'?')
210 icon->windowContentURL_ +=
'&';
213 auto paramGroupMap = child.second.getNode(COL_PARAMETER_LINK).getChildren();
214 bool notFirst =
false;
215 for(
const auto param : paramGroupMap)
217 if(!param.second.isEnabled())
221 icon->windowContentURL_ +=
'&';
224 icon->windowContentURL_ += StringMacros::encodeURIComponent(param.second.getNode(COL_PARAMETER_KEY).getValue<std::string>()) +
"=" +
225 StringMacros::encodeURIComponent(param.second.getNode(COL_PARAMETER_VALUE).getValue<std::string>());
233 std::string DesktopIconTable::removeCommas(
const std::string& str,
bool andHexReplace,
bool andHTMLReplace)
235 std::string retStr =
"";
236 retStr.reserve(str.length());
238 for(
unsigned int i = 0; i < str.length(); ++i)
241 else if(andHexReplace)
243 else if(andHTMLReplace)
250 void DesktopIconTable::setAllDesktopIcons(
const std::vector<DesktopIconTable::DesktopIcon>& newIcons)
252 activeDesktopIcons_.clear();
253 for(
const auto& newIcon : newIcons)
254 activeDesktopIcons_.push_back(newIcon);