1 #include "otsdaq-utilities/ConfigurationGUI/ConfigurationGUISupervisor.h"
3 #include "otsdaq/CgiDataUtilities/CgiDataUtilities.h"
4 #include "otsdaq/Macros/CoutMacros.h"
5 #include "otsdaq/MessageFacility/MessageFacility.h"
6 #include "otsdaq/TablePlugins/IterateTable.h"
7 #include "otsdaq/XmlUtilities/HttpXmlDocument.h"
9 #include <boost/stacktrace.hpp>
11 #include "otsdaq/GatewaySupervisor/GatewaySupervisor.h"
12 #include "otsdaq/TablePlugins/ARTDAQTableBase/ARTDAQTableBase.h"
13 #include "otsdaq/TablePlugins/XDAQContextTable.h"
15 #include <xdaq/NamespaceURI.h>
24 #define __MF_SUBJECT__ "CfgGUI"
26 #define TABLE_INFO_PATH std::string(__ENV__("TABLE_INFO_PATH")) + "/"
27 #define TABLE_INFO_EXT std::string("Info.xml")
29 #define ARTDAQ_CONFIG_LAYOUTS_PATH \
30 std::string(__ENV__("SERVICE_DATA_PATH")) + "/ConfigurationGUI_artdaqLayouts/"
43 ConfigurationGUISupervisor::ConfigurationGUISupervisor(xdaq::ApplicationStub* stub)
44 : CoreSupervisorBase(stub)
46 __SUP_COUT__ <<
"Constructor started." << __E__;
51 mkdir(((std::string)ARTDAQ_CONFIG_LAYOUTS_PATH).c_str(), 0755);
54 __SUP_COUT__ <<
"Constructor complete." << __E__;
58 ConfigurationGUISupervisor::~ConfigurationGUISupervisor(
void) { destroy(); }
61 void ConfigurationGUISupervisor::init(
void)
63 __SUP_COUT__ <<
"Initializing..." << __E__;
65 __SUP_COUT__ <<
"Activating saved context, which may prepare for normal mode..."
74 __SUP_COUT__ <<
"Done with test context." << __E__;
78 __COUT_WARN__ <<
"Failed test context group activation. otsdaq, in Normal mode, "
79 "will not launch when this test fails. "
80 <<
"Check the active context group from within Wizard Mode."
86 void ConfigurationGUISupervisor::destroy(
void)
89 for(std::map<std::string, ConfigurationManagerRW*>::iterator it =
90 userConfigurationManagers_.begin();
91 it != userConfigurationManagers_.end();
97 userConfigurationManagers_.clear();
101 if(ConfigurationInterface::getInstance(
true) != 0)
102 delete ConfigurationInterface::getInstance(
true);
106 void ConfigurationGUISupervisor::defaultPage(xgi::Input* in, xgi::Output* out)
108 cgicc::Cgicc cgiIn(in);
109 std::string configWindowName =
110 CgiDataUtilities::getData(cgiIn,
"configWindowName");
111 if(configWindowName ==
"tableEditor")
112 *out <<
"<!DOCTYPE HTML><html lang='en'><frameset col='100%' row='100%'><frame "
113 "src='/WebPath/html/ConfigurationTableEditor.html?urn="
114 << this->getApplicationDescriptor()->getLocalId() <<
"'></frameset></html>";
115 if(configWindowName ==
"iterate")
116 *out <<
"<!DOCTYPE HTML><html lang='en'><frameset col='100%' row='100%'><frame "
117 "src='/WebPath/html/Iterate.html?urn="
118 << this->getApplicationDescriptor()->getLocalId() <<
"'></frameset></html>";
120 *out <<
"<!DOCTYPE HTML><html lang='en'><frameset col='100%' row='100%'><frame "
121 "src='/WebPath/html/ConfigurationGUI.html?urn="
122 << this->getApplicationDescriptor()->getLocalId() <<
"'></frameset></html>";
128 void ConfigurationGUISupervisor::setSupervisorPropertyDefaults(
void)
130 CorePropertySupervisorBase::setSupervisorProperty(
131 CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.UserPermissionsThreshold,
132 "*=10 | deleteTreeNodeRecords=255 | saveTableInfo=255 | "
133 "deleteTableInfo=255");
134 CorePropertySupervisorBase::setSupervisorProperty(
135 CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.RequireUserLockRequestTypes,
142 void ConfigurationGUISupervisor::forceSupervisorPropertyValues()
144 CorePropertySupervisorBase::setSupervisorProperty(
145 CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.AutomatedRequestTypes,
146 "getActiveTableGroups");
147 CorePropertySupervisorBase::setSupervisorProperty(
148 CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.CheckUserLockRequestTypes,
153 void ConfigurationGUISupervisor::request(
const std::string& requestType,
155 HttpXmlDocument& xmlOut,
156 const WebUsers::RequestUserInfo& userInfo)
try
218 std::string refresh = CgiDataUtilities::getData(cgiIn,
"refresh");
222 ConfigurationManagerRW* cfgMgr = refreshUserSession(
223 userInfo.username_, userInfo.activeUserSessionIndex_, (refresh ==
"1"));
225 if(requestType ==
"saveTableInfo")
227 std::string tableName =
228 CgiDataUtilities::getData(cgiIn,
"tableName");
229 std::string columnCSV =
230 CgiDataUtilities::postData(cgiIn,
"columnCSV");
231 std::string allowOverwrite =
232 CgiDataUtilities::getData(cgiIn,
"allowOverwrite");
233 std::string tableDescription =
234 CgiDataUtilities::postData(cgiIn,
"tableDescription");
235 std::string columnChoicesCSV =
236 CgiDataUtilities::postData(cgiIn,
"columnChoicesCSV");
241 __SUP_COUT__ <<
"tableName: " << tableName << __E__;
242 __SUP_COUT__ <<
"columnCSV: " << columnCSV << __E__;
243 __SUP_COUT__ <<
"tableDescription: " << tableDescription << __E__;
244 __SUP_COUT__ <<
"columnChoicesCSV: " << columnChoicesCSV << __E__;
245 __SUP_COUT__ <<
"allowOverwrite: " << allowOverwrite << __E__;
247 if(!allSupervisorInfo_.isWizardMode())
249 __SUP_SS__ <<
"Improper permissions for saving table info." << __E__;
250 xmlOut.addTextElementToData(
"Error", ss.str());
253 handleSaveTableInfoXML(xmlOut,
259 allowOverwrite ==
"1");
261 else if(requestType ==
"deleteTableInfo")
263 std::string tableName =
264 CgiDataUtilities::getData(cgiIn,
"tableName");
265 __SUP_COUT__ <<
"tableName: " << tableName << __E__;
266 handleDeleteTableInfoXML(xmlOut, cfgMgr, tableName);
268 else if(requestType ==
"gatewayLaunchOTS" || requestType ==
"gatewayLaunchWiz" ||
269 requestType ==
"flattenToSystemAliases")
272 __SUP_COUT_WARN__ << requestType <<
" command received! " << __E__;
273 __MOUT_WARN__ << requestType <<
" command received! " << __E__;
276 __SUP_COUT_INFO__ <<
"Launching " << requestType <<
"... " << __E__;
278 __SUP_COUT__ <<
"Extracting target context hostnames... " << __E__;
279 std::vector<std::string> hostnames;
282 if(requestType ==
"flattenToSystemAliases" &&
283 CorePropertySupervisorBase::allSupervisorInfo_.isWizardMode())
285 hostnames.push_back(__ENV__(
"OTS_CONFIGURATION_WIZARD_SUPERVISOR_SERVER"));
286 __SUP_COUT__ <<
"hostname = " << hostnames.back() << __E__;
294 const XDAQContextTable* contextTable =
295 cfgMgr->__GET_CONFIG__(XDAQContextTable);
297 auto contexts = contextTable->getContexts();
299 for(
const auto& context : contexts)
306 for(i = 0; i < context.address_.size(); ++i)
307 if(context.address_[i] ==
'/')
309 hostnames.push_back(context.address_.substr(j));
310 __SUP_COUT__ <<
"hostname = " << hostnames.back() << __E__;
315 __SUP_SS__ <<
"The Configuration Manager could not be initialized to "
319 __SUP_COUT_ERR__ <<
"\n" << ss.str();
324 if(hostnames.size() == 0)
326 __SUP_SS__ <<
"No hostnames found to launch command '" + requestType +
327 "'... Is there a valid Context group activated?"
329 __SUP_COUT_ERR__ <<
"\n" << ss.str();
331 xmlOut.addTextElementToData(
"Error", ss.str());
334 for(
const auto& hostname : hostnames)
336 std::string fn = (std::string(__ENV__(
"SERVICE_DATA_PATH")) +
337 "/StartOTS_action_" + hostname +
".cmd");
338 FILE* fp = fopen(fn.c_str(),
"w");
341 if(requestType ==
"gatewayLaunchOTS")
342 fprintf(fp,
"LAUNCH_OTS");
343 else if(requestType ==
"gatewayLaunchWiz")
344 fprintf(fp,
"LAUNCH_WIZ");
345 else if(requestType ==
"flattenToSystemAliases")
347 fprintf(fp,
"FLATTEN_TO_SYSTEM_ALIASES");
355 __SUP_COUT_ERR__ <<
"Unable to open command file: " << fn << __E__;
358 else if(requestType ==
"versionTracking")
360 std::string type = CgiDataUtilities::getData(cgiIn,
"Type");
361 __SUP_COUT__ <<
"type: " << type << __E__;
364 xmlOut.addTextElementToData(
365 "versionTrackingStatus",
366 ConfigurationInterface::isVersionTrackingEnabled() ?
"ON" :
"OFF");
367 else if(type ==
"ON")
369 ConfigurationInterface::setVersionTrackingEnabled(
true);
370 xmlOut.addTextElementToData(
371 "versionTrackingStatus",
372 ConfigurationInterface::isVersionTrackingEnabled() ?
"ON" :
"OFF");
374 else if(type ==
"OFF")
376 ConfigurationInterface::setVersionTrackingEnabled(
false);
377 xmlOut.addTextElementToData(
378 "versionTrackingStatus",
379 ConfigurationInterface::isVersionTrackingEnabled() ?
"ON" :
"OFF");
382 else if(requestType ==
"getColumnTypes")
385 std::vector<std::string> allTypes = TableViewColumnInfo::getAllTypesForGUI();
386 std::vector<std::string> allDataTypes =
387 TableViewColumnInfo::getAllDataTypesForGUI();
388 std::map<std::pair<std::string, std::string>, std::string> allDefaults =
389 TableViewColumnInfo::getAllDefaultsForGUI();
391 for(
const auto& type : allTypes)
392 xmlOut.addTextElementToData(
"columnTypeForGUI", type);
393 for(
const auto& dataType : allDataTypes)
394 xmlOut.addTextElementToData(
"columnDataTypeForGUI", dataType);
396 for(
const auto& colDefault : allDefaults)
398 xmlOut.addTextElementToData(
"columnDefaultDataType", colDefault.first.first);
399 xmlOut.addTextElementToData(
"columnDefaultTypeFilter",
400 colDefault.first.second);
401 xmlOut.addTextElementToData(
"columnDefaultValue", colDefault.second);
404 else if(requestType ==
"getGroupAliases")
409 1 == CgiDataUtilities::getDataAsInt(cgiIn,
"reloadActiveGroups");
411 __SUP_COUT__ <<
"reloadActive: " << reloadActive << __E__;
417 cfgMgr->clearAllCachedVersions();
418 cfgMgr->restoreActiveTableGroups(
true);
420 catch(std::runtime_error& e)
422 __SUP_SS__ << (
"Error loading active groups!\n\n" + std::string(e.what()))
424 __SUP_COUT_ERR__ <<
"\n" << ss.str();
425 xmlOut.addTextElementToData(
"Error", ss.str());
430 __SUP_SS__ << (
"Error loading active groups!\n\n") << __E__;
431 __SUP_COUT_ERR__ <<
"\n" << ss.str();
432 xmlOut.addTextElementToData(
"Error", ss.str());
437 handleGroupAliasesXML(xmlOut, cfgMgr);
439 else if(requestType ==
"setGroupAliasInActiveBackbone")
441 std::string groupAlias =
442 CgiDataUtilities::getData(cgiIn,
"groupAlias");
443 std::string groupName = CgiDataUtilities::getData(cgiIn,
"groupName");
445 std::string groupKey = CgiDataUtilities::getData(cgiIn,
"groupKey");
447 __SUP_COUT__ <<
"groupAlias: " << groupAlias << __E__;
448 __SUP_COUT__ <<
"groupName: " << groupName << __E__;
449 __SUP_COUT__ <<
"groupKey: " << groupKey << __E__;
451 handleSetGroupAliasInBackboneXML(xmlOut,
455 TableGroupKey(groupKey),
458 else if(requestType ==
"setVersionAliasInActiveBackbone")
460 std::string versionAlias =
461 CgiDataUtilities::getData(cgiIn,
"versionAlias");
462 std::string tableName =
463 CgiDataUtilities::getData(cgiIn,
"tableName");
464 std::string version = CgiDataUtilities::getData(cgiIn,
"version");
466 __SUP_COUT__ <<
"versionAlias: " << versionAlias << __E__;
467 __SUP_COUT__ <<
"tableName: " << tableName << __E__;
468 __SUP_COUT__ <<
"version: " << version << __E__;
470 handleSetVersionAliasInBackboneXML(xmlOut,
474 TableVersion(version),
477 else if(requestType ==
"setAliasOfGroupMembers")
479 std::string versionAlias =
480 CgiDataUtilities::getData(cgiIn,
"versionAlias");
481 std::string groupName = CgiDataUtilities::getData(cgiIn,
"groupName");
483 std::string groupKey = CgiDataUtilities::getData(cgiIn,
"groupKey");
485 __SUP_COUT__ <<
"versionAlias: " << versionAlias << __E__;
486 __SUP_COUT__ <<
"groupName: " << groupName << __E__;
487 __SUP_COUT__ <<
"groupKey: " << groupKey << __E__;
489 handleAliasGroupMembersInBackboneXML(xmlOut,
493 TableGroupKey(groupKey),
496 else if(requestType ==
"getVersionAliases")
498 handleVersionAliasesXML(xmlOut, cfgMgr);
500 else if(requestType ==
"getTableGroups")
502 bool doNotReturnMembers =
503 CgiDataUtilities::getDataAsInt(cgiIn,
"doNotReturnMembers") == 1
507 __SUP_COUT__ <<
"doNotReturnMembers: " << doNotReturnMembers << __E__;
508 handleTableGroupsXML(xmlOut, cfgMgr, !doNotReturnMembers);
510 else if(requestType ==
"getTableGroupType")
512 std::string tableList =
513 CgiDataUtilities::postData(cgiIn,
"tableList");
514 __SUP_COUT__ <<
"tableList: " << tableList << __E__;
516 handleGetTableGroupTypeXML(xmlOut, cfgMgr, tableList);
518 else if(requestType ==
"getTables")
520 std::string allowIllegalColumns =
521 CgiDataUtilities::getData(cgiIn,
"allowIllegalColumns");
523 __SUP_COUT__ <<
"allowIllegalColumns: " << allowIllegalColumns << __E__;
525 handleTablesXML(xmlOut, cfgMgr, allowIllegalColumns ==
"1");
527 else if(requestType ==
"getContextMemberNames")
529 std::set<std::string> members = cfgMgr->getContextMemberNames();
531 for(
auto& member : members)
532 xmlOut.addTextElementToData(
"ContextMember", member);
534 else if(requestType ==
"getBackboneMemberNames")
536 std::set<std::string> members = cfgMgr->getBackboneMemberNames();
538 for(
auto& member : members)
539 xmlOut.addTextElementToData(
"BackboneMember", member);
541 else if(requestType ==
"getIterateMemberNames")
543 std::set<std::string> members = cfgMgr->getIterateMemberNames();
545 for(
auto& member : members)
546 xmlOut.addTextElementToData(
"IterateMember", member);
548 else if(requestType ==
"getSpecificTableGroup")
550 std::string groupName = CgiDataUtilities::getData(cgiIn,
"groupName");
552 std::string groupKey = CgiDataUtilities::getData(cgiIn,
"groupKey");
554 __SUP_COUT__ <<
"groupName: " << groupName << __E__;
555 __SUP_COUT__ <<
"groupKey: " << groupKey << __E__;
557 ConfigurationSupervisorBase::handleGetTableGroupXML(
558 xmlOut, cfgMgr, groupName, TableGroupKey(groupKey));
560 else if(requestType ==
"saveNewTableGroup")
562 std::string groupName = CgiDataUtilities::getData(cgiIn,
"groupName");
564 bool ignoreWarnings =
565 CgiDataUtilities::getDataAsInt(cgiIn,
"ignoreWarnings");
566 bool allowDuplicates =
567 CgiDataUtilities::getDataAsInt(cgiIn,
"allowDuplicates");
568 bool lookForEquivalent =
569 CgiDataUtilities::getDataAsInt(cgiIn,
"lookForEquivalent");
570 std::string tableList =
571 CgiDataUtilities::postData(cgiIn,
"tableList");
572 std::string comment =
573 CgiDataUtilities::getData(cgiIn,
"groupComment");
575 __SUP_COUT__ <<
"saveNewTableGroup: " << groupName << __E__;
576 __SUP_COUT__ <<
"tableList: " << tableList << __E__;
577 __SUP_COUT__ <<
"ignoreWarnings: " << ignoreWarnings << __E__;
578 __SUP_COUT__ <<
"allowDuplicates: " << allowDuplicates << __E__;
579 __SUP_COUT__ <<
"lookForEquivalent: " << lookForEquivalent << __E__;
580 __SUP_COUT__ <<
"comment: " << comment << __E__;
582 ConfigurationSupervisorBase::handleCreateTableGroupXML(xmlOut,
591 else if(requestType ==
"getSpecificTable")
593 std::string tableName =
594 CgiDataUtilities::getData(cgiIn,
"tableName");
595 std::string versionStr = CgiDataUtilities::getData(cgiIn,
"version");
596 int dataOffset = CgiDataUtilities::getDataAsInt(cgiIn,
"dataOffset");
597 int chunkSize = CgiDataUtilities::getDataAsInt(cgiIn,
"chunkSize");
599 std::string allowIllegalColumns =
600 CgiDataUtilities::getData(cgiIn,
"allowIllegalColumns");
601 __SUP_COUT__ <<
"allowIllegalColumns: " << (allowIllegalColumns ==
"1") << __E__;
603 __SUP_COUT__ <<
"getSpecificTable: " << tableName <<
" versionStr: " << versionStr
604 <<
" chunkSize: " << chunkSize <<
" dataOffset: " << dataOffset
607 TableVersion version;
608 const std::map<std::string, TableInfo>& allTableInfo = cfgMgr->getAllTableInfo();
609 std::string versionAlias;
611 if(allTableInfo.find(tableName) != allTableInfo.end())
613 if(versionStr ==
"" &&
614 allTableInfo.at(tableName).versions_.size())
615 version = *(allTableInfo.at(tableName).versions_.rbegin());
616 else if(versionStr.find(ConfigurationManager::ALIAS_VERSION_PREAMBLE) == 0)
619 std::map<std::string ,
620 std::map<std::string , TableVersion>>
621 versionAliases = cfgMgr->getVersionAliases();
623 versionAlias = versionStr.substr(
624 ConfigurationManager::ALIAS_VERSION_PREAMBLE.size());
635 if(versionAliases.find(tableName) != versionAliases.end() &&
636 versionAliases[tableName].find(versionStr.substr(
637 ConfigurationManager::ALIAS_VERSION_PREAMBLE.size())) !=
638 versionAliases[tableName].end())
640 version = versionAliases[tableName][versionStr.substr(
641 ConfigurationManager::ALIAS_VERSION_PREAMBLE.size())];
642 __SUP_COUT__ <<
"version alias translated to: " << version << __E__;
647 << versionStr.substr(
648 ConfigurationManager::ALIAS_VERSION_PREAMBLE.size())
649 <<
"'was not found in active version aliases!" << __E__;
652 version = atoi(versionStr.c_str());
655 __SUP_COUT__ <<
"version: " << version << __E__;
657 handleGetTableXML(xmlOut,
660 TableVersion(version),
661 (allowIllegalColumns ==
"1"));
663 xmlOut.addTextElementToData(
"DefaultRowValue", userInfo.username_);
665 else if(requestType ==
"saveSpecificTable")
667 std::string tableName =
668 CgiDataUtilities::getData(cgiIn,
"tableName");
669 int version = CgiDataUtilities::getDataAsInt(cgiIn,
"version");
670 int dataOffset = CgiDataUtilities::getDataAsInt(cgiIn,
"dataOffset");
671 bool sourceTableAsIs =
672 CgiDataUtilities::getDataAsInt(cgiIn,
"sourceTableAsIs");
673 bool lookForEquivalent =
674 CgiDataUtilities::getDataAsInt(cgiIn,
"lookForEquivalent");
675 int temporary = CgiDataUtilities::getDataAsInt(cgiIn,
"temporary");
676 std::string comment =
677 CgiDataUtilities::getData(cgiIn,
"tableComment");
679 std::string data = CgiDataUtilities::postData(cgiIn,
"data");
683 __SUP_COUT__ <<
"tableName: " << tableName <<
" version: " << version
684 <<
" temporary: " << temporary <<
" dataOffset: " << dataOffset
686 __SUP_COUT__ <<
"comment: " << comment << __E__;
687 __SUP_COUT__ <<
"data: " << data << __E__;
688 __SUP_COUT__ <<
"sourceTableAsIs: " << sourceTableAsIs << __E__;
689 __SUP_COUT__ <<
"lookForEquivalent: " << lookForEquivalent << __E__;
691 ConfigurationSupervisorBase::handleCreateTableXML(xmlOut,
694 TableVersion(version),
703 else if(requestType ==
"clearTableTemporaryVersions")
705 std::string tableName =
706 CgiDataUtilities::getData(cgiIn,
"tableName");
707 __SUP_COUT__ <<
"tableName: " << tableName << __E__;
711 cfgMgr->eraseTemporaryVersion(tableName);
713 catch(std::runtime_error& e)
715 __SUP_COUT__ <<
"Error detected!\n\n " << e.what() << __E__;
716 xmlOut.addTextElementToData(
717 "Error",
"Error clearing temporary views!\n " + std::string(e.what()));
721 __SUP_COUT__ <<
"Error detected!\n\n " << __E__;
722 xmlOut.addTextElementToData(
"Error",
"Error clearing temporary views! ");
725 else if(requestType ==
"clearTableCachedVersions")
727 std::string tableName =
728 CgiDataUtilities::getData(cgiIn,
"tableName");
729 __SUP_COUT__ <<
"tableName: " << tableName << __E__;
734 cfgMgr->clearAllCachedVersions();
736 cfgMgr->clearCachedVersions(tableName);
740 catch(std::runtime_error& e)
742 __SUP_COUT__ <<
"Error detected!\n\n " << e.what() << __E__;
743 xmlOut.addTextElementToData(
744 "Error",
"Error clearing cached views!\n " + std::string(e.what()));
748 __SUP_COUT__ <<
"Error detected!\n\n " << __E__;
749 xmlOut.addTextElementToData(
"Error",
"Error clearing cached views! ");
752 else if(requestType ==
"getTreeView")
754 std::string tableGroup = CgiDataUtilities::getData(cgiIn,
"tableGroup");
755 std::string tableGroupKey = CgiDataUtilities::getData(cgiIn,
"tableGroupKey");
756 std::string startPath = CgiDataUtilities::postData(cgiIn,
"startPath");
757 std::string modifiedTables = CgiDataUtilities::postData(cgiIn,
"modifiedTables");
758 std::string filterList = CgiDataUtilities::postData(cgiIn,
"filterList");
759 int depth = CgiDataUtilities::getDataAsInt(cgiIn,
"depth");
760 bool hideStatusFalse = CgiDataUtilities::getDataAsInt(cgiIn,
"hideStatusFalse");
770 handleFillTreeViewXML(xmlOut,
773 TableGroupKey(tableGroupKey),
780 else if(requestType ==
"getTreeNodeCommonFields")
782 std::string tableGroup = CgiDataUtilities::getData(cgiIn,
"tableGroup");
783 std::string tableGroupKey = CgiDataUtilities::getData(cgiIn,
"tableGroupKey");
784 std::string startPath = CgiDataUtilities::postData(cgiIn,
"startPath");
785 std::string modifiedTables = CgiDataUtilities::postData(cgiIn,
"modifiedTables");
786 std::string fieldList = CgiDataUtilities::postData(cgiIn,
"fieldList");
787 std::string recordList = CgiDataUtilities::postData(cgiIn,
"recordList");
788 int depth = CgiDataUtilities::getDataAsInt(cgiIn,
"depth");
790 __SUP_COUT__ <<
"tableGroup: " << tableGroup << __E__;
791 __SUP_COUT__ <<
"tableGroupKey: " << tableGroupKey << __E__;
792 __SUP_COUT__ <<
"startPath: " << startPath << __E__;
793 __SUP_COUT__ <<
"depth: " << depth << __E__;
796 __SUP_COUT__ <<
"fieldList: " << fieldList << __E__;
797 __SUP_COUT__ <<
"recordList: " << recordList << __E__;
798 __SUP_COUT__ <<
"modifiedTables: " << modifiedTables << __E__;
800 handleFillTreeNodeCommonFieldsXML(xmlOut,
803 TableGroupKey(tableGroupKey),
810 else if(requestType ==
"getUniqueFieldValuesForRecords")
812 std::string tableGroup = CgiDataUtilities::getData(cgiIn,
"tableGroup");
813 std::string tableGroupKey = CgiDataUtilities::getData(cgiIn,
"tableGroupKey");
814 std::string startPath = CgiDataUtilities::postData(cgiIn,
"startPath");
815 std::string modifiedTables = CgiDataUtilities::postData(cgiIn,
"modifiedTables");
816 std::string fieldList = CgiDataUtilities::postData(cgiIn,
"fieldList");
817 std::string recordList = CgiDataUtilities::postData(cgiIn,
"recordList");
819 __SUP_COUT__ <<
"tableGroup: " << tableGroup << __E__;
820 __SUP_COUT__ <<
"tableGroupKey: " << tableGroupKey << __E__;
821 __SUP_COUT__ <<
"startPath: " << startPath << __E__;
822 __SUP_COUT__ <<
"fieldList: " << fieldList << __E__;
823 __SUP_COUT__ <<
"recordList: " << recordList << __E__;
824 __SUP_COUT__ <<
"modifiedTables: " << modifiedTables << __E__;
826 handleFillUniqueFieldValuesForRecordsXML(xmlOut,
829 TableGroupKey(tableGroupKey),
835 else if(requestType ==
"getTreeNodeFieldValues")
837 std::string tableGroup = CgiDataUtilities::getData(cgiIn,
"tableGroup");
838 std::string tableGroupKey = CgiDataUtilities::getData(cgiIn,
"tableGroupKey");
839 std::string startPath = CgiDataUtilities::postData(cgiIn,
"startPath");
840 std::string modifiedTables = CgiDataUtilities::postData(cgiIn,
"modifiedTables");
841 std::string fieldList = CgiDataUtilities::postData(cgiIn,
"fieldList");
842 std::string recordList = CgiDataUtilities::postData(cgiIn,
"recordList");
844 __SUP_COUT__ <<
"tableGroup: " << tableGroup << __E__;
845 __SUP_COUT__ <<
"tableGroupKey: " << tableGroupKey << __E__;
846 __SUP_COUT__ <<
"startPath: " << startPath << __E__;
847 __SUP_COUT__ <<
"fieldList: " << fieldList << __E__;
848 __SUP_COUT__ <<
"recordList: " << recordList << __E__;
849 __SUP_COUT__ <<
"modifiedTables: " << modifiedTables << __E__;
851 handleFillGetTreeNodeFieldValuesXML(xmlOut,
854 TableGroupKey(tableGroupKey),
860 else if(requestType ==
"setTreeNodeFieldValues")
862 std::string tableGroup = CgiDataUtilities::getData(cgiIn,
"tableGroup");
863 std::string tableGroupKey = CgiDataUtilities::getData(cgiIn,
"tableGroupKey");
864 std::string startPath = CgiDataUtilities::postData(cgiIn,
"startPath");
865 std::string modifiedTables = CgiDataUtilities::postData(cgiIn,
"modifiedTables");
866 std::string fieldList = CgiDataUtilities::postData(cgiIn,
"fieldList");
867 std::string recordList = CgiDataUtilities::postData(cgiIn,
"recordList");
868 std::string valueList = CgiDataUtilities::postData(cgiIn,
"valueList");
870 __SUP_COUT__ <<
"tableGroup: " << tableGroup << __E__;
871 __SUP_COUT__ <<
"tableGroupKey: " << tableGroupKey << __E__;
872 __SUP_COUT__ <<
"startPath: " << startPath << __E__;
873 __SUP_COUT__ <<
"fieldList: " << fieldList << __E__;
874 __SUP_COUT__ <<
"valueList: " << valueList << __E__;
875 __SUP_COUT__ <<
"recordList: " << recordList << __E__;
876 __SUP_COUT__ <<
"modifiedTables: " << modifiedTables << __E__;
878 handleFillSetTreeNodeFieldValuesXML(xmlOut,
881 TableGroupKey(tableGroupKey),
889 else if(requestType ==
"addTreeNodeRecords")
891 std::string tableGroup = CgiDataUtilities::getData(cgiIn,
"tableGroup");
892 std::string tableGroupKey = CgiDataUtilities::getData(cgiIn,
"tableGroupKey");
893 std::string startPath = CgiDataUtilities::postData(cgiIn,
"startPath");
894 std::string modifiedTables = CgiDataUtilities::postData(cgiIn,
"modifiedTables");
895 std::string recordList = CgiDataUtilities::postData(cgiIn,
"recordList");
897 __SUP_COUT__ <<
"tableGroup: " << tableGroup << __E__;
898 __SUP_COUT__ <<
"tableGroupKey: " << tableGroupKey << __E__;
899 __SUP_COUT__ <<
"startPath: " << startPath << __E__;
900 __SUP_COUT__ <<
"recordList: " << recordList << __E__;
901 __SUP_COUT__ <<
"modifiedTables: " << modifiedTables << __E__;
903 handleFillCreateTreeNodeRecordsXML(xmlOut,
906 TableGroupKey(tableGroupKey),
912 else if(requestType ==
"deleteTreeNodeRecords")
914 std::string tableGroup = CgiDataUtilities::getData(cgiIn,
"tableGroup");
915 std::string tableGroupKey = CgiDataUtilities::getData(cgiIn,
"tableGroupKey");
916 std::string startPath = CgiDataUtilities::postData(cgiIn,
"startPath");
917 std::string modifiedTables = CgiDataUtilities::postData(cgiIn,
"modifiedTables");
918 std::string recordList = CgiDataUtilities::postData(cgiIn,
"recordList");
920 __SUP_COUT__ <<
"tableGroup: " << tableGroup << __E__;
921 __SUP_COUT__ <<
"tableGroupKey: " << tableGroupKey << __E__;
922 __SUP_COUT__ <<
"startPath: " << startPath << __E__;
923 __SUP_COUT__ <<
"recordList: " << recordList << __E__;
924 __SUP_COUT__ <<
"modifiedTables: " << modifiedTables << __E__;
926 handleFillDeleteTreeNodeRecordsXML(xmlOut,
929 TableGroupKey(tableGroupKey),
934 else if(requestType ==
"renameTreeNodeRecords")
936 std::string tableGroup = CgiDataUtilities::getData(cgiIn,
"tableGroup");
937 std::string tableGroupKey = CgiDataUtilities::getData(cgiIn,
"tableGroupKey");
938 std::string startPath = CgiDataUtilities::postData(cgiIn,
"startPath");
939 std::string modifiedTables = CgiDataUtilities::postData(cgiIn,
"modifiedTables");
940 std::string recordList = CgiDataUtilities::postData(cgiIn,
"recordList");
941 std::string newRecordList = CgiDataUtilities::postData(cgiIn,
"newRecordList");
943 __SUP_COUT__ <<
"tableGroup: " << tableGroup << __E__;
944 __SUP_COUT__ <<
"tableGroupKey: " << tableGroupKey << __E__;
945 __SUP_COUT__ <<
"startPath: " << startPath << __E__;
946 __SUP_COUT__ <<
"recordList: " << recordList << __E__;
947 __SUP_COUT__ <<
"modifiedTables: " << modifiedTables << __E__;
948 __SUP_COUTV__(newRecordList);
950 handleFillRenameTreeNodeRecordsXML(xmlOut,
953 TableGroupKey(tableGroupKey),
959 else if(requestType ==
"copyTreeNodeRecords")
961 std::string tableGroup = CgiDataUtilities::getData(cgiIn,
"tableGroup");
962 std::string tableGroupKey = CgiDataUtilities::getData(cgiIn,
"tableGroupKey");
963 std::string startPath = CgiDataUtilities::postData(cgiIn,
"startPath");
964 std::string modifiedTables = CgiDataUtilities::postData(cgiIn,
"modifiedTables");
965 std::string recordList = CgiDataUtilities::postData(cgiIn,
"recordList");
966 unsigned int numberOfCopies =
967 CgiDataUtilities::getDataAsInt(cgiIn,
"numberOfCopies");
971 __SUP_COUT__ <<
"tableGroup: " << tableGroup << __E__;
972 __SUP_COUT__ <<
"tableGroupKey: " << tableGroupKey << __E__;
973 __SUP_COUT__ <<
"startPath: " << startPath << __E__;
974 __SUP_COUT__ <<
"recordList: " << recordList << __E__;
975 __SUP_COUT__ <<
"modifiedTables: " << modifiedTables << __E__;
976 __SUP_COUTV__(numberOfCopies);
978 handleFillCopyTreeNodeRecordsXML(xmlOut,
981 TableGroupKey(tableGroupKey),
987 else if(requestType ==
"getArtdaqNodes")
989 std::string modifiedTables = CgiDataUtilities::postData(cgiIn,
"modifiedTables");
991 __SUP_COUTV__(modifiedTables);
993 handleGetArtdaqNodeRecordsXML(xmlOut, cfgMgr, modifiedTables);
995 else if(requestType ==
"saveArtdaqNodes")
997 std::string modifiedTables = CgiDataUtilities::postData(cgiIn,
"modifiedTables");
998 std::string nodeString = CgiDataUtilities::postData(cgiIn,
"nodeString");
999 std::string subsystemString =
1000 CgiDataUtilities::postData(cgiIn,
"subsystemString");
1002 __SUP_COUTV__(modifiedTables);
1003 __SUP_COUTV__(nodeString);
1004 __SUP_COUTV__(subsystemString);
1006 handleSaveArtdaqNodeRecordsXML(
1007 nodeString, subsystemString, xmlOut, cfgMgr, modifiedTables);
1009 else if(requestType ==
"loadArtdaqNodeLayout")
1011 std::string contextGroupName =
1012 CgiDataUtilities::getData(cgiIn,
"contextGroupName");
1013 std::string contextGroupKey = CgiDataUtilities::getData(cgiIn,
"contextGroupKey");
1015 __SUP_COUTV__(contextGroupName);
1016 __SUP_COUTV__(contextGroupKey);
1018 handleLoadArtdaqNodeLayoutXML(
1019 xmlOut, cfgMgr, contextGroupName, TableGroupKey(contextGroupKey));
1021 else if(requestType ==
"saveArtdaqNodeLayout")
1023 std::string layout = CgiDataUtilities::postData(cgiIn,
"layout");
1024 std::string contextGroupName =
1025 CgiDataUtilities::getData(cgiIn,
"contextGroupName");
1026 std::string contextGroupKey = CgiDataUtilities::getData(cgiIn,
"contextGroupKey");
1028 __SUP_COUTV__(layout);
1029 __SUP_COUTV__(contextGroupName);
1030 __SUP_COUTV__(contextGroupKey);
1032 handleSaveArtdaqNodeLayoutXML(
1033 xmlOut, cfgMgr, layout, contextGroupName, TableGroupKey(contextGroupKey));
1035 else if(requestType ==
"getAffectedActiveGroups")
1037 std::string groupName = CgiDataUtilities::getData(cgiIn,
"groupName");
1038 std::string groupKey = CgiDataUtilities::getData(cgiIn,
"groupKey");
1039 std::string modifiedTables = CgiDataUtilities::postData(cgiIn,
"modifiedTables");
1040 __SUP_COUT__ <<
"modifiedTables: " << modifiedTables << __E__;
1041 __SUP_COUT__ <<
"groupName: " << groupName << __E__;
1042 __SUP_COUT__ <<
"groupKey: " << groupKey << __E__;
1044 handleGetAffectedGroupsXML(
1045 xmlOut, cfgMgr, groupName, TableGroupKey(groupKey), modifiedTables);
1047 else if(requestType ==
"saveTreeNodeEdit")
1049 std::string editNodeType = CgiDataUtilities::getData(cgiIn,
"editNodeType");
1050 std::string targetTable = CgiDataUtilities::getData(cgiIn,
"targetTable");
1051 std::string targetTableVersion =
1052 CgiDataUtilities::getData(cgiIn,
"targetTableVersion");
1053 std::string targetUID = CgiDataUtilities::getData(cgiIn,
"targetUID");
1054 std::string targetColumn = CgiDataUtilities::getData(cgiIn,
"targetColumn");
1055 std::string newValue = CgiDataUtilities::postData(cgiIn,
"newValue");
1057 __SUP_COUT__ <<
"editNodeType: " << editNodeType << __E__;
1058 __SUP_COUT__ <<
"targetTable: " << targetTable << __E__;
1059 __SUP_COUT__ <<
"targetTableVersion: " << targetTableVersion << __E__;
1060 __SUP_COUT__ <<
"targetUID: " << targetUID << __E__;
1061 __SUP_COUT__ <<
"targetColumn: " << targetColumn << __E__;
1062 __SUP_COUT__ <<
"newValue: " << newValue << __E__;
1064 handleSaveTreeNodeEditXML(xmlOut,
1067 TableVersion(targetTableVersion),
1069 StringMacros::decodeURIComponent(targetUID),
1070 StringMacros::decodeURIComponent(targetColumn),
1072 userInfo.username_);
1074 else if(requestType ==
"getLinkToChoices")
1076 std::string linkToTableName = CgiDataUtilities::getData(cgiIn,
"linkToTableName");
1077 std::string linkToTableVersion =
1078 CgiDataUtilities::getData(cgiIn,
"linkToTableVersion");
1079 std::string linkIdType = CgiDataUtilities::getData(cgiIn,
"linkIdType");
1080 std::string linkIndex = StringMacros::decodeURIComponent(
1081 CgiDataUtilities::getData(cgiIn,
"linkIndex"));
1082 std::string linkInitId = CgiDataUtilities::getData(cgiIn,
"linkInitId");
1084 __SUP_COUT__ <<
"linkToTableName: " << linkToTableName << __E__;
1085 __SUP_COUT__ <<
"linkToTableVersion: " << linkToTableVersion << __E__;
1086 __SUP_COUT__ <<
"linkIdType: " << linkIdType << __E__;
1087 __SUP_COUT__ <<
"linkIndex: " << linkIndex << __E__;
1088 __SUP_COUT__ <<
"linkInitId: " << linkInitId << __E__;
1090 handleGetLinkToChoicesXML(xmlOut,
1093 TableVersion(linkToTableVersion),
1098 else if(requestType ==
"activateTableGroup")
1100 std::string groupName = CgiDataUtilities::getData(cgiIn,
"groupName");
1101 std::string groupKey = CgiDataUtilities::getData(cgiIn,
"groupKey");
1102 bool ignoreWarnings = CgiDataUtilities::getDataAsInt(cgiIn,
"ignoreWarnings");
1104 __SUP_COUT__ <<
"Activating table: " << groupName <<
"(" << groupKey <<
")"
1106 __SUP_COUTV__(ignoreWarnings);
1109 xmlOut.addTextElementToData(
"AttemptedGroupActivation",
"1");
1110 xmlOut.addTextElementToData(
"AttemptedGroupActivationName", groupName);
1111 xmlOut.addTextElementToData(
"AttemptedGroupActivationKey", groupKey);
1115 std::string accumulatedErrors;
1120 cfgMgr->activateTableGroup(
1121 groupName, TableGroupKey(groupKey), &accumulatedErrors);
1123 if(accumulatedErrors !=
"")
1127 __SS__ <<
"Throwing exception on accumulated errors: "
1128 << accumulatedErrors << __E__;
1132 __COUT_WARN__ <<
"Ignoring warnings so ignoring this error:"
1133 << accumulatedErrors << __E__;
1134 __COUT_WARN__ <<
"Done ignoring the above error(s)." << __E__;
1137 catch(std::runtime_error& e)
1142 __SUP_COUT__ <<
"Error detected!\n\n " << e.what() << __E__;
1143 xmlOut.addTextElementToData(
1145 "Error activating table group '" + groupName +
"(" + groupKey +
")" +
1146 ".' Please see details below:\n\n" + std::string(e.what()));
1147 __SUP_COUT_ERR__ <<
"Errors detected so de-activating group: " << groupName
1148 <<
" (" << groupKey <<
")" << __E__;
1151 cfgMgr->destroyTableGroup(groupName,
true);
1157 catch(cet::exception& e)
1163 __SUP_COUT__ <<
"Error detected!\n\n " << e.what() << __E__;
1164 xmlOut.addTextElementToData(
"Error",
1165 "Error activating table group '" + groupName +
1166 "(" + groupKey +
")" +
"!'\n\n" +
1167 std::string(e.what()));
1168 __SUP_COUT_ERR__ <<
"Errors detected so de-activating group: " << groupName
1169 <<
" (" << groupKey <<
")" << __E__;
1172 cfgMgr->destroyTableGroup(groupName,
true);
1180 __SUP_COUT__ <<
"Unknown error detected!" << __E__;
1184 else if(requestType ==
"getActiveTableGroups")
1186 else if(requestType ==
"copyViewToCurrentColumns")
1188 std::string tableName =
1189 CgiDataUtilities::getData(cgiIn,
"tableName");
1190 std::string sourceVersion = CgiDataUtilities::getData(cgiIn,
"sourceVersion");
1192 __SUP_COUT__ <<
"tableName: " << tableName << __E__;
1193 __SUP_COUT__ <<
"sourceVersion: " << sourceVersion << __E__;
1194 __SUP_COUT__ <<
"userInfo.username_: " << userInfo.username_ << __E__;
1197 TableVersion newTemporaryVersion;
1201 newTemporaryVersion =
1202 cfgMgr->copyViewToCurrentColumns(tableName, TableVersion(sourceVersion));
1215 __SUP_COUT__ <<
"New temporary version = " << newTemporaryVersion << __E__;
1217 catch(std::runtime_error& e)
1219 __SUP_COUT__ <<
"Error detected!\n\n " << e.what() << __E__;
1220 xmlOut.addTextElementToData(
"Error",
1221 "Error copying view from '" + tableName +
"_v" +
1222 sourceVersion +
"'! " +
1223 std::string(e.what()));
1227 __SUP_COUT__ <<
"Error detected!\n\n " << __E__;
1228 xmlOut.addTextElementToData(
1230 "Error copying view from '" + tableName +
"_v" + sourceVersion +
"'! ");
1233 handleGetTableXML(xmlOut, cfgMgr, tableName, newTemporaryVersion);
1235 else if(requestType ==
"getLastTableGroups")
1237 std::string timeString;
1238 std::pair<std::string , TableGroupKey> theGroup;
1240 theGroup = theRemoteWebUsers_.getLastTableGroup(
"Configured", timeString);
1241 xmlOut.addTextElementToData(
"LastConfiguredGroupName", theGroup.first);
1242 xmlOut.addTextElementToData(
"LastConfiguredGroupKey", theGroup.second.toString());
1243 xmlOut.addTextElementToData(
"LastConfiguredGroupTime", timeString);
1244 theGroup = theRemoteWebUsers_.getLastTableGroup(
"Started", timeString);
1245 xmlOut.addTextElementToData(
"LastStartedGroupName", theGroup.first);
1246 xmlOut.addTextElementToData(
"LastStartedGroupKey", theGroup.second.toString());
1247 xmlOut.addTextElementToData(
"LastStartedGroupTime", timeString);
1248 theGroup = theRemoteWebUsers_.getLastTableGroup(
"ActivatedConfig", timeString);
1249 xmlOut.addTextElementToData(
"LastActivatedConfigGroupName", theGroup.first);
1250 xmlOut.addTextElementToData(
"LastActivatedConfigGroupKey", theGroup.second.toString());
1251 xmlOut.addTextElementToData(
"LastActivatedConfigGroupTime", timeString);
1252 theGroup = theRemoteWebUsers_.getLastTableGroup(
"ActivatedContext", timeString);
1253 xmlOut.addTextElementToData(
"LastActivatedContextGroupName", theGroup.first);
1254 xmlOut.addTextElementToData(
"LastActivatedContextGroupKey", theGroup.second.toString());
1255 xmlOut.addTextElementToData(
"LastActivatedContextGroupTime", timeString);
1256 theGroup = theRemoteWebUsers_.getLastTableGroup(
"ActivatedBackbone", timeString);
1257 xmlOut.addTextElementToData(
"LastActivatedBackboneGroupName", theGroup.first);
1258 xmlOut.addTextElementToData(
"LastActivatedBackboneGroupKey", theGroup.second.toString());
1259 xmlOut.addTextElementToData(
"LastActivatedBackboneGroupTime", timeString);
1260 theGroup = theRemoteWebUsers_.getLastTableGroup(
"ActivatedIterator", timeString);
1261 xmlOut.addTextElementToData(
"LastActivatedIteratorGroupName", theGroup.first);
1262 xmlOut.addTextElementToData(
"LastActivatedIteratorGroupKey", theGroup.second.toString());
1263 xmlOut.addTextElementToData(
"LastActivatedIteratorGroupTime", timeString);
1265 else if(requestType ==
"savePlanCommandSequence")
1267 std::string planName = CgiDataUtilities::getData(cgiIn,
"planName");
1268 std::string commands = CgiDataUtilities::postData(cgiIn,
"commands");
1270 std::string modifiedTables = CgiDataUtilities::postData(cgiIn,
"modifiedTables");
1271 std::string groupName = CgiDataUtilities::getData(cgiIn,
"groupName");
1272 std::string groupKey = CgiDataUtilities::getData(cgiIn,
"groupKey");
1274 __SUP_COUT__ <<
"modifiedTables: " << modifiedTables << __E__;
1275 __SUP_COUT__ <<
"planName: " << planName << __E__;
1276 __SUP_COUT__ <<
"commands: " << commands << __E__;
1277 __SUP_COUT__ <<
"groupName: " << groupName << __E__;
1278 __SUP_COUT__ <<
"groupKey: " << groupKey << __E__;
1280 handleSavePlanCommandSequenceXML(xmlOut,
1283 TableGroupKey(groupKey),
1289 else if(requestType ==
"mergeGroups")
1291 std::string groupANameContext =
1292 CgiDataUtilities::getData(cgiIn,
"groupANameContext");
1293 std::string groupAKeyContext =
1294 CgiDataUtilities::getData(cgiIn,
"groupAKeyContext");
1295 std::string groupBNameContext =
1296 CgiDataUtilities::getData(cgiIn,
"groupBNameContext");
1297 std::string groupBKeyContext =
1298 CgiDataUtilities::getData(cgiIn,
"groupBKeyContext");
1299 std::string groupANameConfig =
1300 CgiDataUtilities::getData(cgiIn,
"groupANameConfig");
1301 std::string groupAKeyConfig = CgiDataUtilities::getData(cgiIn,
"groupAKeyConfig");
1302 std::string groupBNameConfig =
1303 CgiDataUtilities::getData(cgiIn,
"groupBNameConfig");
1304 std::string groupBKeyConfig = CgiDataUtilities::getData(cgiIn,
"groupBKeyConfig");
1305 std::string mergeApproach = CgiDataUtilities::getData(cgiIn,
"mergeApproach");
1307 __SUP_COUTV__(groupANameContext);
1308 __SUP_COUTV__(groupAKeyContext);
1309 __SUP_COUTV__(groupBNameContext);
1310 __SUP_COUTV__(groupBKeyContext);
1311 __SUP_COUTV__(groupANameConfig);
1312 __SUP_COUTV__(groupAKeyConfig);
1313 __SUP_COUTV__(groupBNameConfig);
1314 __SUP_COUTV__(groupBKeyConfig);
1315 __SUP_COUTV__(mergeApproach);
1317 handleMergeGroupsXML(xmlOut,
1320 TableGroupKey(groupAKeyContext),
1322 TableGroupKey(groupBKeyContext),
1324 TableGroupKey(groupAKeyConfig),
1326 TableGroupKey(groupBKeyConfig),
1332 __SUP_SS__ <<
"requestType '" << requestType <<
"' request not recognized."
1334 __SUP_COUT__ <<
"\n" << ss.str();
1335 xmlOut.addTextElementToData(
"Error", ss.str());
1341 ConfigurationSupervisorBase::getConfigurationStatusXML(xmlOut, cfgMgr);
1344 catch(
const std::runtime_error& e)
1346 __SS__ <<
"A fatal error occurred while handling the request '" << requestType
1347 <<
".' Error: " << e.what() << __E__;
1348 __COUT_ERR__ <<
"\n" << ss.str();
1349 xmlOut.addTextElementToData(
"Error", ss.str());
1354 xmlOut.addTextElementToData(
1356 ConfigurationInterface::isVersionTrackingEnabled() ?
"ON" :
"OFF");
1360 __COUT_ERR__ <<
"Error getting version tracking status!" << __E__;
1365 __SS__ <<
"An unknown fatal error occurred while handling the request '"
1366 << requestType <<
".'" << __E__;
1367 __COUT_ERR__ <<
"\n" << ss.str();
1368 xmlOut.addTextElementToData(
"Error", ss.str());
1373 xmlOut.addTextElementToData(
1375 ConfigurationInterface::isVersionTrackingEnabled() ?
"ON" :
"OFF");
1379 __COUT_ERR__ <<
"Error getting version tracking status!" << __E__;
1391 void ConfigurationGUISupervisor::handleGetAffectedGroupsXML(
1392 HttpXmlDocument& xmlOut,
1393 ConfigurationManagerRW* cfgMgr,
1394 const std::string& rootGroupName,
1395 const TableGroupKey& rootGroupKey,
1396 const std::string& modifiedTables)
try
1406 std::map<std::string, std::pair<std::string, TableGroupKey>> consideredGroups =
1407 cfgMgr->getActiveTableGroups();
1411 if(consideredGroups[ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT]
1412 .second.isInvalid())
1414 __SUP_COUT__ <<
"Finding a context group to consider..." << __E__;
1415 if(cfgMgr->getFailedTableGroups().find(
1416 ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT) !=
1417 cfgMgr->getFailedTableGroups().end())
1419 consideredGroups[ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT] =
1420 cfgMgr->getFailedTableGroups().at(
1421 ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT);
1423 else if(cfgMgr->getFailedTableGroups().find(
1424 ConfigurationManager::ACTIVE_GROUP_NAME_UNKNOWN) !=
1425 cfgMgr->getFailedTableGroups().end())
1427 consideredGroups[ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT] =
1428 cfgMgr->getFailedTableGroups().at(
1429 ConfigurationManager::ACTIVE_GROUP_NAME_UNKNOWN);
1432 if(consideredGroups[ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION]
1433 .second.isInvalid())
1435 __SUP_COUT__ <<
"Finding a table group to consider..." << __E__;
1436 if(cfgMgr->getFailedTableGroups().find(
1437 ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION) !=
1438 cfgMgr->getFailedTableGroups().end())
1440 consideredGroups[ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION] =
1441 cfgMgr->getFailedTableGroups().at(
1442 ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION);
1444 else if(cfgMgr->getFailedTableGroups().find(
1445 ConfigurationManager::ACTIVE_GROUP_NAME_UNKNOWN) !=
1446 cfgMgr->getFailedTableGroups().end())
1448 consideredGroups[ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION] =
1449 cfgMgr->getFailedTableGroups().at(
1450 ConfigurationManager::ACTIVE_GROUP_NAME_UNKNOWN);
1454 __SUP_COUTV__(StringMacros::mapToString(consideredGroups));
1459 std::map<std::string , TableVersion > rootGroupMemberMap;
1461 cfgMgr->loadTableGroup(rootGroupName,
1464 &rootGroupMemberMap,
1472 const std::string& groupType = cfgMgr->getTypeNameOfGroup(rootGroupMemberMap);
1474 consideredGroups[groupType] =
1475 std::pair<std::string, TableGroupKey>(rootGroupName, rootGroupKey);
1477 catch(
const std::runtime_error& e)
1480 if(rootGroupName.size())
1482 __SUP_SS__ <<
"Failed to determine type of table group for " << rootGroupName
1483 <<
"(" << rootGroupKey <<
")! " << e.what() << __E__;
1484 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1489 __SUP_COUT__ <<
"Did not modify considered active groups due to empty root group "
1490 "name - assuming this was intentional."
1496 if(rootGroupName.size())
1498 __SUP_COUT_ERR__ <<
"Failed to determine type of table group for "
1499 << rootGroupName <<
"(" << rootGroupKey <<
")!" << __E__;
1504 __SUP_COUT__ <<
"Did not modify considered active groups due to empty root group "
1505 "name - assuming this was intentional."
1509 std::map<std::string , TableVersion > modifiedTablesMap;
1510 std::map<std::string , TableVersion >::iterator
1511 modifiedTablesMapIt;
1513 std::istringstream f(modifiedTables);
1514 std::string table, version;
1515 while(getline(f, table,
','))
1517 getline(f, version,
',');
1518 modifiedTablesMap.insert(
1519 std::pair<std::string /*name*/, TableVersion /*version*/>(
1520 table, TableVersion(version)));
1522 __SUP_COUT__ << modifiedTables << __E__;
1523 for(
auto& pair : modifiedTablesMap)
1524 __SUP_COUT__ <<
"modified table " << pair.first <<
":" << pair.second
1529 xercesc::DOMElement* parentEl;
1530 std::string groupComment;
1531 for(
auto group : consideredGroups)
1533 if(group.second.second.isInvalid())
1536 __SUP_COUT__ <<
"Considering " << group.first <<
" group " << group.second.first
1537 <<
" (" << group.second.second <<
")" << __E__;
1541 std::map<std::string , TableVersion > memberMap;
1542 cfgMgr->loadTableGroup(group.second.first,
1543 group.second.second,
1553 __SUP_COUT__ <<
"groupComment = " << groupComment << __E__;
1555 for(
auto& table : memberMap)
1557 if((modifiedTablesMapIt = modifiedTablesMap.find(table.first)) !=
1560 table.second != (*modifiedTablesMapIt).second)
1562 __SUP_COUT__ <<
"Affected by " << (*modifiedTablesMapIt).first <<
":"
1563 << (*modifiedTablesMapIt).second << __E__;
1565 memberMap[table.first] = (*modifiedTablesMapIt).second;
1569 if(group.first == ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION)
1571 __SUP_COUT__ <<
"Considering mockup tables for Configuration Group..." << __E__;
1572 for(
auto& table : modifiedTablesMap)
1574 if(table.second.isMockupVersion() && memberMap.find(table.first) == memberMap.end())
1576 __SUP_COUT__ <<
"Found mockup table '" <<
1577 table.first <<
"' for Configuration Group." << __E__;
1578 memberMap[table.first] = table.second;
1586 parentEl = xmlOut.addTextElementToData(
"AffectedActiveGroup",
"");
1587 xmlOut.addTextElementToParent(
"GroupName", group.second.first, parentEl);
1588 xmlOut.addTextElementToParent(
1589 "GroupKey", group.second.second.toString(), parentEl);
1590 xmlOut.addTextElementToParent(
"GroupComment", groupComment, parentEl);
1592 for(
auto& table : memberMap)
1594 xmlOut.addTextElementToParent(
"MemberName", table.first, parentEl);
1595 xmlOut.addTextElementToParent(
1596 "MemberVersion", table.second.toString(), parentEl);
1601 catch(std::runtime_error& e)
1603 __SUP_COUT__ <<
"Error detected!\n\n " << e.what() << __E__;
1604 xmlOut.addTextElementToData(
1605 "Error",
"Error getting affected groups! " + std::string(e.what()));
1609 __SUP_COUT__ <<
"Error detected!\n\n " << __E__;
1610 xmlOut.addTextElementToData(
"Error",
"Error getting affected groups! ");
1621 void ConfigurationGUISupervisor::setupActiveTablesXML(
1622 HttpXmlDocument& xmlOut,
1623 ConfigurationManagerRW* cfgMgr,
1624 const std::string& groupName,
1625 const TableGroupKey& groupKey,
1626 const std::string& modifiedTables,
1628 bool doGetGroupInfo,
1629 std::map<std::string /*name*/, TableVersion /*version*/>* returnMemberMap,
1630 bool outputActiveTables,
1631 std::string* accumulatedErrors)
try
1636 xmlOut.addTextElementToData(
"tableGroup", groupName);
1637 xmlOut.addTextElementToData(
"tableGroupKey", groupKey.toString());
1639 bool usingActiveGroups = (groupName ==
"" || groupKey.isInvalid());
1642 if(usingActiveGroups || refreshAll)
1644 __SUP_COUT__ <<
"Refreshing all table info, ignoring warnings..." << __E__;
1645 std::string accumulatedWarnings =
"";
1646 cfgMgr->getAllTableInfo(
true, &accumulatedWarnings);
1649 const std::map<std::string, TableInfo>& allTableInfo = cfgMgr->getAllTableInfo(
false);
1651 std::map<std::string , TableVersion > modifiedTablesMap;
1652 std::map<std::string , TableVersion >::iterator
1653 modifiedTablesMapIt;
1655 if(usingActiveGroups)
1658 __SUP_COUT__ <<
"Using active groups." << __E__;
1662 __SUP_COUT__ <<
"Loading group '" << groupName <<
"(" << groupKey <<
")'"
1665 std::string groupComment, groupAuthor, configGroupCreationTime;
1668 cfgMgr->loadTableGroup(groupName,
1674 doGetGroupInfo ? &groupComment : 0,
1675 doGetGroupInfo ? &groupAuthor : 0,
1676 doGetGroupInfo ? &configGroupCreationTime : 0);
1680 xmlOut.addTextElementToData(
"configGroupComment", groupComment);
1681 xmlOut.addTextElementToData(
"configGroupAuthor", groupAuthor);
1682 xmlOut.addTextElementToData(
"configGroupCreationTime",
1683 configGroupCreationTime);
1686 if(accumulatedErrors && *accumulatedErrors !=
"")
1687 __SUP_COUTV__(*accumulatedErrors);
1692 std::istringstream f(modifiedTables);
1693 std::string table, version;
1694 while(getline(f, table,
','))
1696 getline(f, version,
',');
1697 modifiedTablesMap.insert(
1698 std::pair<std::string /*name*/, TableVersion /*version*/>(
1699 table, TableVersion(version)));
1702 for(
auto& pair : modifiedTablesMap)
1703 __SUP_COUT__ <<
"modified table " << pair.first <<
":" << pair.second
1708 std::map<std::string, TableVersion> allActivePairs = cfgMgr->getActiveVersions();
1709 xmlOut.addTextElementToData(
"DefaultNoLink",
1710 TableViewColumnInfo::DATATYPE_LINK_DEFAULT);
1713 std::set<std::string, StringMacros::IgnoreCaseCompareStruct> orderedTableSet;
1714 for(
const auto& tablePair : allActivePairs)
1715 orderedTableSet.emplace(tablePair.first);
1717 std::map<std::string, TableInfo>::const_iterator tableInfoIt;
1718 for(
auto& orderedTableName : orderedTableSet)
1720 tableInfoIt = allTableInfo.find(orderedTableName);
1721 if(tableInfoIt == allTableInfo.end())
1723 __SS__ <<
"Impossible missing table in map '" << orderedTableName <<
"'"
1728 if(outputActiveTables)
1729 xmlOut.addTextElementToData(
"ActiveTableName", orderedTableName);
1733 if((modifiedTablesMapIt = modifiedTablesMap.find(orderedTableName)) !=
1734 modifiedTablesMap.end())
1736 __SUP_COUT__ <<
"Found modified table " << (*modifiedTablesMapIt).first
1737 <<
": trying... " << (*modifiedTablesMapIt).second << __E__;
1741 tableInfoIt->second.tablePtr_->setActiveView(
1742 (*modifiedTablesMapIt).second);
1746 __SUP_SS__ <<
"Modified table version v" << (*modifiedTablesMapIt).second
1747 <<
" failed. Reverting to v"
1748 << tableInfoIt->second.tablePtr_->getView().getVersion() <<
"."
1750 __SUP_COUT_WARN__ <<
"Warning detected!\n\n " << ss.str() << __E__;
1751 xmlOut.addTextElementToData(
1753 "Error setting up active tables!\n\n" + std::string(ss.str()));
1757 if(outputActiveTables)
1759 xmlOut.addTextElementToData(
1760 "ActiveTableVersion",
1761 tableInfoIt->second.tablePtr_->getView().getVersion().toString());
1762 xmlOut.addTextElementToData(
1763 "ActiveTableComment",
1764 tableInfoIt->second.tablePtr_->getView().getComment());
1773 catch(std::runtime_error& e)
1775 __SUP_SS__ << (
"Error setting up active tables!\n\n" + std::string(e.what()))
1777 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1778 xmlOut.addTextElementToData(
"Error", ss.str());
1782 __SUP_SS__ << (
"Error setting up active tables!\n\n") << __E__;
1783 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1784 xmlOut.addTextElementToData(
"Error", ss.str());
1803 void ConfigurationGUISupervisor::handleFillCreateTreeNodeRecordsXML(
1804 HttpXmlDocument& xmlOut,
1805 ConfigurationManagerRW* cfgMgr,
1806 const std::string& groupName,
1807 const TableGroupKey& groupKey,
1808 const std::string& startPath,
1809 const std::string& modifiedTables,
1810 const std::string& recordList,
1811 const std::string& author)
1814 setupActiveTablesXML(xmlOut,
1826 ConfigurationTree targetNode = cfgMgr->getNode(startPath);
1827 TableBase* table = cfgMgr->getTableByName(targetNode.getTableName());
1829 __SUP_COUT__ << table->getTableName() << __E__;
1830 TableVersion temporaryVersion;
1839 bool firstSave =
true;
1842 TableView backupView(targetNode.getTableName());
1846 std::istringstream f(recordList);
1847 std::string recordUID;
1850 while(getline(f, recordUID,
','))
1852 recordUID = StringMacros::decodeURIComponent(recordUID);
1854 __SUP_COUT__ <<
"recordUID " << recordUID << __E__;
1858 if(!(temporaryVersion = targetNode.getTableVersion())
1859 .isTemporaryVersion())
1861 __SUP_COUT__ <<
"Start version " << temporaryVersion << __E__;
1863 temporaryVersion = table->createTemporaryView(temporaryVersion);
1864 cfgMgr->saveNewTable(targetNode.getTableName(),
1869 __SUP_COUT__ <<
"Created temporary version " << temporaryVersion
1873 __SUP_COUT__ <<
"Using temporary version " << temporaryVersion
1879 backupView.copy(table->getView(), temporaryVersion, author);
1888 unsigned int row = table->getViewP()->addRow(
1895 unsigned int col = table->getViewP()->getColStatus();
1896 table->getViewP()->setURIEncodedValue(
"1", row, col);
1903 table->getViewP()->setURIEncodedValue(
1904 recordUID, row, table->getViewP()->getColUID());
1912 table->getViewP()->init();
1916 __SUP_COUT_INFO__ <<
"Reverting to original view." << __E__;
1917 __SUP_COUT__ <<
"Before:" << __E__;
1918 table->getViewP()->print();
1919 table->getViewP()->copy(backupView, temporaryVersion, author);
1920 __SUP_COUT__ <<
"After:" << __E__;
1921 table->getViewP()->print();
1927 handleFillModifiedTablesXML(xmlOut, cfgMgr);
1929 catch(std::runtime_error& e)
1931 __SUP_SS__ << (
"Error creating new record(s)!\n\n" + std::string(e.what()))
1933 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1934 xmlOut.addTextElementToData(
"Error", ss.str());
1938 __SUP_SS__ << (
"Error creating new record(s)!\n\n") << __E__;
1939 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1940 xmlOut.addTextElementToData(
"Error", ss.str());
1947 void ConfigurationGUISupervisor::handleFillModifiedTablesXML(
1948 HttpXmlDocument& xmlOut, ConfigurationManagerRW* cfgMgr)
try
1951 const std::map<std::string, TableInfo>& allTableInfo = cfgMgr->getAllTableInfo();
1952 std::map<std::string, TableVersion> allActivePairs = cfgMgr->getActiveVersions();
1953 for(
auto& activePair : allActivePairs)
1955 xmlOut.addTextElementToData(
"NewActiveTableName", activePair.first);
1956 xmlOut.addTextElementToData(
"NewActiveTableVersion",
1957 allTableInfo.at(activePair.first)
1958 .tablePtr_->getView()
1961 xmlOut.addTextElementToData(
1962 "NewActiveTableComment",
1963 allTableInfo.at(activePair.first).tablePtr_->getView().getComment());
1966 catch(std::runtime_error& e)
1968 __SUP_SS__ << (
"Error!\n\n" + std::string(e.what())) << __E__;
1969 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1970 xmlOut.addTextElementToData(
"Error", ss.str());
1974 __SUP_SS__ << (
"Error!\n\n") << __E__;
1975 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1976 xmlOut.addTextElementToData(
"Error", ss.str());
1994 void ConfigurationGUISupervisor::handleFillDeleteTreeNodeRecordsXML(
1995 HttpXmlDocument& xmlOut,
1996 ConfigurationManagerRW* cfgMgr,
1997 const std::string& groupName,
1998 const TableGroupKey& groupKey,
1999 const std::string& startPath,
2000 const std::string& modifiedTables,
2001 const std::string& recordList)
2004 setupActiveTablesXML(xmlOut,
2016 ConfigurationTree targetNode = cfgMgr->getNode(startPath);
2017 TableBase* table = cfgMgr->getTableByName(targetNode.getTableName());
2019 __SUP_COUT__ << table->getTableName() << __E__;
2020 TableVersion temporaryVersion;
2029 bool firstSave =
true;
2033 std::istringstream f(recordList);
2034 std::string recordUID;
2037 while(getline(f, recordUID,
','))
2039 recordUID = StringMacros::decodeURIComponent(recordUID);
2041 __SUP_COUT__ <<
"recordUID " << recordUID << __E__;
2045 if(!(temporaryVersion = targetNode.getTableVersion())
2046 .isTemporaryVersion())
2048 __SUP_COUT__ <<
"Start version " << temporaryVersion << __E__;
2050 temporaryVersion = table->createTemporaryView(temporaryVersion);
2051 cfgMgr->saveNewTable(targetNode.getTableName(),
2056 __SUP_COUT__ <<
"Created temporary version " << temporaryVersion
2060 __SUP_COUT__ <<
"Using temporary version " << temporaryVersion
2071 table->getViewP()->findRow(table->getViewP()->getColUID(), recordUID);
2072 table->getViewP()->deleteRow(row);
2077 table->getViewP()->init();
2079 handleFillModifiedTablesXML(xmlOut, cfgMgr);
2081 catch(std::runtime_error& e)
2083 __SUP_SS__ << (
"Error removing record(s)!\n\n" + std::string(e.what())) << __E__;
2084 __SUP_COUT_ERR__ <<
"\n" << ss.str();
2085 xmlOut.addTextElementToData(
"Error", ss.str());
2089 __SUP_SS__ << (
"Error removing record(s)!\n\n") << __E__;
2090 __SUP_COUT_ERR__ <<
"\n" << ss.str();
2091 xmlOut.addTextElementToData(
"Error", ss.str());
2111 void ConfigurationGUISupervisor::handleFillRenameTreeNodeRecordsXML(
2112 HttpXmlDocument& xmlOut,
2113 ConfigurationManagerRW* cfgMgr,
2114 const std::string& groupName,
2115 const TableGroupKey& groupKey,
2116 const std::string& startPath,
2117 const std::string& modifiedTables,
2118 const std::string& recordList,
2119 const std::string& newRecordList)
2122 setupActiveTablesXML(xmlOut,
2134 ConfigurationTree targetNode = cfgMgr->getNode(startPath);
2135 TableBase* table = cfgMgr->getTableByName(targetNode.getTableName());
2137 __SUP_COUT__ << table->getTableName() << __E__;
2138 TableVersion temporaryVersion;
2148 std::vector<std::string> recordArray =
2149 StringMacros::getVectorFromString(recordList);
2150 std::vector<std::string> newRecordArray =
2151 StringMacros::getVectorFromString(newRecordList);
2153 __SUP_COUTV__(StringMacros::vectorToString(recordArray));
2154 __SUP_COUTV__(StringMacros::vectorToString(newRecordArray));
2156 if(recordArray.size() == 0 || recordArray.size() != newRecordArray.size())
2159 <<
"Invalid record size vs new record name size, they must be the same: "
2160 << recordArray.size() <<
" vs " << newRecordArray.size() << __E__;
2166 if(!(temporaryVersion = targetNode.getTableVersion()).isTemporaryVersion())
2168 __SUP_COUT__ <<
"Start version " << temporaryVersion << __E__;
2170 temporaryVersion = table->createTemporaryView(temporaryVersion);
2171 cfgMgr->saveNewTable(targetNode.getTableName(),
2176 __SUP_COUT__ <<
"Created temporary version " << temporaryVersion << __E__;
2179 __SUP_COUT__ <<
"Using temporary version " << temporaryVersion << __E__;
2186 for(
unsigned int i = 0; i < recordArray.size(); ++i)
2188 row = table->getViewP()->findRow(
2189 table->getViewP()->getColUID(),
2190 StringMacros::decodeURIComponent(recordArray[i]));
2192 table->getViewP()->setValueAsString(
2193 newRecordArray[i], row, table->getViewP()->getColUID());
2196 table->getViewP()->init();
2198 handleFillModifiedTablesXML(xmlOut, cfgMgr);
2200 catch(std::runtime_error& e)
2202 __SUP_SS__ << (
"Error renaming record(s)!\n\n" + std::string(e.what())) << __E__;
2203 __SUP_COUT_ERR__ <<
"\n" << ss.str();
2204 xmlOut.addTextElementToData(
"Error", ss.str());
2208 __SUP_SS__ << (
"Error renaming record(s)!\n\n") << __E__;
2209 __SUP_COUT_ERR__ <<
"\n" << ss.str();
2210 xmlOut.addTextElementToData(
"Error", ss.str());
2231 void ConfigurationGUISupervisor::handleFillCopyTreeNodeRecordsXML(
2232 HttpXmlDocument& xmlOut,
2233 ConfigurationManagerRW* cfgMgr,
2234 const std::string& groupName,
2235 const TableGroupKey& groupKey,
2236 const std::string& startPath,
2237 const std::string& modifiedTables,
2238 const std::string& recordList,
2239 unsigned int numberOfCopies )
2245 setupActiveTablesXML(xmlOut,
2257 ConfigurationTree targetNode = cfgMgr->getNode(startPath);
2258 TableBase* table = cfgMgr->getTableByName(targetNode.getTableName());
2260 __SUP_COUT__ << table->getTableName() << __E__;
2261 TableVersion temporaryVersion;
2271 std::vector<std::string> recordArray =
2272 StringMacros::getVectorFromString(recordList);
2273 __SUP_COUTV__(StringMacros::vectorToString(recordArray));
2277 if(!(temporaryVersion = targetNode.getTableVersion()).isTemporaryVersion())
2279 __SUP_COUT__ <<
"Start version " << temporaryVersion << __E__;
2281 temporaryVersion = table->createTemporaryView(temporaryVersion);
2282 cfgMgr->saveNewTable(targetNode.getTableName(),
2287 __SUP_COUT__ <<
"Created temporary version " << temporaryVersion << __E__;
2290 __SUP_COUT__ <<
"Using temporary version " << temporaryVersion << __E__;
2297 for(
const auto& recordUID : recordArray)
2299 row = table->getViewP()->findRow(table->getViewP()->getColUID(),
2300 StringMacros::decodeURIComponent(recordUID));
2301 for(
unsigned int i = 0; i < numberOfCopies; ++i)
2302 table->getViewP()->copyRows(
2303 cfgMgr->getUsername(),
2312 table->getViewP()->init();
2314 handleFillModifiedTablesXML(xmlOut, cfgMgr);
2316 catch(std::runtime_error& e)
2318 __SUP_SS__ << (
"Error copying record(s)!\n\n" + std::string(e.what())) << __E__;
2319 __SUP_COUT_ERR__ <<
"\n" << ss.str();
2320 xmlOut.addTextElementToData(
"Error", ss.str());
2324 __SUP_SS__ << (
"Error copying record(s)!\n\n") << __E__;
2325 __SUP_COUT_ERR__ <<
"\n" << ss.str();
2326 xmlOut.addTextElementToData(
"Error", ss.str());
2347 void ConfigurationGUISupervisor::handleFillSetTreeNodeFieldValuesXML(
2348 HttpXmlDocument& xmlOut,
2349 ConfigurationManagerRW* cfgMgr,
2350 const std::string& groupName,
2351 const TableGroupKey& groupKey,
2352 const std::string& startPath,
2353 const std::string& modifiedTables,
2354 const std::string& recordList,
2355 const std::string& fieldList,
2356 const std::string& valueList,
2357 const std::string& author)
2360 setupActiveTablesXML(xmlOut,
2375 std::vector<std::string > fieldPaths;
2378 std::istringstream f(fieldList);
2379 std::string fieldPath;
2380 while(getline(f, fieldPath,
','))
2382 fieldPaths.push_back(StringMacros::decodeURIComponent(fieldPath));
2384 __SUP_COUT__ << fieldList << __E__;
2385 for(
const auto& field : fieldPaths)
2386 __SUP_COUT__ <<
"fieldPath " << field << __E__;
2389 std::vector<std::string > fieldValues;
2392 std::istringstream f(valueList);
2393 std::string fieldValue;
2394 while(getline(f, fieldValue,
','))
2396 fieldValues.push_back(
2402 if(valueList.size() && valueList[valueList.size() - 1] ==
',')
2403 fieldValues.push_back(
"");
2405 __SUP_COUT__ << valueList << __E__;
2406 for(
const auto& value : fieldValues)
2407 __SUP_COUT__ <<
"fieldValue " << value << __E__;
2410 if(fieldPaths.size() != fieldValues.size())
2413 __THROW__(ss.str() +
"Mismatch in fields and values array size!");
2419 TableVersion temporaryVersion;
2420 std::istringstream f(recordList);
2421 std::string recordUID;
2424 while(getline(f, recordUID,
','))
2426 recordUID = StringMacros::decodeURIComponent(recordUID);
2431 xmlOut.addTextElementToData(
"fieldValues", recordUID);
2434 for(i = 0; i < fieldPaths.size(); ++i)
2436 __SUP_COUT__ <<
"fieldPath " << fieldPaths[i] << __E__;
2437 __SUP_COUT__ <<
"fieldValue " << fieldValues[i] << __E__;
2441 ConfigurationTree targetNode =
2442 cfgMgr->getNode(startPath +
"/" + recordUID +
"/" + fieldPaths[i],
2477 __SUP_COUT__ <<
"Getting table " << targetNode.getFieldTableName()
2481 table = cfgMgr->getTableByName(
2482 targetNode.getFieldTableName());
2483 if(!(temporaryVersion = table->getViewP()->getVersion())
2484 .isTemporaryVersion())
2488 table->createTemporaryView(table->getViewP()->getVersion());
2489 cfgMgr->saveNewTable(table->getTableName(),
2494 __SUP_COUT__ <<
"Created temporary version "
2495 << table->getTableName() <<
"-v" << temporaryVersion
2499 __SUP_COUT__ <<
"Using temporary version " << table->getTableName()
2500 <<
"-v" << temporaryVersion << __E__;
2504 table->getViewP()->setURIEncodedValue(fieldValues[i],
2505 targetNode.getFieldRow(),
2506 targetNode.getFieldColumn(),
2515 handleFillModifiedTablesXML(xmlOut, cfgMgr);
2517 catch(std::runtime_error& e)
2519 __SUP_SS__ << (
"Error setting field values!\n\n" + std::string(e.what()))
2521 __SUP_COUT_ERR__ <<
"\n" << ss.str();
2522 xmlOut.addTextElementToData(
"Error", ss.str());
2526 __SUP_SS__ << (
"Error setting field values!\n\n") << __E__;
2527 __SUP_COUT_ERR__ <<
"\n" << ss.str();
2528 xmlOut.addTextElementToData(
"Error", ss.str());
2547 void ConfigurationGUISupervisor::handleFillGetTreeNodeFieldValuesXML(
2548 HttpXmlDocument& xmlOut,
2549 ConfigurationManagerRW* cfgMgr,
2550 const std::string& groupName,
2551 const TableGroupKey& groupKey,
2552 const std::string& startPath,
2553 const std::string& modifiedTables,
2554 const std::string& recordList,
2555 const std::string& fieldList)
2558 setupActiveTablesXML(xmlOut, cfgMgr, groupName, groupKey, modifiedTables);
2565 std::vector<std::string > fieldPaths;
2568 std::istringstream f(fieldList);
2569 std::string fieldPath;
2570 while(getline(f, fieldPath,
','))
2572 fieldPaths.push_back(StringMacros::decodeURIComponent(fieldPath));
2574 __SUP_COUT__ << fieldList << __E__;
2581 std::istringstream f(recordList);
2582 std::string recordUID;
2583 while(getline(f, recordUID,
','))
2585 recordUID = StringMacros::decodeURIComponent(recordUID);
2587 __SUP_COUT__ <<
"recordUID " << recordUID << __E__;
2589 xercesc::DOMElement* parentEl =
2590 xmlOut.addTextElementToData(
"fieldValues", recordUID);
2593 for(
const auto& fieldPath : fieldPaths)
2595 __SUP_COUT__ <<
"fieldPath " << fieldPath << __E__;
2597 ConfigurationTree node =
2598 cfgMgr->getNode(startPath +
"/" + recordUID +
"/" + fieldPath);
2600 xmlOut.addTextElementToParent(
"FieldPath", fieldPath, parentEl);
2602 xmlOut.addTextElementToParent(
2604 cfgMgr->getNode(startPath +
"/" + recordUID +
"/" + fieldPath)
2605 .getValueAsString(
true ),
2611 catch(std::runtime_error& e)
2613 __SUP_SS__ << (
"Error getting field values!\n\n" + std::string(e.what()))
2615 __SUP_COUT_ERR__ <<
"\n" << ss.str();
2616 xmlOut.addTextElementToData(
"Error", ss.str());
2620 __SUP_SS__ << (
"Error getting field values!\n\n") << __E__;
2621 __SUP_COUT_ERR__ <<
"\n" << ss.str();
2622 xmlOut.addTextElementToData(
"Error", ss.str());
2645 void ConfigurationGUISupervisor::handleFillTreeNodeCommonFieldsXML(
2646 HttpXmlDocument& xmlOut,
2647 ConfigurationManagerRW* cfgMgr,
2648 const std::string& groupName,
2649 const TableGroupKey& groupKey,
2650 const std::string& startPath,
2652 const std::string& modifiedTables,
2653 const std::string& recordList,
2654 const std::string& fieldList)
2657 setupActiveTablesXML(xmlOut, cfgMgr, groupName, groupKey, modifiedTables);
2661 xercesc::DOMElement* parentEl = xmlOut.addTextElementToData(
"fields", startPath);
2665 __SUP_SS__ <<
"Depth of search must be greater than 0." << __E__;
2666 __SUP_COUT__ << ss.str();
2675 std::vector<ConfigurationTree::RecordField> retFieldList;
2678 ConfigurationTree startNode = cfgMgr->getNode(startPath);
2679 if(startNode.isLinkNode() && startNode.isDisconnected())
2681 __SUP_SS__ <<
"Start path was a disconnected link node!" << __E__;
2687 std::vector<std::string > fieldAcceptList, fieldRejectList;
2692 std::istringstream f(fieldList);
2693 std::string fieldPath, decodedFieldPath;
2694 while(getline(f, fieldPath,
','))
2696 decodedFieldPath = StringMacros::decodeURIComponent(fieldPath);
2698 if(decodedFieldPath[0] ==
'!')
2699 fieldRejectList.push_back(decodedFieldPath.substr(1));
2701 fieldAcceptList.push_back(decodedFieldPath);
2703 __SUP_COUT__ << fieldList << __E__;
2704 for(
auto& field : fieldAcceptList)
2705 __SUP_COUT__ <<
"fieldAcceptList " << field << __E__;
2706 for(
auto& field : fieldRejectList)
2707 __SUP_COUT__ <<
"fieldRejectList " << field << __E__;
2711 std::vector<std::string > records;
2712 if(recordList ==
"*")
2715 records = startNode.getChildrenNames();
2716 __SUP_COUT__ <<
"Translating wildcard..." << __E__;
2717 for(
auto& record : records)
2718 __SUP_COUT__ <<
"recordList " << record << __E__;
2720 else if(recordList !=
"")
2724 std::istringstream f(recordList);
2725 std::string recordStr;
2726 while(getline(f, recordStr,
','))
2728 records.push_back(StringMacros::decodeURIComponent(recordStr));
2730 __SUP_COUT__ << recordList << __E__;
2731 for(
auto& record : records)
2732 __SUP_COUT__ <<
"recordList " << record << __E__;
2737 retFieldList = startNode.getCommonFields(
2738 records, fieldAcceptList, fieldRejectList, depth);
2742 xercesc::DOMElement* parentTypeEl;
2743 for(
const auto& fieldInfo : retFieldList)
2745 xmlOut.addTextElementToParent(
2746 "FieldTableName", fieldInfo.tableName_, parentEl);
2747 xmlOut.addTextElementToParent(
2748 "FieldColumnName", fieldInfo.columnName_, parentEl);
2749 xmlOut.addTextElementToParent(
2750 "FieldRelativePath", fieldInfo.relativePath_, parentEl);
2751 xmlOut.addTextElementToParent(
2752 "FieldColumnType", fieldInfo.columnInfo_->getType(), parentEl);
2753 xmlOut.addTextElementToParent(
2754 "FieldColumnDataType", fieldInfo.columnInfo_->getDataType(), parentEl);
2755 xmlOut.addTextElementToParent(
"FieldColumnDefaultValue",
2756 fieldInfo.columnInfo_->getDefaultValue(),
2760 xmlOut.addTextElementToParent(
"FieldColumnDataChoices",
"", parentEl);
2763 auto dataChoices = fieldInfo.columnInfo_->getDataChoices();
2764 xmlOut.addTextElementToParent(
2765 "FieldColumnDataChoice",
2766 fieldInfo.columnInfo_->getDefaultValue(),
2768 for(
const auto& dataChoice : dataChoices)
2769 xmlOut.addTextElementToParent(
2770 "FieldColumnDataChoice", dataChoice, parentTypeEl);
2773 catch(std::runtime_error& e)
2775 __SUP_SS__ << (
"Error getting common fields!\n\n" + std::string(e.what()))
2777 __SUP_COUT_ERR__ <<
"\n" << ss.str();
2778 xmlOut.addTextElementToData(
"Error", ss.str());
2782 __SUP_SS__ << (
"Error getting common fields!\n\n") << __E__;
2783 __SUP_COUT_ERR__ <<
"\n" << ss.str();
2784 xmlOut.addTextElementToData(
"Error", ss.str());
2816 void ConfigurationGUISupervisor::handleFillUniqueFieldValuesForRecordsXML(
2817 HttpXmlDocument& xmlOut,
2818 ConfigurationManagerRW* cfgMgr,
2819 const std::string& groupName,
2820 const TableGroupKey& groupKey,
2821 const std::string& startPath,
2822 const std::string& modifiedTables,
2823 const std::string& recordList,
2824 const std::string& fieldList)
2827 setupActiveTablesXML(xmlOut, cfgMgr, groupName, groupKey, modifiedTables);
2833 if(startPath ==
"/")
2836 ConfigurationTree startNode = cfgMgr->getNode(startPath);
2837 if(startNode.isLinkNode() && startNode.isDisconnected())
2839 __SUP_SS__ <<
"Start path was a disconnected link node!" << __E__;
2840 __SUP_COUT_ERR__ <<
"\n" << ss.str();
2845 std::vector<std::string > records;
2846 if(recordList ==
"*")
2849 records = startNode.getChildrenNames();
2850 __SUP_COUT__ <<
"Translating wildcard..." << __E__;
2851 for(
auto& record : records)
2852 __SUP_COUT__ <<
"recordList " << record << __E__;
2854 else if(recordList !=
"")
2858 std::istringstream f(recordList);
2859 std::string recordStr;
2860 while(getline(f, recordStr,
','))
2862 records.push_back(StringMacros::decodeURIComponent(recordStr));
2864 __SUP_COUT__ << recordList << __E__;
2865 for(
auto& record : records)
2866 __SUP_COUT__ <<
"recordList " << record << __E__;
2871 std::vector<std::string > fieldsToGet;
2876 if(fieldList ==
"AUTO")
2881 __SUP_COUT__ <<
"Getting AUTO filter fields!" << __E__;
2883 std::vector<ConfigurationTree::RecordField> retFieldList;
2884 std::vector<std::string > fieldAcceptList,
2886 fieldRejectList.push_back(
"*" + TableViewColumnInfo::COL_NAME_COMMENT);
2887 retFieldList = startNode.getCommonFields(
2888 records, fieldAcceptList, fieldRejectList, 5,
true );
2890 for(
const auto& retField : retFieldList)
2891 fieldsToGet.push_back(retField.relativePath_ + retField.columnName_);
2895 std::istringstream f(fieldList);
2896 std::string fieldPath;
2897 while(getline(f, fieldPath,
','))
2899 fieldsToGet.push_back(StringMacros::decodeURIComponent(fieldPath));
2901 __SUP_COUTV__(fieldList);
2905 __SUP_COUTV__(StringMacros::vectorToString(fieldsToGet));
2909 ConfigurationTree startNode = cfgMgr->getNode(startPath);
2910 std::string fieldGroupIDChildLinkIndex;
2911 for(
auto& field : fieldsToGet)
2913 __SUP_COUTV__(field);
2915 xercesc::DOMElement* parentEl =
2916 xmlOut.addTextElementToData(
"field", field);
2922 std::set<std::string > uniqueValues =
2923 startNode.getUniqueValuesForField(
2924 records, field, &fieldGroupIDChildLinkIndex);
2926 if(fieldGroupIDChildLinkIndex !=
"")
2927 xmlOut.addTextElementToParent(
2928 "childLinkIndex", fieldGroupIDChildLinkIndex, parentEl);
2930 for(
auto& uniqueValue : uniqueValues)
2932 __SUP_COUT__ <<
"uniqueValue " << uniqueValue << __E__;
2934 xmlOut.addTextElementToParent(
"uniqueValue", uniqueValue, parentEl);
2939 catch(std::runtime_error& e)
2941 __SUP_SS__ << (
"Error getting common fields!\n\n" + std::string(e.what()))
2943 __SUP_COUT_ERR__ <<
"\n" << ss.str();
2944 xmlOut.addTextElementToData(
"Error", ss.str());
2948 __SUP_SS__ << (
"Error getting common fields!\n\n") << __E__;
2949 __SUP_COUT_ERR__ <<
"\n" << ss.str();
2950 xmlOut.addTextElementToData(
"Error", ss.str());
2974 void ConfigurationGUISupervisor::handleFillTreeViewXML(HttpXmlDocument& xmlOut,
2975 ConfigurationManagerRW* cfgMgr,
2976 const std::string& groupName,
2977 const TableGroupKey& groupKey,
2978 const std::string& startPath,
2980 bool hideStatusFalse,
2981 const std::string& modifiedTables,
2982 const std::string& filterList)
3013 bool usingActiveGroups = (groupName ==
"" || groupKey.isInvalid());
3014 std::map<std::string , TableVersion > memberMap;
3016 std::string accumulatedErrors =
"";
3019 setupActiveTablesXML(xmlOut,
3033 catch(
const std::runtime_error& e)
3035 __SS__ <<
"Error occured setting up active tables: " << e.what() << __E__;
3036 accumulatedErrors += ss.str();
3040 __SS__ <<
"Unknown error occured setting up active tables." << __E__;
3041 accumulatedErrors += ss.str();
3044 if(accumulatedErrors !=
"")
3046 xmlOut.addTextElementToData(
"Warning", accumulatedErrors);
3048 __SUP_COUT__ <<
"Active tables are setup. Warning string: '" << accumulatedErrors
3051 __SUP_COUT__ <<
"Active table versions: "
3052 << StringMacros::mapToString(cfgMgr->getActiveVersions()) << __E__;
3055 __SUP_COUT__ <<
"Active tables are setup. No issues found." << __E__;
3059 xercesc::DOMElement* parentEl = xmlOut.addTextElementToData(
"tree", startPath);
3064 std::vector<std::pair<std::string, ConfigurationTree>> rootMap;
3066 if(startPath ==
"/")
3070 std::string accumulateTreeErrs;
3072 if(usingActiveGroups)
3073 rootMap = cfgMgr->getChildren(0, &accumulateTreeErrs);
3075 rootMap = cfgMgr->getChildren(&memberMap, &accumulateTreeErrs);
3077 __SUP_COUT__ <<
"accumulateTreeErrs = " << accumulateTreeErrs << __E__;
3078 if(accumulateTreeErrs !=
"")
3079 xmlOut.addTextElementToData(
"TreeErrors", accumulateTreeErrs);
3083 ConfigurationTree startNode =
3084 cfgMgr->getNode(startPath,
true );
3085 if(startNode.isLinkNode() && startNode.isDisconnected())
3087 xmlOut.addTextElementToData(
"DisconnectedStartNode",
"1");
3092 std::map<std::string , std::string > filterMap;
3093 StringMacros::getMapFromString(
3096 std::set<char>({
';'}) ,
3097 std::set<char>({
'='}) );
3099 __COUTV__(StringMacros::mapToString(filterMap));
3101 rootMap = cfgMgr->getNode(startPath).getChildren(filterMap);
3104 for(
auto& treePair : rootMap)
3106 treePair.second, depth - 1, xmlOut, parentEl, hideStatusFalse);
3108 catch(std::runtime_error& e)
3110 __SUP_SS__ <<
"Error detected generating XML tree!\n\n " << e.what() << __E__;
3111 __SUP_COUT_ERR__ <<
"\n" << ss.str();
3112 xmlOut.addTextElementToData(
"Error", ss.str());
3116 __SUP_SS__ <<
"Error detected generating XML tree!" << __E__;
3117 __SUP_COUT_ERR__ <<
"\n" << ss.str();
3118 xmlOut.addTextElementToData(
"Error", ss.str());
3128 void ConfigurationGUISupervisor::recursiveTreeToXML(
const ConfigurationTree& t,
3130 HttpXmlDocument& xmlOut,
3131 xercesc::DOMElement* parentEl,
3132 bool hideStatusFalse)
3138 parentEl = xmlOut.addTextElementToParent(
"node", t.getValueName(), parentEl);
3139 xmlOut.addTextElementToParent(
"value", t.getValueAsString(), parentEl);
3140 parentEl = xmlOut.addTextElementToParent(
"valueType", t.getValueType(), parentEl);
3144 if(t.getValueType() == TableViewColumnInfo::TYPE_FIXED_CHOICE_DATA ||
3145 t.getValueType() == TableViewColumnInfo::TYPE_BITMAP_DATA)
3149 std::vector<std::string> choices = t.getFixedChoices();
3150 for(
const auto& choice : choices)
3151 xmlOut.addTextElementToParent(
"fixedChoice", choice, parentEl);
3162 parentEl = xmlOut.addTextElementToParent(
"node", t.getValueName(), parentEl);
3164 if(t.isDisconnected())
3166 __COUT__ << t.getValueName() << __E__;
3172 xmlOut.addTextElementToParent(
"valueType", t.getValueType(), parentEl);
3175 xmlOut.addTextElementToParent(
3176 (t.isGroupLinkNode() ?
"Group" :
"U") + std::string(
"ID"),
3177 t.getDisconnectedLinkID(),
3179 xmlOut.addTextElementToParent(
3180 "LinkTableName", t.getDisconnectedTableName(), parentEl);
3181 xmlOut.addTextElementToParent(
3182 "LinkIndex", t.getChildLinkIndex(), parentEl);
3185 xercesc::DOMElement* choicesParentEl =
3186 xmlOut.addTextElementToParent(
"fixedChoices",
"", parentEl);
3190 std::vector<std::string> choices = t.getFixedChoices();
3191 __COUT__ <<
"choices.size() " << choices.size() << __E__;
3193 for(
const auto& choice : choices)
3194 xmlOut.addTextElementToParent(
"fixedChoice", choice, choicesParentEl);
3206 xmlOut.addTextElementToParent(
3207 (t.isGroupLinkNode() ?
"Group" :
"U") + std::string(
"ID"),
3208 t.getValueAsString(),
3211 xmlOut.addTextElementToParent(
"LinkTableName", t.getTableName(), parentEl);
3212 xmlOut.addTextElementToParent(
"LinkIndex", t.getChildLinkIndex(), parentEl);
3216 xercesc::DOMElement* choicesParentEl =
3217 xmlOut.addTextElementToParent(
"fixedChoices",
"", parentEl);
3218 std::vector<std::string> choices = t.getFixedChoices();
3222 for(
const auto& choice : choices)
3223 xmlOut.addTextElementToParent(
"fixedChoice", choice, choicesParentEl);
3228 bool returnNode =
true;
3234 t.getNode(TableViewColumnInfo::COL_NAME_STATUS).getValue(returnNode);
3243 xmlOut.addTextElementToParent(
"node", t.getValueAsString(), parentEl);
3252 auto C = t.getChildren();
3255 c.second, depth - 1, xmlOut, parentEl, hideStatusFalse);
3267 void ConfigurationGUISupervisor::handleGetLinkToChoicesXML(
3268 HttpXmlDocument& xmlOut,
3269 ConfigurationManagerRW* cfgMgr,
3270 const std::string& linkToTableName,
3271 const TableVersion& linkToTableVersion,
3272 const std::string& linkIdType,
3273 const std::string& linkIndex,
3274 const std::string& linkInitId)
try
3286 const std::string& tableName = linkToTableName;
3287 const TableVersion& version = linkToTableVersion;
3288 TableBase* table = cfgMgr->getTableByName(tableName);
3291 table->setActiveView(version);
3295 __SUP_COUT__ <<
"Failed to find stored version, so attempting to load version: "
3296 << version << __E__;
3297 cfgMgr->getVersionedTableByName(tableName, version);
3300 if(version != table->getViewVersion())
3302 __SUP_SS__ <<
"Target table version (" << version
3303 <<
") is not the currently active version (" << table->getViewVersion()
3304 <<
". Try refreshing the tree." << __E__;
3305 __SUP_COUT_WARN__ << ss.str();
3309 __SUP_COUT__ <<
"Active version is " << table->getViewVersion() << __E__;
3311 if(linkIdType ==
"UID")
3314 unsigned int col = table->getView().getColUID();
3315 for(
unsigned int row = 0; row < table->getView().getNumberOfRows(); ++row)
3316 xmlOut.addTextElementToData(
"linkToChoice",
3317 table->getView().getDataView()[row][col]);
3319 else if(linkIdType ==
"GroupID")
3325 __SUP_COUTV__(linkIndex);
3326 __SUP_COUTV__(linkInitId);
3328 std::set<std::string> setOfGroupIDs =
3329 table->getView().getSetOfGroupIDs(linkIndex);
3334 bool foundInitId =
false;
3335 for(
const auto& groupID : setOfGroupIDs)
3337 if(!foundInitId && linkInitId == groupID)
3340 xmlOut.addTextElementToData(
"linkToChoice", groupID);
3344 xmlOut.addTextElementToData(
"linkToChoice", linkInitId);
3347 unsigned int col = table->getView().getColUID();
3348 for(
unsigned int row = 0; row < table->getView().getNumberOfRows(); ++row)
3350 xmlOut.addTextElementToData(
"groupChoice",
3351 table->getView().getDataView()[row][col]);
3352 if(table->getView().isEntryInGroup(row, linkIndex, linkInitId))
3353 xmlOut.addTextElementToData(
"groupMember",
3354 table->getView().getDataView()[row][col]);
3359 __SUP_SS__ <<
"Unrecognized linkIdType '" << linkIdType <<
".'" << __E__;
3363 catch(std::runtime_error& e)
3365 __SUP_SS__ <<
"Error detected saving tree node!\n\n " << e.what() << __E__;
3366 __SUP_COUT_ERR__ <<
"\n" << ss.str() << __E__;
3367 xmlOut.addTextElementToData(
"Error", ss.str());
3371 __SUP_SS__ <<
"Error detected saving tree node!\n\n " << __E__;
3372 __SUP_COUT_ERR__ <<
"\n" << ss.str() << __E__;
3373 xmlOut.addTextElementToData(
"Error", ss.str());
3378 void ConfigurationGUISupervisor::handleMergeGroupsXML(
3379 HttpXmlDocument& xmlOut,
3380 ConfigurationManagerRW* cfgMgr,
3381 const std::string& groupANameContext,
3382 const TableGroupKey& groupAKeyContext,
3383 const std::string& groupBNameContext,
3384 const TableGroupKey& groupBKeyContext,
3385 const std::string& groupANameConfig,
3386 const TableGroupKey& groupAKeyConfig,
3387 const std::string& groupBNameConfig,
3388 const TableGroupKey& groupBKeyConfig,
3389 const std::string& author,
3390 const std::string& mergeApproach)
try
3392 __SUP_COUT__ <<
"Merging context group pair " << groupANameContext <<
" ("
3393 << groupAKeyContext <<
") & " << groupBNameContext <<
" ("
3394 << groupBKeyContext <<
") and table group pair " << groupANameConfig
3395 <<
" (" << groupAKeyConfig <<
") & " << groupBNameConfig <<
" ("
3396 << groupBKeyConfig <<
") with approach '" << mergeApproach << __E__;
3412 if(!(mergeApproach ==
"Rename" || mergeApproach ==
"Replace" ||
3413 mergeApproach ==
"Skip"))
3415 __SS__ <<
"Error! Invalid merge approach '" << mergeApproach <<
".'" << __E__;
3419 std::map<std::string , TableVersion > memberMapAContext,
3420 memberMapBContext, memberMapAConfig, memberMapBConfig;
3423 bool skippingContextPair =
false;
3424 bool skippingConfigPair =
false;
3425 if(groupANameContext.size() == 0 || groupANameContext[0] ==
' ' ||
3426 groupBNameContext.size() == 0 || groupBNameContext[0] ==
' ')
3428 skippingContextPair =
true;
3429 __SUP_COUTV__(skippingContextPair);
3431 if(groupANameConfig.size() == 0 || groupANameConfig[0] ==
' ' ||
3432 groupBNameConfig.size() == 0 || groupBNameConfig[0] ==
' ')
3434 skippingConfigPair =
true;
3435 __SUP_COUTV__(skippingConfigPair);
3439 if(!skippingContextPair)
3441 cfgMgr->loadTableGroup(groupANameContext,
3453 __SUP_COUTV__(StringMacros::mapToString(memberMapAContext));
3455 cfgMgr->loadTableGroup(groupBNameContext,
3468 __SUP_COUTV__(StringMacros::mapToString(memberMapBContext));
3472 if(!skippingConfigPair)
3474 cfgMgr->loadTableGroup(groupANameConfig,
3486 __SUP_COUTV__(StringMacros::mapToString(memberMapAConfig));
3488 cfgMgr->loadTableGroup(groupBNameConfig,
3501 __SUP_COUTV__(StringMacros::mapToString(memberMapBConfig));
3509 std::map<std::pair<std::string , std::string >,
3513 std::pair<std::string ,
3514 std::pair<std::string , std::string >>,
3516 groupidConversionMap;
3520 for(
unsigned int i = 0; i < 2; ++i)
3522 if(i == 0 && mergeApproach !=
"Rename")
3526 for(
unsigned int j = 0; j < 2; ++j)
3528 if(j == 0 && skippingContextPair)
3530 __COUT__ <<
"Skipping context pair..." << __E__;
3533 else if(j == 1 && skippingConfigPair)
3535 __COUT__ <<
"Skipping table pair..." << __E__;
3539 std::map<std::string , TableVersion >& memberMapAref =
3540 j == 0 ? memberMapAContext : memberMapAConfig;
3542 std::map<std::string , TableVersion >& memberMapBref =
3543 j == 0 ? memberMapBContext : memberMapBConfig;
3546 __COUT__ <<
"Context pair..." << __E__;
3548 __COUT__ <<
"Table pair..." << __E__;
3550 __COUT__ <<
"Starting member map B scan." << __E__;
3551 for(
const auto bkey : memberMapBref)
3553 __SUP_COUTV__(bkey.first);
3555 if(memberMapAref.find(bkey.first) == memberMapAref.end())
3558 memberMapAref[bkey.first] = bkey.second;
3560 else if(memberMapAref[bkey.first] != bkey.second)
3563 __SUP_COUTV__(memberMapAref[bkey.first]);
3564 __SUP_COUTV__(bkey.second);
3567 TableBase* table = cfgMgr->getTableByName(bkey.first);
3569 __SUP_COUT__ <<
"Got table." << __E__;
3571 TableVersion newVersion = table->mergeViews(
3573 ->getVersionedTableByName(bkey.first,
3574 memberMapAref[bkey.first])
3576 cfgMgr->getVersionedTableByName(bkey.first, bkey.second)
3582 groupidConversionMap,
3585 table->getTableName() ==
3586 ConfigurationManager::
3587 XDAQ_APPLICATION_TABLE_NAME
3593 __SUP_COUTV__(newVersion);
3600 ConfigurationSupervisorBase::saveModifiedVersionXML(
3611 catch(std::runtime_error& e)
3614 <<
"There was an error saving the '"
3615 << table->getTableName()
3616 <<
"' merge result to a persistent table version. "
3617 <<
"Perhaps you can modify this table in one of the "
3618 "groups to resolve this issue, and then re-merge."
3619 << __E__ << e.what();
3623 __SUP_COUTV__(newVersion);
3625 memberMapAref[bkey.first] = newVersion;
3634 if(!skippingContextPair)
3636 __SUP_COUT__ <<
"New context member map complete." << __E__;
3637 __SUP_COUTV__(StringMacros::mapToString(memberMapAContext));
3640 TableGroupKey newKeyContext = cfgMgr->saveNewTableGroup(
3643 "Merger of group " + groupANameContext +
" (" + groupAKeyContext.toString() +
3644 ") and " + groupBNameContext +
" (" + groupBKeyContext.toString() +
").");
3647 xmlOut.addTextElementToData(
"ContextGroupName", groupANameContext);
3648 xmlOut.addTextElementToData(
"ContextGroupKey", newKeyContext.toString());
3650 if(!skippingConfigPair)
3652 __SUP_COUT__ <<
"New table member map complete." << __E__;
3653 __SUP_COUTV__(StringMacros::mapToString(memberMapAConfig));
3656 TableGroupKey newKeyConfig = cfgMgr->saveNewTableGroup(
3659 "Merger of group " + groupANameConfig +
" (" + groupAKeyConfig.toString() +
3660 ") and " + groupBNameConfig +
" (" + groupBKeyConfig.toString() +
").");
3663 xmlOut.addTextElementToData(
"ConfigGroupName", groupANameConfig);
3664 xmlOut.addTextElementToData(
"ConfigGroupKey", newKeyConfig.toString());
3668 catch(std::runtime_error& e)
3670 __SUP_SS__ <<
"Error merging context group pair " << groupANameContext <<
" ("
3671 << groupAKeyContext <<
") & " << groupBNameContext <<
" ("
3672 << groupBKeyContext <<
") and table group pair " << groupANameConfig
3673 <<
" (" << groupAKeyConfig <<
") & " << groupBNameConfig <<
" ("
3674 << groupBKeyConfig <<
") with approach '" << mergeApproach <<
"': \n\n"
3675 << e.what() << __E__;
3676 __SUP_COUT_ERR__ <<
"\n" << ss.str() << __E__;
3677 xmlOut.addTextElementToData(
"Error", ss.str());
3681 __SUP_SS__ <<
"Unknown error merging context group pair " << groupANameContext <<
" ("
3682 << groupAKeyContext <<
") & " << groupBNameContext <<
" ("
3683 << groupBKeyContext <<
") and table group pair " << groupANameConfig
3684 <<
" (" << groupAKeyConfig <<
") & " << groupBNameConfig <<
" ("
3685 << groupBKeyConfig <<
") with approach '" << mergeApproach <<
".' \n\n";
3686 __SUP_COUT_ERR__ <<
"\n" << ss.str() << __E__;
3687 xmlOut.addTextElementToData(
"Error", ss.str());
3692 void ConfigurationGUISupervisor::handleSavePlanCommandSequenceXML(
3693 HttpXmlDocument& xmlOut,
3694 ConfigurationManagerRW* cfgMgr,
3695 const std::string& groupName,
3696 const TableGroupKey& groupKey,
3697 const std::string& modifiedTables,
3698 const std::string& author,
3699 const std::string& planName,
3700 const std::string& commandString)
try
3702 __MOUT__ <<
"handleSavePlanCommandSequenceXML" << __E__;
3705 setupActiveTablesXML(xmlOut,
3715 TableEditStruct planTable(IterateTable::PLAN_TABLE,
3717 TableEditStruct targetTable(IterateTable::TARGET_TABLE,
3721 std::map<std::string, TableEditStruct> commandTypeToCommandTableMap;
3722 for(
const auto& commandPair : IterateTable::commandToTableMap_)
3723 if(commandPair.second !=
"")
3724 commandTypeToCommandTableMap.emplace(std::pair<std::string, TableEditStruct>(
3725 commandPair.first, TableEditStruct(commandPair.second, cfgMgr)));
3741 std::string groupName = planName +
"-Plan";
3742 __SUP_COUT__ <<
"Handling commands for group " << groupName << __E__;
3744 unsigned int groupIdCol =
3745 planTable.tableView_->findCol(IterateTable::planTableCols_.GroupID_);
3746 unsigned int cmdTypeCol =
3747 planTable.tableView_->findCol(IterateTable::planTableCols_.CommandType_);
3749 unsigned int targetGroupIdCol =
3750 targetTable.tableView_->findCol(IterateTable::targetCols_.GroupID_);
3751 unsigned int targetTableCol =
3752 targetTable.tableView_->findCol(IterateTable::targetCols_.TargetLink_);
3753 unsigned int targetUIDCol =
3754 targetTable.tableView_->findCol(IterateTable::targetCols_.TargetLinkUID_);
3756 std::string groupLinkIndex =
3757 planTable.tableView_->getColumnInfo(groupIdCol).getChildLinkIndex();
3758 __SUP_COUT__ <<
"groupLinkIndex: " << groupLinkIndex << __E__;
3760 std::pair<
unsigned int ,
unsigned int > commandUidLink;
3763 planTable.tableView_->getChildLink(
3764 planTable.tableView_->findCol(IterateTable::planTableCols_.CommandLink_),
3769 unsigned int cmdRow, cmdCol;
3770 std::string targetGroupName;
3774 std::string targetUID, cmdType;
3776 for(
unsigned int row = 0; row < planTable.tableView_->getNumberOfRows();
3779 targetUID = planTable.tableView_
3780 ->getDataView()[row][planTable.tableView_->getColUID()];
3781 __SUP_COUT__ <<
"targetUID: " << targetUID << __E__;
3784 if(planTable.tableView_->isEntryInGroup(row, groupLinkIndex, groupName))
3786 __SUP_COUT__ <<
"Removing." << __E__;
3790 cmdType = planTable.tableView_->getDataView()[row][cmdTypeCol];
3791 if(commandTypeToCommandTableMap.find(cmdType) !=
3792 commandTypeToCommandTableMap
3796 commandTypeToCommandTableMap[cmdType].tableView_->findRow(
3797 commandTypeToCommandTableMap[cmdType]
3798 .tableView_->getColUID(),
3799 planTable.tableView_
3800 ->getDataView()[row][commandUidLink.second]);
3808 commandTypeToCommandTableMap[cmdType].tableView_->findCol(
3809 IterateTable::commandTargetCols_.TargetsLinkGroupID_);
3811 commandTypeToCommandTableMap[cmdType]
3812 .tableView_->getDataView()[cmdRow][cmdCol];
3814 for(
unsigned int trow = 0;
3815 trow < targetTable.tableView_->getNumberOfRows();
3819 if(targetTable.tableView_->isEntryInGroup(
3821 commandTypeToCommandTableMap[cmdType]
3822 .tableView_->getColumnInfo(cmdCol)
3823 .getChildLinkIndex(),
3826 __SUP_COUT__ <<
"Removing target." << __E__;
3828 if(targetTable.tableView_->removeRowFromGroup(
3839 __SUP_COUT__ <<
"No targets." << __E__;
3844 commandTypeToCommandTableMap[cmdType].tableView_->deleteRow(
3847 commandTypeToCommandTableMap[cmdType].modified_ =
true;
3851 if(planTable.tableView_->removeRowFromGroup(
3852 row, groupIdCol, groupName,
true ))
3861 std::vector<IterateTable::Command> commands;
3866 std::istringstream f(commandString);
3867 std::string commandSubString, paramSubString, paramValue;
3869 while(getline(f, commandSubString,
';'))
3872 std::istringstream g(commandSubString);
3875 while(getline(g, paramSubString,
','))
3880 if(paramSubString !=
"type")
3882 __SUP_SS__ <<
"Invalid command sequence" << __E__;
3886 commands.push_back(IterateTable::Command());
3888 getline(g, paramValue,
',');
3891 commands.back().type_ = paramValue;
3895 getline(g, paramValue,
',');
3899 commands.back().params_.emplace(
3900 std::pair<std::string ,
3903 StringMacros::decodeURIComponent(paramValue)));
3912 __SUP_COUT__ <<
"commands size " << commands.size() << __E__;
3919 unsigned int row, tgtRow;
3920 unsigned int targetIndex;
3921 std::string targetStr, cmdUID;
3923 for(
auto& command : commands)
3925 __SUP_COUT__ <<
"command " << command.type_ << __E__;
3926 __SUP_COUT__ <<
"table " << IterateTable::commandToTableMap_.at(command.type_)
3930 row = planTable.tableView_->addRow(
3931 author,
true ,
"planCommand");
3932 planTable.tableView_->addRowToGroup(row, groupIdCol, groupName);
3935 planTable.tableView_->setURIEncodedValue(command.type_, row, cmdTypeCol);
3938 planTable.tableView_->setValueAsString(
3939 "1", row, planTable.tableView_->getColStatus());
3942 if(commandTypeToCommandTableMap.find(command.type_) !=
3943 commandTypeToCommandTableMap.end())
3946 __SUP_COUT__ <<
"table "
3947 << commandTypeToCommandTableMap[command.type_].tableName_
3953 cmdRow = commandTypeToCommandTableMap[command.type_].tableView_->addRow(
3954 author,
true , command.type_ +
"_COMMAND_");
3960 for(
auto& param : command.params_)
3962 __SUP_COUT__ <<
"\t param " << param.first <<
" : " << param.second
3965 if(param.first == IterateTable::targetParams_.Tables_)
3967 __SUP_COUT__ <<
"\t\t found target tables" << __E__;
3968 std::istringstream f(param.second);
3971 while(getline(f, targetStr,
'='))
3973 __SUP_COUT__ <<
"\t\t targetStr = " << targetStr << __E__;
3974 if(!command.targets_.size() ||
3975 command.targets_.back().table_ !=
"")
3977 __SUP_COUT__ <<
"\t\t make targetStr = " << targetStr
3980 command.addTarget();
3981 command.targets_.back().table_ = targetStr;
3984 command.targets_[targetIndex++].table_ = targetStr;
3990 if(param.first == IterateTable::targetParams_.UIDs_)
3992 __SUP_COUT__ <<
"\t\t found target UIDs" << __E__;
3993 std::istringstream f(param.second);
3996 while(getline(f, targetStr,
'='))
3998 __SUP_COUT__ <<
"\t\t targetStr = " << targetStr << __E__;
3999 if(!command.targets_.size() ||
4000 command.targets_.back().UID_ !=
"")
4002 __SUP_COUT__ <<
"\t\t make targetStr = " << targetStr
4005 command.addTarget();
4006 command.targets_.back().UID_ = targetStr;
4009 command.targets_[targetIndex++].UID_ = targetStr;
4015 commandTypeToCommandTableMap[command.type_].tableView_->findCol(
4018 __SUP_COUT__ <<
"param col " << cmdCol << __E__;
4020 commandTypeToCommandTableMap[command.type_]
4021 .tableView_->setURIEncodedValue(param.second, cmdRow, cmdCol);
4025 commandTypeToCommandTableMap[command.type_].tableView_->getDataView()
4026 [cmdRow][commandTypeToCommandTableMap[command.type_]
4027 .tableView_->getColUID()];
4029 if(command.targets_.size())
4033 __SUP_COUT__ <<
"targets found for command UID=" << cmdUID << __E__;
4037 commandTypeToCommandTableMap[command.type_].tableView_->findCol(
4038 IterateTable::commandTargetCols_.TargetsLink_);
4039 commandTypeToCommandTableMap[command.type_]
4040 .tableView_->setValueAsString(
4041 IterateTable::TARGET_TABLE, cmdRow, cmdCol);
4044 commandTypeToCommandTableMap[command.type_].tableView_->findCol(
4045 IterateTable::commandTargetCols_.TargetsLinkGroupID_);
4046 commandTypeToCommandTableMap[command.type_]
4047 .tableView_->setValueAsString(
4048 cmdUID +
"_Targets", cmdRow, cmdCol);
4052 for(
const auto& target : command.targets_)
4054 __SUP_COUT__ << target.table_ <<
" " << target.UID_ << __E__;
4057 tgtRow = targetTable.tableView_->addRow(
4058 author,
true ,
"commandTarget");
4059 targetTable.tableView_->addRowToGroup(
4060 tgtRow, targetGroupIdCol, cmdUID +
"_Targets");
4063 targetTable.tableView_->setValueAsString(
4064 target.table_, tgtRow, targetTableCol);
4067 targetTable.tableView_->setValueAsString(
4068 target.UID_, tgtRow, targetUIDCol);
4073 planTable.tableView_->setValueAsString(
4074 commandTypeToCommandTableMap[command.type_].tableName_,
4076 commandUidLink.first);
4077 planTable.tableView_->setValueAsString(
4078 cmdUID, row, commandUidLink.second);
4080 __SUP_COUT__ <<
"linked to uid = " << cmdUID << __E__;
4082 commandTypeToCommandTableMap[command.type_].modified_ =
true;
4090 planTable.tableView_->print();
4091 planTable.tableView_->init();
4093 __SUP_COUT__ <<
"requestType tables:" << __E__;
4095 for(
auto& modifiedConfig : commandTypeToCommandTableMap)
4097 modifiedConfig.second.tableView_->print();
4098 modifiedConfig.second.tableView_->init();
4101 targetTable.tableView_->print();
4102 targetTable.tableView_->init();
4107 __SUP_COUT__ <<
"Handling command table errors while saving. Erasing all newly "
4113 if(planTable.createdTemporaryVersion_)
4115 __SUP_COUT__ <<
"Erasing temporary version " << planTable.tableName_ <<
"-v"
4116 << planTable.temporaryVersion_ << __E__;
4118 cfgMgr->eraseTemporaryVersion(planTable.tableName_,
4119 planTable.temporaryVersion_);
4122 if(targetTable.createdTemporaryVersion_)
4124 __SUP_COUT__ <<
"Erasing temporary version " << targetTable.tableName_ <<
"-v"
4125 << targetTable.temporaryVersion_ << __E__;
4127 cfgMgr->eraseTemporaryVersion(targetTable.tableName_,
4128 targetTable.temporaryVersion_);
4131 for(
auto& modifiedConfig : commandTypeToCommandTableMap)
4133 if(modifiedConfig.second
4134 .createdTemporaryVersion_)
4136 __SUP_COUT__ <<
"Erasing temporary version "
4137 << modifiedConfig.second.tableName_ <<
"-v"
4138 << modifiedConfig.second.temporaryVersion_ << __E__;
4140 cfgMgr->eraseTemporaryVersion(modifiedConfig.second.tableName_,
4141 modifiedConfig.second.temporaryVersion_);
4152 TableVersion finalVersion = ConfigurationSupervisorBase::saveModifiedVersionXML(
4155 planTable.tableName_,
4156 planTable.originalVersion_,
4159 planTable.temporaryVersion_,
4162 __SUP_COUT__ <<
"Final plan version is " << planTable.tableName_ <<
"-v"
4163 << finalVersion << __E__;
4165 finalVersion = ConfigurationSupervisorBase::saveModifiedVersionXML(
4168 targetTable.tableName_,
4169 targetTable.originalVersion_,
4172 targetTable.temporaryVersion_,
4175 __SUP_COUT__ <<
"Final target version is " << targetTable.tableName_ <<
"-v"
4176 << finalVersion << __E__;
4178 for(
auto& modifiedConfig : commandTypeToCommandTableMap)
4180 if(!modifiedConfig.second.modified_)
4182 if(modifiedConfig.second
4183 .createdTemporaryVersion_)
4185 __SUP_COUT__ <<
"Erasing unmodified temporary version "
4186 << modifiedConfig.second.tableName_ <<
"-v"
4187 << modifiedConfig.second.temporaryVersion_ << __E__;
4189 cfgMgr->eraseTemporaryVersion(modifiedConfig.second.tableName_,
4190 modifiedConfig.second.temporaryVersion_);
4195 finalVersion = ConfigurationSupervisorBase::saveModifiedVersionXML(
4198 modifiedConfig.second.tableName_,
4199 modifiedConfig.second.originalVersion_,
4201 modifiedConfig.second.table_,
4202 modifiedConfig.second.temporaryVersion_,
4205 __SUP_COUT__ <<
"Final version is " << modifiedConfig.second.tableName_ <<
"-v"
4206 << finalVersion << __E__;
4209 handleFillModifiedTablesXML(xmlOut, cfgMgr);
4211 catch(std::runtime_error& e)
4213 __SUP_SS__ <<
"Error detected saving Iteration Plan!\n\n " << e.what() << __E__;
4214 __SUP_COUT_ERR__ <<
"\n" << ss.str() << __E__;
4215 xmlOut.addTextElementToData(
"Error", ss.str());
4219 __SUP_SS__ <<
"Error detected saving Iteration Plan!\n\n " << __E__;
4220 __SUP_COUT_ERR__ <<
"\n" << ss.str() << __E__;
4221 xmlOut.addTextElementToData(
"Error", ss.str());
4234 void ConfigurationGUISupervisor::handleSaveTreeNodeEditXML(HttpXmlDocument& xmlOut,
4235 ConfigurationManagerRW* cfgMgr,
4236 const std::string& tableName,
4237 TableVersion version,
4238 const std::string& type,
4239 const std::string& uid,
4240 const std::string& colName,
4241 const std::string& newValue,
4242 const std::string& author)
try
4244 __SUP_COUT__ <<
"table " << tableName <<
"(" << version <<
")" << __E__;
4251 TableBase* table = cfgMgr->getTableByName(tableName);
4254 table->setActiveView(version);
4258 if(version.isTemporaryVersion())
4261 __SUP_COUT__ <<
"Failed to find stored version, so attempting to load version: "
4262 << version << __E__;
4263 cfgMgr->getVersionedTableByName(tableName, version);
4266 __SUP_COUT__ <<
"Active version is " << table->getViewVersion() << __E__;
4268 if(version != table->getViewVersion())
4270 __SUP_SS__ <<
"Target table version (" << version
4271 <<
") is not the currently active version (" << table->getViewVersion()
4272 <<
"). Try refreshing the tree." << __E__;
4276 unsigned int col = -1;
4277 if(type ==
"uid" || type ==
"delete-uid")
4278 col = table->getView().getColUID();
4279 else if(type ==
"link-UID" || type ==
"link-GroupID" || type ==
"value" ||
4280 type ==
"value-groupid" || type ==
"value-bool" || type ==
"value-bitmap")
4281 col = table->getView().findCol(colName);
4282 else if(type ==
"table" || type ==
"link-comment" || type ==
"table-newGroupRow" ||
4283 type ==
"table-newUIDRow" || type ==
"table-newRow")
4287 __SUP_SS__ <<
"Impossible! Unrecognized edit type: " << type << __E__;
4292 if(type ==
"table" || type ==
"link-comment")
4295 if(table->getView().isURIEncodedCommentTheSame(newValue))
4297 __SUP_SS__ <<
"Comment '" << newValue
4298 <<
"' is the same as the current comment. No need to save change."
4314 TableVersion temporaryVersion = table->createTemporaryView(version);
4316 __SUP_COUT__ <<
"Created temporary version " << temporaryVersion << __E__;
4318 TableView* cfgView = table->getTemporaryView(temporaryVersion);
4325 if(type ==
"table" || type ==
"link-comment")
4328 cfgView->setURIEncodedComment(newValue);
4330 else if(type ==
"table-newRow" || type ==
"table-newUIDRow")
4333 unsigned int row = cfgView->addRow(author,
true );
4338 col = cfgView->getColStatus();
4339 cfgView->setValueAsString(
"1", row, col);
4346 cfgView->setURIEncodedValue(newValue, row, cfgView->getColUID());
4348 else if(type ==
"table-newGroupRow")
4351 unsigned int row = cfgView->addRow(author,
true );
4354 unsigned int csvIndex = newValue.find(
',');
4356 std::string linkIndex = newValue.substr(0, csvIndex);
4357 std::string groupId = newValue.substr(csvIndex + 1);
4360 csvIndex = groupId.find(
',');
4361 std::string newRowUID = groupId.substr(csvIndex + 1);
4362 groupId = groupId.substr(0, csvIndex);
4364 __SUP_COUT__ <<
"newValue " << linkIndex <<
"," << groupId <<
"," << newRowUID
4368 cfgView->setURIEncodedValue(newRowUID, row, cfgView->getColUID());
4371 col = cfgView->getLinkGroupIDColumn(linkIndex);
4374 cfgView->setURIEncodedValue(groupId, row, col);
4379 col = cfgView->getColStatus();
4380 cfgView->setValueAsString(
"1", row, col);
4386 else if(type ==
"delete-uid")
4389 unsigned int row = cfgView->findRow(col, uid);
4390 cfgView->deleteRow(row);
4392 else if(type ==
"uid" || type ==
"value" || type ==
"value-groupid" ||
4393 type ==
"value-bool" || type ==
"value-bitmap")
4395 unsigned int row = cfgView->findRow(cfgView->getColUID(), uid);
4396 if(!cfgView->setURIEncodedValue(newValue, row, col, author))
4399 __SUP_SS__ <<
"Value '" << newValue
4400 <<
"' is the same as the current value. No need to save "
4401 "change to tree node."
4406 else if(type ==
"link-UID" || type ==
"link-GroupID")
4409 std::pair<
unsigned int ,
unsigned int > linkPair;
4410 if(!cfgView->getChildLink(col, isGroup, linkPair))
4413 __SUP_SS__ <<
"Col '" << colName <<
"' is not a link column." << __E__;
4417 __SUP_COUT__ <<
"linkPair " << linkPair.first <<
"," << linkPair.second
4420 std::string linkIndex = cfgView->getColumnInfo(col).getChildLinkIndex();
4422 __SUP_COUT__ <<
"linkIndex " << linkIndex << __E__;
4425 unsigned int csvIndexStart = 0, csvIndex = newValue.find(
',');
4427 std::string newTable = newValue.substr(csvIndexStart, csvIndex);
4428 csvIndexStart = csvIndex + 1;
4429 csvIndex = newValue.find(
',', csvIndexStart);
4430 std::string newLinkId = newValue.substr(
4435 __SUP_COUT__ <<
"newValue " << newTable <<
"," << newLinkId << __E__;
4438 unsigned int row = cfgView->findRow(cfgView->getColUID(), uid);
4439 bool changed =
false;
4440 if(!cfgView->setURIEncodedValue(newTable, row, linkPair.first, author))
4443 __SUP_COUT__ <<
"Value '" << newTable
4444 <<
"' is the same as the current value." << __E__;
4449 if(!cfgView->setURIEncodedValue(newLinkId, row, linkPair.second, author))
4452 __SUP_COUT__ <<
"Value '" << newLinkId
4453 <<
"' is the same as the current value." << __E__;
4461 if(type ==
"link-GroupID")
4463 bool secondaryChanged =
false;
4468 __SUP_COUT__ <<
"No changes to primary view. Erasing temporary table."
4470 table->eraseView(temporaryVersion);
4478 ConfigurationSupervisorBase::saveModifiedVersionXML(
4491 catch(std::runtime_error&
4494 __SUP_COUT__ <<
"Caught error while editing main table. Erasing "
4495 "temporary version."
4497 table->eraseView(temporaryVersion);
4501 xmlOut.addTextElementToData(
4503 "Error saving primary tree node! " + std::string(e.what()));
4513 csvIndexStart = csvIndex + 1;
4514 csvIndex = newValue.find(
',', csvIndexStart);
4515 version = TableVersion(newValue.substr(
4516 csvIndexStart, csvIndex - csvIndexStart));
4519 if(newTable == TableViewColumnInfo::DATATYPE_LINK_DEFAULT)
4527 table = cfgMgr->getTableByName(newTable);
4530 table->setActiveView(version);
4534 __SUP_COUT__ <<
"Failed to find stored version, so attempting to "
4536 << version << __E__;
4537 cfgMgr->getVersionedTableByName(newTable, version);
4540 __SUP_COUT__ <<
"Active version is " << table->getViewVersion() << __E__;
4542 if(version != table->getViewVersion())
4545 if(version.isMockupVersion())
4546 ss <<
"Target table '" << newTable
4547 <<
"' is likely not a member of the current table group "
4548 <<
"since the mock-up version was not successfully loaded. "
4551 (std::string(
"") +
"To add a table to a group, click the group name to go to the " +
4552 "group view, then click 'Add/Remove/Modify Member Tables.' You " +
4553 "can then add or remove tables and save the new group." +
4555 "OR!!! Click the following button to add the table '" + newTable +
4556 "' to the currently active Configuration Group: " +
4557 "<input type='button' style='color:black !important;' " +
4558 "title='Click to add table to the active Configuration Group' " +
4559 "onclick='addTableToConfigurationGroup(\"" +
4560 newTable +
"\"); Debug.closeErrorPop();event.stopPropagation();' value='Add Table'>" +
4564 ss <<
"Target table version (" << version
4565 <<
") is not the currently active version ("
4566 << table->getViewVersion() <<
"). Try refreshing the tree."
4572 temporaryVersion = table->createTemporaryView(version);
4574 __SUP_COUT__ <<
"Created temporary version " << temporaryVersion << __E__;
4576 cfgView = table->getTemporaryView(temporaryVersion);
4579 col = cfgView->getLinkGroupIDColumn(linkIndex);
4581 __SUP_COUT__ <<
"target col " << col << __E__;
4584 std::vector<std::string> memberUIDs;
4587 csvIndexStart = csvIndex + 1;
4588 csvIndex = newValue.find(
',', csvIndexStart);
4589 memberUIDs.push_back(
4590 newValue.substr(csvIndexStart, csvIndex - csvIndexStart));
4591 __SUP_COUT__ <<
"memberUIDs: " << memberUIDs.back() << __E__;
4592 }
while(csvIndex != (
unsigned int)std::string::npos);
4602 std::string targetUID;
4603 bool shouldBeInGroup;
4604 bool defaultIsInGroup =
4608 for(
unsigned int row = 0; row < cfgView->getNumberOfRows(); ++row)
4610 targetUID = cfgView->getDataView()[row][cfgView->getColUID()];
4611 __SUP_COUT__ <<
"targetUID: " << targetUID << __E__;
4613 shouldBeInGroup =
false;
4614 for(
unsigned int i = 0; i < memberUIDs.size(); ++i)
4615 if(targetUID == memberUIDs[i])
4618 shouldBeInGroup =
true;
4622 isInGroup = cfgView->isEntryInGroup(row, linkIndex, newLinkId);
4625 if(shouldBeInGroup && !isInGroup)
4627 __SUP_COUT__ <<
"Changed YES: " << row << __E__;
4628 secondaryChanged =
true;
4630 cfgView->addRowToGroup(row, col, newLinkId);
4633 else if(!shouldBeInGroup && isInGroup)
4635 __SUP_COUT__ <<
"Changed NO: " << row << __E__;
4636 secondaryChanged =
true;
4638 cfgView->removeRowFromGroup(row, col, newLinkId);
4640 else if(targetUID ==
4641 cfgView->getDefaultRowValues()[cfgView->getColUID()] &&
4645 defaultIsInGroup =
true;
4650 if(!secondaryChanged)
4653 <<
"No changes to secondary view. Erasing temporary table."
4655 table->eraseView(temporaryVersion);
4663 ConfigurationSupervisorBase::saveModifiedVersionXML(
4676 catch(std::runtime_error&
4679 __SUP_COUT__ <<
"Caught error while editing secondary table. "
4680 "Erasing temporary version."
4682 table->eraseView(temporaryVersion);
4683 secondaryChanged =
false;
4686 xmlOut.addTextElementToData(
4688 "Error saving secondary tree node! " + std::string(e.what()));
4696 if(0 && !changed && !secondaryChanged && !defaultIsInGroup)
4698 __SUP_SS__ <<
"Link to table '" << newTable <<
"', linkID '"
4700 <<
"', and selected group members are the same as the "
4702 <<
"No need to save changes to tree." << __E__;
4708 else if(0 && !changed)
4713 __SUP_SS__ <<
"Link to table '" << newTable <<
"' and linkID '"
4715 <<
"' are the same as the current values. No need to save "
4716 "change to tree node."
4726 __SUP_COUT__ <<
"Caught error while editing. Erasing temporary version." << __E__;
4727 table->eraseView(temporaryVersion);
4731 ConfigurationSupervisorBase::saveModifiedVersionXML(
4741 catch(std::runtime_error& e)
4743 __SUP_SS__ <<
"Error saving tree node! " << e.what() << __E__;
4744 __SUP_COUT_ERR__ <<
"\n" << ss.str() << __E__;
4745 xmlOut.addTextElementToData(
"Error", ss.str());
4749 __SUP_SS__ <<
"Unknown Error saving tree node! " << __E__;
4750 __SUP_COUT_ERR__ <<
"\n" << ss.str() << __E__;
4751 xmlOut.addTextElementToData(
"Error", ss.str());
4795 void ConfigurationGUISupervisor::handleGetTableXML(HttpXmlDocument& xmlOut,
4796 ConfigurationManagerRW* cfgMgr,
4797 const std::string& tableName,
4798 TableVersion version,
4799 bool allowIllegalColumns)
try
4801 char tmpIntStr[100];
4802 xercesc::DOMElement *parentEl, *subparentEl;
4804 std::string accumulatedErrors =
"";
4808 if(allowIllegalColumns)
4809 xmlOut.addTextElementToData(
"allowIllegalColumns",
"1");
4811 const std::map<std::string, TableInfo>&
4813 cfgMgr->getAllTableInfo(allowIllegalColumns,
4814 allowIllegalColumns ? &accumulatedErrors : 0,
4817 TableBase* table = cfgMgr->getTableByName(tableName);
4823 xmlOut.addTextElementToData(
"ExistingTableNames",
4824 TableViewColumnInfo::DATATYPE_LINK_DEFAULT);
4825 for(
auto& configPair : allTableInfo)
4827 xmlOut.addTextElementToData(
"ExistingTableNames", configPair.first);
4828 if(configPair.first == tableName &&
4829 configPair.second.versions_.find(version) == configPair.second.versions_.end())
4831 __SUP_COUT__ <<
"Version not found, so using mockup." << __E__;
4832 version = TableVersion();
4836 xmlOut.addTextElementToData(
"TableName", tableName);
4837 xmlOut.addTextElementToData(
"TableDescription",
4838 table->getTableDescription());
4845 std::map<std::string , TableVersion >>
4850 versionAliases = cfgMgr->getVersionAliases();
4851 for(
const auto& aliases : versionAliases)
4852 for(
const auto& alias : aliases.second)
4853 __SUP_COUT__ <<
"ALIAS: " << aliases.first <<
" " << alias.first
4854 <<
" ==> " << alias.second << __E__;
4856 catch(
const std::runtime_error& e)
4858 __SUP_COUT__ <<
"Could not get backbone information for version aliases: "
4859 << e.what() << __E__;
4862 auto tableIterator = versionAliases.find(tableName);
4864 parentEl = xmlOut.addTextElementToData(
"TableVersions",
"");
4865 for(
const TableVersion& v : allTableInfo.at(tableName).versions_)
4868 xmlOut.addTextElementToParent(
"Version", v.toString(), parentEl);
4870 if(tableIterator != versionAliases.end())
4873 for(
const auto& aliasPair : tableIterator->second)
4881 if(v == aliasPair.second)
4883 __SUP_COUT__ <<
"Found Alias " << aliasPair.second <<
" --> "
4884 << aliasPair.first << __E__;
4885 xmlOut.addTextElementToParent(
4886 "VersionAlias", aliasPair.first, subparentEl);
4896 TableView* cfgViewPtr;
4897 if(version.isInvalid())
4899 cfgViewPtr = table->getMockupViewP();
4909 std::string localAccumulatedErrors =
"";
4912 ->getVersionedTableByName(tableName,
4914 allowIllegalColumns ,
4915 &localAccumulatedErrors)
4918 if(localAccumulatedErrors !=
"")
4919 xmlOut.addTextElementToData(
"Error", localAccumulatedErrors);
4921 catch(std::runtime_error& e)
4923 __SUP_SS__ <<
"Failed to get table " << tableName <<
" version " << version
4924 <<
"... defaulting to mock-up! " << __E__;
4925 ss <<
"\n\n...Here is why it failed:\n\n" << e.what() << __E__;
4927 __SUP_COUT_ERR__ <<
"\n" << ss.str();
4928 version = TableVersion();
4929 cfgViewPtr = table->getMockupViewP();
4931 xmlOut.addTextElementToData(
"Error",
"Error getting view! " + ss.str());
4935 __SUP_SS__ <<
"Failed to get table " << tableName <<
" version: " << version
4936 <<
"... defaulting to mock-up! "
4937 <<
"(You may want to try again to see what was partially loaded "
4938 "into cache before failure. "
4939 <<
"If you think, the failure is due to a column name change, "
4940 <<
"you can also try to Copy the failing view to the new column "
4942 <<
"'Copy and Move' functionality.)" << __E__;
4944 __SUP_COUT_ERR__ <<
"\n" << ss.str();
4945 version = TableVersion();
4946 cfgViewPtr = table->getMockupViewP();
4948 xmlOut.addTextElementToData(
"Error",
"Error getting view! " + ss.str());
4951 xmlOut.addTextElementToData(
"TableVersion", version.toString());
4954 xercesc::DOMElement* choicesParentEl;
4955 parentEl = xmlOut.addTextElementToData(
"CurrentVersionColumnHeaders",
"");
4957 std::vector<TableViewColumnInfo> colInfo = cfgViewPtr->getColumnsInfo();
4959 for(
int i = 0; i < (int)colInfo.size(); ++i)
4967 xmlOut.addTextElementToParent(
"ColumnHeader", colInfo[i].getName(), parentEl);
4968 xmlOut.addTextElementToParent(
"ColumnType", colInfo[i].getType(), parentEl);
4969 xmlOut.addTextElementToParent(
4970 "ColumnDataType", colInfo[i].getDataType(), parentEl);
4972 choicesParentEl = xmlOut.addTextElementToParent(
"ColumnChoices",
"", parentEl);
4974 if(colInfo[i].getType() == TableViewColumnInfo::TYPE_FIXED_CHOICE_DATA ||
4975 colInfo[i].getType() == TableViewColumnInfo::TYPE_BITMAP_DATA ||
4976 colInfo[i].isChildLink())
4978 for(
auto& choice : colInfo[i].getDataChoices())
4979 xmlOut.addTextElementToParent(
"ColumnChoice", choice, choicesParentEl);
4986 if(version.isInvalid())
4989 catch(std::runtime_error& e)
4992 __THROW__(e.what() + std::string(
"\n\n") + accumulatedErrors);
4999 parentEl = xmlOut.addTextElementToData(
"CurrentVersionRows",
"");
5001 for(
int r = 0; r < (int)cfgViewPtr->getNumberOfRows(); ++r)
5005 sprintf(tmpIntStr,
"%d", r);
5006 xercesc::DOMElement* tmpParentEl =
5007 xmlOut.addTextElementToParent(
"Row", tmpIntStr, parentEl);
5009 for(
int c = 0; c < (int)cfgViewPtr->getNumberOfColumns(); ++c)
5011 if(colInfo[c].getDataType() == TableViewColumnInfo::DATATYPE_TIME)
5013 std::string timeAsString;
5014 cfgViewPtr->getValue(timeAsString, r, c);
5015 xmlOut.addTextElementToParent(
"Entry", timeAsString, tmpParentEl);
5018 xmlOut.addTextElementToParent(
5019 "Entry", cfgViewPtr->getDataView()[r][c], tmpParentEl);
5024 xmlOut.addTextElementToData(
"TableComment", cfgViewPtr->getComment());
5025 xmlOut.addTextElementToData(
"TableAuthor", cfgViewPtr->getAuthor());
5026 xmlOut.addTextElementToData(
"TableCreationTime",
5027 std::to_string(cfgViewPtr->getCreationTime()));
5028 xmlOut.addTextElementToData(
"TableLastAccessTime",
5029 std::to_string(cfgViewPtr->getLastAccessTime()));
5032 std::vector<std::string> defaultRowValues = cfgViewPtr->getDefaultRowValues();
5034 for(
unsigned int c = 0; c < defaultRowValues.size() - 2; ++c)
5039 xmlOut.addTextElementToData(
"DefaultRowValue", defaultRowValues[c]);
5042 const std::set<std::string> srcColNames = cfgViewPtr->getSourceColumnNames();
5044 if(accumulatedErrors !=
"")
5046 __SUP_SS__ << (std::string(
"Column errors were allowed for this request, so "
5047 "perhaps you can ignore this, ") +
5048 "but please note the following warnings:\n" + accumulatedErrors)
5050 __SUP_COUT_ERR__ << ss.str();
5051 xmlOut.addTextElementToData(
"TableWarnings", ss.str());
5053 else if(!version.isTemporaryVersion() &&
5055 (srcColNames.size() != cfgViewPtr->getNumberOfColumns() ||
5056 cfgViewPtr->getSourceColumnMismatch() !=
5059 __SUP_SS__ <<
"\n\nThere were warnings found when loading the table " << tableName
5060 <<
":v" << version <<
". Please see the details below:\n\n"
5061 <<
"The source column size was found to be " << srcColNames.size()
5062 <<
", and the current number of columns for this table is "
5063 << cfgViewPtr->getNumberOfColumns() <<
". This resulted in a count of "
5064 << cfgViewPtr->getSourceColumnMismatch()
5065 <<
" source column mismatches, and a count of "
5066 << cfgViewPtr->getSourceColumnMissing() <<
" table entries missing in "
5067 << cfgViewPtr->getNumberOfRows() <<
" row(s) of data." << __E__;
5069 ss <<
"\n\nSource column names in ALPHABETICAL order were as follows:\n";
5071 std::string preIndexStr =
"";
5072 for(
auto& srcColName : srcColNames)
5074 ss <<
"\n\t" << preIndexStr << index <<
". " << srcColName;
5085 std::set<std::string> destColNames = cfgViewPtr->getColumnStorageNames();
5086 ss <<
"\n\nCurrent table column names in ALPHABETICAL order are as follows:\n";
5089 for(
auto& destColName : destColNames)
5091 ss <<
"\n\t" << preIndexStr << index <<
". " << destColName;
5102 __SUP_COUT__ <<
"\n" << ss.str();
5103 xmlOut.addTextElementToData(
"TableWarnings", ss.str());
5107 catch(std::runtime_error& e)
5109 __SUP_COUT__ <<
"Error detected!\n\n " << e.what() << __E__;
5110 xmlOut.addTextElementToData(
"Error",
"Error getting view! " + std::string(e.what()));
5114 __SUP_COUT__ <<
"Error detected!\n\n " << __E__;
5115 xmlOut.addTextElementToData(
"Error",
"Error getting view! ");
5129 ConfigurationManagerRW* ConfigurationGUISupervisor::refreshUserSession(
5130 std::string username, uint64_t activeSessionIndex,
bool refresh)
5133 activeSessionIndex =
5136 std::stringstream ssMapKey;
5137 ssMapKey << username <<
":" << activeSessionIndex;
5138 std::string mapKey = ssMapKey.str();
5143 time_t now = time(0);
5146 if(userConfigurationManagers_.find(mapKey) == userConfigurationManagers_.end())
5148 __SUP_COUT_INFO__ <<
"Creating new Configuration Manager." << __E__;
5149 userConfigurationManagers_[mapKey] =
new ConfigurationManagerRW(username);
5154 userConfigurationManagers_[mapKey]->getAllTableInfo(
5157 else if(userLastUseTime_.find(mapKey) == userLastUseTime_.end())
5159 __SUP_SS__ <<
"Fatal error managing userLastUseTime_!" << __E__;
5160 __SUP_COUT_ERR__ <<
"\n" << ss.str();
5163 else if(refresh || (now - userLastUseTime_[mapKey]) >
5164 CONFIGURATION_MANAGER_REFRESH_THRESHOLD)
5168 __SUP_COUT_INFO__ <<
"Refreshing all table info." << __E__;
5169 userConfigurationManagers_[mapKey]->getAllTableInfo(
true);
5178 userLastUseTime_[mapKey] = now;
5181 for(std::map<std::string, time_t>::iterator it = userLastUseTime_.begin();
5182 it != userLastUseTime_.end();
5184 if(now - it->second > CONFIGURATION_MANAGER_EXPIRATION_TIME)
5186 __SUP_COUT__ << now <<
":" << it->second <<
" = " << now - it->second
5188 delete userConfigurationManagers_[it->first];
5189 if(!(userConfigurationManagers_.erase(it->first)))
5191 __SUP_SS__ <<
"Fatal error erasing configuration manager by key!"
5193 __SUP_COUT_ERR__ <<
"\n" << ss.str();
5196 userLastUseTime_.erase(it);
5198 it = userLastUseTime_.begin();
5203 return userConfigurationManagers_[mapKey];
5211 void ConfigurationGUISupervisor::handleDeleteTableInfoXML(HttpXmlDocument& xmlOut,
5212 ConfigurationManagerRW* cfgMgr,
5213 std::string& tableName)
5215 if(0 == rename((TABLE_INFO_PATH + tableName + TABLE_INFO_EXT).c_str(),
5216 (TABLE_INFO_PATH + tableName + TABLE_INFO_EXT +
".unused").c_str()))
5217 __SUP_COUT_INFO__ << (
"Table Info File successfully renamed: " +
5218 (TABLE_INFO_PATH + tableName + TABLE_INFO_EXT +
".unused"))
5222 __SUP_COUT_ERR__ << (
"Error renaming file to " +
5223 (TABLE_INFO_PATH + tableName + TABLE_INFO_EXT +
".unused"))
5226 xmlOut.addTextElementToData(
5228 (
"Error renaming Table Info File to " +
5229 (TABLE_INFO_PATH + tableName + TABLE_INFO_EXT +
".unused")));
5234 cfgMgr->getAllTableInfo(
true);
5244 void ConfigurationGUISupervisor::handleSaveTableInfoXML(
5245 HttpXmlDocument& xmlOut,
5246 ConfigurationManagerRW* cfgMgr,
5247 std::string& tableName,
5248 const std::string& data,
5249 const std::string& tableDescription,
5250 const std::string& columnChoicesCSV,
5251 bool allowOverwrite)
5255 std::string capsName;
5258 capsName = TableBase::convertToCaps(tableName,
true);
5260 catch(std::runtime_error& e)
5262 xmlOut.addTextElementToData(
"Error", e.what());
5268 FILE* fp = fopen((TABLE_INFO_PATH + tableName + TABLE_INFO_EXT).c_str(),
"r");
5272 xmlOut.addTextElementToData(
"TableName", tableName);
5273 xmlOut.addTextElementToData(
"OverwriteError",
"1");
5274 xmlOut.addTextElementToData(
5276 "File already exists! ('" +
5277 (TABLE_INFO_PATH + tableName + TABLE_INFO_EXT) +
"')");
5282 __SUP_COUT__ <<
"capsName=" << capsName << __E__;
5283 __SUP_COUT__ <<
"tableName=" << tableName << __E__;
5284 __SUP_COUT__ <<
"tableDescription=" << tableDescription << __E__;
5285 __SUP_COUT__ <<
"columnChoicesCSV=" << columnChoicesCSV << __E__;
5288 std::stringstream outss;
5290 outss <<
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>\n";
5291 outss <<
"\t<ROOT xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
5292 "xsi:noNamespaceSchemaLocation=\"TableInfo.xsd\">\n";
5293 outss <<
"\t\t<TABLE Name=\"" << tableName <<
"\">\n";
5294 outss <<
"\t\t\t<VIEW Name=\"" << capsName
5295 <<
"\" Type=\"File,Database,DatabaseTest\" Description=\"" << tableDescription
5301 int j = data.find(
',', i);
5302 int k = data.find(
';', i);
5304 std::istringstream columnChoicesISS(columnChoicesCSV);
5305 std::string columnChoicesString;
5306 std::string columnType;
5308 while(k != (
int)(std::string::npos))
5311 columnType = data.substr(i, j - i);
5312 outss <<
"\t\t\t\t<COLUMN Type=\"";
5313 outss << columnType;
5316 j = data.find(
',', i);
5319 outss <<
"\" \t Name=\"";
5320 capsName = data.substr(i, j - i);
5322 outss <<
"\" \t StorageName=\"";
5326 outss << TableBase::convertToCaps(capsName);
5328 catch(std::runtime_error& e)
5330 xmlOut.addTextElementToData(
"Error",
5331 std::string(
"For column name '") +
5332 data.substr(i, j - i) +
"' - " + e.what());
5337 j = data.find(
',', i);
5340 outss <<
"\" \t DataType=\"";
5341 outss << data.substr(i, k - i);
5344 getline(columnChoicesISS, columnChoicesString,
';');
5346 outss <<
"\" \t DataChoices=\"";
5347 outss << columnChoicesString;
5353 j = data.find(
',', i);
5354 k = data.find(
';', i);
5357 outss <<
"\t\t\t</VIEW>\n";
5358 outss <<
"\t\t</TABLE>\n";
5359 outss <<
"\t</ROOT>\n";
5361 __SUP_COUT__ << outss.str() << __E__;
5363 FILE* fp = fopen((TABLE_INFO_PATH + tableName + TABLE_INFO_EXT).c_str(),
"w");
5366 xmlOut.addTextElementToData(
"Error",
5367 "Failed to open destination Table Info file:" +
5368 (TABLE_INFO_PATH + tableName + TABLE_INFO_EXT));
5372 fprintf(fp,
"%s", outss.str().c_str());
5377 std::string accumulatedErrors =
"";
5378 cfgMgr->getAllTableInfo(
true, &accumulatedErrors, tableName);
5381 if(accumulatedErrors !=
"")
5383 __SUP_SS__ << (
"The new version of the '" + tableName +
5384 "' table column info was saved, however errors were detected "
5385 "reading back the table '" +
5386 tableName +
"' after the save attempt:\n\n" + accumulatedErrors)
5389 __SUP_COUT_ERR__ << ss.str() << __E__;
5390 xmlOut.addTextElementToData(
"Error", ss.str());
5402 rename((TABLE_INFO_PATH + tableName + TABLE_INFO_EXT).c_str(),
5403 (TABLE_INFO_PATH + tableName + TABLE_INFO_EXT +
".unused").c_str()))
5405 << (
"File successfully renamed: " +
5406 (TABLE_INFO_PATH + tableName + TABLE_INFO_EXT +
".unused"))
5411 << (
"Error renaming file to " +
5412 (TABLE_INFO_PATH + tableName + TABLE_INFO_EXT +
".unused"))
5416 cfgMgr->getAllTableInfo(
true);
5422 handleGetTableXML(xmlOut, cfgMgr, tableName, TableVersion());
5426 const std::map<std::string, TableInfo>& allTableInfo = cfgMgr->getAllTableInfo();
5429 __SUP_COUT_INFO__ <<
"Looking for errors in all table column info..." << __E__;
5430 for(
const auto& cfgInfo : allTableInfo)
5434 cfgMgr->getTableByName(cfgInfo.first)->getMockupViewP()->init();
5436 catch(std::runtime_error& e)
5438 __SUP_COUT_WARN__ <<
"\n\n##############################################\n"
5439 <<
"Error identified in column info of table '"
5440 << cfgInfo.first <<
"':\n\n"
5441 << e.what() <<
"\n\n"
5455 void ConfigurationGUISupervisor::handleSetGroupAliasInBackboneXML(
5456 HttpXmlDocument& xmlOut,
5457 ConfigurationManagerRW* cfgMgr,
5458 const std::string& groupAlias,
5459 const std::string& groupName,
5460 TableGroupKey groupKey,
5461 const std::string& author)
try
5463 cfgMgr->loadConfigurationBackbone();
5464 std::map<std::string, TableVersion> activeVersions = cfgMgr->getActiveVersions();
5466 const std::string groupAliasesTableName =
5467 ConfigurationManager::GROUP_ALIASES_TABLE_NAME;
5468 if(activeVersions.find(groupAliasesTableName) == activeVersions.end())
5470 __SUP_SS__ <<
"Active version of " << groupAliasesTableName <<
" missing!"
5472 xmlOut.addTextElementToData(
"Error", ss.str());
5477 const std::set<std::string> backboneMembers = cfgMgr->getBackboneMemberNames();
5478 for(
auto& memberName : backboneMembers)
5480 __SUP_COUT__ <<
"activeVersions[\"" << memberName
5481 <<
"\"]=" << activeVersions[memberName] << __E__;
5483 xmlOut.addTextElementToData(
"oldBackboneName", memberName);
5484 xmlOut.addTextElementToData(
"oldBackboneVersion",
5485 activeVersions[memberName].toString());
5492 TableBase* table = cfgMgr->getTableByName(groupAliasesTableName);
5493 TableVersion originalVersion = activeVersions[groupAliasesTableName];
5494 TableVersion temporaryVersion = table->createTemporaryView(originalVersion);
5496 __SUP_COUT__ <<
"\t\t temporaryVersion: " << temporaryVersion << __E__;
5497 bool isDifferent =
false;
5501 TableView* configView = table->getTemporaryView(temporaryVersion);
5503 unsigned int col = configView->findCol(
"GroupKeyAlias");
5507 unsigned int row = -1;
5511 row = configView->findRow(col, groupAlias);
5516 if(row == (
unsigned int)-1)
5519 row = configView->addRow();
5522 col = configView->findCol(TableViewColumnInfo::COL_NAME_COMMENT);
5523 configView->setValue(
5524 "This Group Alias was automatically setup by the server.", row, col);
5525 col = configView->findCol(
"GroupKeyAlias");
5526 configView->setValue(groupAlias, row, col);
5529 __SUP_COUT__ <<
"\t\t row: " << row << __E__;
5531 col = configView->findCol(
"GroupName");
5533 __SUP_COUT__ <<
"\t\t groupName: " << groupName <<
" vs "
5534 << configView->getDataView()[row][col] << __E__;
5535 if(groupName != configView->getDataView()[row][col])
5537 configView->setValue(groupName, row, col);
5541 col = configView->findCol(
"GroupKey");
5542 __SUP_COUT__ <<
"\t\t groupKey: " << groupKey <<
" vs "
5543 << configView->getDataView()[row][col] << __E__;
5544 if(groupKey.toString() != configView->getDataView()[row][col])
5546 configView->setValue(groupKey.toString(), row, col);
5552 configView->setValue(
5553 author, row, configView->findCol(TableViewColumnInfo::COL_NAME_AUTHOR));
5554 configView->setValue(
5557 configView->findCol(TableViewColumnInfo::COL_NAME_CREATION));
5562 __SUP_COUT_ERR__ <<
"Error editing Group Alias view!" << __E__;
5565 table->eraseView(temporaryVersion);
5569 TableVersion newAssignedVersion;
5572 __SUP_COUT__ <<
"\t\t**************************** Save as new table version"
5580 newAssignedVersion = ConfigurationSupervisorBase::saveModifiedVersionXML(
5583 table->getTableName(),
5594 <<
"\t\t**************************** Using the existing table version"
5598 table->eraseView(temporaryVersion);
5599 newAssignedVersion = activeVersions[groupAliasesTableName];
5601 xmlOut.addTextElementToData(
"savedName", groupAliasesTableName);
5602 xmlOut.addTextElementToData(
"savedVersion", newAssignedVersion.toString());
5605 __SUP_COUT__ <<
"\t\t newAssignedVersion: " << newAssignedVersion << __E__;
5607 catch(std::runtime_error& e)
5609 __SUP_COUT_ERR__ <<
"Error detected!\n\n " << e.what() << __E__;
5610 xmlOut.addTextElementToData(
5611 "Error",
"Error saving new Group Alias view!\n " + std::string(e.what()));
5615 __SUP_COUT_ERR__ <<
"Error detected!\n\n " << __E__;
5616 xmlOut.addTextElementToData(
"Error",
"Error saving new Group Alias view! ");
5627 void ConfigurationGUISupervisor::handleSetVersionAliasInBackboneXML(
5628 HttpXmlDocument& xmlOut,
5629 ConfigurationManagerRW* cfgMgr,
5630 const std::string& versionAlias,
5631 const std::string& tableName,
5632 TableVersion version,
5633 const std::string& author)
try
5635 cfgMgr->loadConfigurationBackbone();
5636 std::map<std::string, TableVersion> activeVersions = cfgMgr->getActiveVersions();
5638 const std::string versionAliasesTableName =
5639 ConfigurationManager::VERSION_ALIASES_TABLE_NAME;
5640 if(activeVersions.find(versionAliasesTableName) == activeVersions.end())
5642 __SUP_SS__ <<
"Active version of " << versionAliasesTableName <<
" missing!"
5644 xmlOut.addTextElementToData(
"Error", ss.str());
5649 const std::set<std::string> backboneMembers = cfgMgr->getBackboneMemberNames();
5650 for(
auto& memberName : backboneMembers)
5652 __SUP_COUT__ <<
"activeVersions[\"" << memberName
5653 <<
"\"]=" << activeVersions[memberName] << __E__;
5655 xmlOut.addTextElementToData(
"oldBackboneName", memberName);
5656 xmlOut.addTextElementToData(
"oldBackboneVersion",
5657 activeVersions[memberName].toString());
5664 TableBase* table = cfgMgr->getTableByName(versionAliasesTableName);
5665 TableVersion originalVersion = activeVersions[versionAliasesTableName];
5666 TableVersion temporaryVersion = table->createTemporaryView(originalVersion);
5668 __SUP_COUT__ <<
"\t\t temporaryVersion: " << temporaryVersion << __E__;
5670 bool isDifferent =
false;
5674 TableView* configView = table->getTemporaryView(temporaryVersion);
5677 unsigned int col2 = configView->findCol(
"VersionAlias");
5678 unsigned int col3 = configView->findCol(
"TableName");
5682 unsigned int row = -1;
5687 unsigned int tmpRow = -1;
5690 tmpRow = configView->findRow(col3, tableName, tmpRow + 1);
5691 }
while(configView->getDataView()[tmpRow][col2] != versionAlias);
5698 if(row == (
unsigned int)-1)
5701 row = configView->addRow();
5704 col = configView->findCol(TableViewColumnInfo::COL_NAME_COMMENT);
5705 configView->setValue(
5706 std::string(
"Entry was added by server in ") +
5707 "ConfigurationGUISupervisor::setVersionAliasInActiveBackbone().",
5711 col = configView->findCol(
"VersionAliasUID");
5712 configView->setValue(
5713 tableName.substr(0, tableName.rfind(
"Table")) + versionAlias, row, col);
5715 configView->setValue(versionAlias, row, col2);
5716 configView->setValue(tableName, row, col3);
5719 __SUP_COUT__ <<
"\t\t row: " << row << __E__;
5721 col = configView->findCol(
"Version");
5722 __SUP_COUT__ <<
"\t\t version: " << version <<
" vs "
5723 << configView->getDataView()[row][col] << __E__;
5724 if(version.toString() != configView->getDataView()[row][col])
5726 configView->setValue(version.toString(), row, col);
5732 configView->setValue(
5733 author, row, configView->findCol(TableViewColumnInfo::COL_NAME_AUTHOR));
5734 configView->setValue(
5737 configView->findCol(TableViewColumnInfo::COL_NAME_CREATION));
5742 __SUP_COUT_ERR__ <<
"Error editing Version Alias view!" << __E__;
5745 table->eraseView(temporaryVersion);
5749 TableVersion newAssignedVersion;
5752 __SUP_COUT__ <<
"\t\t**************************** Save as new table version"
5758 newAssignedVersion = ConfigurationSupervisorBase::saveModifiedVersionXML(
5761 table->getTableName(),
5771 __SUP_COUT__ <<
"\t\t**************************** Using existing table version"
5775 table->eraseView(temporaryVersion);
5776 newAssignedVersion = activeVersions[versionAliasesTableName];
5778 xmlOut.addTextElementToData(
"savedName", versionAliasesTableName);
5779 xmlOut.addTextElementToData(
"savedVersion", newAssignedVersion.toString());
5782 __SUP_COUT__ <<
"\t\t newAssignedVersion: " << newAssignedVersion << __E__;
5784 catch(std::runtime_error& e)
5786 __SUP_COUT__ <<
"Error detected!\n\n " << e.what() << __E__;
5787 xmlOut.addTextElementToData(
5788 "Error",
"Error saving new Version Alias view!\n " + std::string(e.what()));
5792 __SUP_COUT__ <<
"Error detected!\n\n " << __E__;
5793 xmlOut.addTextElementToData(
"Error",
"Error saving new Version Alias view! ");
5802 void ConfigurationGUISupervisor::handleAliasGroupMembersInBackboneXML(
5803 HttpXmlDocument& xmlOut,
5804 ConfigurationManagerRW* cfgMgr,
5805 const std::string& versionAlias,
5806 const std::string& groupName,
5807 TableGroupKey groupKey,
5808 const std::string& author)
try
5810 cfgMgr->loadConfigurationBackbone();
5811 std::map<std::string, TableVersion> activeVersions = cfgMgr->getActiveVersions();
5813 const std::string versionAliasesTableName =
5814 ConfigurationManager::VERSION_ALIASES_TABLE_NAME;
5815 if(activeVersions.find(versionAliasesTableName) == activeVersions.end())
5817 __SUP_SS__ <<
"Active version of " << versionAliasesTableName <<
" missing!"
5819 xmlOut.addTextElementToData(
"Error", ss.str());
5824 const std::set<std::string> backboneMembers = cfgMgr->getBackboneMemberNames();
5825 for(
auto& memberName : backboneMembers)
5827 __SUP_COUT__ <<
"activeVersions[\"" << memberName
5828 <<
"\"]=" << activeVersions[memberName] << __E__;
5830 xmlOut.addTextElementToData(
"oldBackboneName", memberName);
5831 xmlOut.addTextElementToData(
"oldBackboneVersion",
5832 activeVersions[memberName].toString());
5839 TableBase* table = cfgMgr->getTableByName(versionAliasesTableName);
5840 TableVersion temporaryVersion =
5841 table->createTemporaryView(activeVersions[versionAliasesTableName]);
5843 __SUP_COUT__ <<
"\t\t temporaryVersion: " << temporaryVersion << __E__;
5845 TableView* configView = table->getTemporaryView(temporaryVersion);
5848 bool isDifferent =
false;
5851 std::map<std::string , TableVersion > memberMap;
5854 cfgMgr->loadTableGroup(groupName,
5867 xmlOut.addTextElementToData(
5869 "Table group \"" + TableGroupKey::getFullGroupString(groupName, groupKey) +
5870 "\" can not be retrieved!");
5875 unsigned int col2 = configView->findCol(
"VersionAlias");
5876 unsigned int col3 = configView->findCol(
"TableName");
5878 for(
auto& memberPair : memberMap)
5880 bool thisMemberIsDifferent =
false;
5881 unsigned int row = -1;
5883 __SUP_COUT__ <<
"Adding alias for " << memberPair.first <<
"_v"
5884 << memberPair.second <<
" to " << versionAlias << __E__;
5890 unsigned int tmpRow = -1;
5893 tmpRow = configView->findRow(col3, memberPair.first, tmpRow + 1);
5896 }
while(configView->getDataView()[tmpRow][col2] != versionAlias);
5903 if(row == (
unsigned int)-1)
5905 thisMemberIsDifferent =
true;
5906 row = configView->addRow();
5909 col = configView->findCol(TableViewColumnInfo::COL_NAME_COMMENT);
5910 configView->setValue(
5911 std::string(
"Entry was added by server in ") +
5912 "ConfigurationGUISupervisor::setVersionAliasInActiveBackbone().",
5916 col = configView->getColUID();
5917 configView->setValue(
5918 memberPair.first.substr(0, memberPair.first.rfind(
"Table")) +
5923 configView->setValue(versionAlias, row, col2);
5924 configView->setValue(memberPair.first, row, col3);
5929 col = configView->findCol(
"Version");
5933 if(memberPair.second.toString() != configView->getDataView()[row][col])
5935 configView->setValue(memberPair.second.toString(), row, col);
5936 thisMemberIsDifferent =
true;
5939 if(thisMemberIsDifferent)
5941 configView->setValue(
5942 author, row, configView->findCol(TableViewColumnInfo::COL_NAME_AUTHOR));
5943 configView->setValue(
5946 configView->findCol(TableViewColumnInfo::COL_NAME_CREATION));
5949 if(thisMemberIsDifferent)
5955 TableVersion newAssignedVersion;
5958 __SUP_COUT__ <<
"\t\t**************************** Save v" << temporaryVersion
5959 <<
" as new table version" << __E__;
5961 newAssignedVersion =
5962 cfgMgr->saveNewTable(versionAliasesTableName, temporaryVersion);
5966 __SUP_COUT__ <<
"\t\t**************************** Using existing table version"
5970 table->eraseView(temporaryVersion);
5971 newAssignedVersion = activeVersions[versionAliasesTableName];
5974 xmlOut.addTextElementToData(
"savedName", versionAliasesTableName);
5975 xmlOut.addTextElementToData(
"savedVersion", newAssignedVersion.toString());
5976 __SUP_COUT__ <<
"\t\t Resulting Version: " << newAssignedVersion << __E__;
5978 catch(std::runtime_error& e)
5980 __SUP_COUT__ <<
"Error detected!\n\n " << e.what() << __E__;
5981 xmlOut.addTextElementToData(
5982 "Error",
"Error saving new Version Alias view!\n " + std::string(e.what()));
5986 __SUP_COUT__ <<
"Error detected!\n\n " << __E__;
5987 xmlOut.addTextElementToData(
"Error",
"Error saving new Version Alias view! ");
6001 void ConfigurationGUISupervisor::handleGroupAliasesXML(HttpXmlDocument& xmlOut,
6002 ConfigurationManagerRW* cfgMgr)
6004 cfgMgr->loadConfigurationBackbone();
6005 std::map<std::string, TableVersion> activeVersions = cfgMgr->getActiveVersions();
6007 std::string groupAliasesTableName = ConfigurationManager::GROUP_ALIASES_TABLE_NAME;
6008 if(activeVersions.find(groupAliasesTableName) == activeVersions.end())
6010 __SUP_SS__ <<
"\nActive version of " << groupAliasesTableName <<
" missing! "
6011 << groupAliasesTableName
6012 <<
" is a required member of the Backbone table group."
6013 <<
"\n\nLikely you need to activate a valid Backbone table group."
6015 __SUP_COUT__ << ss.str();
6020 __SUP_COUT__ <<
"activeVersions[\"" << groupAliasesTableName
6021 <<
"\"]=" << activeVersions[groupAliasesTableName] << __E__;
6022 xmlOut.addTextElementToData(
"GroupAliasesTableName", groupAliasesTableName);
6023 xmlOut.addTextElementToData(
"GroupAliasesTableVersion",
6024 activeVersions[groupAliasesTableName].toString());
6026 std::vector<std::pair<std::string, ConfigurationTree>> aliasNodePairs =
6027 cfgMgr->getNode(groupAliasesTableName).getChildren();
6029 std::string groupName, groupKey, groupComment, groupType;
6030 for(
auto& aliasNodePair : aliasNodePairs)
6032 groupName = aliasNodePair.second.getNode(
"GroupName").getValueAsString();
6033 groupKey = aliasNodePair.second.getNode(
"GroupKey").getValueAsString();
6035 xmlOut.addTextElementToData(
"GroupAlias", aliasNodePair.first);
6036 xmlOut.addTextElementToData(
"GroupName", groupName);
6037 xmlOut.addTextElementToData(
"GroupKey", groupKey);
6038 xmlOut.addTextElementToData(
6040 aliasNodePair.second.getNode(TableViewColumnInfo::COL_NAME_COMMENT)
6041 .getValueAsString());
6045 groupType =
"Invalid";
6048 cfgMgr->loadTableGroup(groupName,
6049 TableGroupKey(groupKey),
6062 __SUP_COUT_WARN__ <<
"Failed to load group '" << groupName <<
"(" << groupKey
6063 <<
")' to extract group comment and type." << __E__;
6065 xmlOut.addTextElementToData(
"GroupComment", groupComment);
6066 xmlOut.addTextElementToData(
"GroupType", groupType);
6081 void ConfigurationGUISupervisor::handleVersionAliasesXML(HttpXmlDocument& xmlOut,
6082 ConfigurationManagerRW* cfgMgr)
6084 cfgMgr->loadConfigurationBackbone();
6085 std::map<std::string, TableVersion> activeVersions = cfgMgr->getActiveVersions();
6087 std::string versionAliasesTableName =
6088 ConfigurationManager::VERSION_ALIASES_TABLE_NAME;
6089 if(activeVersions.find(versionAliasesTableName) == activeVersions.end())
6091 __SUP_SS__ <<
"Active version of VersionAliases missing!"
6092 <<
"Make sure you have a valid active Backbone Group." << __E__;
6093 xmlOut.addTextElementToData(
"Error", ss.str());
6096 __SUP_COUT__ <<
"activeVersions[\"" << versionAliasesTableName
6097 <<
"\"]=" << activeVersions[versionAliasesTableName] << __E__;
6098 xmlOut.addTextElementToData(
"VersionAliasesVersion",
6099 activeVersions[versionAliasesTableName].toString());
6101 std::vector<std::pair<std::string, ConfigurationTree>> aliasNodePairs =
6102 cfgMgr->getNode(versionAliasesTableName).getChildren();
6104 for(
auto& aliasNodePair : aliasNodePairs)
6108 xmlOut.addTextElementToData(
6110 aliasNodePair.second.getNode(
"VersionAlias").getValueAsString());
6111 xmlOut.addTextElementToData(
6112 "TableName", aliasNodePair.second.getNode(
"TableName").getValueAsString());
6113 xmlOut.addTextElementToData(
6114 "Version", aliasNodePair.second.getNode(
"Version").getValueAsString());
6115 xmlOut.addTextElementToData(
6117 aliasNodePair.second.getNode(TableViewColumnInfo::COL_NAME_COMMENT)
6118 .getValueAsString());
6128 void ConfigurationGUISupervisor::handleGetTableGroupTypeXML(
6129 HttpXmlDocument& xmlOut, ConfigurationManagerRW* cfgMgr,
const std::string& tableList)
6131 std::map<std::string , TableVersion > memberMap;
6132 std::string name, versionStr;
6133 auto c = tableList.find(
',', 0);
6136 while(c < tableList.length())
6139 name = tableList.substr(i, c - i);
6141 c = tableList.find(
',', i);
6142 if(c == std::string::npos)
6144 __SUP_SS__ <<
"Incomplete Table Name-Version pair!" << __E__;
6145 __SUP_COUT_ERR__ <<
"\n" << ss.str();
6146 xmlOut.addTextElementToData(
"Error", ss.str());
6150 versionStr = tableList.substr(i, c - i);
6152 c = tableList.find(
',', i);
6154 memberMap[name] = TableVersion(versionStr);
6157 std::string groupTypeString =
"";
6162 groupTypeString = cfgMgr->getTypeNameOfGroup(memberMap);
6163 xmlOut.addTextElementToData(
"TableGroupType", groupTypeString);
6165 catch(std::runtime_error& e)
6167 __SUP_SS__ <<
"Table group has invalid type! " << e.what() << __E__;
6168 __SUP_COUT__ <<
"\n" << ss.str();
6169 groupTypeString =
"Invalid";
6170 xmlOut.addTextElementToData(
"TableGroupType", groupTypeString);
6174 __SUP_SS__ <<
"Table group has invalid type! " << __E__;
6175 __SUP_COUT__ <<
"\n" << ss.str();
6176 groupTypeString =
"Invalid";
6177 xmlOut.addTextElementToData(
"TableGroupType", groupTypeString);
6197 void ConfigurationGUISupervisor::handleTableGroupsXML(HttpXmlDocument& xmlOut,
6198 ConfigurationManagerRW* cfgMgr,
6201 xercesc::DOMElement* parentEl;
6205 if(!cfgMgr->getAllGroupInfo()
6208 __SUP_COUT__ <<
"Cache is empty? Attempting to regenerate." << __E__;
6209 cfgMgr->getAllTableInfo(
true );
6212 const std::map<std::string, GroupInfo>& allGroupInfo = cfgMgr->getAllGroupInfo();
6232 TableGroupKey groupKey;
6233 std::string groupName;
6234 std::string groupString, groupTypeString, groupComment, groupCreationTime,
6236 for(
auto& groupInfo : allGroupInfo)
6238 groupName = groupInfo.first;
6239 if(groupInfo.second.keys_.size() == 0)
6241 __SUP_COUT__ <<
"Group name '" << groupName
6242 <<
"' found, but no keys so ignoring." << __E__;
6246 groupKey = *(groupInfo.second.keys_.rbegin());
6248 xmlOut.addTextElementToData(
"TableGroupName", groupName);
6249 xmlOut.addTextElementToData(
"TableGroupKey", groupKey.toString());
6252 xmlOut.addTextElementToData(
"TableGroupType",
6253 groupInfo.second.latestKeyGroupTypeString_);
6254 xmlOut.addTextElementToData(
"TableGroupComment",
6255 groupInfo.second.latestKeyGroupComment_);
6256 xmlOut.addTextElementToData(
"TableGroupAuthor",
6257 groupInfo.second.latestKeyGroupAuthor_);
6258 xmlOut.addTextElementToData(
"TableGroupCreationTime",
6259 groupInfo.second.latestKeyGroupCreationTime_);
6272 parentEl = xmlOut.addTextElementToData(
"TableGroupMembers",
"");
6312 for(
auto& memberPair : groupInfo.second.latestKeyMemberMap_)
6316 xmlOut.addTextElementToParent(
"MemberName", memberPair.first, parentEl);
6317 xmlOut.addTextElementToParent(
6318 "MemberVersion", memberPair.second.toString(), parentEl);
6324 for(
auto& keyInSet : groupInfo.second.keys_)
6326 if(keyInSet == groupKey)
6328 xmlOut.addTextElementToData(
"TableGroupName", groupName);
6329 xmlOut.addTextElementToData(
"TableGroupKey", keyInSet.toString());
6332 xmlOut.addTextElementToData(
"TableGroupType",
6333 groupInfo.second.latestKeyGroupTypeString_);
6334 xmlOut.addTextElementToData(
"TableGroupComment",
6335 groupInfo.second.latestKeyGroupComment_);
6336 xmlOut.addTextElementToData(
"TableGroupAuthor",
6337 groupInfo.second.latestKeyGroupAuthor_);
6338 xmlOut.addTextElementToData(
"TableGroupCreationTime",
6339 groupInfo.second.latestKeyGroupCreationTime_);
6343 xmlOut.addTextElementToData(
"TableGroupMembers",
"");
6346 bool loadingHistoricalInfo =
false;
6347 if(loadingHistoricalInfo)
6352 cfgMgr->loadTableGroup(groupName,
6366 groupTypeString =
"Invalid";
6368 <<
"Failed to load group '" << groupName <<
"(" << keyInSet
6369 <<
")' to extract group comment and type." << __E__;
6372 xmlOut.addTextElementToData(
"TableGroupType", groupTypeString);
6373 xmlOut.addTextElementToData(
"TableGroupComment", groupComment);
6374 xmlOut.addTextElementToData(
"TableGroupAuthor", groupAuthor);
6375 xmlOut.addTextElementToData(
"TableGroupCreationTime",
6396 void ConfigurationGUISupervisor::handleTablesXML(HttpXmlDocument& xmlOut,
6397 ConfigurationManagerRW* cfgMgr,
6398 bool allowIllegalColumns)
6400 xercesc::DOMElement* parentEl;
6402 __COUTV__(allowIllegalColumns);
6403 std::string accumulatedErrors =
"";
6404 const std::map<std::string, TableInfo>& allTableInfo = cfgMgr->getAllTableInfo(
6406 &accumulatedErrors);
6409 std::set<std::string, StringMacros::IgnoreCaseCompareStruct> orderedTableSet;
6410 for(
const auto& tablePair : allTableInfo)
6411 orderedTableSet.emplace(tablePair.first);
6415 __SUP_COUT__ <<
"# of tables found: " << allTableInfo.size() << __E__;
6417 std::map<std::string, std::map<std::string, TableVersion>> versionAliases =
6418 cfgMgr->getVersionAliases();
6420 __SUP_COUT__ <<
"# of tables w/aliases: " << versionAliases.size() << __E__;
6422 for(
const auto& orderedTableName : orderedTableSet)
6425 std::map<std::string, TableInfo>::const_iterator it =
6426 allTableInfo.find(orderedTableName);
6427 if(it == allTableInfo.end())
6429 __SS__ <<
"Impossible missing table in map '" << orderedTableName <<
"'"
6441 xmlOut.addTextElementToData(
"TableName", it->first);
6442 parentEl = xmlOut.addTextElementToData(
"TableVersions",
"");
6445 if(versionAliases.find(it->first) != versionAliases.end())
6446 for(
auto& aliasVersion : versionAliases[it->first])
6447 if(it->second.versions_.find(aliasVersion.second) !=
6448 it->second.versions_.end())
6452 xmlOut.addTextElementToParent(
6454 ConfigurationManager::ALIAS_VERSION_PREAMBLE + aliasVersion.first,
6472 for(
auto& version : it->second.versions_)
6473 if(!version.isScratchVersion())
6474 xmlOut.addTextElementToParent(
"Version", version.toString(), parentEl);
6479 if(accumulatedErrors !=
"")
6480 xmlOut.addTextElementToData(
6482 std::string(
"Column errors were allowed for this request, ") +
6483 "but please note the following errors:\n" + accumulatedErrors);
6493 void ConfigurationGUISupervisor::handleGetArtdaqNodeRecordsXML(
6494 HttpXmlDocument& xmlOut,
6495 ConfigurationManagerRW* cfgMgr,
6496 const std::string& modifiedTables)
6498 __COUT__ <<
"Retrieving artdaq nodes..." << __E__;
6501 setupActiveTablesXML(xmlOut, cfgMgr,
"", TableGroupKey(-1), modifiedTables);
6503 std::map<std::string ,
6504 std::map<std::string , std::vector<std::string >>>
6505 nodeTypeToObjectMap;
6506 std::map<std::string , std::string >
6509 std::vector<std::string > artdaqSupervisorInfo;
6511 std::string artdaqSupervisorName;
6512 const ARTDAQTableBase::ARTDAQInfo& info = ARTDAQTableBase::getARTDAQSystem(
6513 cfgMgr, nodeTypeToObjectMap, subsystemObjectMap, artdaqSupervisorInfo);
6515 if(artdaqSupervisorInfo.size() != 4 )
6517 __SUP_COUT__ <<
"No artdaq supervisor found." << __E__;
6521 __SUP_COUT__ <<
"========== "
6522 <<
"Found " << info.subsystems.size() <<
" subsystems." << __E__;
6524 unsigned int paramIndex = 0;
6526 auto parentEl = xmlOut.addTextElementToData(
"artdaqSupervisor",
6527 artdaqSupervisorInfo[paramIndex++]);
6529 std::string typeString =
"artdaqSupervisor";
6531 xmlOut.addTextElementToParent(
6532 typeString +
"-status", artdaqSupervisorInfo[paramIndex++], parentEl);
6533 xmlOut.addTextElementToParent(
6534 typeString +
"-contextAddress", artdaqSupervisorInfo[paramIndex++], parentEl);
6535 xmlOut.addTextElementToParent(
6536 typeString +
"-contextPort", artdaqSupervisorInfo[paramIndex++], parentEl);
6538 for(
auto& subsystem : info.subsystems)
6540 typeString =
"subsystem";
6542 __SUP_COUT__ <<
"\t\t"
6543 <<
"Found " << typeString <<
" " << subsystem.first <<
" \t := '"
6544 << subsystem.second.label <<
"'" << __E__;
6546 xmlOut.addTextElementToParent(typeString, subsystem.second.label, parentEl);
6547 xmlOut.addTextElementToParent(
6548 typeString +
"-id", std::to_string(subsystem.first), parentEl);
6550 xmlOut.addTextElementToParent(typeString +
"-sourcesCount",
6551 std::to_string(subsystem.second.sources.size()),
6555 xmlOut.addTextElementToParent(typeString +
"-destination",
6556 std::to_string(subsystem.second.destination),
6561 __SUP_COUT__ <<
"========== "
6562 <<
"Found " << nodeTypeToObjectMap.size() <<
" process types." << __E__;
6564 for(
auto& nameTypePair : nodeTypeToObjectMap)
6566 typeString = nameTypePair.first;
6568 __SUP_COUT__ <<
"\t"
6569 <<
"Found " << nameTypePair.second.size() <<
" " << typeString
6572 for(
auto& artdaqNode : nameTypePair.second)
6574 __SUP_COUT__ <<
"\t\t"
6575 <<
"Found '" << artdaqNode.first <<
"' " << typeString << __E__;
6576 __SUP_COUTV__(StringMacros::vectorToString(artdaqNode.second));
6578 if(artdaqNode.second.size() < 2)
6580 __SUP_SS__ <<
"Impossible parameter size for node '" << artdaqNode.first
6581 <<
"' " << typeString <<
" - please notify admins!" << __E__;
6586 xmlOut.addTextElementToParent(typeString, artdaqNode.first, parentEl);
6589 if(artdaqNode.second.size() > paramIndex)
6590 xmlOut.addTextElementToParent(
6591 typeString +
"-multinode", artdaqNode.second[paramIndex++], nodeEl);
6592 if(artdaqNode.second.size() > paramIndex)
6593 xmlOut.addTextElementToParent(typeString +
"-nodefixedwidth",
6594 artdaqNode.second[paramIndex++],
6596 if(artdaqNode.second.size() > paramIndex)
6597 xmlOut.addTextElementToParent(
6598 typeString +
"-hostarray", artdaqNode.second[paramIndex++], nodeEl);
6599 if(artdaqNode.second.size() > paramIndex)
6600 xmlOut.addTextElementToParent(typeString +
"-hostfixedwidth",
6601 artdaqNode.second[paramIndex++],
6605 xmlOut.addTextElementToParent(
6606 typeString +
"-status", artdaqNode.second[paramIndex++], parentEl);
6607 xmlOut.addTextElementToParent(
6608 typeString +
"-hostname", artdaqNode.second[paramIndex++], parentEl);
6609 xmlOut.addTextElementToParent(
6610 typeString +
"-subsystem", artdaqNode.second[paramIndex], parentEl);
6614 __SUP_COUT__ <<
"Done retrieving artdaq nodes." << __E__;
6625 void ConfigurationGUISupervisor::handleSaveArtdaqNodeRecordsXML(
6626 const std::string& nodeString,
6627 const std::string& subsystemString,
6628 HttpXmlDocument& xmlOut,
6629 ConfigurationManagerRW* cfgMgr,
6630 const std::string& modifiedTables)
6632 __SUP_COUT__ <<
"Saving artdaq nodes..." << __E__;
6635 setupActiveTablesXML(xmlOut, cfgMgr,
"", TableGroupKey(-1), modifiedTables);
6638 std::map<std::string ,
6639 std::map<std::string , std::vector<std::string >>>
6640 nodeTypeToObjectMap;
6646 std::map<std::string , std::string >
6647 nodeTypeToStringMap;
6648 StringMacros::getMapFromString(nodeString, nodeTypeToStringMap, {
'|'}, {
':'});
6650 __SUP_COUTV__(StringMacros::mapToString(nodeTypeToStringMap));
6652 for(
auto& typePair : nodeTypeToStringMap)
6654 if(typePair.first ==
"")
6657 __SUP_COUTV__(StringMacros::decodeURIComponent(typePair.first));
6659 nodeTypeToObjectMap.emplace(
6660 std::make_pair(StringMacros::decodeURIComponent(typePair.first),
6661 std::map<std::string ,
6662 std::vector<std::string /*property*/>>()));
6664 std::map<std::string , std::string >
6665 nodeRecordToStringMap;
6667 StringMacros::getMapFromString(
6668 typePair.second, nodeRecordToStringMap, {
';'}, {
'='});
6670 __SUP_COUTV__(StringMacros::mapToString(nodeRecordToStringMap));
6672 for(
auto& nodePair : nodeRecordToStringMap)
6674 if(nodePair.first ==
"")
6677 __SUP_COUTV__(StringMacros::decodeURIComponent(nodePair.first));
6679 std::vector<std::string > nodePropertyVector;
6681 StringMacros::getVectorFromString(
6682 nodePair.second, nodePropertyVector, {
','});
6684 __SUP_COUTV__(StringMacros::vectorToString(nodePropertyVector));
6687 for(
unsigned int i = 0; i < nodePropertyVector.size(); ++i)
6690 StringMacros::decodeURIComponent(nodePropertyVector[i]));
6692 nodePropertyVector[i] =
6693 StringMacros::decodeURIComponent(nodePropertyVector[i]);
6696 nodeTypeToObjectMap[typePair.first].emplace(
6697 std::make_pair(StringMacros::decodeURIComponent(nodePair.first),
6698 nodePropertyVector));
6704 std::map<std::string , std::string >
6711 std::map<std::string , std::string >
6712 tmpSubsystemObjectMap;
6713 StringMacros::getMapFromString(
6714 subsystemString, tmpSubsystemObjectMap, {
';'}, {
':'});
6716 __SUP_COUTV__(StringMacros::mapToString(tmpSubsystemObjectMap));
6719 for(
auto& subsystemPair : tmpSubsystemObjectMap)
6721 __SUP_COUTV__(StringMacros::decodeURIComponent(subsystemPair.first));
6722 __SUP_COUTV__(StringMacros::decodeURIComponent(subsystemPair.second));
6724 subsystemObjectMap.emplace(
6725 std::make_pair(StringMacros::decodeURIComponent(subsystemPair.first),
6726 StringMacros::decodeURIComponent(subsystemPair.second)));
6730 ARTDAQTableBase::setAndActivateARTDAQSystem(
6731 cfgMgr, nodeTypeToObjectMap, subsystemObjectMap);
6733 __SUP_COUT__ <<
"Done saving artdaq nodes." << __E__;
6743 void ConfigurationGUISupervisor::handleLoadArtdaqNodeLayoutXML(
6744 HttpXmlDocument& xmlOut,
6745 ConfigurationManagerRW* cfgMgr,
6746 const std::string& contextGroupName ,
6747 const TableGroupKey& contextGroupKey )
6749 bool usingActiveGroups = (contextGroupName ==
"" || contextGroupKey.isInvalid());
6751 const std::string& finalContextGroupName =
6753 ? cfgMgr->getActiveGroupName(ConfigurationManager::GroupType::CONTEXT_TYPE)
6755 const TableGroupKey& finalContextGroupKey =
6757 ? cfgMgr->getActiveGroupKey(ConfigurationManager::GroupType::CONTEXT_TYPE)
6760 std::stringstream layoutPath;
6761 layoutPath << ARTDAQ_CONFIG_LAYOUTS_PATH << finalContextGroupName <<
"_"
6762 << finalContextGroupKey <<
".dat";
6763 __SUP_COUTV__(layoutPath.str());
6765 FILE* fp = fopen(layoutPath.str().c_str(),
"r");
6768 __SUP_COUT__ <<
"Layout file not found for '" << finalContextGroupName <<
"("
6769 << finalContextGroupKey <<
")'" << __E__;
6777 const size_t maxLineSz = 1000;
6778 char line[maxLineSz];
6779 if(!fgets(line, maxLineSz, fp))
6788 unsigned int rows, cols;
6790 sscanf(line,
"%u %u", &rows, &cols);
6792 __COUT__ <<
"Grid rows,cols = " << rows <<
"," << cols << __E__;
6794 xmlOut.addTextElementToData(
"grid-rows", std::to_string(rows));
6795 xmlOut.addTextElementToData(
"grid-cols", std::to_string(cols));
6798 char name[maxLineSz];
6799 char type[maxLineSz];
6801 while(fgets(line, maxLineSz, fp))
6804 sscanf(line,
"%s %s %u %u", type, name, &x, &y);
6806 xmlOut.addTextElementToData(
"node-type", type);
6807 xmlOut.addTextElementToData(
"node-name", name);
6808 xmlOut.addTextElementToData(
"node-x", std::to_string(x));
6809 xmlOut.addTextElementToData(
"node-y", std::to_string(y));
6823 void ConfigurationGUISupervisor::handleSaveArtdaqNodeLayoutXML(
6825 ConfigurationManagerRW* cfgMgr,
6826 const std::string& layoutString,
6827 const std::string& contextGroupName,
6828 const TableGroupKey& contextGroupKey)
6830 bool usingActiveGroups = (contextGroupName ==
"" || contextGroupKey.isInvalid());
6832 const std::string& finalContextGroupName =
6834 ? cfgMgr->getActiveGroupName(ConfigurationManager::GroupType::CONTEXT_TYPE)
6836 const TableGroupKey& finalContextGroupKey =
6838 ? cfgMgr->getActiveGroupKey(ConfigurationManager::GroupType::CONTEXT_TYPE)
6841 __SUP_COUTV__(layoutString);
6843 std::stringstream layoutPath;
6844 layoutPath << ARTDAQ_CONFIG_LAYOUTS_PATH << finalContextGroupName <<
"_"
6845 << finalContextGroupKey <<
".dat";
6846 __SUP_COUTV__(layoutPath.str());
6848 std::vector<std::string> fields = StringMacros::getVectorFromString(layoutString);
6849 __SUP_COUTV__(StringMacros::vectorToString(fields));
6851 if(fields.size() < 2 || (fields.size() - 2) % 4 != 0)
6853 __SUP_SS__ <<
"Invalid layout string fields size of " << fields.size() << __E__;
6857 FILE* fp = fopen(layoutPath.str().c_str(),
"w");
6860 __SUP_SS__ <<
"Could not open layout file for writing for '"
6861 << finalContextGroupName <<
"(" << finalContextGroupKey <<
")'"
6869 fprintf(fp,
"%s %s\n", fields[0].c_str(), fields[1].c_str());
6872 for(
unsigned int i = 2; i < fields.size(); i += 4)
6875 fields[i + 0].c_str(),
6876 fields[i + 1].c_str(),
6877 fields[i + 2].c_str(),
6878 fields[i + 3].c_str());
6887 void ConfigurationGUISupervisor::testXDAQContext()
6891 __SUP_COUT__ <<
"Attempting test activation of the context group." << __E__;
6892 ConfigurationManager cfgMgr;
6894 catch(
const std::runtime_error& e)
6897 <<
"The test activation of the context group failed. Ignoring error: \n"
6898 << e.what() << __E__;
6902 __SUP_COUT_WARN__ <<
"The test activation of the context group failed. Ignoring."
static xdaq::Application * instantiate(xdaq::ApplicationStub *s)