1 #include "otsdaq-utilities/ConfigurationGUI/ConfigurationGUISupervisor.h"
2 #include "otsdaq-core/CgiDataUtilities/CgiDataUtilities.h"
3 #include "otsdaq-core/Macros/CoutMacros.h"
4 #include "otsdaq-core/MessageFacility/MessageFacility.h"
5 #include "otsdaq-core/TablePluginDataFormats/IterateTable.h"
6 #include "otsdaq-core/XmlUtilities/HttpXmlDocument.h"
8 #if MESSAGEFACILITY_HEX_VERSION > 0x20100
9 #include <boost/stacktrace.hpp>
12 #include "otsdaq-core/TablePluginDataFormats/XDAQContextTable.h"
14 #include <xdaq/NamespaceURI.h>
23 #define __MF_SUBJECT__ "CfgGUI"
25 #define TABLE_INFO_PATH std::string(getenv("TABLE_INFO_PATH")) + "/"
26 #define TABLE_INFO_EXT std::string("Info.xml")
39 ConfigurationGUISupervisor::ConfigurationGUISupervisor(xdaq::ApplicationStub* stub)
40 : CoreSupervisorBase(stub)
42 __SUP_COUT__ <<
"Constructor started." << __E__;
44 INIT_MF(
"ConfigurationGUI");
47 __SUP_COUT__ <<
"Constructor complete." << __E__;
51 ConfigurationGUISupervisor::~ConfigurationGUISupervisor(
void) { destroy(); }
54 void ConfigurationGUISupervisor::init(
void)
56 __SUP_COUT__ <<
"Initializing..." << __E__;
58 __SUP_COUT__ <<
"Activating saved context, which may prepare for normal mode..."
66 __COUT_WARN__ <<
"Failed test context group activation. otsdaq, in Normal mode, "
67 "will not launch when this test fails. "
68 <<
"Check the active context group from within Wizard Mode."
74 void ConfigurationGUISupervisor::destroy(
void)
77 for(std::map<std::string, ConfigurationManagerRW*>::iterator it =
78 userConfigurationManagers_.begin();
79 it != userConfigurationManagers_.end();
85 userConfigurationManagers_.clear();
89 if(ConfigurationInterface::getInstance(
true) != 0)
90 delete ConfigurationInterface::getInstance(
true);
94 void ConfigurationGUISupervisor::defaultPage(xgi::Input* in, xgi::Output* out)
96 cgicc::Cgicc cgiIn(in);
97 std::string configWindowName =
98 CgiDataUtilities::getData(cgiIn,
"configWindowName");
99 if(configWindowName ==
"tableEditor")
100 *out <<
"<!DOCTYPE HTML><html lang='en'><frameset col='100%' row='100%'><frame "
101 "src='/WebPath/html/ConfigurationTableEditor.html?urn="
102 << this->getApplicationDescriptor()->getLocalId() <<
"'></frameset></html>";
103 if(configWindowName ==
"iterate")
104 *out <<
"<!DOCTYPE HTML><html lang='en'><frameset col='100%' row='100%'><frame "
105 "src='/WebPath/html/Iterate.html?urn="
106 << this->getApplicationDescriptor()->getLocalId() <<
"'></frameset></html>";
108 *out <<
"<!DOCTYPE HTML><html lang='en'><frameset col='100%' row='100%'><frame "
109 "src='/WebPath/html/ConfigurationGUI.html?urn="
110 << this->getApplicationDescriptor()->getLocalId() <<
"'></frameset></html>";
116 void ConfigurationGUISupervisor::setSupervisorPropertyDefaults(
void)
118 CorePropertySupervisorBase::setSupervisorProperty(
119 CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.UserPermissionsThreshold,
120 "*=10 | deleteTreeNodeRecords=255 | saveTableInfo=255 | "
121 "deleteTableInfo=255");
122 CorePropertySupervisorBase::setSupervisorProperty(
123 CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.RequireUserLockRequestTypes,
130 void ConfigurationGUISupervisor::forceSupervisorPropertyValues()
132 CorePropertySupervisorBase::setSupervisorProperty(
133 CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.AutomatedRequestTypes,
135 CorePropertySupervisorBase::setSupervisorProperty(
136 CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.CheckUserLockRequestTypes,
141 void ConfigurationGUISupervisor::request(
const std::string& requestType,
143 HttpXmlDocument& xmlOut,
144 const WebUsers::RequestUserInfo& userInfo)
try
197 std::string refresh = CgiDataUtilities::getData(cgiIn,
"refresh");
201 ConfigurationManagerRW* cfgMgr = refreshUserSession(
202 userInfo.username_, userInfo.activeUserSessionIndex_, (refresh ==
"1"));
204 if(requestType ==
"saveTableInfo")
206 std::string tableName =
207 CgiDataUtilities::getData(cgiIn,
"tableName");
208 std::string columnCSV =
209 CgiDataUtilities::postData(cgiIn,
"columnCSV");
210 std::string allowOverwrite =
211 CgiDataUtilities::getData(cgiIn,
"allowOverwrite");
212 std::string tableDescription =
213 CgiDataUtilities::postData(cgiIn,
"tableDescription");
214 std::string columnChoicesCSV =
215 CgiDataUtilities::postData(cgiIn,
"columnChoicesCSV");
220 __SUP_COUT__ <<
"tableName: " << tableName << __E__;
221 __SUP_COUT__ <<
"columnCSV: " << columnCSV << __E__;
222 __SUP_COUT__ <<
"tableDescription: " << tableDescription << __E__;
223 __SUP_COUT__ <<
"columnChoicesCSV: " << columnChoicesCSV << __E__;
224 __SUP_COUT__ <<
"allowOverwrite: " << allowOverwrite << __E__;
226 if(!allSupervisorInfo_.isWizardMode())
228 __SUP_SS__ <<
"Improper permissions for saving table info." << __E__;
229 xmlOut.addTextElementToData(
"Error", ss.str());
232 handleSaveTableInfoXML(xmlOut,
238 allowOverwrite ==
"1");
240 else if(requestType ==
"deleteTableInfo")
242 std::string tableName =
243 CgiDataUtilities::getData(cgiIn,
"tableName");
244 __SUP_COUT__ <<
"tableName: " << tableName << __E__;
245 handleDeleteTableInfoXML(xmlOut, cfgMgr, tableName);
247 else if(requestType ==
"gatewayLaunchOTS" || requestType ==
"gatewayLaunchWiz" ||
248 requestType ==
"flattenToSystemAliases")
251 __SUP_COUT_WARN__ << requestType <<
" command received! " << __E__;
252 __MOUT_WARN__ << requestType <<
" command received! " << __E__;
255 __SUP_COUT_INFO__ <<
"Launching... " << __E__;
257 __SUP_COUT__ <<
"Extracting target context hostnames... " << __E__;
258 std::vector<std::string> hostnames;
263 const XDAQContextTable* contextTable =
264 cfgMgr->__GET_CONFIG__(XDAQContextTable);
266 auto contexts = contextTable->getContexts();
268 for(
const auto& context : contexts)
275 for(i = 0; i < context.address_.size(); ++i)
276 if(context.address_[i] ==
'/')
278 hostnames.push_back(context.address_.substr(j));
279 __SUP_COUT__ <<
"hostname = " << hostnames.back() << __E__;
284 __SUP_SS__ <<
"\nTransition to Configuring interrupted! "
285 <<
"The Configuration Manager could not be initialized." << __E__;
287 __SUP_COUT_ERR__ <<
"\n" << ss.str();
291 for(
const auto& hostname : hostnames)
293 std::string fn = (std::string(getenv(
"SERVICE_DATA_PATH")) +
294 "/StartOTS_action_" + hostname +
".cmd");
295 FILE* fp = fopen(fn.c_str(),
"w");
298 if(requestType ==
"gatewayLaunchOTS")
299 fprintf(fp,
"LAUNCH_OTS");
300 else if(requestType ==
"gatewayLaunchWiz")
301 fprintf(fp,
"LAUNCH_WIZ");
302 else if(requestType ==
"flattenToSystemAliases")
304 fprintf(fp,
"FLATTEN_TO_SYSTEM_ALIASES");
312 __SUP_COUT_ERR__ <<
"Unable to open command file: " << fn << __E__;
365 else if(requestType ==
"versionTracking")
367 std::string type = CgiDataUtilities::getData(cgiIn,
"Type");
368 __SUP_COUT__ <<
"type: " << type << __E__;
371 xmlOut.addTextElementToData(
372 "versionTrackingStatus",
373 ConfigurationInterface::isVersionTrackingEnabled() ?
"ON" :
"OFF");
374 else if(type ==
"ON")
376 ConfigurationInterface::setVersionTrackingEnabled(
true);
377 xmlOut.addTextElementToData(
378 "versionTrackingStatus",
379 ConfigurationInterface::isVersionTrackingEnabled() ?
"ON" :
"OFF");
381 else if(type ==
"OFF")
383 ConfigurationInterface::setVersionTrackingEnabled(
false);
384 xmlOut.addTextElementToData(
385 "versionTrackingStatus",
386 ConfigurationInterface::isVersionTrackingEnabled() ?
"ON" :
"OFF");
389 else if(requestType ==
"getColumnTypes")
392 std::vector<std::string> allTypes = TableViewColumnInfo::getAllTypesForGUI();
393 std::vector<std::string> allDataTypes =
394 TableViewColumnInfo::getAllDataTypesForGUI();
395 std::map<std::pair<std::string, std::string>, std::string> allDefaults =
396 TableViewColumnInfo::getAllDefaultsForGUI();
398 for(
const auto& type : allTypes)
399 xmlOut.addTextElementToData(
"columnTypeForGUI", type);
400 for(
const auto& dataType : allDataTypes)
401 xmlOut.addTextElementToData(
"columnDataTypeForGUI", dataType);
403 for(
const auto& colDefault : allDefaults)
405 xmlOut.addTextElementToData(
"columnDefaultDataType", colDefault.first.first);
406 xmlOut.addTextElementToData(
"columnDefaultTypeFilter",
407 colDefault.first.second);
408 xmlOut.addTextElementToData(
"columnDefaultValue", colDefault.second);
411 else if(requestType ==
"getGroupAliases")
416 1 == CgiDataUtilities::getDataAsInt(cgiIn,
"reloadActiveGroups");
418 __SUP_COUT__ <<
"reloadActive: " << reloadActive << __E__;
419 bool wasError =
false;
424 cfgMgr->clearAllCachedVersions();
425 cfgMgr->restoreActiveTableGroups(
true);
427 catch(std::runtime_error& e)
429 __SUP_SS__ << (
"Error loading active groups!\n\n" + std::string(e.what()))
431 __SUP_COUT_ERR__ <<
"\n" << ss.str();
432 xmlOut.addTextElementToData(
"Error", ss.str());
437 __SUP_SS__ << (
"Error loading active groups!\n\n") << __E__;
438 __SUP_COUT_ERR__ <<
"\n" << ss.str();
439 xmlOut.addTextElementToData(
"Error", ss.str());
444 handleGroupAliasesXML(xmlOut, cfgMgr);
446 else if(requestType ==
"setGroupAliasInActiveBackbone")
448 std::string groupAlias =
449 CgiDataUtilities::getData(cgiIn,
"groupAlias");
450 std::string groupName = CgiDataUtilities::getData(cgiIn,
"groupName");
452 std::string groupKey = CgiDataUtilities::getData(cgiIn,
"groupKey");
454 __SUP_COUT__ <<
"groupAlias: " << groupAlias << __E__;
455 __SUP_COUT__ <<
"groupName: " << groupName << __E__;
456 __SUP_COUT__ <<
"groupKey: " << groupKey << __E__;
458 handleSetGroupAliasInBackboneXML(xmlOut,
462 TableGroupKey(groupKey),
465 else if(requestType ==
"setVersionAliasInActiveBackbone")
467 std::string versionAlias =
468 CgiDataUtilities::getData(cgiIn,
"versionAlias");
469 std::string tableName =
470 CgiDataUtilities::getData(cgiIn,
"tableName");
471 std::string version = CgiDataUtilities::getData(cgiIn,
"version");
473 __SUP_COUT__ <<
"versionAlias: " << versionAlias << __E__;
474 __SUP_COUT__ <<
"tableName: " << tableName << __E__;
475 __SUP_COUT__ <<
"version: " << version << __E__;
477 handleSetVersionAliasInBackboneXML(xmlOut,
481 TableVersion(version),
484 else if(requestType ==
"setAliasOfGroupMembers")
486 std::string versionAlias =
487 CgiDataUtilities::getData(cgiIn,
"versionAlias");
488 std::string groupName = CgiDataUtilities::getData(cgiIn,
"groupName");
490 std::string groupKey = CgiDataUtilities::getData(cgiIn,
"groupKey");
492 __SUP_COUT__ <<
"versionAlias: " << versionAlias << __E__;
493 __SUP_COUT__ <<
"groupName: " << groupName << __E__;
494 __SUP_COUT__ <<
"groupKey: " << groupKey << __E__;
496 handleAliasGroupMembersInBackboneXML(xmlOut,
500 TableGroupKey(groupKey),
503 else if(requestType ==
"getVersionAliases")
505 handleVersionAliasesXML(xmlOut, cfgMgr);
507 else if(requestType ==
"getTableGroups")
509 bool doNotReturnMembers =
510 CgiDataUtilities::getDataAsInt(cgiIn,
"doNotReturnMembers") == 1
514 __SUP_COUT__ <<
"doNotReturnMembers: " << doNotReturnMembers << __E__;
515 handleTableGroupsXML(xmlOut, cfgMgr, !doNotReturnMembers);
517 else if(requestType ==
"getTableGroupType")
519 std::string tableList =
520 CgiDataUtilities::postData(cgiIn,
"tableList");
521 __SUP_COUT__ <<
"tableList: " << tableList << __E__;
523 handleGetTableGroupTypeXML(xmlOut, cfgMgr, tableList);
525 else if(requestType ==
"getTables")
527 std::string allowIllegalColumns =
528 CgiDataUtilities::getData(cgiIn,
"allowIllegalColumns");
530 __SUP_COUT__ <<
"allowIllegalColumns: " << allowIllegalColumns << __E__;
532 handleTablesXML(xmlOut, cfgMgr, allowIllegalColumns ==
"1");
534 else if(requestType ==
"getContextMemberNames")
536 std::set<std::string> members = cfgMgr->getContextMemberNames();
538 for(
auto& member : members)
539 xmlOut.addTextElementToData(
"ContextMember", member);
541 else if(requestType ==
"getBackboneMemberNames")
543 std::set<std::string> members = cfgMgr->getBackboneMemberNames();
545 for(
auto& member : members)
546 xmlOut.addTextElementToData(
"BackboneMember", member);
548 else if(requestType ==
"getIterateMemberNames")
550 std::set<std::string> members = cfgMgr->getIterateMemberNames();
552 for(
auto& member : members)
553 xmlOut.addTextElementToData(
"IterateMember", member);
555 else if(requestType ==
"getSpecificTableGroup")
557 std::string groupName = CgiDataUtilities::getData(cgiIn,
"groupName");
559 std::string groupKey = CgiDataUtilities::getData(cgiIn,
"groupKey");
561 __SUP_COUT__ <<
"groupName: " << groupName << __E__;
562 __SUP_COUT__ <<
"groupKey: " << groupKey << __E__;
564 handleGetTableGroupXML(xmlOut, cfgMgr, groupName, TableGroupKey(groupKey));
566 else if(requestType ==
"saveNewTableGroup")
568 std::string groupName = CgiDataUtilities::getData(cgiIn,
"groupName");
570 bool ignoreWarnings =
571 CgiDataUtilities::getDataAsInt(cgiIn,
"ignoreWarnings");
572 bool allowDuplicates =
573 CgiDataUtilities::getDataAsInt(cgiIn,
"allowDuplicates");
574 bool lookForEquivalent =
575 CgiDataUtilities::getDataAsInt(cgiIn,
"lookForEquivalent");
576 std::string tableList =
577 CgiDataUtilities::postData(cgiIn,
"tableList");
578 std::string comment =
579 CgiDataUtilities::getData(cgiIn,
"groupComment");
581 __SUP_COUT__ <<
"saveNewTableGroup: " << groupName << __E__;
582 __SUP_COUT__ <<
"tableList: " << tableList << __E__;
583 __SUP_COUT__ <<
"ignoreWarnings: " << ignoreWarnings << __E__;
584 __SUP_COUT__ <<
"allowDuplicates: " << allowDuplicates << __E__;
585 __SUP_COUT__ <<
"lookForEquivalent: " << lookForEquivalent << __E__;
586 __SUP_COUT__ <<
"comment: " << comment << __E__;
588 handleCreateTableGroupXML(xmlOut,
597 else if(requestType ==
"getSpecificTable")
599 std::string tableName =
600 CgiDataUtilities::getData(cgiIn,
"tableName");
601 std::string versionStr = CgiDataUtilities::getData(cgiIn,
"version");
602 int dataOffset = CgiDataUtilities::getDataAsInt(cgiIn,
"dataOffset");
603 int chunkSize = CgiDataUtilities::getDataAsInt(cgiIn,
"chunkSize");
605 std::string allowIllegalColumns =
606 CgiDataUtilities::getData(cgiIn,
"allowIllegalColumns");
607 __SUP_COUT__ <<
"allowIllegalColumns: " << (allowIllegalColumns ==
"1") << __E__;
609 __SUP_COUT__ <<
"getSpecificTable: " << tableName <<
" versionStr: " << versionStr
610 <<
" chunkSize: " << chunkSize <<
" dataOffset: " << dataOffset
613 TableVersion version;
614 const std::map<std::string, TableInfo>& allTableInfo = cfgMgr->getAllTableInfo();
615 std::string versionAlias;
617 if(allTableInfo.find(tableName) != allTableInfo.end())
619 if(versionStr ==
"" &&
620 allTableInfo.at(tableName).versions_.size())
621 version = *(allTableInfo.at(tableName).versions_.rbegin());
622 else if(versionStr.find(ConfigurationManager::ALIAS_VERSION_PREAMBLE) == 0)
625 std::map<std::string ,
626 std::map<std::string , TableVersion>>
627 versionAliases = cfgMgr->getVersionAliases();
629 versionAlias = versionStr.substr(
630 ConfigurationManager::ALIAS_VERSION_PREAMBLE.size());
641 if(versionAliases.find(tableName) != versionAliases.end() &&
642 versionAliases[tableName].find(versionStr.substr(
643 ConfigurationManager::ALIAS_VERSION_PREAMBLE.size())) !=
644 versionAliases[tableName].end())
646 version = versionAliases[tableName][versionStr.substr(
647 ConfigurationManager::ALIAS_VERSION_PREAMBLE.size())];
648 __SUP_COUT__ <<
"version alias translated to: " << version << __E__;
653 << versionStr.substr(
654 ConfigurationManager::ALIAS_VERSION_PREAMBLE.size())
655 <<
"'was not found in active version aliases!" << __E__;
658 version = atoi(versionStr.c_str());
661 __SUP_COUT__ <<
"version: " << version << __E__;
663 handleGetTableXML(xmlOut,
666 TableVersion(version),
667 (allowIllegalColumns ==
"1"));
669 xmlOut.addTextElementToData(
"DefaultRowValue", userInfo.username_);
671 else if(requestType ==
"saveSpecificTable")
673 std::string tableName =
674 CgiDataUtilities::getData(cgiIn,
"tableName");
675 int version = CgiDataUtilities::getDataAsInt(cgiIn,
"version");
676 int dataOffset = CgiDataUtilities::getDataAsInt(cgiIn,
"dataOffset");
677 bool sourceTableAsIs =
678 CgiDataUtilities::getDataAsInt(cgiIn,
"sourceTableAsIs");
679 bool lookForEquivalent =
680 CgiDataUtilities::getDataAsInt(cgiIn,
"lookForEquivalent");
681 int temporary = CgiDataUtilities::getDataAsInt(cgiIn,
"temporary");
682 std::string comment =
683 CgiDataUtilities::getData(cgiIn,
"tableComment");
685 std::string data = CgiDataUtilities::postData(cgiIn,
"data");
689 __SUP_COUT__ <<
"tableName: " << tableName <<
" version: " << version
690 <<
" temporary: " << temporary <<
" dataOffset: " << dataOffset
692 __SUP_COUT__ <<
"comment: " << comment << __E__;
693 __SUP_COUT__ <<
"data: " << data << __E__;
694 __SUP_COUT__ <<
"sourceTableAsIs: " << sourceTableAsIs << __E__;
695 __SUP_COUT__ <<
"lookForEquivalent: " << lookForEquivalent << __E__;
697 handleCreateTableXML(xmlOut,
700 TableVersion(version),
709 else if(requestType ==
"clearTableTemporaryVersions")
711 std::string tableName =
712 CgiDataUtilities::getData(cgiIn,
"tableName");
713 __SUP_COUT__ <<
"tableName: " << tableName << __E__;
717 cfgMgr->eraseTemporaryVersion(tableName);
719 catch(std::runtime_error& e)
721 __SUP_COUT__ <<
"Error detected!\n\n " << e.what() << __E__;
722 xmlOut.addTextElementToData(
723 "Error",
"Error clearing temporary views!\n " + std::string(e.what()));
727 __SUP_COUT__ <<
"Error detected!\n\n " << __E__;
728 xmlOut.addTextElementToData(
"Error",
"Error clearing temporary views! ");
731 else if(requestType ==
"clearTableCachedVersions")
733 std::string tableName =
734 CgiDataUtilities::getData(cgiIn,
"tableName");
735 __SUP_COUT__ <<
"tableName: " << tableName << __E__;
739 cfgMgr->clearCachedVersions(tableName);
741 catch(std::runtime_error& e)
743 __SUP_COUT__ <<
"Error detected!\n\n " << e.what() << __E__;
744 xmlOut.addTextElementToData(
745 "Error",
"Error clearing cached views!\n " + std::string(e.what()));
749 __SUP_COUT__ <<
"Error detected!\n\n " << __E__;
750 xmlOut.addTextElementToData(
"Error",
"Error clearing cached views! ");
753 else if(requestType ==
"getTreeView")
755 std::string configGroup = CgiDataUtilities::getData(cgiIn,
"configGroup");
756 std::string configGroupKey = CgiDataUtilities::getData(cgiIn,
"configGroupKey");
757 std::string startPath = CgiDataUtilities::postData(cgiIn,
"startPath");
758 std::string modifiedTables = CgiDataUtilities::postData(cgiIn,
"modifiedTables");
759 std::string filterList = CgiDataUtilities::postData(cgiIn,
"filterList");
760 int depth = CgiDataUtilities::getDataAsInt(cgiIn,
"depth");
761 bool hideStatusFalse = CgiDataUtilities::getDataAsInt(cgiIn,
"hideStatusFalse");
763 __SUP_COUT__ <<
"configGroup: " << configGroup << __E__;
764 __SUP_COUT__ <<
"configGroupKey: " << configGroupKey << __E__;
765 __SUP_COUT__ <<
"startPath: " << startPath << __E__;
766 __SUP_COUT__ <<
"depth: " << depth << __E__;
767 __SUP_COUT__ <<
"hideStatusFalse: " << hideStatusFalse << __E__;
768 __SUP_COUT__ <<
"modifiedTables: " << modifiedTables << __E__;
769 __SUP_COUT__ <<
"filterList: " << filterList << __E__;
771 handleFillTreeViewXML(xmlOut,
774 TableGroupKey(configGroupKey),
781 else if(requestType ==
"getTreeNodeCommonFields")
783 std::string configGroup = CgiDataUtilities::getData(cgiIn,
"configGroup");
784 std::string configGroupKey = CgiDataUtilities::getData(cgiIn,
"configGroupKey");
785 std::string startPath = CgiDataUtilities::postData(cgiIn,
"startPath");
786 std::string modifiedTables = CgiDataUtilities::postData(cgiIn,
"modifiedTables");
787 std::string fieldList = CgiDataUtilities::postData(cgiIn,
"fieldList");
788 std::string recordList = CgiDataUtilities::postData(cgiIn,
"recordList");
789 int depth = CgiDataUtilities::getDataAsInt(cgiIn,
"depth");
791 __SUP_COUT__ <<
"configGroup: " << configGroup << __E__;
792 __SUP_COUT__ <<
"configGroupKey: " << configGroupKey << __E__;
793 __SUP_COUT__ <<
"startPath: " << startPath << __E__;
794 __SUP_COUT__ <<
"depth: " << depth << __E__;
795 __SUP_COUT__ <<
"fieldList: " << fieldList << __E__;
796 __SUP_COUT__ <<
"recordList: " << recordList << __E__;
797 __SUP_COUT__ <<
"modifiedTables: " << modifiedTables << __E__;
799 handleFillTreeNodeCommonFieldsXML(xmlOut,
802 TableGroupKey(configGroupKey),
809 else if(requestType ==
"getUniqueFieldValuesForRecords")
811 std::string configGroup = CgiDataUtilities::getData(cgiIn,
"configGroup");
812 std::string configGroupKey = CgiDataUtilities::getData(cgiIn,
"configGroupKey");
813 std::string startPath = CgiDataUtilities::postData(cgiIn,
"startPath");
814 std::string modifiedTables = CgiDataUtilities::postData(cgiIn,
"modifiedTables");
815 std::string fieldList = CgiDataUtilities::postData(cgiIn,
"fieldList");
816 std::string recordList = CgiDataUtilities::postData(cgiIn,
"recordList");
818 __SUP_COUT__ <<
"configGroup: " << configGroup << __E__;
819 __SUP_COUT__ <<
"configGroupKey: " << configGroupKey << __E__;
820 __SUP_COUT__ <<
"startPath: " << startPath << __E__;
821 __SUP_COUT__ <<
"fieldList: " << fieldList << __E__;
822 __SUP_COUT__ <<
"recordList: " << recordList << __E__;
823 __SUP_COUT__ <<
"modifiedTables: " << modifiedTables << __E__;
825 handleFillUniqueFieldValuesForRecordsXML(xmlOut,
828 TableGroupKey(configGroupKey),
834 else if(requestType ==
"getTreeNodeFieldValues")
836 std::string configGroup = CgiDataUtilities::getData(cgiIn,
"configGroup");
837 std::string configGroupKey = CgiDataUtilities::getData(cgiIn,
"configGroupKey");
838 std::string startPath = CgiDataUtilities::postData(cgiIn,
"startPath");
839 std::string modifiedTables = CgiDataUtilities::postData(cgiIn,
"modifiedTables");
840 std::string fieldList = CgiDataUtilities::postData(cgiIn,
"fieldList");
841 std::string recordList = CgiDataUtilities::postData(cgiIn,
"recordList");
843 __SUP_COUT__ <<
"configGroup: " << configGroup << __E__;
844 __SUP_COUT__ <<
"configGroupKey: " << configGroupKey << __E__;
845 __SUP_COUT__ <<
"startPath: " << startPath << __E__;
846 __SUP_COUT__ <<
"fieldList: " << fieldList << __E__;
847 __SUP_COUT__ <<
"recordList: " << recordList << __E__;
848 __SUP_COUT__ <<
"modifiedTables: " << modifiedTables << __E__;
850 handleFillGetTreeNodeFieldValuesXML(xmlOut,
853 TableGroupKey(configGroupKey),
859 else if(requestType ==
"setTreeNodeFieldValues")
861 std::string configGroup = CgiDataUtilities::getData(cgiIn,
"configGroup");
862 std::string configGroupKey = CgiDataUtilities::getData(cgiIn,
"configGroupKey");
863 std::string startPath = CgiDataUtilities::postData(cgiIn,
"startPath");
864 std::string modifiedTables = CgiDataUtilities::postData(cgiIn,
"modifiedTables");
865 std::string fieldList = CgiDataUtilities::postData(cgiIn,
"fieldList");
866 std::string recordList = CgiDataUtilities::postData(cgiIn,
"recordList");
867 std::string valueList = CgiDataUtilities::postData(cgiIn,
"valueList");
869 __SUP_COUT__ <<
"configGroup: " << configGroup << __E__;
870 __SUP_COUT__ <<
"configGroupKey: " << configGroupKey << __E__;
871 __SUP_COUT__ <<
"startPath: " << startPath << __E__;
872 __SUP_COUT__ <<
"fieldList: " << fieldList << __E__;
873 __SUP_COUT__ <<
"valueList: " << valueList << __E__;
874 __SUP_COUT__ <<
"recordList: " << recordList << __E__;
875 __SUP_COUT__ <<
"modifiedTables: " << modifiedTables << __E__;
877 handleFillSetTreeNodeFieldValuesXML(xmlOut,
880 TableGroupKey(configGroupKey),
888 else if(requestType ==
"addTreeNodeRecords")
890 std::string configGroup = CgiDataUtilities::getData(cgiIn,
"configGroup");
891 std::string configGroupKey = CgiDataUtilities::getData(cgiIn,
"configGroupKey");
892 std::string startPath = CgiDataUtilities::postData(cgiIn,
"startPath");
893 std::string modifiedTables = CgiDataUtilities::postData(cgiIn,
"modifiedTables");
894 std::string recordList = CgiDataUtilities::postData(cgiIn,
"recordList");
896 __SUP_COUT__ <<
"configGroup: " << configGroup << __E__;
897 __SUP_COUT__ <<
"configGroupKey: " << configGroupKey << __E__;
898 __SUP_COUT__ <<
"startPath: " << startPath << __E__;
899 __SUP_COUT__ <<
"recordList: " << recordList << __E__;
900 __SUP_COUT__ <<
"modifiedTables: " << modifiedTables << __E__;
902 handleFillCreateTreeNodeRecordsXML(xmlOut,
905 TableGroupKey(configGroupKey),
911 else if(requestType ==
"deleteTreeNodeRecords")
913 std::string configGroup = CgiDataUtilities::getData(cgiIn,
"configGroup");
914 std::string configGroupKey = CgiDataUtilities::getData(cgiIn,
"configGroupKey");
915 std::string startPath = CgiDataUtilities::postData(cgiIn,
"startPath");
916 std::string modifiedTables = CgiDataUtilities::postData(cgiIn,
"modifiedTables");
917 std::string recordList = CgiDataUtilities::postData(cgiIn,
"recordList");
919 __SUP_COUT__ <<
"configGroup: " << configGroup << __E__;
920 __SUP_COUT__ <<
"configGroupKey: " << configGroupKey << __E__;
921 __SUP_COUT__ <<
"startPath: " << startPath << __E__;
922 __SUP_COUT__ <<
"recordList: " << recordList << __E__;
923 __SUP_COUT__ <<
"modifiedTables: " << modifiedTables << __E__;
925 handleFillDeleteTreeNodeRecordsXML(xmlOut,
928 TableGroupKey(configGroupKey),
933 else if(requestType ==
"getAffectedActiveGroups")
935 std::string groupName = CgiDataUtilities::getData(cgiIn,
"groupName");
936 std::string groupKey = CgiDataUtilities::getData(cgiIn,
"groupKey");
937 std::string modifiedTables = CgiDataUtilities::postData(cgiIn,
"modifiedTables");
938 __SUP_COUT__ <<
"modifiedTables: " << modifiedTables << __E__;
939 __SUP_COUT__ <<
"groupName: " << groupName << __E__;
940 __SUP_COUT__ <<
"groupKey: " << groupKey << __E__;
942 handleGetAffectedGroupsXML(
943 xmlOut, cfgMgr, groupName, TableGroupKey(groupKey), modifiedTables);
945 else if(requestType ==
"saveTreeNodeEdit")
947 std::string editNodeType = CgiDataUtilities::getData(cgiIn,
"editNodeType");
948 std::string targetTable = CgiDataUtilities::getData(cgiIn,
"targetTable");
949 std::string targetTableVersion =
950 CgiDataUtilities::getData(cgiIn,
"targetTableVersion");
951 std::string targetUID = CgiDataUtilities::getData(cgiIn,
"targetUID");
952 std::string targetColumn = CgiDataUtilities::getData(cgiIn,
"targetColumn");
953 std::string newValue = CgiDataUtilities::postData(cgiIn,
"newValue");
955 __SUP_COUT__ <<
"editNodeType: " << editNodeType << __E__;
956 __SUP_COUT__ <<
"targetTable: " << targetTable << __E__;
957 __SUP_COUT__ <<
"targetTableVersion: " << targetTableVersion << __E__;
958 __SUP_COUT__ <<
"targetUID: " << targetUID << __E__;
959 __SUP_COUT__ <<
"targetColumn: " << targetColumn << __E__;
960 __SUP_COUT__ <<
"newValue: " << newValue << __E__;
962 handleSaveTreeNodeEditXML(xmlOut,
965 TableVersion(targetTableVersion),
967 CgiDataUtilities::decodeURIComponent(targetUID),
968 CgiDataUtilities::decodeURIComponent(targetColumn),
972 else if(requestType ==
"getLinkToChoices")
974 std::string linkToTableName = CgiDataUtilities::getData(cgiIn,
"linkToTableName");
975 std::string linkToTableVersion =
976 CgiDataUtilities::getData(cgiIn,
"linkToTableVersion");
977 std::string linkIdType = CgiDataUtilities::getData(cgiIn,
"linkIdType");
978 std::string linkIndex = CgiDataUtilities::decodeURIComponent(
979 CgiDataUtilities::getData(cgiIn,
"linkIndex"));
980 std::string linkInitId = CgiDataUtilities::getData(cgiIn,
"linkInitId");
982 __SUP_COUT__ <<
"linkToTableName: " << linkToTableName << __E__;
983 __SUP_COUT__ <<
"linkToTableVersion: " << linkToTableVersion << __E__;
984 __SUP_COUT__ <<
"linkIdType: " << linkIdType << __E__;
985 __SUP_COUT__ <<
"linkIndex: " << linkIndex << __E__;
986 __SUP_COUT__ <<
"linkInitId: " << linkInitId << __E__;
988 handleGetLinkToChoicesXML(xmlOut,
991 TableVersion(linkToTableVersion),
996 else if(requestType ==
"activateTableGroup")
998 std::string groupName = CgiDataUtilities::getData(cgiIn,
"groupName");
999 std::string groupKey = CgiDataUtilities::getData(cgiIn,
"groupKey");
1000 bool ignoreWarnings = CgiDataUtilities::getDataAsInt(cgiIn,
"ignoreWarnings");
1002 __SUP_COUT__ <<
"Activating config: " << groupName <<
"(" << groupKey <<
")"
1004 __SUP_COUT__ <<
"ignoreWarnings: " << ignoreWarnings << __E__;
1007 xmlOut.addTextElementToData(
"AttemptedGroupActivation",
"1");
1008 xmlOut.addTextElementToData(
"AttemptedGroupActivationName", groupName);
1009 xmlOut.addTextElementToData(
"AttemptedGroupActivationKey", groupKey);
1011 std::string accumulatedTreeErrors;
1014 cfgMgr->activateTableGroup(
1016 TableGroupKey(groupKey),
1019 : &accumulatedTreeErrors);
1021 catch(std::runtime_error& e)
1026 __SUP_COUT__ <<
"Error detected!\n\n " << e.what() << __E__;
1027 xmlOut.addTextElementToData(
1029 "Error activating config group '" + groupName +
"(" + groupKey +
")" +
1030 ".' Please see details below:\n\n" + std::string(e.what()));
1031 __SUP_COUT_ERR__ <<
"Errors detected so de-activating group: " << groupName
1032 <<
" (" << groupKey <<
")" << __E__;
1035 cfgMgr->destroyTableGroup(groupName,
true);
1041 catch(cet::exception& e)
1047 __SUP_COUT__ <<
"Error detected!\n\n " << e.what() << __E__;
1048 xmlOut.addTextElementToData(
"Error",
1049 "Error activating config group '" + groupName +
1050 "(" + groupKey +
")" +
"!'\n\n" +
1051 std::string(e.what()));
1052 __SUP_COUT_ERR__ <<
"Errors detected so de-activating group: " << groupName
1053 <<
" (" << groupKey <<
")" << __E__;
1056 cfgMgr->destroyTableGroup(groupName,
true);
1064 __SUP_COUT__ <<
"Error detected!" << __E__;
1068 if(accumulatedTreeErrors !=
"")
1069 xmlOut.addTextElementToData(
"Error",
1070 "Warnings were found when activating group '" +
1071 groupName +
"(" + groupKey +
")" +
1072 "'! Please see details below:\n\n" +
1073 accumulatedTreeErrors);
1075 else if(requestType ==
"getActiveTableGroups")
1077 else if(requestType ==
"copyViewToCurrentColumns")
1079 std::string tableName =
1080 CgiDataUtilities::getData(cgiIn,
"tableName");
1081 std::string sourceVersion = CgiDataUtilities::getData(cgiIn,
"sourceVersion");
1083 __SUP_COUT__ <<
"tableName: " << tableName << __E__;
1084 __SUP_COUT__ <<
"sourceVersion: " << sourceVersion << __E__;
1085 __SUP_COUT__ <<
"userInfo.username_: " << userInfo.username_ << __E__;
1088 TableVersion newTemporaryVersion;
1092 newTemporaryVersion =
1093 cfgMgr->copyViewToCurrentColumns(tableName, TableVersion(sourceVersion));
1106 __SUP_COUT__ <<
"New temporary version = " << newTemporaryVersion << __E__;
1108 catch(std::runtime_error& e)
1110 __SUP_COUT__ <<
"Error detected!\n\n " << e.what() << __E__;
1111 xmlOut.addTextElementToData(
"Error",
1112 "Error copying view from '" + tableName +
"_v" +
1113 sourceVersion +
"'! " +
1114 std::string(e.what()));
1118 __SUP_COUT__ <<
"Error detected!\n\n " << __E__;
1119 xmlOut.addTextElementToData(
1121 "Error copying view from '" + tableName +
"_v" + sourceVersion +
"'! ");
1124 handleGetTableXML(xmlOut, cfgMgr, tableName, newTemporaryVersion);
1126 else if(requestType ==
"getLastTableGroups")
1128 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* gatewaySupervisor =
1129 allSupervisorInfo_.isWizardMode() ? allSupervisorInfo_.getWizardDescriptor()
1130 : allSupervisorInfo_.getGatewayDescriptor();
1132 std::string timeString;
1133 std::pair<std::string , TableGroupKey> theGroup =
1134 theRemoteWebUsers_.getLastConfigGroup(
1135 gatewaySupervisor,
"Configured", timeString);
1136 xmlOut.addTextElementToData(
"LastConfiguredGroupName", theGroup.first);
1137 xmlOut.addTextElementToData(
"LastConfiguredGroupKey", theGroup.second.toString());
1138 xmlOut.addTextElementToData(
"LastConfiguredGroupTime", timeString);
1139 theGroup = theRemoteWebUsers_.getLastConfigGroup(
1140 gatewaySupervisor,
"Started", timeString);
1141 xmlOut.addTextElementToData(
"LastStartedGroupName", theGroup.first);
1142 xmlOut.addTextElementToData(
"LastStartedGroupKey", theGroup.second.toString());
1143 xmlOut.addTextElementToData(
"LastStartedGroupTime", timeString);
1145 else if(requestType ==
"savePlanCommandSequence")
1147 std::string planName = CgiDataUtilities::getData(cgiIn,
"planName");
1148 std::string commands = CgiDataUtilities::postData(cgiIn,
"commands");
1150 std::string modifiedTables = CgiDataUtilities::postData(cgiIn,
"modifiedTables");
1151 std::string groupName = CgiDataUtilities::getData(cgiIn,
"groupName");
1152 std::string groupKey = CgiDataUtilities::getData(cgiIn,
"groupKey");
1154 __SUP_COUT__ <<
"modifiedTables: " << modifiedTables << __E__;
1155 __SUP_COUT__ <<
"planName: " << planName << __E__;
1156 __SUP_COUT__ <<
"commands: " << commands << __E__;
1157 __SUP_COUT__ <<
"groupName: " << groupName << __E__;
1158 __SUP_COUT__ <<
"groupKey: " << groupKey << __E__;
1160 handleSavePlanCommandSequenceXML(xmlOut,
1163 TableGroupKey(groupKey),
1169 else if(requestType ==
"mergeGroups")
1171 std::string groupANameContext =
1172 CgiDataUtilities::getData(cgiIn,
"groupANameContext");
1173 std::string groupAKeyContext =
1174 CgiDataUtilities::getData(cgiIn,
"groupAKeyContext");
1175 std::string groupBNameContext =
1176 CgiDataUtilities::getData(cgiIn,
"groupBNameContext");
1177 std::string groupBKeyContext =
1178 CgiDataUtilities::getData(cgiIn,
"groupBKeyContext");
1179 std::string groupANameConfig =
1180 CgiDataUtilities::getData(cgiIn,
"groupANameConfig");
1181 std::string groupAKeyConfig =
1182 CgiDataUtilities::getData(cgiIn,
"groupAKeyConfig");
1183 std::string groupBNameConfig =
1184 CgiDataUtilities::getData(cgiIn,
"groupBNameConfig");
1185 std::string groupBKeyConfig =
1186 CgiDataUtilities::getData(cgiIn,
"groupBKeyConfig");
1187 std::string mergeApproach =
1188 CgiDataUtilities::getData(cgiIn,
"mergeApproach");
1190 __SUP_COUTV__(groupANameContext);
1191 __SUP_COUTV__(groupAKeyContext);
1192 __SUP_COUTV__(groupBNameContext);
1193 __SUP_COUTV__(groupBKeyContext);
1194 __SUP_COUTV__(groupANameConfig);
1195 __SUP_COUTV__(groupAKeyConfig);
1196 __SUP_COUTV__(groupBNameConfig);
1197 __SUP_COUTV__(groupBKeyConfig);
1198 __SUP_COUTV__(mergeApproach);
1200 handleMergeGroupsXML(xmlOut,
1203 TableGroupKey(groupAKeyContext),
1205 TableGroupKey(groupBKeyContext),
1207 TableGroupKey(groupAKeyConfig),
1209 TableGroupKey(groupBKeyConfig),
1215 __SUP_SS__ <<
"requestType '" << requestType <<
"' request not recognized."
1217 __SUP_COUT__ <<
"\n" << ss.str();
1218 xmlOut.addTextElementToData(
"Error", ss.str());
1224 std::map<std::string , std::pair<std::string , TableGroupKey>>
1225 activeGroupMap = cfgMgr->getActiveTableGroups();
1227 for(
auto& type : activeGroupMap)
1229 xmlOut.addTextElementToData(type.first +
"-ActiveGroupName", type.second.first);
1230 xmlOut.addTextElementToData(type.first +
"-ActiveGroupKey",
1231 type.second.second.toString());
1237 xmlOut.addTextElementToData(
1239 ConfigurationInterface::isVersionTrackingEnabled() ?
"ON" :
"OFF");
1246 catch(
const std::runtime_error& e)
1248 __SS__ <<
"A fatal error occurred while handling the request '" << requestType
1249 <<
".' Error: " << e.what() << __E__;
1250 __COUT_ERR__ <<
"\n" << ss.str();
1251 xmlOut.addTextElementToData(
"Error", ss.str());
1256 xmlOut.addTextElementToData(
1258 ConfigurationInterface::isVersionTrackingEnabled() ?
"ON" :
"OFF");
1262 __COUT_ERR__ <<
"Error getting version tracking status!" << __E__;
1267 __SS__ <<
"An unknown fatal error occurred while handling the request '"
1268 << requestType <<
".'" << __E__;
1269 __COUT_ERR__ <<
"\n" << ss.str();
1270 xmlOut.addTextElementToData(
"Error", ss.str());
1275 xmlOut.addTextElementToData(
1277 ConfigurationInterface::isVersionTrackingEnabled() ?
"ON" :
"OFF");
1281 __COUT_ERR__ <<
"Error getting version tracking status!" << __E__;
1293 void ConfigurationGUISupervisor::handleGetAffectedGroupsXML(
1294 HttpXmlDocument& xmlOut,
1295 ConfigurationManagerRW* cfgMgr,
1296 const std::string& rootGroupName,
1297 const TableGroupKey& rootGroupKey,
1298 const std::string& modifiedTables)
try
1308 std::map<std::string, std::pair<std::string, TableGroupKey>> consideredGroups =
1309 cfgMgr->getActiveTableGroups();
1313 if(consideredGroups[ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT]
1314 .second.isInvalid())
1316 __SUP_COUT__ <<
"Finding a context group to consider..." << __E__;
1317 if(cfgMgr->getFailedTableGroups().find(
1318 ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT) !=
1319 cfgMgr->getFailedTableGroups().end())
1321 consideredGroups[ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT] =
1322 cfgMgr->getFailedTableGroups().at(
1323 ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT);
1325 else if(cfgMgr->getFailedTableGroups().find(
1326 ConfigurationManager::ACTIVE_GROUP_NAME_UNKNOWN) !=
1327 cfgMgr->getFailedTableGroups().end())
1329 consideredGroups[ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT] =
1330 cfgMgr->getFailedTableGroups().at(
1331 ConfigurationManager::ACTIVE_GROUP_NAME_UNKNOWN);
1334 if(consideredGroups[ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION]
1335 .second.isInvalid())
1337 __SUP_COUT__ <<
"Finding a table group to consider..." << __E__;
1338 if(cfgMgr->getFailedTableGroups().find(
1339 ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION) !=
1340 cfgMgr->getFailedTableGroups().end())
1342 consideredGroups[ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION] =
1343 cfgMgr->getFailedTableGroups().at(
1344 ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION);
1346 else if(cfgMgr->getFailedTableGroups().find(
1347 ConfigurationManager::ACTIVE_GROUP_NAME_UNKNOWN) !=
1348 cfgMgr->getFailedTableGroups().end())
1350 consideredGroups[ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION] =
1351 cfgMgr->getFailedTableGroups().at(
1352 ConfigurationManager::ACTIVE_GROUP_NAME_UNKNOWN);
1356 __SUP_COUTV__(StringMacros::mapToString(consideredGroups));
1361 std::map<std::string , TableVersion > rootGroupMemberMap;
1363 cfgMgr->loadTableGroup(rootGroupName,
1366 &rootGroupMemberMap,
1374 const std::string& groupType = cfgMgr->getTypeNameOfGroup(rootGroupMemberMap);
1376 consideredGroups[groupType] =
1377 std::pair<std::string, TableGroupKey>(rootGroupName, rootGroupKey);
1379 catch(
const std::runtime_error& e)
1382 if(rootGroupName.size())
1384 __SUP_SS__ <<
"Failed to determine type of table group for " << rootGroupName
1385 <<
"(" << rootGroupKey <<
")! " << e.what() << __E__;
1386 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1391 __SUP_COUT__ <<
"Did not modify considered active groups due to empty root group "
1392 "name - assuming this was intentional."
1398 if(rootGroupName.size())
1400 __SUP_COUT_ERR__ <<
"Failed to determine type of table group for "
1401 << rootGroupName <<
"(" << rootGroupKey <<
")!" << __E__;
1406 __SUP_COUT__ <<
"Did not modify considered active groups due to empty root group "
1407 "name - assuming this was intentional."
1411 std::map<std::string , TableVersion > modifiedTablesMap;
1412 std::map<std::string , TableVersion >::iterator
1413 modifiedTablesMapIt;
1415 std::istringstream f(modifiedTables);
1416 std::string table, version;
1417 while(getline(f, table,
','))
1419 getline(f, version,
',');
1420 modifiedTablesMap.insert(
1421 std::pair<std::string /*name*/, TableVersion /*version*/>(
1422 table, TableVersion(version)));
1424 __SUP_COUT__ << modifiedTables << __E__;
1425 for(
auto& pair : modifiedTablesMap)
1426 __SUP_COUT__ <<
"modified table " << pair.first <<
":" << pair.second
1431 DOMElement* parentEl;
1432 std::string groupComment;
1433 for(
auto group : consideredGroups)
1435 if(group.second.second.isInvalid())
1438 __SUP_COUT__ <<
"Considering " << group.first <<
" group " << group.second.first
1439 <<
" (" << group.second.second <<
")" << __E__;
1443 std::map<std::string , TableVersion > memberMap;
1444 cfgMgr->loadTableGroup(group.second.first,
1445 group.second.second,
1455 __SUP_COUT__ <<
"groupComment = " << groupComment << __E__;
1457 for(
auto& table : memberMap)
1459 if((modifiedTablesMapIt = modifiedTablesMap.find(table.first)) !=
1462 table.second != (*modifiedTablesMapIt).second)
1464 __SUP_COUT__ <<
"Affected by " << (*modifiedTablesMapIt).first <<
":"
1465 << (*modifiedTablesMapIt).second << __E__;
1467 memberMap[table.first] = (*modifiedTablesMapIt).second;
1473 parentEl = xmlOut.addTextElementToData(
"AffectedActiveGroup",
"");
1474 xmlOut.addTextElementToParent(
"GroupName", group.second.first, parentEl);
1475 xmlOut.addTextElementToParent(
1476 "GroupKey", group.second.second.toString(), parentEl);
1477 xmlOut.addTextElementToParent(
"GroupComment", groupComment, parentEl);
1479 for(
auto& table : memberMap)
1481 xmlOut.addTextElementToParent(
"MemberName", table.first, parentEl);
1482 xmlOut.addTextElementToParent(
1483 "MemberVersion", table.second.toString(), parentEl);
1488 catch(std::runtime_error& e)
1490 __SUP_COUT__ <<
"Error detected!\n\n " << e.what() << __E__;
1491 xmlOut.addTextElementToData(
1492 "Error",
"Error getting affected groups! " + std::string(e.what()));
1496 __SUP_COUT__ <<
"Error detected!\n\n " << __E__;
1497 xmlOut.addTextElementToData(
"Error",
"Error getting affected groups! ");
1508 void ConfigurationGUISupervisor::setupActiveTablesXML(
1509 HttpXmlDocument& xmlOut,
1510 ConfigurationManagerRW* cfgMgr,
1511 const std::string& groupName,
1512 const TableGroupKey& groupKey,
1513 const std::string& modifiedTables,
1515 bool doGetGroupInfo,
1516 std::map<std::string /*name*/, TableVersion /*version*/>* returnMemberMap,
1517 bool outputActiveTables,
1518 std::string* accumulatedErrors)
try
1520 if(accumulatedErrors)
1521 *accumulatedErrors =
"";
1523 xmlOut.addTextElementToData(
"configGroup", groupName);
1524 xmlOut.addTextElementToData(
"configGroupKey", groupKey.toString());
1526 bool usingActiveGroups = (groupName ==
"" || groupKey.isInvalid());
1529 if(usingActiveGroups || refreshAll)
1530 cfgMgr->getAllTableInfo(
true, accumulatedErrors);
1532 const std::map<std::string, TableInfo>& allTableInfo = cfgMgr->getAllTableInfo(
false);
1534 std::map<std::string , TableVersion > modifiedTablesMap;
1535 std::map<std::string , TableVersion >::iterator
1536 modifiedTablesMapIt;
1538 if(usingActiveGroups)
1541 __SUP_COUT__ <<
"Using active groups." << __E__;
1545 __SUP_COUT__ <<
"Loading group '" << groupName <<
"(" << groupKey <<
")'"
1548 std::string groupComment, groupAuthor, configGroupCreationTime;
1551 cfgMgr->loadTableGroup(groupName,
1557 doGetGroupInfo ? &groupComment : 0,
1558 doGetGroupInfo ? &groupAuthor : 0,
1559 doGetGroupInfo ? &configGroupCreationTime : 0);
1563 xmlOut.addTextElementToData(
"configGroupComment", groupComment);
1564 xmlOut.addTextElementToData(
"configGroupAuthor", groupAuthor);
1565 xmlOut.addTextElementToData(
"configGroupCreationTime",
1566 configGroupCreationTime);
1569 if(accumulatedErrors && *accumulatedErrors !=
"")
1570 __SUP_COUTV__(*accumulatedErrors);
1576 std::istringstream f(modifiedTables);
1577 std::string table, version;
1578 while(getline(f, table,
','))
1580 getline(f, version,
',');
1581 modifiedTablesMap.insert(
1582 std::pair<std::string /*name*/, TableVersion /*version*/>(
1583 table, TableVersion(version)));
1586 for(
auto& pair : modifiedTablesMap)
1587 __SUP_COUT__ <<
"modified table " << pair.first <<
":" << pair.second
1592 std::map<std::string, TableVersion> allActivePairs = cfgMgr->getActiveVersions();
1593 xmlOut.addTextElementToData(
"DefaultNoLink",
1594 TableViewColumnInfo::DATATYPE_LINK_DEFAULT);
1595 for(
auto& activePair : allActivePairs)
1597 if(outputActiveTables)
1598 xmlOut.addTextElementToData(
"ActiveTableName", activePair.first);
1602 if((modifiedTablesMapIt = modifiedTablesMap.find(activePair.first)) !=
1603 modifiedTablesMap.end())
1605 __SUP_COUT__ <<
"Found modified table " << (*modifiedTablesMapIt).first
1606 <<
": trying... " << (*modifiedTablesMapIt).second << __E__;
1610 allTableInfo.at(activePair.first)
1611 .tablePtr_->setActiveView((*modifiedTablesMapIt).second);
1616 <<
"Modified table version v" << (*modifiedTablesMapIt).second
1617 <<
" failed. Reverting to v"
1618 << allTableInfo.at(activePair.first).tablePtr_->getView().getVersion()
1620 __SUP_COUT_WARN__ <<
"Warning detected!\n\n " << ss.str() << __E__;
1621 xmlOut.addTextElementToData(
1623 "Error setting up active tables!\n\n" + std::string(ss.str()));
1627 if(outputActiveTables)
1629 xmlOut.addTextElementToData(
"ActiveTableVersion",
1630 allTableInfo.at(activePair.first)
1631 .tablePtr_->getView()
1634 xmlOut.addTextElementToData(
1635 "ActiveTableComment",
1636 allTableInfo.at(activePair.first).tablePtr_->getView().getComment());
1645 catch(std::runtime_error& e)
1647 __SUP_SS__ << (
"Error setting up active tables!\n\n" + std::string(e.what()))
1649 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1650 xmlOut.addTextElementToData(
"Error", ss.str());
1654 __SUP_SS__ << (
"Error setting up active tables!\n\n") << __E__;
1655 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1656 xmlOut.addTextElementToData(
"Error", ss.str());
1674 void ConfigurationGUISupervisor::handleFillCreateTreeNodeRecordsXML(
1675 HttpXmlDocument& xmlOut,
1676 ConfigurationManagerRW* cfgMgr,
1677 const std::string& groupName,
1678 const TableGroupKey& groupKey,
1679 const std::string& startPath,
1680 const std::string& modifiedTables,
1681 const std::string& recordList,
1682 const std::string& author)
1685 setupActiveTablesXML(xmlOut,
1697 ConfigurationTree targetNode = cfgMgr->getNode(startPath);
1698 TableBase* config = cfgMgr->getTableByName(targetNode.getTableName());
1700 __SUP_COUT__ << config->getTableName() << __E__;
1701 TableVersion temporaryVersion;
1710 bool firstSave =
true;
1713 TableView backupView;
1717 std::istringstream f(recordList);
1718 std::string recordUID;
1721 while(getline(f, recordUID,
','))
1723 recordUID = StringMacros::decodeURIComponent(recordUID);
1725 __SUP_COUT__ <<
"recordUID " << recordUID << __E__;
1729 if(!(temporaryVersion = targetNode.getTableVersion())
1730 .isTemporaryVersion())
1732 __SUP_COUT__ <<
"Start version " << temporaryVersion << __E__;
1734 temporaryVersion = config->createTemporaryView(temporaryVersion);
1735 cfgMgr->saveNewTable(targetNode.getTableName(),
1740 __SUP_COUT__ <<
"Created temporary version " << temporaryVersion
1744 __SUP_COUT__ <<
"Using temporary version " << temporaryVersion
1750 backupView.copy(config->getView(), temporaryVersion, author);
1759 unsigned int row = config->getViewP()->addRow(
1766 unsigned int col = config->getViewP()->getColStatus();
1767 config->getViewP()->setURIEncodedValue(
"1", row, col);
1774 config->getViewP()->setURIEncodedValue(
1775 recordUID, row, config->getViewP()->getColUID());
1783 config->getViewP()->init();
1787 __SUP_COUT_INFO__ <<
"Reverting to original view." << __E__;
1788 __SUP_COUT__ <<
"Before:" << __E__;
1789 config->getViewP()->print();
1790 config->getViewP()->copy(backupView, temporaryVersion, author);
1791 __SUP_COUT__ <<
"After:" << __E__;
1792 config->getViewP()->print();
1798 handleFillModifiedTablesXML(xmlOut, cfgMgr);
1800 catch(std::runtime_error& e)
1802 __SUP_SS__ << (
"Error creating new record(s)!\n\n" + std::string(e.what()))
1804 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1805 xmlOut.addTextElementToData(
"Error", ss.str());
1809 __SUP_SS__ << (
"Error creating new record(s)!\n\n") << __E__;
1810 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1811 xmlOut.addTextElementToData(
"Error", ss.str());
1818 void ConfigurationGUISupervisor::handleFillModifiedTablesXML(
1819 HttpXmlDocument& xmlOut, ConfigurationManagerRW* cfgMgr)
try
1822 const std::map<std::string, TableInfo>& allTableInfo = cfgMgr->getAllTableInfo();
1823 std::map<std::string, TableVersion> allActivePairs = cfgMgr->getActiveVersions();
1824 for(
auto& activePair : allActivePairs)
1826 xmlOut.addTextElementToData(
"NewActiveTableName", activePair.first);
1827 xmlOut.addTextElementToData(
"NewActiveTableVersion",
1828 allTableInfo.at(activePair.first)
1829 .tablePtr_->getView()
1832 xmlOut.addTextElementToData(
1833 "NewActiveTableComment",
1834 allTableInfo.at(activePair.first).tablePtr_->getView().getComment());
1837 catch(std::runtime_error& e)
1839 __SUP_SS__ << (
"Error!\n\n" + std::string(e.what())) << __E__;
1840 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1841 xmlOut.addTextElementToData(
"Error", ss.str());
1845 __SUP_SS__ << (
"Error!\n\n") << __E__;
1846 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1847 xmlOut.addTextElementToData(
"Error", ss.str());
1865 void ConfigurationGUISupervisor::handleFillDeleteTreeNodeRecordsXML(
1866 HttpXmlDocument& xmlOut,
1867 ConfigurationManagerRW* cfgMgr,
1868 const std::string& groupName,
1869 const TableGroupKey& groupKey,
1870 const std::string& startPath,
1871 const std::string& modifiedTables,
1872 const std::string& recordList)
1875 setupActiveTablesXML(xmlOut,
1887 ConfigurationTree targetNode = cfgMgr->getNode(startPath);
1888 TableBase* config = cfgMgr->getTableByName(targetNode.getTableName());
1890 __SUP_COUT__ << config->getTableName() << __E__;
1891 TableVersion temporaryVersion;
1900 bool firstSave =
true;
1904 std::istringstream f(recordList);
1905 std::string recordUID;
1908 while(getline(f, recordUID,
','))
1910 recordUID = StringMacros::decodeURIComponent(recordUID);
1912 __SUP_COUT__ <<
"recordUID " << recordUID << __E__;
1916 if(!(temporaryVersion = targetNode.getTableVersion())
1917 .isTemporaryVersion())
1919 __SUP_COUT__ <<
"Start version " << temporaryVersion << __E__;
1921 temporaryVersion = config->createTemporaryView(temporaryVersion);
1922 cfgMgr->saveNewTable(targetNode.getTableName(),
1927 __SUP_COUT__ <<
"Created temporary version " << temporaryVersion
1931 __SUP_COUT__ <<
"Using temporary version " << temporaryVersion
1941 unsigned int row = config->getViewP()->findRow(
1942 config->getViewP()->getColUID(), recordUID);
1943 config->getViewP()->deleteRow(row);
1948 config->getViewP()->init();
1950 handleFillModifiedTablesXML(xmlOut, cfgMgr);
1952 catch(std::runtime_error& e)
1954 __SUP_SS__ << (
"Error removing record(s)!\n\n" + std::string(e.what())) << __E__;
1955 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1956 xmlOut.addTextElementToData(
"Error", ss.str());
1960 __SUP_SS__ << (
"Error removing record(s)!\n\n") << __E__;
1961 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1962 xmlOut.addTextElementToData(
"Error", ss.str());
1983 void ConfigurationGUISupervisor::handleFillSetTreeNodeFieldValuesXML(
1984 HttpXmlDocument& xmlOut,
1985 ConfigurationManagerRW* cfgMgr,
1986 const std::string& groupName,
1987 const TableGroupKey& groupKey,
1988 const std::string& startPath,
1989 const std::string& modifiedTables,
1990 const std::string& recordList,
1991 const std::string& fieldList,
1992 const std::string& valueList,
1993 const std::string& author)
1996 setupActiveTablesXML(xmlOut,
2011 std::vector<std::string > fieldPaths;
2014 std::istringstream f(fieldList);
2015 std::string fieldPath;
2016 while(getline(f, fieldPath,
','))
2018 fieldPaths.push_back(StringMacros::decodeURIComponent(fieldPath));
2020 __SUP_COUT__ << fieldList << __E__;
2021 for(
const auto& field : fieldPaths)
2022 __SUP_COUT__ <<
"fieldPath " << field << __E__;
2025 std::vector<std::string > fieldValues;
2028 std::istringstream f(valueList);
2029 std::string fieldValue;
2030 while(getline(f, fieldValue,
','))
2032 fieldValues.push_back(
2038 if(valueList.size() && valueList[valueList.size() - 1] ==
',')
2039 fieldValues.push_back(
"");
2041 __SUP_COUT__ << valueList << __E__;
2042 for(
const auto& value : fieldValues)
2043 __SUP_COUT__ <<
"fieldValue " << value << __E__;
2046 if(fieldPaths.size() != fieldValues.size())
2049 __THROW__(ss.str() +
"Mismatch in fields and values array size!");
2055 TableVersion temporaryVersion;
2056 std::istringstream f(recordList);
2057 std::string recordUID;
2060 while(getline(f, recordUID,
','))
2062 recordUID = StringMacros::decodeURIComponent(recordUID);
2066 DOMElement* parentEl =
2067 xmlOut.addTextElementToData(
"fieldValues", recordUID);
2070 for(i = 0; i < fieldPaths.size(); ++i)
2072 __SUP_COUT__ <<
"fieldPath " << fieldPaths[i] << __E__;
2073 __SUP_COUT__ <<
"fieldValue " << fieldValues[i] << __E__;
2077 ConfigurationTree targetNode =
2078 cfgMgr->getNode(startPath +
"/" + recordUID +
"/" + fieldPaths[i],
2113 __SUP_COUT__ <<
"Getting table " << targetNode.getFieldTableName()
2117 config = cfgMgr->getTableByName(
2118 targetNode.getFieldTableName());
2119 if(!(temporaryVersion = config->getViewP()->getVersion())
2120 .isTemporaryVersion())
2124 config->createTemporaryView(config->getViewP()->getVersion());
2125 cfgMgr->saveNewTable(config->getTableName(),
2130 __SUP_COUT__ <<
"Created temporary version "
2131 << config->getTableName() <<
"-v" << temporaryVersion
2135 __SUP_COUT__ <<
"Using temporary version " << config->getTableName()
2136 <<
"-v" << temporaryVersion << __E__;
2140 config->getViewP()->setURIEncodedValue(fieldValues[i],
2141 targetNode.getFieldRow(),
2142 targetNode.getFieldColumn(),
2151 handleFillModifiedTablesXML(xmlOut, cfgMgr);
2153 catch(std::runtime_error& e)
2155 __SUP_SS__ << (
"Error setting field values!\n\n" + std::string(e.what()))
2157 __SUP_COUT_ERR__ <<
"\n" << ss.str();
2158 xmlOut.addTextElementToData(
"Error", ss.str());
2162 __SUP_SS__ << (
"Error setting field values!\n\n") << __E__;
2163 __SUP_COUT_ERR__ <<
"\n" << ss.str();
2164 xmlOut.addTextElementToData(
"Error", ss.str());
2183 void ConfigurationGUISupervisor::handleFillGetTreeNodeFieldValuesXML(
2184 HttpXmlDocument& xmlOut,
2185 ConfigurationManagerRW* cfgMgr,
2186 const std::string& groupName,
2187 const TableGroupKey& groupKey,
2188 const std::string& startPath,
2189 const std::string& modifiedTables,
2190 const std::string& recordList,
2191 const std::string& fieldList)
2194 setupActiveTablesXML(xmlOut, cfgMgr, groupName, groupKey, modifiedTables);
2201 std::vector<std::string > fieldPaths;
2204 std::istringstream f(fieldList);
2205 std::string fieldPath;
2206 while(getline(f, fieldPath,
','))
2208 fieldPaths.push_back(StringMacros::decodeURIComponent(fieldPath));
2210 __SUP_COUT__ << fieldList << __E__;
2211 for(
auto& field : fieldPaths)
2212 __SUP_COUT__ <<
"fieldPath " << field << __E__;
2217 std::istringstream f(recordList);
2218 std::string recordUID;
2219 while(getline(f, recordUID,
','))
2221 recordUID = StringMacros::decodeURIComponent(recordUID);
2223 __SUP_COUT__ <<
"recordUID " << recordUID << __E__;
2225 DOMElement* parentEl =
2226 xmlOut.addTextElementToData(
"fieldValues", recordUID);
2229 for(
const auto& fieldPath : fieldPaths)
2231 __SUP_COUT__ <<
"fieldPath " << fieldPath << __E__;
2233 xmlOut.addTextElementToParent(
"FieldPath", fieldPath, parentEl);
2234 xmlOut.addTextElementToParent(
2236 cfgMgr->getNode(startPath +
"/" + recordUID +
"/" + fieldPath)
2237 .getValueAsString(),
2243 catch(std::runtime_error& e)
2245 __SUP_SS__ << (
"Error getting field values!\n\n" + std::string(e.what()))
2247 __SUP_COUT_ERR__ <<
"\n" << ss.str();
2248 xmlOut.addTextElementToData(
"Error", ss.str());
2252 __SUP_SS__ << (
"Error getting field values!\n\n") << __E__;
2253 __SUP_COUT_ERR__ <<
"\n" << ss.str();
2254 xmlOut.addTextElementToData(
"Error", ss.str());
2277 void ConfigurationGUISupervisor::handleFillTreeNodeCommonFieldsXML(
2278 HttpXmlDocument& xmlOut,
2279 ConfigurationManagerRW* cfgMgr,
2280 const std::string& groupName,
2281 const TableGroupKey& groupKey,
2282 const std::string& startPath,
2284 const std::string& modifiedTables,
2285 const std::string& recordList,
2286 const std::string& fieldList)
2289 setupActiveTablesXML(xmlOut, cfgMgr, groupName, groupKey, modifiedTables);
2293 DOMElement* parentEl = xmlOut.addTextElementToData(
"fields", startPath);
2297 __SUP_SS__ <<
"Depth of search must be greater than 0." << __E__;
2298 __SUP_COUT__ << ss.str();
2307 std::vector<ConfigurationTree::RecordField> retFieldList;
2310 ConfigurationTree startNode = cfgMgr->getNode(startPath);
2311 if(startNode.isLinkNode() && startNode.isDisconnected())
2313 __SUP_SS__ <<
"Start path was a disconnected link node!" << __E__;
2314 __SUP_COUT_ERR__ <<
"\n" << ss.str();
2320 std::vector<std::string > fieldAcceptList, fieldRejectList;
2325 std::istringstream f(fieldList);
2326 std::string fieldPath, decodedFieldPath;
2327 while(getline(f, fieldPath,
','))
2329 decodedFieldPath = StringMacros::decodeURIComponent(fieldPath);
2331 if(decodedFieldPath[0] ==
'!')
2332 fieldRejectList.push_back(decodedFieldPath.substr(1));
2334 fieldAcceptList.push_back(decodedFieldPath);
2336 __SUP_COUT__ << fieldList << __E__;
2337 for(
auto& field : fieldAcceptList)
2338 __SUP_COUT__ <<
"fieldAcceptList " << field << __E__;
2339 for(
auto& field : fieldRejectList)
2340 __SUP_COUT__ <<
"fieldRejectList " << field << __E__;
2344 std::vector<std::string > records;
2345 if(recordList ==
"*")
2348 records = startNode.getChildrenNames();
2349 __SUP_COUT__ <<
"Translating wildcard..." << __E__;
2350 for(
auto& record : records)
2351 __SUP_COUT__ <<
"recordList " << record << __E__;
2353 else if(recordList !=
"")
2357 std::istringstream f(recordList);
2358 std::string recordStr;
2359 while(getline(f, recordStr,
','))
2361 records.push_back(StringMacros::decodeURIComponent(recordStr));
2363 __SUP_COUT__ << recordList << __E__;
2364 for(
auto& record : records)
2365 __SUP_COUT__ <<
"recordList " << record << __E__;
2369 retFieldList = startNode.getCommonFields(
2370 records, fieldAcceptList, fieldRejectList, depth);
2373 DOMElement* parentTypeEl;
2374 for(
const auto& fieldInfo : retFieldList)
2376 xmlOut.addTextElementToParent(
2377 "FieldTableName", fieldInfo.tableName_, parentEl);
2378 xmlOut.addTextElementToParent(
2379 "FieldColumnName", fieldInfo.columnName_, parentEl);
2380 xmlOut.addTextElementToParent(
2381 "FieldRelativePath", fieldInfo.relativePath_, parentEl);
2382 xmlOut.addTextElementToParent(
2383 "FieldColumnType", fieldInfo.columnInfo_->getType(), parentEl);
2384 xmlOut.addTextElementToParent(
2385 "FieldColumnDataType", fieldInfo.columnInfo_->getDataType(), parentEl);
2386 xmlOut.addTextElementToParent(
"FieldColumnDefaultValue",
2387 fieldInfo.columnInfo_->getDefaultValue(),
2391 xmlOut.addTextElementToParent(
"FieldColumnDataChoices",
"", parentEl);
2394 auto dataChoices = fieldInfo.columnInfo_->getDataChoices();
2395 xmlOut.addTextElementToParent(
2396 "FieldColumnDataChoice",
2397 fieldInfo.columnInfo_->getDefaultValue(),
2399 for(
const auto& dataChoice : dataChoices)
2400 xmlOut.addTextElementToParent(
2401 "FieldColumnDataChoice", dataChoice, parentTypeEl);
2404 catch(std::runtime_error& e)
2406 __SUP_SS__ << (
"Error getting common fields!\n\n" + std::string(e.what()))
2408 __SUP_COUT_ERR__ <<
"\n" << ss.str();
2409 xmlOut.addTextElementToData(
"Error", ss.str());
2413 __SUP_SS__ << (
"Error getting common fields!\n\n") << __E__;
2414 __SUP_COUT_ERR__ <<
"\n" << ss.str();
2415 xmlOut.addTextElementToData(
"Error", ss.str());
2445 void ConfigurationGUISupervisor::handleFillUniqueFieldValuesForRecordsXML(
2446 HttpXmlDocument& xmlOut,
2447 ConfigurationManagerRW* cfgMgr,
2448 const std::string& groupName,
2449 const TableGroupKey& groupKey,
2450 const std::string& startPath,
2451 const std::string& modifiedTables,
2452 const std::string& recordList,
2453 const std::string& fieldList)
2456 setupActiveTablesXML(xmlOut, cfgMgr, groupName, groupKey, modifiedTables);
2462 if(startPath ==
"/")
2465 std::vector<std::string > fieldsToGet;
2470 std::istringstream f(fieldList);
2471 std::string fieldPath;
2472 while(getline(f, fieldPath,
','))
2474 fieldsToGet.push_back(StringMacros::decodeURIComponent(fieldPath));
2476 __SUP_COUT__ << fieldList << __E__;
2477 for(
auto& field : fieldsToGet)
2478 __SUP_COUT__ <<
"fieldsToGet " << field << __E__;
2482 ConfigurationTree startNode = cfgMgr->getNode(startPath);
2483 if(startNode.isLinkNode() && startNode.isDisconnected())
2485 __SUP_SS__ <<
"Start path was a disconnected link node!" << __E__;
2486 __SUP_COUT_ERR__ <<
"\n" << ss.str();
2490 std::vector<std::string > records;
2491 if(recordList ==
"*")
2494 records = startNode.getChildrenNames();
2495 __SUP_COUT__ <<
"Translating wildcard..." << __E__;
2496 for(
auto& record : records)
2497 __SUP_COUT__ <<
"recordList " << record << __E__;
2499 else if(recordList !=
"")
2503 std::istringstream f(recordList);
2504 std::string recordStr;
2505 while(getline(f, recordStr,
','))
2507 records.push_back(StringMacros::decodeURIComponent(recordStr));
2509 __SUP_COUT__ << recordList << __E__;
2510 for(
auto& record : records)
2511 __SUP_COUT__ <<
"recordList " << record << __E__;
2516 for(
auto& field : fieldsToGet)
2518 __SUP_COUT__ <<
"fieldsToGet " << field << __E__;
2520 DOMElement* parentEl = xmlOut.addTextElementToData(
"field", field);
2523 std::set<std::string > uniqueValues;
2526 cfgMgr->getNode(startPath).getUniqueValuesForField(records, field);
2528 for(
auto& uniqueValue : uniqueValues)
2530 __SUP_COUT__ <<
"uniqueValue " << uniqueValue << __E__;
2532 xmlOut.addTextElementToParent(
"uniqueValue", uniqueValue, parentEl);
2536 catch(std::runtime_error& e)
2538 __SUP_SS__ << (
"Error getting common fields!\n\n" + std::string(e.what()))
2540 __SUP_COUT_ERR__ <<
"\n" << ss.str();
2541 xmlOut.addTextElementToData(
"Error", ss.str());
2545 __SUP_SS__ << (
"Error getting common fields!\n\n") << __E__;
2546 __SUP_COUT_ERR__ <<
"\n" << ss.str();
2547 xmlOut.addTextElementToData(
"Error", ss.str());
2571 void ConfigurationGUISupervisor::handleFillTreeViewXML(HttpXmlDocument& xmlOut,
2572 ConfigurationManagerRW* cfgMgr,
2573 const std::string& groupName,
2574 const TableGroupKey& groupKey,
2575 const std::string& startPath,
2577 bool hideStatusFalse,
2578 const std::string& modifiedTables,
2579 const std::string& filterList)
2610 bool usingActiveGroups = (groupName ==
"" || groupKey.isInvalid());
2611 std::map<std::string , TableVersion > memberMap;
2613 std::string accumulatedErrors =
"";
2616 setupActiveTablesXML(
2631 catch(
const std::runtime_error& e)
2633 __SS__ <<
"Error occured setting up active tables: " << e.what() << __E__;
2634 accumulatedErrors += ss.str();
2638 __SS__ <<
"Unknown error occured setting up active tables." << __E__;
2639 accumulatedErrors += ss.str();
2642 if(accumulatedErrors !=
"")
2644 xmlOut.addTextElementToData(
"Warning", accumulatedErrors);
2646 __SUP_COUT__ <<
"Active tables are setup. Warning string: '" << accumulatedErrors
2650 __SUP_COUT__ <<
"Active tables are setup. No issues found." << __E__;
2654 DOMElement* parentEl = xmlOut.addTextElementToData(
"tree", startPath);
2659 std::vector<std::pair<std::string, ConfigurationTree>> rootMap;
2661 if(startPath ==
"/")
2665 std::string accumulateTreeErrs;
2667 if(usingActiveGroups)
2668 rootMap = cfgMgr->getChildren(0, &accumulateTreeErrs);
2670 rootMap = cfgMgr->getChildren(&memberMap, &accumulateTreeErrs);
2672 __SUP_COUT__ <<
"accumulateTreeErrs = " << accumulateTreeErrs << __E__;
2673 if(accumulateTreeErrs !=
"")
2674 xmlOut.addTextElementToData(
"TreeErrors", accumulateTreeErrs);
2678 ConfigurationTree startNode =
2679 cfgMgr->getNode(startPath,
true );
2680 if(startNode.isLinkNode() && startNode.isDisconnected())
2682 xmlOut.addTextElementToData(
"DisconnectedStartNode",
"1");
2687 std::map<std::string , std::string > filterMap;
2688 StringMacros::getMapFromString(
2691 std::set<char>({
';'}) ,
2692 std::set<char>({
'='}) );
2694 __COUTV__(StringMacros::mapToString(filterMap));
2696 rootMap = cfgMgr->getNode(startPath).getChildren(filterMap);
2699 for(
auto& treePair : rootMap)
2701 treePair.second, depth - 1, xmlOut, parentEl, hideStatusFalse);
2703 catch(std::runtime_error& e)
2705 __SUP_SS__ <<
"Error detected generating XML tree!\n\n " << e.what() << __E__;
2706 __SUP_COUT_ERR__ <<
"\n" << ss.str();
2707 xmlOut.addTextElementToData(
"Error", ss.str());
2711 __SUP_SS__ <<
"Error detected generating XML tree!" << __E__;
2712 __SUP_COUT_ERR__ <<
"\n" << ss.str();
2713 xmlOut.addTextElementToData(
"Error", ss.str());
2723 void ConfigurationGUISupervisor::recursiveTreeToXML(
const ConfigurationTree& t,
2725 HttpXmlDocument& xmlOut,
2726 DOMElement* parentEl,
2727 bool hideStatusFalse)
2733 parentEl = xmlOut.addTextElementToParent(
"node", t.getValueName(), parentEl);
2734 xmlOut.addTextElementToParent(
"value", t.getValueAsString(), parentEl);
2735 parentEl = xmlOut.addTextElementToParent(
"valueType", t.getValueType(), parentEl);
2739 if(t.getValueType() == TableViewColumnInfo::TYPE_FIXED_CHOICE_DATA ||
2740 t.getValueType() == TableViewColumnInfo::TYPE_BITMAP_DATA)
2744 std::vector<std::string> choices = t.getFixedChoices();
2745 for(
const auto& choice : choices)
2746 xmlOut.addTextElementToParent(
"fixedChoice", choice, parentEl);
2757 parentEl = xmlOut.addTextElementToParent(
"node", t.getValueName(), parentEl);
2759 if(t.isDisconnected())
2761 __COUT__ << t.getValueName() << __E__;
2767 xmlOut.addTextElementToParent(
"valueType", t.getValueType(), parentEl);
2770 xmlOut.addTextElementToParent(
2771 (t.isGroupLinkNode() ?
"Group" :
"U") + std::string(
"ID"),
2772 t.getDisconnectedLinkID(),
2774 xmlOut.addTextElementToParent(
2775 "LinkTableName", t.getDisconnectedTableName(), parentEl);
2776 xmlOut.addTextElementToParent(
2777 "LinkIndex", t.getChildLinkIndex(), parentEl);
2780 DOMElement* choicesParentEl =
2781 xmlOut.addTextElementToParent(
"fixedChoices",
"", parentEl);
2785 std::vector<std::string> choices = t.getFixedChoices();
2786 __COUT__ <<
"choices.size() " << choices.size() << __E__;
2788 for(
const auto& choice : choices)
2789 xmlOut.addTextElementToParent(
"fixedChoice", choice, choicesParentEl);
2801 xmlOut.addTextElementToParent(
2802 (t.isGroupLinkNode() ?
"Group" :
"U") + std::string(
"ID"),
2803 t.getValueAsString(),
2806 xmlOut.addTextElementToParent(
"LinkTableName", t.getTableName(), parentEl);
2808 xmlOut.addTextElementToParent(
"LinkIndex", t.getChildLinkIndex(), parentEl);
2812 DOMElement* choicesParentEl =
2813 xmlOut.addTextElementToParent(
"fixedChoices",
"", parentEl);
2814 std::vector<std::string> choices = t.getFixedChoices();
2818 for(
const auto& choice : choices)
2819 xmlOut.addTextElementToParent(
"fixedChoice", choice, choicesParentEl);
2824 bool returnNode =
true;
2830 t.getNode(TableViewColumnInfo::COL_NAME_STATUS).getValue(returnNode);
2839 xmlOut.addTextElementToParent(
"node", t.getValueAsString(), parentEl);
2848 auto C = t.getChildren();
2851 c.second, depth - 1, xmlOut, parentEl, hideStatusFalse);
2863 void ConfigurationGUISupervisor::handleGetLinkToChoicesXML(
2864 HttpXmlDocument& xmlOut,
2865 ConfigurationManagerRW* cfgMgr,
2866 const std::string& linkToTableName,
2867 const TableVersion& linkToTableVersion,
2868 const std::string& linkIdType,
2869 const std::string& linkIndex,
2870 const std::string& linkInitId)
try
2882 const std::string& tableName = linkToTableName;
2883 const TableVersion& version = linkToTableVersion;
2884 TableBase* config = cfgMgr->getTableByName(tableName);
2887 config->setActiveView(version);
2891 __SUP_COUT__ <<
"Failed to find stored version, so attempting to load version: "
2892 << version << __E__;
2893 cfgMgr->getVersionedTableByName(tableName, version);
2896 if(version != config->getViewVersion())
2898 __SUP_SS__ <<
"Target table version (" << version
2899 <<
") is not the currently active version ("
2900 << config->getViewVersion() <<
". Try refreshing the tree." << __E__;
2901 __SUP_COUT_WARN__ << ss.str();
2905 __SUP_COUT__ <<
"Active version is " << config->getViewVersion() << __E__;
2907 if(linkIdType ==
"UID")
2910 unsigned int col = config->getView().getColUID();
2911 for(
unsigned int row = 0; row < config->getView().getNumberOfRows(); ++row)
2912 xmlOut.addTextElementToData(
"linkToChoice",
2913 config->getView().getDataView()[row][col]);
2915 else if(linkIdType ==
"GroupID")
2921 __SUP_COUTV__(linkIndex);
2922 __SUP_COUTV__(linkInitId);
2924 std::set<std::string> setOfGroupIDs =
2925 config->getView().getSetOfGroupIDs(linkIndex);
2930 bool foundInitId =
false;
2931 for(
const auto& groupID : setOfGroupIDs)
2933 if(!foundInitId && linkInitId == groupID)
2936 xmlOut.addTextElementToData(
"linkToChoice", groupID);
2940 xmlOut.addTextElementToData(
"linkToChoice", linkInitId);
2943 unsigned int col = config->getView().getColUID();
2944 for(
unsigned int row = 0; row < config->getView().getNumberOfRows(); ++row)
2946 xmlOut.addTextElementToData(
"groupChoice",
2947 config->getView().getDataView()[row][col]);
2948 if(config->getView().isEntryInGroup(row, linkIndex, linkInitId))
2949 xmlOut.addTextElementToData(
"groupMember",
2950 config->getView().getDataView()[row][col]);
2955 __SUP_SS__ <<
"Unrecognized linkIdType '" << linkIdType <<
".'" << __E__;
2959 catch(std::runtime_error& e)
2961 __SUP_SS__ <<
"Error detected saving tree node!\n\n " << e.what() << __E__;
2962 __SUP_COUT_ERR__ <<
"\n" << ss.str() << __E__;
2963 xmlOut.addTextElementToData(
"Error", ss.str());
2967 __SUP_SS__ <<
"Error detected saving tree node!\n\n " << __E__;
2968 __SUP_COUT_ERR__ <<
"\n" << ss.str() << __E__;
2969 xmlOut.addTextElementToData(
"Error", ss.str());
2974 void ConfigurationGUISupervisor::handleMergeGroupsXML(
2975 HttpXmlDocument& xmlOut,
2976 ConfigurationManagerRW* cfgMgr,
2977 const std::string& groupANameContext,
2978 const TableGroupKey& groupAKeyContext,
2979 const std::string& groupBNameContext,
2980 const TableGroupKey& groupBKeyContext,
2981 const std::string& groupANameConfig,
2982 const TableGroupKey& groupAKeyConfig,
2983 const std::string& groupBNameConfig,
2984 const TableGroupKey& groupBKeyConfig,
2985 const std::string& author,
2986 const std::string& mergeApproach)
try
2988 __SUP_COUT__ <<
"Merging context group pair " << groupANameContext <<
" ("
2989 << groupAKeyContext <<
") & " << groupBNameContext <<
" ("
2990 << groupBKeyContext <<
") and config group pair " << groupANameConfig
2991 <<
" (" << groupAKeyConfig <<
") & " << groupBNameConfig <<
" ("
2992 << groupBKeyConfig <<
") with approach '" << mergeApproach << __E__;
3008 if(!(mergeApproach ==
"Rename" || mergeApproach ==
"Replace" ||
3009 mergeApproach ==
"Skip"))
3011 __SS__ <<
"Error! Invalid merge approach '" << mergeApproach <<
".'" << __E__;
3015 std::map<std::string , TableVersion > memberMapAContext,
3016 memberMapBContext, memberMapAConfig, memberMapBConfig;
3019 bool skippingContextPair =
false;
3020 bool skippingConfigPair =
false;
3021 if(groupANameContext.size() == 0 || groupANameContext[0] ==
' ' ||
3022 groupBNameContext.size() == 0 || groupBNameContext[0] ==
' ')
3024 skippingContextPair =
true;
3025 __SUP_COUTV__(skippingContextPair);
3027 if(groupANameConfig.size() == 0 || groupANameConfig[0] ==
' ' ||
3028 groupBNameConfig.size() == 0 || groupBNameConfig[0] ==
' ')
3030 skippingConfigPair =
true;
3031 __SUP_COUTV__(skippingConfigPair);
3035 if(!skippingContextPair)
3037 cfgMgr->loadTableGroup(groupANameContext,
3049 __SUP_COUTV__(StringMacros::mapToString(memberMapAContext));
3051 cfgMgr->loadTableGroup(groupBNameContext,
3064 __SUP_COUTV__(StringMacros::mapToString(memberMapBContext));
3068 if(!skippingConfigPair)
3070 cfgMgr->loadTableGroup(groupANameConfig,
3082 __SUP_COUTV__(StringMacros::mapToString(memberMapAConfig));
3084 cfgMgr->loadTableGroup(groupBNameConfig,
3097 __SUP_COUTV__(StringMacros::mapToString(memberMapBConfig));
3105 std::map<std::pair<std::string , std::string >,
3109 std::pair<std::string ,
3110 std::pair<std::string , std::string >>,
3112 groupidConversionMap;
3116 for(
unsigned int i = 0; i < 2; ++i)
3118 if(i == 0 && mergeApproach !=
"Rename")
3122 for(
unsigned int j = 0; j < 2; ++j)
3124 if(j == 0 && skippingContextPair)
3126 __COUT__ <<
"Skipping context pair..." << __E__;
3129 else if(j == 1 && skippingConfigPair)
3131 __COUT__ <<
"Skipping config pair..." << __E__;
3135 std::map<std::string , TableVersion >& memberMapAref =
3136 j == 0 ? memberMapAContext : memberMapAConfig;
3138 std::map<std::string , TableVersion >& memberMapBref =
3139 j == 0 ? memberMapBContext : memberMapBConfig;
3142 __COUT__ <<
"Context pair..." << __E__;
3144 __COUT__ <<
"Config pair..." << __E__;
3146 __COUT__ <<
"Starting member map B scan." << __E__;
3147 for(
const auto bkey : memberMapBref)
3149 __SUP_COUTV__(bkey.first);
3151 if(memberMapAref.find(bkey.first) == memberMapAref.end())
3154 memberMapAref[bkey.first] = bkey.second;
3156 else if(memberMapAref[bkey.first] != bkey.second)
3159 __SUP_COUTV__(memberMapAref[bkey.first]);
3160 __SUP_COUTV__(bkey.second);
3163 TableBase* config = cfgMgr->getTableByName(bkey.first);
3165 __SUP_COUT__ <<
"Got table." << __E__;
3167 TableVersion newVersion = config->mergeViews(
3169 ->getVersionedTableByName(bkey.first,
3170 memberMapAref[bkey.first])
3172 cfgMgr->getVersionedTableByName(bkey.first, bkey.second)
3178 groupidConversionMap,
3181 config->getTableName() ==
3182 ConfigurationManager::
3183 XDAQ_APPLICATION_TABLE_NAME
3189 __SUP_COUTV__(newVersion);
3195 newVersion = saveModifiedVersionXML(
3206 catch(std::runtime_error& e)
3209 <<
"There was an error saving the '"
3210 << config->getTableName()
3211 <<
"' merge result to a persistent table version. "
3212 <<
"Perhaps you can modify this table in one of the "
3213 "groups to resolve this issue, and then re-merge."
3214 << __E__ << e.what();
3218 __SUP_COUTV__(newVersion);
3220 memberMapAref[bkey.first] = newVersion;
3229 if(!skippingContextPair)
3231 __SUP_COUT__ <<
"New context member map complete." << __E__;
3232 __SUP_COUTV__(StringMacros::mapToString(memberMapAContext));
3235 TableGroupKey newKeyContext = cfgMgr->saveNewTableGroup(
3238 "Merger of group " + groupANameContext +
" (" + groupAKeyContext.toString() +
3239 ") and " + groupBNameContext +
" (" + groupBKeyContext.toString() +
").");
3242 xmlOut.addTextElementToData(
"ContextGroupName", groupANameContext);
3243 xmlOut.addTextElementToData(
"ContextGroupKey", newKeyContext.toString());
3245 if(!skippingConfigPair)
3247 __SUP_COUT__ <<
"New config member map complete." << __E__;
3248 __SUP_COUTV__(StringMacros::mapToString(memberMapAConfig));
3251 TableGroupKey newKeyConfig = cfgMgr->saveNewTableGroup(
3254 "Merger of group " + groupANameConfig +
" (" + groupAKeyConfig.toString() +
3255 ") and " + groupBNameConfig +
" (" + groupBKeyConfig.toString() +
").");
3258 xmlOut.addTextElementToData(
"ConfigGroupName", groupANameConfig);
3259 xmlOut.addTextElementToData(
"ConfigGroupKey", newKeyConfig.toString());
3263 catch(std::runtime_error& e)
3265 __SUP_SS__ <<
"Error merging context group pair " << groupANameContext <<
" ("
3266 << groupAKeyContext <<
") & " << groupBNameContext <<
" ("
3267 << groupBKeyContext <<
") and config group pair " << groupANameConfig
3268 <<
" (" << groupAKeyConfig <<
") & " << groupBNameConfig <<
" ("
3269 << groupBKeyConfig <<
") with approach '" << mergeApproach <<
"': \n\n"
3270 << e.what() << __E__;
3271 __SUP_COUT_ERR__ <<
"\n" << ss.str() << __E__;
3272 xmlOut.addTextElementToData(
"Error", ss.str());
3276 __SUP_SS__ <<
"Unknown error merging context group pair " << groupANameContext <<
" ("
3277 << groupAKeyContext <<
") & " << groupBNameContext <<
" ("
3278 << groupBKeyContext <<
") and config group pair " << groupANameConfig
3279 <<
" (" << groupAKeyConfig <<
") & " << groupBNameConfig <<
" ("
3280 << groupBKeyConfig <<
") with approach '" << mergeApproach <<
".' \n\n";
3281 __SUP_COUT_ERR__ <<
"\n" << ss.str() << __E__;
3282 xmlOut.addTextElementToData(
"Error", ss.str());
3287 void ConfigurationGUISupervisor::handleSavePlanCommandSequenceXML(
3288 HttpXmlDocument& xmlOut,
3289 ConfigurationManagerRW* cfgMgr,
3290 const std::string& groupName,
3291 const TableGroupKey& groupKey,
3292 const std::string& modifiedTables,
3293 const std::string& author,
3294 const std::string& planName,
3295 const std::string& commandString)
try
3297 __MOUT__ <<
"handleSavePlanCommandSequenceXML" << __E__;
3300 setupActiveTablesXML(xmlOut,
3310 TableEditStruct planTable(IterateTable::PLAN_TABLE,
3312 TableEditStruct targetTable(IterateTable::TARGET_TABLE,
3316 std::map<std::string, TableEditStruct> commandTypeToCommandTableMap;
3317 for(
const auto& commandPair : IterateTable::commandToTableMap_)
3318 if(commandPair.second !=
"")
3319 commandTypeToCommandTableMap.emplace(std::pair<std::string, TableEditStruct>(
3320 commandPair.first, TableEditStruct(commandPair.second, cfgMgr)));
3336 std::string groupName = planName +
"-Plan";
3337 __SUP_COUT__ <<
"Handling commands for group " << groupName << __E__;
3339 unsigned int groupIdCol =
3340 planTable.tableView_->findCol(IterateTable::planTableCols_.GroupID_);
3341 unsigned int cmdTypeCol =
3342 planTable.tableView_->findCol(IterateTable::planTableCols_.CommandType_);
3344 unsigned int targetGroupIdCol =
3345 targetTable.tableView_->findCol(IterateTable::targetCols_.GroupID_);
3346 unsigned int targetTableCol =
3347 targetTable.tableView_->findCol(IterateTable::targetCols_.TargetLink_);
3348 unsigned int targetUIDCol =
3349 targetTable.tableView_->findCol(IterateTable::targetCols_.TargetLinkUID_);
3351 std::string groupLinkIndex =
3352 planTable.tableView_->getColumnInfo(groupIdCol).getChildLinkIndex();
3353 __SUP_COUT__ <<
"groupLinkIndex: " << groupLinkIndex << __E__;
3355 std::pair<
unsigned int ,
unsigned int > commandUidLink;
3358 planTable.tableView_->getChildLink(
3359 planTable.tableView_->findCol(IterateTable::planTableCols_.CommandLink_),
3364 unsigned int cmdRow, cmdCol;
3365 std::string targetGroupName;
3369 std::string targetUID, cmdType;
3371 for(
unsigned int row = 0; row < planTable.tableView_->getNumberOfRows();
3374 targetUID = planTable.tableView_
3375 ->getDataView()[row][planTable.tableView_->getColUID()];
3376 __SUP_COUT__ <<
"targetUID: " << targetUID << __E__;
3379 if(planTable.tableView_->isEntryInGroup(row, groupLinkIndex, groupName))
3381 __SUP_COUT__ <<
"Removing." << __E__;
3385 cmdType = planTable.tableView_->getDataView()[row][cmdTypeCol];
3386 if(commandTypeToCommandTableMap.find(cmdType) !=
3387 commandTypeToCommandTableMap
3391 commandTypeToCommandTableMap[cmdType].tableView_->findRow(
3392 commandTypeToCommandTableMap[cmdType]
3393 .tableView_->getColUID(),
3394 planTable.tableView_
3395 ->getDataView()[row][commandUidLink.second]);
3403 commandTypeToCommandTableMap[cmdType].tableView_->findCol(
3404 IterateTable::commandTargetCols_.TargetsLinkGroupID_);
3406 commandTypeToCommandTableMap[cmdType]
3407 .tableView_->getDataView()[cmdRow][cmdCol];
3409 for(
unsigned int trow = 0;
3410 trow < targetTable.tableView_->getNumberOfRows();
3414 if(targetTable.tableView_->isEntryInGroup(
3416 commandTypeToCommandTableMap[cmdType]
3417 .tableView_->getColumnInfo(cmdCol)
3418 .getChildLinkIndex(),
3421 __SUP_COUT__ <<
"Removing target." << __E__;
3423 if(targetTable.tableView_->removeRowFromGroup(
3434 __SUP_COUT__ <<
"No targets." << __E__;
3439 commandTypeToCommandTableMap[cmdType].tableView_->deleteRow(
3442 commandTypeToCommandTableMap[cmdType].modified_ =
true;
3446 if(planTable.tableView_->removeRowFromGroup(
3447 row, groupIdCol, groupName,
true ))
3456 std::vector<IterateTable::Command> commands;
3461 std::istringstream f(commandString);
3462 std::string commandSubString, paramSubString, paramValue;
3464 while(getline(f, commandSubString,
';'))
3467 std::istringstream g(commandSubString);
3470 while(getline(g, paramSubString,
','))
3475 if(paramSubString !=
"type")
3477 __SUP_SS__ <<
"Invalid command sequence" << __E__;
3481 commands.push_back(IterateTable::Command());
3483 getline(g, paramValue,
',');
3486 commands.back().type_ = paramValue;
3490 getline(g, paramValue,
',');
3494 commands.back().params_.emplace(
3495 std::pair<std::string ,
3498 StringMacros::decodeURIComponent(paramValue)));
3507 __SUP_COUT__ <<
"commands size " << commands.size() << __E__;
3514 unsigned int row, tgtRow;
3515 unsigned int targetIndex;
3516 std::string targetStr, cmdUID;
3518 for(
auto& command : commands)
3520 __SUP_COUT__ <<
"command " << command.type_ << __E__;
3521 __SUP_COUT__ <<
"table " << IterateTable::commandToTableMap_.at(command.type_)
3525 row = planTable.tableView_->addRow(author,
"planCommand");
3526 planTable.tableView_->addRowToGroup(row, groupIdCol, groupName);
3529 planTable.tableView_->setURIEncodedValue(command.type_, row, cmdTypeCol);
3532 planTable.tableView_->setValueAsString(
3533 "1", row, planTable.tableView_->getColStatus());
3536 if(commandTypeToCommandTableMap.find(command.type_) !=
3537 commandTypeToCommandTableMap.end())
3540 __SUP_COUT__ <<
"table "
3541 << commandTypeToCommandTableMap[command.type_].tableName_
3547 cmdRow = commandTypeToCommandTableMap[command.type_].tableView_->addRow(
3548 author,
true , command.type_ +
"_COMMAND_");
3554 for(
auto& param : command.params_)
3556 __SUP_COUT__ <<
"\t param " << param.first <<
" : " << param.second
3559 if(param.first == IterateTable::targetParams_.Tables_)
3561 __SUP_COUT__ <<
"\t\t found target tables" << __E__;
3562 std::istringstream f(param.second);
3565 while(getline(f, targetStr,
'='))
3567 __SUP_COUT__ <<
"\t\t targetStr = " << targetStr << __E__;
3568 if(!command.targets_.size() ||
3569 command.targets_.back().table_ !=
"")
3571 __SUP_COUT__ <<
"\t\t make targetStr = " << targetStr
3574 command.addTarget();
3575 command.targets_.back().table_ = targetStr;
3578 command.targets_[targetIndex++].table_ = targetStr;
3584 if(param.first == IterateTable::targetParams_.UIDs_)
3586 __SUP_COUT__ <<
"\t\t found target UIDs" << __E__;
3587 std::istringstream f(param.second);
3590 while(getline(f, targetStr,
'='))
3592 __SUP_COUT__ <<
"\t\t targetStr = " << targetStr << __E__;
3593 if(!command.targets_.size() ||
3594 command.targets_.back().UID_ !=
"")
3596 __SUP_COUT__ <<
"\t\t make targetStr = " << targetStr
3599 command.addTarget();
3600 command.targets_.back().UID_ = targetStr;
3603 command.targets_[targetIndex++].UID_ = targetStr;
3609 commandTypeToCommandTableMap[command.type_].tableView_->findCol(
3612 __SUP_COUT__ <<
"param col " << cmdCol << __E__;
3614 commandTypeToCommandTableMap[command.type_]
3615 .tableView_->setURIEncodedValue(param.second, cmdRow, cmdCol);
3619 commandTypeToCommandTableMap[command.type_].tableView_->getDataView()
3620 [cmdRow][commandTypeToCommandTableMap[command.type_]
3621 .tableView_->getColUID()];
3623 if(command.targets_.size())
3627 __SUP_COUT__ <<
"targets found for command UID=" << cmdUID << __E__;
3631 commandTypeToCommandTableMap[command.type_].tableView_->findCol(
3632 IterateTable::commandTargetCols_.TargetsLink_);
3633 commandTypeToCommandTableMap[command.type_]
3634 .tableView_->setValueAsString(
3635 IterateTable::TARGET_TABLE, cmdRow, cmdCol);
3638 commandTypeToCommandTableMap[command.type_].tableView_->findCol(
3639 IterateTable::commandTargetCols_.TargetsLinkGroupID_);
3640 commandTypeToCommandTableMap[command.type_]
3641 .tableView_->setValueAsString(
3642 cmdUID +
"_Targets", cmdRow, cmdCol);
3646 for(
const auto& target : command.targets_)
3648 __SUP_COUT__ << target.table_ <<
" " << target.UID_ << __E__;
3651 tgtRow = targetTable.tableView_->addRow(author,
"commandTarget");
3652 targetTable.tableView_->addRowToGroup(
3653 tgtRow, targetGroupIdCol, cmdUID +
"_Targets");
3656 targetTable.tableView_->setValueAsString(
3657 target.table_, tgtRow, targetTableCol);
3660 targetTable.tableView_->setValueAsString(
3661 target.UID_, tgtRow, targetUIDCol);
3666 planTable.tableView_->setValueAsString(
3667 commandTypeToCommandTableMap[command.type_].tableName_,
3669 commandUidLink.first);
3670 planTable.tableView_->setValueAsString(
3671 cmdUID, row, commandUidLink.second);
3673 __SUP_COUT__ <<
"linked to uid = " << cmdUID << __E__;
3675 commandTypeToCommandTableMap[command.type_].modified_ =
true;
3683 planTable.tableView_->print();
3684 planTable.tableView_->init();
3686 __SUP_COUT__ <<
"requestType tables:" << __E__;
3688 for(
auto& modifiedConfig : commandTypeToCommandTableMap)
3690 modifiedConfig.second.tableView_->print();
3691 modifiedConfig.second.tableView_->init();
3694 targetTable.tableView_->print();
3695 targetTable.tableView_->init();
3700 __SUP_COUT__ <<
"Handling command table errors while saving. Erasing all newly "
3706 if(planTable.createdTemporaryVersion_)
3708 __SUP_COUT__ <<
"Erasing temporary version " << planTable.tableName_ <<
"-v"
3709 << planTable.temporaryVersion_ << __E__;
3711 cfgMgr->eraseTemporaryVersion(planTable.tableName_,
3712 planTable.temporaryVersion_);
3715 if(targetTable.createdTemporaryVersion_)
3717 __SUP_COUT__ <<
"Erasing temporary version " << targetTable.tableName_ <<
"-v"
3718 << targetTable.temporaryVersion_ << __E__;
3720 cfgMgr->eraseTemporaryVersion(targetTable.tableName_,
3721 targetTable.temporaryVersion_);
3724 for(
auto& modifiedConfig : commandTypeToCommandTableMap)
3726 if(modifiedConfig.second
3727 .createdTemporaryVersion_)
3729 __SUP_COUT__ <<
"Erasing temporary version "
3730 << modifiedConfig.second.tableName_ <<
"-v"
3731 << modifiedConfig.second.temporaryVersion_ << __E__;
3733 cfgMgr->eraseTemporaryVersion(modifiedConfig.second.tableName_,
3734 modifiedConfig.second.temporaryVersion_);
3745 TableVersion finalVersion = saveModifiedVersionXML(
3748 planTable.tableName_,
3749 planTable.originalVersion_,
3752 planTable.temporaryVersion_,
3755 __SUP_COUT__ <<
"Final plan version is " << planTable.tableName_ <<
"-v"
3756 << finalVersion << __E__;
3758 finalVersion = saveModifiedVersionXML(
3761 targetTable.tableName_,
3762 targetTable.originalVersion_,
3765 targetTable.temporaryVersion_,
3768 __SUP_COUT__ <<
"Final target version is " << targetTable.tableName_ <<
"-v"
3769 << finalVersion << __E__;
3771 for(
auto& modifiedConfig : commandTypeToCommandTableMap)
3773 if(!modifiedConfig.second.modified_)
3775 if(modifiedConfig.second
3776 .createdTemporaryVersion_)
3778 __SUP_COUT__ <<
"Erasing unmodified temporary version "
3779 << modifiedConfig.second.tableName_ <<
"-v"
3780 << modifiedConfig.second.temporaryVersion_ << __E__;
3782 cfgMgr->eraseTemporaryVersion(modifiedConfig.second.tableName_,
3783 modifiedConfig.second.temporaryVersion_);
3788 finalVersion = saveModifiedVersionXML(
3791 modifiedConfig.second.tableName_,
3792 modifiedConfig.second.originalVersion_,
3794 modifiedConfig.second.table_,
3795 modifiedConfig.second.temporaryVersion_,
3798 __SUP_COUT__ <<
"Final version is " << modifiedConfig.second.tableName_ <<
"-v"
3799 << finalVersion << __E__;
3802 handleFillModifiedTablesXML(xmlOut, cfgMgr);
3804 catch(std::runtime_error& e)
3806 __SUP_SS__ <<
"Error detected saving Iteration Plan!\n\n " << e.what() << __E__;
3807 __SUP_COUT_ERR__ <<
"\n" << ss.str() << __E__;
3808 xmlOut.addTextElementToData(
"Error", ss.str());
3812 __SUP_SS__ <<
"Error detected saving Iteration Plan!\n\n " << __E__;
3813 __SUP_COUT_ERR__ <<
"\n" << ss.str() << __E__;
3814 xmlOut.addTextElementToData(
"Error", ss.str());
3827 void ConfigurationGUISupervisor::handleSaveTreeNodeEditXML(HttpXmlDocument& xmlOut,
3828 ConfigurationManagerRW* cfgMgr,
3829 const std::string& tableName,
3830 TableVersion version,
3831 const std::string& type,
3832 const std::string& uid,
3833 const std::string& colName,
3834 const std::string& newValue,
3835 const std::string& author)
try
3837 __SUP_COUT__ <<
"table " << tableName <<
"(" << version <<
")" << __E__;
3844 TableBase* config = cfgMgr->getTableByName(tableName);
3847 config->setActiveView(version);
3851 if(version.isTemporaryVersion())
3854 __SUP_COUT__ <<
"Failed to find stored version, so attempting to load version: "
3855 << version << __E__;
3856 cfgMgr->getVersionedTableByName(tableName, version);
3859 __SUP_COUT__ <<
"Active version is " << config->getViewVersion() << __E__;
3861 if(version != config->getViewVersion())
3863 __SUP_SS__ <<
"Target table version (" << version
3864 <<
") is not the currently active version ("
3865 << config->getViewVersion() <<
". Try refreshing the tree." << __E__;
3869 unsigned int col = -1;
3870 if(type ==
"uid" || type ==
"delete-uid")
3871 col = config->getView().getColUID();
3872 else if(type ==
"link-UID" || type ==
"link-GroupID" || type ==
"value" ||
3873 type ==
"value-groupid" || type ==
"value-bool" || type ==
"value-bitmap")
3874 col = config->getView().findCol(colName);
3875 else if(type ==
"table" || type ==
"link-comment" || type ==
"table-newGroupRow" ||
3876 type ==
"table-newUIDRow" || type ==
"table-newRow")
3880 __SUP_SS__ <<
"Impossible! Unrecognized edit type: " << type << __E__;
3885 if(type ==
"table" || type ==
"link-comment")
3888 if(config->getView().isURIEncodedCommentTheSame(newValue))
3890 __SUP_SS__ <<
"Comment '" << newValue
3891 <<
"' is the same as the current comment. No need to save change."
3907 TableVersion temporaryVersion = config->createTemporaryView(version);
3909 __SUP_COUT__ <<
"Created temporary version " << temporaryVersion << __E__;
3911 TableView* cfgView = config->getTemporaryView(temporaryVersion);
3917 if(type ==
"table" || type ==
"link-comment")
3920 cfgView->setURIEncodedComment(newValue);
3922 else if(type ==
"table-newRow" || type ==
"table-newUIDRow")
3925 unsigned int row = cfgView->addRow(author,
true );
3930 col = cfgView->getColStatus();
3931 cfgView->setValueAsString(
"1", row, col);
3938 cfgView->setURIEncodedValue(newValue, row, cfgView->getColUID());
3940 else if(type ==
"table-newGroupRow")
3943 unsigned int row = cfgView->addRow(author,
true );
3946 unsigned int csvIndex = newValue.find(
',');
3948 std::string linkIndex = newValue.substr(0, csvIndex);
3949 std::string groupId = newValue.substr(csvIndex + 1);
3952 csvIndex = groupId.find(
',');
3953 std::string newRowUID = groupId.substr(csvIndex + 1);
3954 groupId = groupId.substr(0, csvIndex);
3956 __SUP_COUT__ <<
"newValue " << linkIndex <<
"," << groupId <<
"," << newRowUID
3960 cfgView->setURIEncodedValue(newRowUID, row, cfgView->getColUID());
3963 col = cfgView->getColLinkGroupID(linkIndex);
3966 cfgView->setURIEncodedValue(groupId, row, col);
3971 col = cfgView->getColStatus();
3972 cfgView->setValueAsString(
"1", row, col);
3978 else if(type ==
"delete-uid")
3981 unsigned int row = cfgView->findRow(col, uid);
3982 cfgView->deleteRow(row);
3984 else if(type ==
"uid" || type ==
"value" || type ==
"value-groupid" ||
3985 type ==
"value-bool" || type ==
"value-bitmap")
3987 unsigned int row = cfgView->findRow(cfgView->getColUID(), uid);
3988 if(!cfgView->setURIEncodedValue(newValue, row, col, author))
3991 __SUP_SS__ <<
"Value '" << newValue
3992 <<
"' is the same as the current value. No need to save "
3993 "change to tree node."
3998 else if(type ==
"link-UID" || type ==
"link-GroupID")
4001 std::pair<
unsigned int ,
unsigned int > linkPair;
4002 if(!cfgView->getChildLink(col, isGroup, linkPair))
4005 __SUP_SS__ <<
"Col '" << colName <<
"' is not a link column." << __E__;
4009 __SUP_COUT__ <<
"linkPair " << linkPair.first <<
"," << linkPair.second
4012 std::string linkIndex = cfgView->getColumnInfo(col).getChildLinkIndex();
4014 __SUP_COUT__ <<
"linkIndex " << linkIndex << __E__;
4017 unsigned int csvIndexStart = 0, csvIndex = newValue.find(
',');
4019 std::string newTable = newValue.substr(csvIndexStart, csvIndex);
4020 csvIndexStart = csvIndex + 1;
4021 csvIndex = newValue.find(
',', csvIndexStart);
4022 std::string newLinkId = newValue.substr(
4027 __SUP_COUT__ <<
"newValue " << newTable <<
"," << newLinkId << __E__;
4030 unsigned int row = cfgView->findRow(cfgView->getColUID(), uid);
4031 bool changed =
false;
4032 if(!cfgView->setURIEncodedValue(newTable, row, linkPair.first, author))
4035 __SUP_COUT__ <<
"Value '" << newTable
4036 <<
"' is the same as the current value." << __E__;
4041 if(!cfgView->setURIEncodedValue(newLinkId, row, linkPair.second, author))
4044 __SUP_COUT__ <<
"Value '" << newLinkId
4045 <<
"' is the same as the current value." << __E__;
4053 if(type ==
"link-GroupID")
4055 bool secondaryChanged =
false;
4060 __SUP_COUT__ <<
"No changes to primary view. Erasing temporary table."
4062 config->eraseView(temporaryVersion);
4070 saveModifiedVersionXML(xmlOut,
4082 catch(std::runtime_error&
4085 __SUP_COUT__ <<
"Caught error while editing main table. Erasing "
4086 "temporary version."
4088 config->eraseView(temporaryVersion);
4092 xmlOut.addTextElementToData(
4094 "Error saving primary tree node! " + std::string(e.what()));
4104 csvIndexStart = csvIndex + 1;
4105 csvIndex = newValue.find(
',', csvIndexStart);
4106 version = TableVersion(newValue.substr(
4107 csvIndexStart, csvIndex - csvIndexStart));
4110 if(newTable == TableViewColumnInfo::DATATYPE_LINK_DEFAULT)
4118 config = cfgMgr->getTableByName(newTable);
4121 config->setActiveView(version);
4125 __SUP_COUT__ <<
"Failed to find stored version, so attempting to "
4127 << version << __E__;
4128 cfgMgr->getVersionedTableByName(newTable, version);
4131 __SUP_COUT__ <<
"Active version is " << config->getViewVersion() << __E__;
4133 if(version != config->getViewVersion())
4135 __SUP_SS__ <<
"Target table version (" << version
4136 <<
") is not the currently active version ("
4137 << config->getViewVersion() <<
". Try refreshing the tree."
4143 temporaryVersion = config->createTemporaryView(version);
4145 __SUP_COUT__ <<
"Created temporary version " << temporaryVersion << __E__;
4147 cfgView = config->getTemporaryView(temporaryVersion);
4149 col = cfgView->getColLinkGroupID(linkIndex);
4151 __SUP_COUT__ <<
"target col " << col << __E__;
4154 std::vector<std::string> memberUIDs;
4157 csvIndexStart = csvIndex + 1;
4158 csvIndex = newValue.find(
',', csvIndexStart);
4159 memberUIDs.push_back(
4160 newValue.substr(csvIndexStart, csvIndex - csvIndexStart));
4161 __SUP_COUT__ <<
"memberUIDs: " << memberUIDs.back() << __E__;
4162 }
while(csvIndex != (
unsigned int)std::string::npos);
4172 std::string targetUID;
4173 bool shouldBeInGroup;
4174 bool defaultIsInGroup =
4178 for(
unsigned int row = 0; row < cfgView->getNumberOfRows(); ++row)
4180 targetUID = cfgView->getDataView()[row][cfgView->getColUID()];
4181 __SUP_COUT__ <<
"targetUID: " << targetUID << __E__;
4183 shouldBeInGroup =
false;
4184 for(
unsigned int i = 0; i < memberUIDs.size(); ++i)
4185 if(targetUID == memberUIDs[i])
4188 shouldBeInGroup =
true;
4192 isInGroup = cfgView->isEntryInGroup(row, linkIndex, newLinkId);
4195 if(shouldBeInGroup && !isInGroup)
4197 __SUP_COUT__ <<
"Changed YES: " << row << __E__;
4198 secondaryChanged =
true;
4200 cfgView->addRowToGroup(row, col, newLinkId);
4203 else if(!shouldBeInGroup && isInGroup)
4205 __SUP_COUT__ <<
"Changed NO: " << row << __E__;
4206 secondaryChanged =
true;
4208 cfgView->removeRowFromGroup(row, col, newLinkId);
4210 else if(targetUID ==
4211 cfgView->getDefaultRowValues()[cfgView->getColUID()] &&
4215 defaultIsInGroup =
true;
4220 if(!secondaryChanged)
4223 <<
"No changes to secondary view. Erasing temporary table."
4225 config->eraseView(temporaryVersion);
4233 saveModifiedVersionXML(xmlOut,
4245 catch(std::runtime_error&
4248 __SUP_COUT__ <<
"Caught error while editing secondary table. "
4249 "Erasing temporary version."
4251 config->eraseView(temporaryVersion);
4252 secondaryChanged =
false;
4255 xmlOut.addTextElementToData(
4257 "Error saving secondary tree node! " + std::string(e.what()));
4265 if(0 && !changed && !secondaryChanged && !defaultIsInGroup)
4267 __SUP_SS__ <<
"Link to table '" << newTable <<
"', linkID '"
4269 <<
"', and selected group members are the same as the "
4271 <<
"No need to save changes to tree." << __E__;
4277 else if(0 && !changed)
4282 __SUP_SS__ <<
"Link to table '" << newTable <<
"' and linkID '"
4284 <<
"' are the same as the current values. No need to save "
4285 "change to tree node."
4295 __SUP_COUT__ <<
"Caught error while editing. Erasing temporary version." << __E__;
4296 config->eraseView(temporaryVersion);
4300 saveModifiedVersionXML(xmlOut,
4309 catch(std::runtime_error& e)
4311 __SUP_SS__ <<
"Error saving tree node! " << e.what() << __E__;
4312 __SUP_COUT_ERR__ <<
"\n" << ss.str() << __E__;
4313 xmlOut.addTextElementToData(
"Error", ss.str());
4317 __SUP_SS__ <<
"Unknown Error saving tree node! " << __E__;
4318 __SUP_COUT_ERR__ <<
"\n" << ss.str() << __E__;
4319 xmlOut.addTextElementToData(
"Error", ss.str());
4345 void ConfigurationGUISupervisor::handleGetTableGroupXML(HttpXmlDocument& xmlOut,
4346 ConfigurationManagerRW* cfgMgr,
4347 const std::string& groupName,
4348 TableGroupKey groupKey)
try
4350 char tmpIntStr[100];
4351 DOMElement *parentEl, *configEl;
4374 const GroupInfo& groupInfo = cfgMgr->getGroupInfo(groupName);
4375 const std::set<TableGroupKey>& sortedKeys = groupInfo.keys_;
4377 if(groupKey.isInvalid() ||
4378 sortedKeys.find(groupKey) == sortedKeys.end())
4380 if(sortedKeys.size())
4381 groupKey = *sortedKeys.rbegin();
4382 __SUP_COUT__ <<
"Group key requested was invalid or not found, going with latest "
4383 << groupKey << __E__;
4386 xmlOut.addTextElementToData(
"TableGroupName", groupName);
4387 xmlOut.addTextElementToData(
"TableGroupKey", groupKey.toString());
4390 for(
auto& keyInOrder : sortedKeys)
4391 xmlOut.addTextElementToData(
"HistoricalTableGroupKey", keyInOrder.toString());
4393 parentEl = xmlOut.addTextElementToData(
"TableGroupMembers",
"");
4396 std::map<std::string , TableVersion > memberMap;
4397 std::map<std::string , std::string > groupMemberAliases;
4399 __SUP_COUT__ <<
"groupName=" << groupName << __E__;
4400 __SUP_COUT__ <<
"groupKey=" << groupKey << __E__;
4402 const std::map<std::string, TableInfo>& allTableInfo = cfgMgr->getAllTableInfo();
4403 std::map<std::string, TableInfo>::const_iterator it;
4409 std::string groupAuthor, groupComment, groupCreationTime, groupTypeString;
4410 std::string accumulateErrors;
4412 cfgMgr->loadTableGroup(groupName,
4423 &groupMemberAliases);
4425 if(accumulateErrors !=
"")
4427 __SUP_SS__ << accumulateErrors;
4431 xmlOut.addTextElementToData(
"TableGroupAuthor", groupAuthor);
4432 xmlOut.addTextElementToData(
"TableGroupComment", groupComment);
4433 xmlOut.addTextElementToData(
"TableGroupCreationTime", groupCreationTime);
4434 xmlOut.addTextElementToData(
"TableGroupType", groupTypeString);
4436 catch(
const std::runtime_error& e)
4438 __SUP_SS__ <<
"Table group \"" + groupName +
"(" + groupKey.toString() +
")" +
4439 "\" members can not be loaded!\n\n" + e.what();
4440 __SUP_COUT_ERR__ << ss.str();
4441 xmlOut.addTextElementToData(
"Error", ss.str());
4446 __SUP_SS__ <<
"Table group \"" + groupName +
"(" + groupKey.toString() +
")" +
4447 "\" members can not be loaded!"
4449 __SUP_COUT_ERR__ << ss.str();
4450 xmlOut.addTextElementToData(
"Error", ss.str());
4454 __COUTV__(StringMacros::mapToString(groupMemberAliases));
4456 std::map<std::string, std::map<std::string, TableVersion>> versionAliases =
4457 cfgMgr->getVersionAliases();
4459 __SUP_COUT__ <<
"# of table version aliases: " << versionAliases.size() << __E__;
4462 for(
auto& memberPair : memberMap)
4464 xmlOut.addTextElementToParent(
"MemberName", memberPair.first, parentEl);
4467 if(groupMemberAliases.find(memberPair.first) != groupMemberAliases.end())
4468 configEl = xmlOut.addTextElementToParent(
4470 ConfigurationManager::ALIAS_VERSION_PREAMBLE +
4471 groupMemberAliases[memberPair.first],
4474 configEl = xmlOut.addTextElementToParent(
4475 "MemberVersion", memberPair.second.toString(), parentEl);
4477 it = allTableInfo.find(memberPair.first);
4478 if(it == allTableInfo.end())
4480 xmlOut.addTextElementToData(
4481 "Error",
"Table \"" + memberPair.first +
"\" can not be retrieved!");
4485 if(versionAliases.find(it->first) != versionAliases.end())
4486 for(
auto& aliasVersion : versionAliases[it->first])
4487 xmlOut.addTextElementToParent(
4488 "TableExistingVersion",
4489 ConfigurationManager::ALIAS_VERSION_PREAMBLE + aliasVersion.first,
4492 for(
auto& version : it->second.versions_)
4495 xmlOut.addTextElementToParent(
4496 "TableExistingVersion", version.toString(), configEl);
4499 for(
auto& memberPair : memberMap)
4506 xmlOut.addTextElementToParent(
4508 allTableInfo.at(memberPair.first).tablePtr_->getView().getComment(),
4546 catch(std::runtime_error& e)
4548 __SUP_SS__ << (
"Error!\n\n" + std::string(e.what())) << __E__;
4549 __SUP_COUT_ERR__ <<
"\n" << ss.str();
4550 xmlOut.addTextElementToData(
"Error", ss.str());
4554 __SUP_SS__ << (
"Error!\n\n") << __E__;
4555 __SUP_COUT_ERR__ <<
"\n" << ss.str();
4556 xmlOut.addTextElementToData(
"Error", ss.str());
4600 void ConfigurationGUISupervisor::handleGetTableXML(HttpXmlDocument& xmlOut,
4601 ConfigurationManagerRW* cfgMgr,
4602 const std::string& tableName,
4603 TableVersion version,
4604 bool allowIllegalColumns)
try
4606 char tmpIntStr[100];
4607 DOMElement *parentEl, *subparentEl;
4609 std::string accumulatedErrors =
"";
4611 const std::map<std::string, TableInfo>&
4613 cfgMgr->getAllTableInfo(allowIllegalColumns,
4614 allowIllegalColumns ? &accumulatedErrors : 0,
4617 TableBase* table = cfgMgr->getTableByName(tableName);
4621 xmlOut.addTextElementToData(
"ExistingTableNames",
4622 TableViewColumnInfo::DATATYPE_LINK_DEFAULT);
4623 for(
auto& configPair : allTableInfo)
4625 xmlOut.addTextElementToData(
"ExistingTableNames", configPair.first);
4626 if(configPair.first == tableName &&
4627 configPair.second.versions_.find(version) == configPair.second.versions_.end())
4629 __SUP_COUT__ <<
"Version not found, so using mockup." << __E__;
4630 version = TableVersion();
4634 xmlOut.addTextElementToData(
"TableName", tableName);
4635 xmlOut.addTextElementToData(
"TableDescription",
4636 table->getTableDescription());
4643 std::map<std::string , TableVersion >>
4648 versionAliases = cfgMgr->getVersionAliases();
4649 for(
const auto& aliases : versionAliases)
4650 for(
const auto& alias : aliases.second)
4651 __SUP_COUT__ <<
"ALIAS: " << aliases.first <<
" " << alias.first
4652 <<
" ==> " << alias.second << __E__;
4654 catch(
const std::runtime_error& e)
4656 __SUP_COUT__ <<
"Could not get backbone information for version aliases: "
4657 << e.what() << __E__;
4660 auto tableIterator = versionAliases.find(tableName);
4662 parentEl = xmlOut.addTextElementToData(
"TableVersions",
"");
4663 for(
const TableVersion& v : allTableInfo.at(tableName).versions_)
4666 xmlOut.addTextElementToParent(
"Version", v.toString(), parentEl);
4668 if(tableIterator != versionAliases.end())
4671 for(
const auto& aliasPair : tableIterator->second)
4679 if(v == aliasPair.second)
4681 __SUP_COUT__ <<
"Found Alias " << aliasPair.second <<
" --> "
4682 << aliasPair.first << __E__;
4683 xmlOut.addTextElementToParent(
4684 "VersionAlias", aliasPair.first, subparentEl);
4694 TableView* cfgViewPtr;
4695 if(version.isInvalid())
4697 cfgViewPtr = table->getMockupViewP();
4703 cfgViewPtr = cfgMgr->getVersionedTableByName(tableName, version)->getViewP();
4705 catch(std::runtime_error& e)
4707 __SUP_SS__ <<
"Failed to get table " << tableName <<
" version " << version
4708 <<
"... defaulting to mock-up! " << __E__;
4709 ss <<
"\n\n...Here is why it failed:\n\n" << e.what() << __E__;
4711 __SUP_COUT_ERR__ <<
"\n" << ss.str();
4712 version = TableVersion();
4713 cfgViewPtr = table->getMockupViewP();
4715 xmlOut.addTextElementToData(
"Error",
"Error getting view! " + ss.str());
4719 __SUP_SS__ <<
"Failed to get table " << tableName <<
" version: " << version
4720 <<
"... defaulting to mock-up! "
4721 <<
"(You may want to try again to see what was partially loaded "
4722 "into cache before failure. "
4723 <<
"If you think, the failure is due to a column name change, "
4724 <<
"you can also try to Copy the failing view to the new column "
4726 <<
"'Copy and Move' functionality.)" << __E__;
4728 __SUP_COUT_ERR__ <<
"\n" << ss.str();
4729 version = TableVersion();
4730 cfgViewPtr = table->getMockupViewP();
4732 xmlOut.addTextElementToData(
"Error",
"Error getting view! " + ss.str());
4735 xmlOut.addTextElementToData(
"TableVersion", version.toString());
4738 DOMElement* choicesParentEl;
4739 parentEl = xmlOut.addTextElementToData(
"CurrentVersionColumnHeaders",
"");
4741 std::vector<TableViewColumnInfo> colInfo = cfgViewPtr->getColumnsInfo();
4743 for(
int i = 0; i < (int)colInfo.size(); ++i)
4751 xmlOut.addTextElementToParent(
"ColumnHeader", colInfo[i].getName(), parentEl);
4752 xmlOut.addTextElementToParent(
"ColumnType", colInfo[i].getType(), parentEl);
4753 xmlOut.addTextElementToParent(
4754 "ColumnDataType", colInfo[i].getDataType(), parentEl);
4756 choicesParentEl = xmlOut.addTextElementToParent(
"ColumnChoices",
"", parentEl);
4758 if(colInfo[i].getType() == TableViewColumnInfo::TYPE_FIXED_CHOICE_DATA ||
4759 colInfo[i].getType() == TableViewColumnInfo::TYPE_BITMAP_DATA ||
4760 colInfo[i].isChildLink())
4762 for(
auto& choice : colInfo[i].getDataChoices())
4763 xmlOut.addTextElementToParent(
"ColumnChoice", choice, choicesParentEl);
4770 if(version.isInvalid())
4773 catch(std::runtime_error& e)
4776 __THROW__(e.what() + std::string(
"\n\n") + accumulatedErrors);
4783 parentEl = xmlOut.addTextElementToData(
"CurrentVersionRows",
"");
4785 for(
int r = 0; r < (int)cfgViewPtr->getNumberOfRows(); ++r)
4789 sprintf(tmpIntStr,
"%d", r);
4790 DOMElement* tmpParentEl =
4791 xmlOut.addTextElementToParent(
"Row", tmpIntStr, parentEl);
4793 for(
int c = 0; c < (int)cfgViewPtr->getNumberOfColumns(); ++c)
4795 if(colInfo[c].getDataType() == TableViewColumnInfo::DATATYPE_TIME)
4797 std::string timeAsString;
4798 cfgViewPtr->getValue(timeAsString, r, c);
4799 xmlOut.addTextElementToParent(
"Entry", timeAsString, tmpParentEl);
4802 xmlOut.addTextElementToParent(
4803 "Entry", cfgViewPtr->getDataView()[r][c], tmpParentEl);
4808 xmlOut.addTextElementToData(
"TableComment", cfgViewPtr->getComment());
4809 xmlOut.addTextElementToData(
"TableAuthor", cfgViewPtr->getAuthor());
4810 xmlOut.addTextElementToData(
"TableCreationTime",
4811 std::to_string(cfgViewPtr->getCreationTime()));
4812 xmlOut.addTextElementToData(
"TableLastAccessTime",
4813 std::to_string(cfgViewPtr->getLastAccessTime()));
4816 std::vector<std::string> defaultRowValues = cfgViewPtr->getDefaultRowValues();
4818 for(
unsigned int c = 0; c < defaultRowValues.size() - 2; ++c)
4823 xmlOut.addTextElementToData(
"DefaultRowValue", defaultRowValues[c]);
4826 if(accumulatedErrors !=
"")
4828 __SUP_SS__ << (std::string(
"Column errors were allowed for this request, so "
4829 "maybe you can ignore this, ") +
4830 "but please note the following errors:\n" + accumulatedErrors)
4832 __SUP_COUT_ERR__ << ss.str();
4833 xmlOut.addTextElementToData(
"Error", ss.str());
4835 else if(!version.isTemporaryVersion() &&
4837 (cfgViewPtr->getDataColumnSize() != cfgViewPtr->getNumberOfColumns() ||
4838 cfgViewPtr->getSourceColumnMismatch() !=
4841 __SUP_SS__ <<
"\n\nThere were warnings found when loading the table " << tableName
4842 <<
":v" << version <<
". Please see the details below:\n\n"
4843 <<
"The source column size was found to be "
4844 << cfgViewPtr->getDataColumnSize()
4845 <<
", and the current number of columns for this table is "
4846 << cfgViewPtr->getNumberOfColumns() <<
". This resulted in a count of "
4847 << cfgViewPtr->getSourceColumnMismatch()
4848 <<
" source column mismatches, and a count of "
4849 << cfgViewPtr->getSourceColumnMissing() <<
" table entries missing in "
4850 << cfgViewPtr->getNumberOfRows() <<
" row(s) of data." << __E__;
4852 const std::set<std::string> srcColNames = cfgViewPtr->getSourceColumnNames();
4853 ss <<
"\n\nSource column names in ALPHABETICAL order were as follows:\n";
4855 std::string preIndexStr =
"";
4856 for(
auto& srcColName : srcColNames)
4858 ss <<
"\n\t" << preIndexStr << index <<
". " << srcColName;
4869 std::set<std::string> destColNames = cfgViewPtr->getColumnStorageNames();
4870 ss <<
"\n\nCurrent table column names in ALPHABETICAL order are as follows:\n";
4873 for(
auto& destColName : destColNames)
4875 ss <<
"\n\t" << preIndexStr << index <<
". " << destColName;
4886 __SUP_COUT__ <<
"\n" << ss.str();
4887 xmlOut.addTextElementToData(
"TableWarnings", ss.str());
4890 catch(std::runtime_error& e)
4892 __SUP_COUT__ <<
"Error detected!\n\n " << e.what() << __E__;
4893 xmlOut.addTextElementToData(
"Error",
"Error getting view! " + std::string(e.what()));
4897 __SUP_COUT__ <<
"Error detected!\n\n " << __E__;
4898 xmlOut.addTextElementToData(
"Error",
"Error getting view! ");
4906 TableVersion ConfigurationGUISupervisor::saveModifiedVersionXML(
4907 HttpXmlDocument& xmlOut,
4908 ConfigurationManagerRW* cfgMgr,
4909 const std::string& tableName,
4910 TableVersion originalVersion,
4913 TableVersion temporaryModifiedVersion,
4914 bool ignoreDuplicates,
4915 bool lookForEquivalent)
4917 bool needToEraseTemporarySource =
4918 (originalVersion.isTemporaryVersion() && !makeTemporary);
4921 if(!ignoreDuplicates)
4923 __SUP_COUT__ <<
"Checking for duplicate tables..." << __E__;
4925 TableVersion duplicateVersion;
4932 const std::map<std::string, TableInfo>& allTableInfo =
4933 cfgMgr->getAllTableInfo();
4935 auto versionReverseIterator =
4936 allTableInfo.at(tableName).versions_.rbegin();
4937 __SUP_COUT__ <<
"Filling up cached from " << config->getNumberOfStoredViews()
4938 <<
" to max count of " << config->MAX_VIEWS_IN_CACHE << __E__;
4939 for(; config->getNumberOfStoredViews() < config->MAX_VIEWS_IN_CACHE &&
4940 versionReverseIterator != allTableInfo.at(tableName).versions_.rend();
4941 ++versionReverseIterator)
4943 __SUP_COUT__ <<
"Versions in reverse order " << *versionReverseIterator
4947 cfgMgr->getVersionedTableByName(
4948 tableName, *versionReverseIterator);
4950 catch(
const std::runtime_error& e)
4953 <<
"Error loadiing historical version, but ignoring: " << e.what()
4959 __SUP_COUT__ <<
"Checking duplicate..." << __E__;
4961 duplicateVersion = config->checkForDuplicate(
4962 temporaryModifiedVersion,
4963 (!originalVersion.isTemporaryVersion() && !makeTemporary)
4969 if(lookForEquivalent && !duplicateVersion.isInvalid())
4972 __SUP_COUT__ <<
"Equivalent table found in version v" << duplicateVersion
4976 if(duplicateVersion.isTemporaryVersion() && !makeTemporary)
4978 __SUP_COUT__ <<
"Need persistent. Duplicate version was temporary. "
4979 "Abandoning duplicate."
4981 duplicateVersion = TableVersion();
4988 cfgMgr->eraseTemporaryVersion(tableName, temporaryModifiedVersion);
4991 if(needToEraseTemporarySource)
4992 cfgMgr->eraseTemporaryVersion(tableName, originalVersion);
4994 xmlOut.addTextElementToData(
"savedName", tableName);
4995 xmlOut.addTextElementToData(
"savedVersion", duplicateVersion.toString());
4996 xmlOut.addTextElementToData(
"foundEquivalentVersion",
"1");
4998 __SUP_COUT__ <<
"\t\t equivalent AssignedVersion: " << duplicateVersion
5001 return duplicateVersion;
5005 if(!duplicateVersion.isInvalid())
5008 <<
"This version of table '" << tableName <<
5009 "' is identical to another version currently cached v"
5010 << duplicateVersion <<
". No reason to save a duplicate." << __E__;
5011 __SUP_COUT_ERR__ <<
"\n" << ss.str();
5014 config->eraseView(temporaryModifiedVersion);
5018 __SUP_COUT__ <<
"Check for duplicate tables complete." << __E__;
5022 __SUP_COUT__ <<
"\t\t**************************** Save as temporary table version"
5025 __SUP_COUT__ <<
"\t\t**************************** Save as new table version"
5028 TableVersion newAssignedVersion =
5029 cfgMgr->saveNewTable(tableName, temporaryModifiedVersion, makeTemporary);
5031 if(needToEraseTemporarySource)
5032 cfgMgr->eraseTemporaryVersion(tableName, originalVersion);
5034 xmlOut.addTextElementToData(
"savedName", tableName);
5035 xmlOut.addTextElementToData(
"savedVersion", newAssignedVersion.toString());
5037 __SUP_COUT__ <<
"\t\t newAssignedVersion: " << newAssignedVersion << __E__;
5038 return newAssignedVersion;
5049 void ConfigurationGUISupervisor::handleCreateTableXML(HttpXmlDocument& xmlOut,
5050 ConfigurationManagerRW* cfgMgr,
5051 const std::string& tableName,
5052 TableVersion version,
5054 const std::string& data,
5055 const int& dataOffset,
5056 const std::string& author,
5057 const std::string& comment,
5058 bool sourceTableAsIs,
5059 bool lookForEquivalent)
try
5068 if(!version.isInvalid())
5073 cfgMgr->getVersionedTableByName(tableName, version);
5078 version = TableVersion();
5082 TableBase* config = cfgMgr->getTableByName(tableName);
5086 if(!version.isInvalid())
5090 if(config->getViewP()->getDataColumnSize() !=
5091 config->getMockupViewP()->getNumberOfColumns() ||
5092 config->getViewP()->getSourceColumnMismatch() != 0)
5094 __SUP_COUT__ <<
"config->getViewP()->getNumberOfColumns() "
5095 << config->getViewP()->getNumberOfColumns() << __E__;
5096 __SUP_COUT__ <<
"config->getMockupViewP()->getNumberOfColumns() "
5097 << config->getMockupViewP()->getNumberOfColumns() << __E__;
5098 __SUP_COUT__ <<
"config->getViewP()->getSourceColumnMismatch() "
5099 << config->getViewP()->getSourceColumnMismatch() << __E__;
5101 <<
"Source view v" << version
5102 <<
" has a mismatch in the number of columns, so using mockup as source."
5104 version = TableVersion();
5109 TableVersion temporaryVersion = config->createTemporaryView(version);
5111 __SUP_COUT__ <<
"\t\ttemporaryVersion: " << temporaryVersion << __E__;
5113 TableView* cfgView = config->getTemporaryView(temporaryVersion);
5119 retVal = sourceTableAsIs ? 0 : cfgView->fillFromCSV(data, dataOffset, author);
5123 __SUP_COUT__ <<
"Data was the same, but columns have changed!" << __E__;
5124 __SUP_COUTV__(sourceTableAsIs);
5125 lookForEquivalent =
false;
5128 cfgView->setURIEncodedComment(comment);
5129 __SUP_COUT__ <<
"Table comment was set to:\n\t" << cfgView->getComment() << __E__;
5133 __SUP_COUT__ <<
"Caught error while editing. Erasing temporary version." << __E__;
5134 config->eraseView(temporaryVersion);
5144 if(retVal < 0 && (!version.isTemporaryVersion() || makeTemporary) &&
5145 ConfigurationInterface::isVersionTrackingEnabled())
5147 if(!version.isInvalid() &&
5149 !version.isScratchVersion())
5153 <<
"No rows were modified! No reason to fill a view with same content."
5155 __SUP_COUT_ERR__ <<
"\n" << ss.str();
5157 config->eraseView(temporaryVersion);
5160 else if(version.isInvalid())
5161 __SUP_COUT__ <<
"This was interpreted as an attempt to create a blank table."
5163 else if(version.isScratchVersion())
5164 __SUP_COUT__ <<
"This was interpreted as an attempt to make a persistent "
5165 "version of the scratch table."
5170 __THROW__(ss.str() +
"impossible!");
5173 else if(retVal < 0 && (version.isTemporaryVersion() && !makeTemporary))
5175 __SUP_COUT__ <<
"Allowing the static data because this is converting from "
5176 "temporary to persistent version."
5179 else if(retVal < 0 && !ConfigurationInterface::isVersionTrackingEnabled())
5181 __SUP_COUT__ <<
"Allowing the static data because version tracking is OFF."
5186 __SUP_SS__ <<
"This should not be possible! Fatal error." << __E__;
5188 config->eraseView(temporaryVersion);
5193 saveModifiedVersionXML(xmlOut,
5201 lookForEquivalent || sourceTableAsIs );
5203 catch(std::runtime_error& e)
5205 __SUP_COUT__ <<
"Error detected!\n\n " << e.what() << __E__;
5206 xmlOut.addTextElementToData(
"Error",
5207 "Error saving new view!\n " + std::string(e.what()));
5211 __SUP_COUT__ <<
"Error detected!\n\n " << __E__;
5212 xmlOut.addTextElementToData(
"Error",
"Error saving new view! ");
5226 ConfigurationManagerRW* ConfigurationGUISupervisor::refreshUserSession(
5227 std::string username, uint64_t activeSessionIndex,
bool refresh)
5230 activeSessionIndex =
5233 std::stringstream ssMapKey;
5234 ssMapKey << username <<
":" << activeSessionIndex;
5235 std::string mapKey = ssMapKey.str();
5236 __SUP_COUT__ <<
"Config Session: " << mapKey
5237 <<
" ... out of size: " << userConfigurationManagers_.size() << __E__;
5239 time_t now = time(0);
5242 if(userConfigurationManagers_.find(mapKey) == userConfigurationManagers_.end())
5244 __SUP_COUT_INFO__ <<
"Creating new Configuration Manager." << __E__;
5245 userConfigurationManagers_[mapKey] =
new ConfigurationManagerRW(username);
5250 userConfigurationManagers_[mapKey]->getAllTableInfo(
5253 else if(userLastUseTime_.find(mapKey) == userLastUseTime_.end())
5255 __SUP_SS__ <<
"Fatal error managing userLastUseTime_!" << __E__;
5256 __SUP_COUT_ERR__ <<
"\n" << ss.str();
5259 else if(refresh || (now - userLastUseTime_[mapKey]) >
5260 CONFIGURATION_MANAGER_REFRESH_THRESHOLD)
5264 __SUP_COUT_INFO__ <<
"Refreshing all table info." << __E__;
5265 userConfigurationManagers_[mapKey]->getAllTableInfo(
true);
5274 userLastUseTime_[mapKey] = now;
5277 for(std::map<std::string, time_t>::iterator it = userLastUseTime_.begin();
5278 it != userLastUseTime_.end();
5280 if(now - it->second > CONFIGURATION_MANAGER_EXPIRATION_TIME)
5282 __SUP_COUT__ << now <<
":" << it->second <<
" = " << now - it->second
5284 delete userConfigurationManagers_[it->first];
5285 if(!(userConfigurationManagers_.erase(it->first)))
5287 __SUP_SS__ <<
"Fatal error erasing configuration manager by key!"
5289 __SUP_COUT_ERR__ <<
"\n" << ss.str();
5292 userLastUseTime_.erase(it);
5294 it = userLastUseTime_.begin();
5299 return userConfigurationManagers_[mapKey];
5321 void ConfigurationGUISupervisor::handleCreateTableGroupXML(
5322 HttpXmlDocument& xmlOut,
5323 ConfigurationManagerRW* cfgMgr,
5324 const std::string& groupName,
5325 const std::string& tableList,
5326 bool allowDuplicates,
5327 bool ignoreWarnings,
5328 const std::string& groupComment,
5329 bool lookForEquivalent)
try
5331 __SUP_COUT__ <<
"handleCreateTableGroupXML \n";
5333 xmlOut.addTextElementToData(
"AttemptedNewGroupName", groupName);
5337 const std::map<std::string, TableInfo>& allTableInfo = cfgMgr->getAllTableInfo(
true);
5338 cfgMgr->loadConfigurationBackbone();
5340 std::map<std::string ,
5341 std::map<std::string , TableVersion >>
5342 versionAliases = cfgMgr->getVersionAliases();
5343 for(
const auto& aliases : versionAliases)
5344 for(
const auto& alias : aliases.second)
5345 __SUP_COUT__ << aliases.first <<
" " << alias.first <<
" " << alias.second
5348 std::map<std::string , TableVersion > groupMembers;
5349 std::map<std::string , std::string > groupAliases;
5351 std::string name, versionStr, alias;
5352 TableVersion version;
5353 auto c = tableList.find(
',', 0);
5356 while(c < tableList.length())
5359 name = tableList.substr(i, c - i);
5361 c = tableList.find(
',', i);
5362 if(c == std::string::npos)
5364 __SUP_SS__ <<
"Incomplete Table Name-Version pair!" << __E__;
5365 __SUP_COUT_ERR__ <<
"\n" << ss.str();
5366 xmlOut.addTextElementToData(
"Error", ss.str());
5370 versionStr = tableList.substr(i, c - i);
5372 c = tableList.find(
',', i);
5378 if(versionStr.find(ConfigurationManager::ALIAS_VERSION_PREAMBLE) == 0)
5381 versionStr.substr(ConfigurationManager::ALIAS_VERSION_PREAMBLE.size());
5383 __SUP_COUT__ <<
"Found alias " << name <<
" " << versionStr << __E__;
5386 if(versionAliases.find(name) != versionAliases.end() &&
5387 versionAliases[name].find(alias) != versionAliases[name].end())
5389 version = versionAliases[name][alias];
5390 __SUP_COUT__ <<
"version alias '" << alias
5391 <<
"'translated to: " << version << __E__;
5393 groupAliases[name] = alias;
5397 __SUP_SS__ <<
"version alias '"
5398 << versionStr.substr(
5399 ConfigurationManager::ALIAS_VERSION_PREAMBLE.size())
5400 <<
"' was not found in active version aliases!" << __E__;
5401 __SUP_COUT_ERR__ <<
"\n" << ss.str();
5402 xmlOut.addTextElementToData(
"Error", ss.str());
5407 version = TableVersion(versionStr);
5409 if(version.isTemporaryVersion())
5411 __SUP_SS__ <<
"Groups can not be created using temporary member tables. "
5412 <<
"Table member '" << name <<
"' with temporary version '"
5413 << version <<
"' is illegal." << __E__;
5414 xmlOut.addTextElementToData(
"Error", ss.str());
5419 if(allTableInfo.find(name) == allTableInfo.end())
5421 __SUP_SS__ <<
"Groups can not be created using mock-up member tables of "
5422 "undefined tables. "
5423 <<
"Table member '" << name <<
"' is not defined." << __E__;
5424 xmlOut.addTextElementToData(
"Error", ss.str());
5428 if(version.isMockupVersion())
5431 TableBase* config = cfgMgr->getTableByName(name);
5433 TableVersion temporaryVersion = config->createTemporaryView();
5434 __SUP_COUT__ <<
"\t\ttemporaryVersion: " << temporaryVersion << __E__;
5437 __SUP_COUT__ <<
"Creating version from mock-up for name: " << name
5438 <<
" inputVersionStr: " << versionStr << __E__;
5441 config->getTemporaryView(temporaryVersion)
5442 ->setComment(
"Auto-generated from mock-up.");
5446 saveModifiedVersionXML(xmlOut,
5456 __SUP_COUT__ <<
"Using mockup version: " << version << __E__;
5460 groupMembers[name] = version;
5463 __COUTV__(StringMacros::mapToString(groupAliases));
5465 if(!allowDuplicates)
5467 __SUP_COUT__ <<
"Checking for duplicate groups..." << __E__;
5468 TableGroupKey foundKey =
5469 cfgMgr->findTableGroup(groupName, groupMembers, groupAliases);
5471 if(!foundKey.isInvalid())
5474 xmlOut.addTextElementToData(
"TableGroupName", groupName);
5475 xmlOut.addTextElementToData(
"TableGroupKey", foundKey.toString());
5477 if(lookForEquivalent)
5479 __SUP_COUT__ <<
"Found equivalent group key (" << foundKey <<
") for "
5480 << groupName <<
"." << __E__;
5482 xmlOut.addTextElementToData(
"foundEquivalentKey",
"1");
5485 handleGetTableGroupXML(xmlOut, cfgMgr, groupName, foundKey);
5490 __SUP_COUT__ <<
"Treating duplicate group as error." << __E__;
5491 __SUP_SS__ << (
"Failed to create table group: " + groupName +
5492 ". It is a duplicate of an existing group key (" +
5493 foundKey.toString() +
")");
5494 __SUP_COUT_ERR__ << ss.str() << __E__;
5495 xmlOut.addTextElementToData(
"Error", ss.str());
5500 __SUP_COUT__ <<
"Check for duplicate groups complete." << __E__;
5506 cfgMgr->loadMemberMap(groupMembers);
5508 std::string accumulateErrors =
"";
5509 for(
auto& groupMemberPair : groupMembers)
5511 TableView* cfgViewPtr =
5512 cfgMgr->getTableByName(groupMemberPair.first)->getViewP();
5513 if(cfgViewPtr->getDataColumnSize() != cfgViewPtr->getNumberOfColumns() ||
5514 cfgViewPtr->getSourceColumnMismatch() !=
5517 __SUP_SS__ <<
"\n\nThere were errors found in loading a member table "
5518 << groupMemberPair.first <<
":v" << cfgViewPtr->getVersion()
5519 <<
". Please see the details below:\n\n"
5520 <<
"The source column size was found to be "
5521 << cfgViewPtr->getDataColumnSize()
5522 <<
", and the current number of columns for this table is "
5523 << cfgViewPtr->getNumberOfColumns()
5524 <<
". This resulted in a count of "
5525 << cfgViewPtr->getSourceColumnMismatch()
5526 <<
" source column mismatches, and a count of "
5527 << cfgViewPtr->getSourceColumnMissing()
5528 <<
" table entries missing in "
5529 << cfgViewPtr->getNumberOfRows() <<
" row(s) of data."
5532 const std::set<std::string> srcColNames =
5533 cfgViewPtr->getSourceColumnNames();
5534 ss <<
"\n\nSource column names were as follows:\n";
5536 for(
auto& srcColName : srcColNames)
5537 ss <<
"\n\t" << index++ <<
". " << srcColName;
5540 std::set<std::string> destColNames = cfgViewPtr->getColumnStorageNames();
5541 ss <<
"\n\nCurrent table column names are as follows:\n";
5543 for(
auto& destColName : destColNames)
5544 ss <<
"\n\t" << index++ <<
". " << destColName;
5547 __SUP_COUT_ERR__ <<
"\n" << ss.str();
5548 xmlOut.addTextElementToData(
"Error", ss.str());
5553 catch(std::runtime_error& e)
5555 __SUP_SS__ <<
"Failed to create config group: " << groupName
5556 <<
".\nThere were problems loading the chosen members:\n\n"
5557 << e.what() << __E__;
5558 __SUP_COUT_ERR__ <<
"\n" << ss.str();
5559 xmlOut.addTextElementToData(
"Error", ss.str());
5564 __SUP_SS__ <<
"Failed to create config group: " << groupName << __E__;
5565 __SUP_COUT_ERR__ <<
"\n" << ss.str();
5566 xmlOut.addTextElementToData(
"Error", ss.str());
5571 std::string accumulateTreeErrs;
5572 cfgMgr->getChildren(&groupMembers, &accumulateTreeErrs);
5573 if(accumulateTreeErrs !=
"")
5575 __SUP_COUT_WARN__ <<
"\n" << accumulateTreeErrs << __E__;
5578 xmlOut.addTextElementToData(
"TreeErrors", accumulateTreeErrs);
5583 TableGroupKey newKey;
5586 __COUT__ <<
"Saving new group..." << __E__;
5587 newKey = cfgMgr->saveNewTableGroup(
5588 groupName, groupMembers, groupComment, &groupAliases);
5590 catch(std::runtime_error& e)
5592 __SUP_COUT_ERR__ <<
"Failed to create config group: " << groupName << __E__;
5593 __SUP_COUT_ERR__ <<
"\n\n" << e.what() << __E__;
5594 xmlOut.addTextElementToData(
5595 "Error",
"Failed to create table group: " + groupName +
".\n\n" + e.what());
5600 __SUP_COUT_ERR__ <<
"Failed to create table group: " << groupName << __E__;
5601 xmlOut.addTextElementToData(
"Error",
5602 "Failed to create table group: " + groupName);
5607 __COUT__ <<
"Loading new table group..." << __E__;
5608 handleGetTableGroupXML(xmlOut, cfgMgr, groupName, newKey);
5610 catch(std::runtime_error& e)
5612 __SUP_COUT__ <<
"Error detected!\n\n " << e.what() << __E__;
5613 xmlOut.addTextElementToData(
"Error",
5614 "Error saving table group! " + std::string(e.what()));
5618 __SUP_COUT__ <<
"Unknown Error detected!\n\n " << __E__;
5619 xmlOut.addTextElementToData(
"Error",
"Error saving table group! ");
5627 void ConfigurationGUISupervisor::handleDeleteTableInfoXML(HttpXmlDocument& xmlOut,
5628 ConfigurationManagerRW* cfgMgr,
5629 std::string& tableName)
5631 if(0 == rename((TABLE_INFO_PATH + tableName + TABLE_INFO_EXT).c_str(),
5632 (TABLE_INFO_PATH + tableName + TABLE_INFO_EXT +
".unused").c_str()))
5633 __SUP_COUT_INFO__ << (
"Table Info File successfully renamed: " +
5634 (TABLE_INFO_PATH + tableName + TABLE_INFO_EXT +
".unused"))
5638 __SUP_COUT_ERR__ << (
"Error renaming file to " +
5639 (TABLE_INFO_PATH + tableName + TABLE_INFO_EXT +
".unused"))
5642 xmlOut.addTextElementToData(
5644 (
"Error renaming Table Info File to " +
5645 (TABLE_INFO_PATH + tableName + TABLE_INFO_EXT +
".unused")));
5650 cfgMgr->getAllTableInfo(
true);
5660 void ConfigurationGUISupervisor::handleSaveTableInfoXML(
5661 HttpXmlDocument& xmlOut,
5662 ConfigurationManagerRW* cfgMgr,
5663 std::string& tableName,
5664 const std::string& data,
5665 const std::string& tableDescription,
5666 const std::string& columnChoicesCSV,
5667 bool allowOverwrite)
5671 std::string capsName;
5674 capsName = TableBase::convertToCaps(tableName,
true);
5676 catch(std::runtime_error& e)
5678 xmlOut.addTextElementToData(
"Error", e.what());
5684 FILE* fp = fopen((TABLE_INFO_PATH + tableName + TABLE_INFO_EXT).c_str(),
"r");
5688 xmlOut.addTextElementToData(
"TableName", tableName);
5689 xmlOut.addTextElementToData(
"OverwriteError",
"1");
5690 xmlOut.addTextElementToData(
5692 "File already exists! ('" +
5693 (TABLE_INFO_PATH + tableName + TABLE_INFO_EXT) +
"')");
5698 __SUP_COUT__ <<
"capsName=" << capsName << __E__;
5699 __SUP_COUT__ <<
"tableName=" << tableName << __E__;
5700 __SUP_COUT__ <<
"tableDescription=" << tableDescription << __E__;
5701 __SUP_COUT__ <<
"columnChoicesCSV=" << columnChoicesCSV << __E__;
5704 std::stringstream outss;
5706 outss <<
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>\n";
5707 outss <<
"\t<ROOT xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
5708 "xsi:noNamespaceSchemaLocation=\"TableInfo.xsd\">\n";
5709 outss <<
"\t\t<TABLE Name=\"" << tableName <<
"\">\n";
5710 outss <<
"\t\t\t<VIEW Name=\"" << capsName
5711 <<
"\" Type=\"File,Database,DatabaseTest\" Description=\"" << tableDescription
5717 int j = data.find(
',', i);
5718 int k = data.find(
';', i);
5720 std::istringstream columnChoicesISS(columnChoicesCSV);
5721 std::string columnChoicesString;
5722 std::string columnType;
5724 while(k != (
int)(std::string::npos))
5727 columnType = data.substr(i, j - i);
5728 outss <<
"\t\t\t\t<COLUMN Type=\"";
5729 outss << columnType;
5732 j = data.find(
',', i);
5735 outss <<
"\" \t Name=\"";
5736 capsName = data.substr(i, j - i);
5738 outss <<
"\" \t StorageName=\"";
5742 outss << TableBase::convertToCaps(capsName);
5744 catch(std::runtime_error& e)
5746 xmlOut.addTextElementToData(
"Error",
5747 std::string(
"For column name '") +
5748 data.substr(i, j - i) +
"' - " + e.what());
5753 j = data.find(
',', i);
5756 outss <<
"\" \t DataType=\"";
5757 outss << data.substr(i, k - i);
5760 getline(columnChoicesISS, columnChoicesString,
';');
5762 outss <<
"\" \t DataChoices=\"";
5763 outss << columnChoicesString;
5769 j = data.find(
',', i);
5770 k = data.find(
';', i);
5773 outss <<
"\t\t\t</VIEW>\n";
5774 outss <<
"\t\t</TABLE>\n";
5775 outss <<
"\t</ROOT>\n";
5777 __SUP_COUT__ << outss.str() << __E__;
5779 FILE* fp = fopen((TABLE_INFO_PATH + tableName + TABLE_INFO_EXT).c_str(),
"w");
5782 xmlOut.addTextElementToData(
"Error",
5783 "Failed to open destination Table Info file:" +
5784 (TABLE_INFO_PATH + tableName + TABLE_INFO_EXT));
5788 fprintf(fp,
"%s", outss.str().c_str());
5793 std::string accumulatedErrors =
"";
5794 cfgMgr->getAllTableInfo(
true, &accumulatedErrors, tableName);
5797 if(accumulatedErrors !=
"")
5799 __SUP_SS__ << (
"The new version of the '" + tableName +
5800 "' table column info was saved, however errors were detected "
5801 "reading back the table '" +
5802 tableName +
"' after the save attempt:\n\n" + accumulatedErrors)
5805 __SUP_COUT_ERR__ << ss.str() << __E__;
5806 xmlOut.addTextElementToData(
"Error", ss.str());
5818 rename((TABLE_INFO_PATH + tableName + TABLE_INFO_EXT).c_str(),
5819 (TABLE_INFO_PATH + tableName + TABLE_INFO_EXT +
".unused").c_str()))
5821 << (
"File successfully renamed: " +
5822 (TABLE_INFO_PATH + tableName + TABLE_INFO_EXT +
".unused"))
5827 << (
"Error renaming file to " +
5828 (TABLE_INFO_PATH + tableName + TABLE_INFO_EXT +
".unused"))
5832 cfgMgr->getAllTableInfo(
true);
5838 handleGetTableXML(xmlOut, cfgMgr, tableName, TableVersion());
5842 const std::map<std::string, TableInfo>& allTableInfo = cfgMgr->getAllTableInfo();
5845 __SUP_COUT_INFO__ <<
"Looking for errors in all table column info..." << __E__;
5846 for(
const auto& cfgInfo : allTableInfo)
5850 cfgMgr->getTableByName(cfgInfo.first)->getMockupViewP()->init();
5852 catch(std::runtime_error& e)
5854 __SUP_COUT_WARN__ <<
"\n\n##############################################\n"
5855 <<
"Error identified in column info of table '"
5856 << cfgInfo.first <<
"':\n\n"
5857 << e.what() <<
"\n\n"
5871 void ConfigurationGUISupervisor::handleSetGroupAliasInBackboneXML(
5872 HttpXmlDocument& xmlOut,
5873 ConfigurationManagerRW* cfgMgr,
5874 const std::string& groupAlias,
5875 const std::string& groupName,
5876 TableGroupKey groupKey,
5877 const std::string& author)
try
5879 cfgMgr->loadConfigurationBackbone();
5880 std::map<std::string, TableVersion> activeVersions = cfgMgr->getActiveVersions();
5882 const std::string groupAliasesTableName =
5883 ConfigurationManager::GROUP_ALIASES_TABLE_NAME;
5884 if(activeVersions.find(groupAliasesTableName) == activeVersions.end())
5886 __SUP_SS__ <<
"Active version of " << groupAliasesTableName <<
" missing!"
5888 xmlOut.addTextElementToData(
"Error", ss.str());
5893 const std::set<std::string> backboneMembers = cfgMgr->getBackboneMemberNames();
5894 for(
auto& memberName : backboneMembers)
5896 __SUP_COUT__ <<
"activeVersions[\"" << memberName
5897 <<
"\"]=" << activeVersions[memberName] << __E__;
5899 xmlOut.addTextElementToData(
"oldBackboneName", memberName);
5900 xmlOut.addTextElementToData(
"oldBackboneVersion",
5901 activeVersions[memberName].toString());
5908 TableBase* config = cfgMgr->getTableByName(groupAliasesTableName);
5909 TableVersion originalVersion = activeVersions[groupAliasesTableName];
5910 TableVersion temporaryVersion = config->createTemporaryView(originalVersion);
5912 __SUP_COUT__ <<
"\t\t temporaryVersion: " << temporaryVersion << __E__;
5913 bool isDifferent =
false;
5917 TableView* configView = config->getTemporaryView(temporaryVersion);
5919 unsigned int col = configView->findCol(
"GroupKeyAlias");
5923 unsigned int row = -1;
5927 row = configView->findRow(col, groupAlias);
5932 if(row == (
unsigned int)-1)
5935 row = configView->addRow();
5938 col = configView->findCol(
"CommentDescription");
5939 configView->setValue(
5940 "This Group Alias was automatically setup by the server.", row, col);
5941 col = configView->findCol(
"GroupKeyAlias");
5942 configView->setValue(groupAlias, row, col);
5945 __SUP_COUT__ <<
"\t\t row: " << row << __E__;
5947 col = configView->findCol(
"GroupName");
5949 __SUP_COUT__ <<
"\t\t groupName: " << groupName <<
" vs "
5950 << configView->getDataView()[row][col] << __E__;
5951 if(groupName != configView->getDataView()[row][col])
5953 configView->setValue(groupName, row, col);
5957 col = configView->findCol(
"GroupKey");
5958 __SUP_COUT__ <<
"\t\t groupKey: " << groupKey <<
" vs "
5959 << configView->getDataView()[row][col] << __E__;
5960 if(groupKey.toString() != configView->getDataView()[row][col])
5962 configView->setValue(groupKey.toString(), row, col);
5968 configView->setValue(author, row, configView->findCol(
"Author"));
5969 configView->setValue(
5970 time(0), row, configView->findCol(
"RecordInsertionTime"));
5975 __SUP_COUT_ERR__ <<
"Error editing Group Alias view!" << __E__;
5978 config->eraseView(temporaryVersion);
5982 TableVersion newAssignedVersion;
5985 __SUP_COUT__ <<
"\t\t**************************** Save as new table version"
5993 newAssignedVersion = saveModifiedVersionXML(xmlOut,
5995 config->getTableName(),
6006 <<
"\t\t**************************** Using the existing table version"
6010 config->eraseView(temporaryVersion);
6011 newAssignedVersion = activeVersions[groupAliasesTableName];
6013 xmlOut.addTextElementToData(
"savedName", groupAliasesTableName);
6014 xmlOut.addTextElementToData(
"savedVersion", newAssignedVersion.toString());
6017 __SUP_COUT__ <<
"\t\t newAssignedVersion: " << newAssignedVersion << __E__;
6019 catch(std::runtime_error& e)
6021 __SUP_COUT_ERR__ <<
"Error detected!\n\n " << e.what() << __E__;
6022 xmlOut.addTextElementToData(
6023 "Error",
"Error saving new Group Alias view!\n " + std::string(e.what()));
6027 __SUP_COUT_ERR__ <<
"Error detected!\n\n " << __E__;
6028 xmlOut.addTextElementToData(
"Error",
"Error saving new Group Alias view! ");
6039 void ConfigurationGUISupervisor::handleSetVersionAliasInBackboneXML(
6040 HttpXmlDocument& xmlOut,
6041 ConfigurationManagerRW* cfgMgr,
6042 const std::string& versionAlias,
6043 const std::string& tableName,
6044 TableVersion version,
6045 const std::string& author)
try
6047 cfgMgr->loadConfigurationBackbone();
6048 std::map<std::string, TableVersion> activeVersions = cfgMgr->getActiveVersions();
6050 const std::string versionAliasesTableName =
6051 ConfigurationManager::VERSION_ALIASES_TABLE_NAME;
6052 if(activeVersions.find(versionAliasesTableName) == activeVersions.end())
6054 __SUP_SS__ <<
"Active version of " << versionAliasesTableName <<
" missing!"
6056 xmlOut.addTextElementToData(
"Error", ss.str());
6061 const std::set<std::string> backboneMembers = cfgMgr->getBackboneMemberNames();
6062 for(
auto& memberName : backboneMembers)
6064 __SUP_COUT__ <<
"activeVersions[\"" << memberName
6065 <<
"\"]=" << activeVersions[memberName] << __E__;
6067 xmlOut.addTextElementToData(
"oldBackboneName", memberName);
6068 xmlOut.addTextElementToData(
"oldBackboneVersion",
6069 activeVersions[memberName].toString());
6076 TableBase* config = cfgMgr->getTableByName(versionAliasesTableName);
6077 TableVersion originalVersion = activeVersions[versionAliasesTableName];
6078 TableVersion temporaryVersion = config->createTemporaryView(originalVersion);
6080 __SUP_COUT__ <<
"\t\t temporaryVersion: " << temporaryVersion << __E__;
6082 bool isDifferent =
false;
6086 TableView* configView = config->getTemporaryView(temporaryVersion);
6089 unsigned int col2 = configView->findCol(
"VersionAlias");
6090 unsigned int col3 = configView->findCol(
"TableName");
6094 unsigned int row = -1;
6099 unsigned int tmpRow = -1;
6102 tmpRow = configView->findRow(col3, tableName, tmpRow + 1);
6103 }
while(configView->getDataView()[tmpRow][col2] != versionAlias);
6110 if(row == (
unsigned int)-1)
6113 row = configView->addRow();
6116 col = configView->findCol(
"CommentDescription");
6117 configView->setValue(
6118 std::string(
"Entry was added by server in ") +
6119 "ConfigurationGUISupervisor::setVersionAliasInActiveBackbone().",
6123 col = configView->findCol(
"VersionAliasUID");
6124 configView->setValue(
6125 tableName.substr(0, tableName.rfind(
"Table")) + versionAlias, row, col);
6127 configView->setValue(versionAlias, row, col2);
6128 configView->setValue(tableName, row, col3);
6131 __SUP_COUT__ <<
"\t\t row: " << row << __E__;
6133 col = configView->findCol(
"Version");
6134 __SUP_COUT__ <<
"\t\t version: " << version <<
" vs "
6135 << configView->getDataView()[row][col] << __E__;
6136 if(version.toString() != configView->getDataView()[row][col])
6138 configView->setValue(version.toString(), row, col);
6144 configView->setValue(author, row, configView->findCol(
"Author"));
6145 configView->setValue(
6146 time(0), row, configView->findCol(
"RecordInsertionTime"));
6151 __SUP_COUT_ERR__ <<
"Error editing Version Alias view!" << __E__;
6154 config->eraseView(temporaryVersion);
6158 TableVersion newAssignedVersion;
6161 __SUP_COUT__ <<
"\t\t**************************** Save as new table version"
6167 newAssignedVersion = saveModifiedVersionXML(xmlOut,
6169 config->getTableName(),
6179 __SUP_COUT__ <<
"\t\t**************************** Using existing table version"
6183 config->eraseView(temporaryVersion);
6184 newAssignedVersion = activeVersions[versionAliasesTableName];
6186 xmlOut.addTextElementToData(
"savedAlias", versionAliasesTableName);
6187 xmlOut.addTextElementToData(
"savedVersion", newAssignedVersion.toString());
6190 __SUP_COUT__ <<
"\t\t newAssignedVersion: " << newAssignedVersion << __E__;
6192 catch(std::runtime_error& e)
6194 __SUP_COUT__ <<
"Error detected!\n\n " << e.what() << __E__;
6195 xmlOut.addTextElementToData(
6196 "Error",
"Error saving new Version Alias view!\n " + std::string(e.what()));
6200 __SUP_COUT__ <<
"Error detected!\n\n " << __E__;
6201 xmlOut.addTextElementToData(
"Error",
"Error saving new Version Alias view! ");
6210 void ConfigurationGUISupervisor::handleAliasGroupMembersInBackboneXML(
6211 HttpXmlDocument& xmlOut,
6212 ConfigurationManagerRW* cfgMgr,
6213 const std::string& versionAlias,
6214 const std::string& groupName,
6215 TableGroupKey groupKey,
6216 const std::string& author)
try
6218 cfgMgr->loadConfigurationBackbone();
6219 std::map<std::string, TableVersion> activeVersions = cfgMgr->getActiveVersions();
6221 const std::string versionAliasesTableName =
6222 ConfigurationManager::VERSION_ALIASES_TABLE_NAME;
6223 if(activeVersions.find(versionAliasesTableName) == activeVersions.end())
6225 __SUP_SS__ <<
"Active version of " << versionAliasesTableName <<
" missing!"
6227 xmlOut.addTextElementToData(
"Error", ss.str());
6232 const std::set<std::string> backboneMembers = cfgMgr->getBackboneMemberNames();
6233 for(
auto& memberName : backboneMembers)
6235 __SUP_COUT__ <<
"activeVersions[\"" << memberName
6236 <<
"\"]=" << activeVersions[memberName] << __E__;
6238 xmlOut.addTextElementToData(
"oldBackboneName", memberName);
6239 xmlOut.addTextElementToData(
"oldBackboneVersion",
6240 activeVersions[memberName].toString());
6247 TableBase* config = cfgMgr->getTableByName(versionAliasesTableName);
6248 TableVersion temporaryVersion =
6249 config->createTemporaryView(activeVersions[versionAliasesTableName]);
6251 __SUP_COUT__ <<
"\t\t temporaryVersion: " << temporaryVersion << __E__;
6253 TableView* configView = config->getTemporaryView(temporaryVersion);
6256 bool isDifferent =
false;
6259 std::map<std::string , TableVersion > memberMap;
6262 cfgMgr->loadTableGroup(groupName,
6275 xmlOut.addTextElementToData(
6277 "Table group \"" + TableGroupKey::getFullGroupString(groupName, groupKey) +
6278 "\" can not be retrieved!");
6283 unsigned int col2 = configView->findCol(
"VersionAlias");
6284 unsigned int col3 = configView->findCol(
"TableName");
6286 for(
auto& memberPair : memberMap)
6288 bool thisMemberIsDifferent =
false;
6289 unsigned int row = -1;
6291 __SUP_COUT__ <<
"Adding alias for " << memberPair.first <<
"_v"
6292 << memberPair.second << __E__;
6298 unsigned int tmpRow = -1;
6301 tmpRow = configView->findRow(col3, memberPair.first, tmpRow + 1);
6302 __SUP_COUT__ << configView->getDataView()[tmpRow][col2] << __E__;
6303 }
while(configView->getDataView()[tmpRow][col2] != versionAlias);
6310 if(row == (
unsigned int)-1)
6312 thisMemberIsDifferent =
true;
6313 row = configView->addRow();
6316 col = configView->findCol(
"CommentDescription");
6317 configView->setValue(
6318 std::string(
"Entry was added by server in ") +
6319 "ConfigurationGUISupervisor::setVersionAliasInActiveBackbone().",
6323 col = configView->getColUID();
6324 configView->setValue(
6325 memberPair.first.substr(0, memberPair.first.rfind(
"Table")) +
6330 configView->setValue(versionAlias, row, col2);
6331 configView->setValue(memberPair.first, row, col3);
6334 __SUP_COUT__ <<
"\t\t row: " << row << __E__;
6336 col = configView->findCol(
"Version");
6337 __SUP_COUT__ <<
"\t\t col: " << col << __E__;
6338 __SUP_COUT__ <<
"\t\t version: " << memberPair.second <<
" vs "
6339 << configView->getDataView()[row][col] << __E__;
6340 if(memberPair.second.toString() != configView->getDataView()[row][col])
6342 configView->setValue(memberPair.second.toString(), row, col);
6343 thisMemberIsDifferent =
true;
6346 if(thisMemberIsDifferent)
6348 configView->setValue(author, row, configView->findCol(
"Author"));
6349 configView->setValue(
6350 time(0), row, configView->findCol(
"RecordInsertionTime"));
6353 if(thisMemberIsDifferent)
6359 TableVersion newAssignedVersion;
6362 __SUP_COUT__ <<
"\t\t**************************** Save as new table version"
6365 newAssignedVersion =
6366 cfgMgr->saveNewTable(versionAliasesTableName, temporaryVersion);
6370 __SUP_COUT__ <<
"\t\t**************************** Using existing table version"
6374 config->eraseView(temporaryVersion);
6375 newAssignedVersion = activeVersions[versionAliasesTableName];
6378 xmlOut.addTextElementToData(
"savedAlias", versionAliasesTableName);
6379 xmlOut.addTextElementToData(
"savedVersion", newAssignedVersion.toString());
6380 __SUP_COUT__ <<
"\t\t newAssignedVersion: " << newAssignedVersion << __E__;
6382 catch(std::runtime_error& e)
6384 __SUP_COUT__ <<
"Error detected!\n\n " << e.what() << __E__;
6385 xmlOut.addTextElementToData(
6386 "Error",
"Error saving new Version Alias view!\n " + std::string(e.what()));
6390 __SUP_COUT__ <<
"Error detected!\n\n " << __E__;
6391 xmlOut.addTextElementToData(
"Error",
"Error saving new Version Alias view! ");
6405 void ConfigurationGUISupervisor::handleGroupAliasesXML(HttpXmlDocument& xmlOut,
6406 ConfigurationManagerRW* cfgMgr)
6408 cfgMgr->loadConfigurationBackbone();
6409 std::map<std::string, TableVersion> activeVersions = cfgMgr->getActiveVersions();
6411 std::string groupAliasesTableName = ConfigurationManager::GROUP_ALIASES_TABLE_NAME;
6412 if(activeVersions.find(groupAliasesTableName) == activeVersions.end())
6414 __SUP_SS__ <<
"\nActive version of " << groupAliasesTableName <<
" missing! "
6415 << groupAliasesTableName
6416 <<
" is a required member of the Backbone table group."
6417 <<
"\n\nLikely you need to activate a valid Backbone table group."
6419 xmlOut.addTextElementToData(
"Error", ss.str());
6422 __SUP_COUT__ <<
"activeVersions[\"" << groupAliasesTableName
6423 <<
"\"]=" << activeVersions[groupAliasesTableName] << __E__;
6424 xmlOut.addTextElementToData(
"GroupAliasesTableName", groupAliasesTableName);
6425 xmlOut.addTextElementToData(
"GroupAliasesTableVersion",
6426 activeVersions[groupAliasesTableName].toString());
6428 std::vector<std::pair<std::string, ConfigurationTree>> aliasNodePairs =
6429 cfgMgr->getNode(groupAliasesTableName).getChildren();
6431 std::string groupName, groupKey, groupComment, groupType;
6432 for(
auto& aliasNodePair : aliasNodePairs)
6434 groupName = aliasNodePair.second.getNode(
"GroupName").getValueAsString();
6435 groupKey = aliasNodePair.second.getNode(
"GroupKey").getValueAsString();
6437 xmlOut.addTextElementToData(
"GroupAlias", aliasNodePair.first);
6438 xmlOut.addTextElementToData(
"GroupName", groupName);
6439 xmlOut.addTextElementToData(
"GroupKey", groupKey);
6440 xmlOut.addTextElementToData(
6442 aliasNodePair.second.getNode(
"CommentDescription").getValueAsString());
6446 groupType =
"Invalid";
6449 cfgMgr->loadTableGroup(groupName,
6450 TableGroupKey(groupKey),
6463 __SUP_COUT_WARN__ <<
"Failed to load group '" << groupName <<
"(" << groupKey
6464 <<
")' to extract group comment and type." << __E__;
6466 xmlOut.addTextElementToData(
"GroupComment", groupComment);
6467 xmlOut.addTextElementToData(
"GroupType", groupType);
6482 void ConfigurationGUISupervisor::handleVersionAliasesXML(HttpXmlDocument& xmlOut,
6483 ConfigurationManagerRW* cfgMgr)
6485 cfgMgr->loadConfigurationBackbone();
6486 std::map<std::string, TableVersion> activeVersions = cfgMgr->getActiveVersions();
6488 std::string versionAliasesTableName =
6489 ConfigurationManager::VERSION_ALIASES_TABLE_NAME;
6490 if(activeVersions.find(versionAliasesTableName) == activeVersions.end())
6492 __SUP_SS__ <<
"Active version of VersionAliases missing!"
6493 <<
"Make sure you have a valid active Backbone Group." << __E__;
6494 xmlOut.addTextElementToData(
"Error", ss.str());
6497 __SUP_COUT__ <<
"activeVersions[\"" << versionAliasesTableName
6498 <<
"\"]=" << activeVersions[versionAliasesTableName] << __E__;
6499 xmlOut.addTextElementToData(
"VersionAliasesVersion",
6500 activeVersions[versionAliasesTableName].toString());
6502 std::vector<std::pair<std::string, ConfigurationTree>> aliasNodePairs =
6503 cfgMgr->getNode(versionAliasesTableName).getChildren();
6505 for(
auto& aliasNodePair : aliasNodePairs)
6509 xmlOut.addTextElementToData(
6511 aliasNodePair.second.getNode(
"VersionAlias").getValueAsString());
6512 xmlOut.addTextElementToData(
6513 "TableName", aliasNodePair.second.getNode(
"TableName").getValueAsString());
6514 xmlOut.addTextElementToData(
6515 "Version", aliasNodePair.second.getNode(
"Version").getValueAsString());
6516 xmlOut.addTextElementToData(
6518 aliasNodePair.second.getNode(
"CommentDescription").getValueAsString());
6528 void ConfigurationGUISupervisor::handleGetTableGroupTypeXML(
6529 HttpXmlDocument& xmlOut,
6530 ConfigurationManagerRW* cfgMgr,
6531 const std::string& tableList)
6533 std::map<std::string , TableVersion > memberMap;
6534 std::string name, versionStr;
6535 auto c = tableList.find(
',', 0);
6538 while(c < tableList.length())
6541 name = tableList.substr(i, c - i);
6543 c = tableList.find(
',', i);
6544 if(c == std::string::npos)
6546 __SUP_SS__ <<
"Incomplete Table Name-Version pair!" << __E__;
6547 __SUP_COUT_ERR__ <<
"\n" << ss.str();
6548 xmlOut.addTextElementToData(
"Error", ss.str());
6552 versionStr = tableList.substr(i, c - i);
6554 c = tableList.find(
',', i);
6556 memberMap[name] = TableVersion(versionStr);
6559 std::string groupTypeString =
"";
6564 groupTypeString = cfgMgr->getTypeNameOfGroup(memberMap);
6565 xmlOut.addTextElementToData(
"TableGroupType", groupTypeString);
6567 catch(std::runtime_error& e)
6569 __SUP_SS__ <<
"Table group has invalid type! " << e.what() << __E__;
6570 __SUP_COUT__ <<
"\n" << ss.str();
6571 groupTypeString =
"Invalid";
6572 xmlOut.addTextElementToData(
"TableGroupType", groupTypeString);
6576 __SUP_SS__ <<
"Table group has invalid type! " << __E__;
6577 __SUP_COUT__ <<
"\n" << ss.str();
6578 groupTypeString =
"Invalid";
6579 xmlOut.addTextElementToData(
"TableGroupType", groupTypeString);
6599 void ConfigurationGUISupervisor::handleTableGroupsXML(HttpXmlDocument& xmlOut,
6600 ConfigurationManagerRW* cfgMgr,
6603 DOMElement* parentEl;
6607 if(!cfgMgr->getAllGroupInfo()
6610 __SUP_COUT__ <<
"Cache is empty? Attempting to regenerate." << __E__;
6611 cfgMgr->getAllTableInfo(
true );
6614 const std::map<std::string, GroupInfo>& allGroupInfo = cfgMgr->getAllGroupInfo();
6634 TableGroupKey groupKey;
6635 std::string groupName;
6636 std::string groupString, groupTypeString, groupComment, groupCreationTime,
6638 for(
auto& groupInfo : allGroupInfo)
6640 groupName = groupInfo.first;
6641 if(groupInfo.second.keys_.size() == 0)
6643 __SUP_COUT__ <<
"Group name '" << groupName
6644 <<
"' found, but no keys so ignoring." << __E__;
6648 groupKey = *(groupInfo.second.keys_.rbegin());
6650 xmlOut.addTextElementToData(
"TableGroupName", groupName);
6651 xmlOut.addTextElementToData(
"TableGroupKey", groupKey.toString());
6654 xmlOut.addTextElementToData(
"TableGroupType",
6655 groupInfo.second.latestKeyGroupTypeString_);
6656 xmlOut.addTextElementToData(
"TableGroupComment",
6657 groupInfo.second.latestKeyGroupComment_);
6658 xmlOut.addTextElementToData(
"TableGroupAuthor",
6659 groupInfo.second.latestKeyGroupAuthor_);
6660 xmlOut.addTextElementToData(
"TableGroupCreationTime",
6661 groupInfo.second.latestKeyGroupCreationTime_);
6674 parentEl = xmlOut.addTextElementToData(
"TableGroupMembers",
"");
6714 for(
auto& memberPair : groupInfo.second.latestKeyMemberMap_)
6718 xmlOut.addTextElementToParent(
"MemberName", memberPair.first, parentEl);
6719 xmlOut.addTextElementToParent(
6720 "MemberVersion", memberPair.second.toString(), parentEl);
6726 for(
auto& keyInSet : groupInfo.second.keys_)
6728 if(keyInSet == groupKey)
6730 xmlOut.addTextElementToData(
"TableGroupName", groupName);
6731 xmlOut.addTextElementToData(
"TableGroupKey", keyInSet.toString());
6734 xmlOut.addTextElementToData(
"TableGroupType",
6735 groupInfo.second.latestKeyGroupTypeString_);
6736 xmlOut.addTextElementToData(
"TableGroupComment",
6737 groupInfo.second.latestKeyGroupComment_);
6738 xmlOut.addTextElementToData(
"TableGroupAuthor",
6739 groupInfo.second.latestKeyGroupAuthor_);
6740 xmlOut.addTextElementToData(
"TableGroupCreationTime",
6741 groupInfo.second.latestKeyGroupCreationTime_);
6745 xmlOut.addTextElementToData(
"TableGroupMembers",
"");
6748 bool loadingHistoricalInfo =
false;
6749 if(loadingHistoricalInfo)
6754 cfgMgr->loadTableGroup(groupName,
6768 groupTypeString =
"Invalid";
6770 <<
"Failed to load group '" << groupName <<
"(" << keyInSet
6771 <<
")' to extract group comment and type." << __E__;
6774 xmlOut.addTextElementToData(
"TableGroupType", groupTypeString);
6775 xmlOut.addTextElementToData(
"TableGroupComment", groupComment);
6776 xmlOut.addTextElementToData(
"TableGroupAuthor", groupAuthor);
6777 xmlOut.addTextElementToData(
"TableGroupCreationTime",
6798 void ConfigurationGUISupervisor::handleTablesXML(HttpXmlDocument& xmlOut,
6799 ConfigurationManagerRW* cfgMgr,
6800 bool allowIllegalColumns)
6802 DOMElement* parentEl;
6804 std::string accumulatedErrors =
"";
6805 const std::map<std::string, TableInfo>& allTableInfo = cfgMgr->getAllTableInfo(
6806 allowIllegalColumns,
6807 allowIllegalColumns ? &accumulatedErrors
6809 std::map<std::string, TableInfo>::const_iterator it = allTableInfo.begin();
6811 __SUP_COUT__ <<
"# of tables found: " << allTableInfo.size() << __E__;
6813 std::map<std::string, std::map<std::string, TableVersion>> versionAliases =
6814 cfgMgr->getVersionAliases();
6816 __SUP_COUT__ <<
"# of tables w/aliases: " << versionAliases.size() << __E__;
6818 while(it != allTableInfo.end())
6827 xmlOut.addTextElementToData(
"TableName", it->first);
6828 parentEl = xmlOut.addTextElementToData(
"TableVersions",
"");
6831 if(versionAliases.find(it->first) != versionAliases.end())
6832 for(
auto& aliasVersion : versionAliases[it->first])
6833 if(it->second.versions_.find(aliasVersion.second) !=
6834 it->second.versions_.end())
6838 xmlOut.addTextElementToParent(
6840 ConfigurationManager::ALIAS_VERSION_PREAMBLE + aliasVersion.first,
6858 for(
auto& version : it->second.versions_)
6859 if(!version.isScratchVersion())
6860 xmlOut.addTextElementToParent(
"Version", version.toString(), parentEl);
6865 if(accumulatedErrors !=
"")
6866 xmlOut.addTextElementToData(
6868 std::string(
"Column errors were allowed for this request, ") +
6869 "but please note the following errors:\n" + accumulatedErrors);
6875 void ConfigurationGUISupervisor::testXDAQContext()
6879 __SUP_COUT__ <<
"Attempting test activation of the context group." << __E__;
6880 ConfigurationManager cfgMgr;
6882 catch(
const std::runtime_error& e)
6885 <<
"The test activation of the context group failed. Ignoring error: \n"
6886 << e.what() << __E__;
6890 __SUP_COUT_WARN__ <<
"The test activation of the context group failed. Ignoring."
static xdaq::Application * instantiate(xdaq::ApplicationStub *s)