1 #include "otsdaq/CoreSupervisors/ConfigurationSupervisorBase.h"
3 #include "otsdaq/TablePlugins/XDAQContextTable.h"
11 std::map<std::string , std::pair<std::string ,
TableGroupKey>> activeGroupMap = cfgMgr->getActiveTableGroups();
13 for(
auto& type : activeGroupMap)
15 xmlOut.addTextElementToData(type.first +
"-ActiveGroupName", type.second.first);
16 xmlOut.addTextElementToData(type.first +
"-ActiveGroupKey", type.second.second.toString());
22 xmlOut.addTextElementToData(
"versionTracking", ConfigurationInterface::isVersionTrackingEnabled() ?
"ON" :
"OFF");
34 void ConfigurationSupervisorBase::handleCreateTableXML(
HttpXmlDocument& xmlOut,
36 const std::string& tableName,
39 const std::string& data,
40 const int& dataOffset,
41 const std::string& author,
42 const std::string& comment,
44 bool lookForEquivalent)
try
53 if(!version.isInvalid())
58 cfgMgr->getVersionedTableByName(tableName, version);
67 TableBase* table = cfgMgr->getTableByName(tableName);
71 if(!version.isInvalid())
75 if(table->getViewP()->getDataColumnSize() != table->getMockupViewP()->getNumberOfColumns() || table->getViewP()->getSourceColumnMismatch() != 0)
77 __COUT__ <<
"table->getViewP()->getNumberOfColumns() " << table->getViewP()->getNumberOfColumns() << __E__;
78 __COUT__ <<
"table->getMockupViewP()->getNumberOfColumns() " << table->getMockupViewP()->getNumberOfColumns() << __E__;
79 __COUT__ <<
"table->getViewP()->getSourceColumnMismatch() " << table->getViewP()->getSourceColumnMismatch() << __E__;
80 __COUT_INFO__ <<
"Source view v" << version <<
" has a mismatch in the number of columns, so using mockup as source." << __E__;
86 TableVersion temporaryVersion = table->createTemporaryView(version);
88 __COUT__ <<
"\t\ttemporaryVersion: " << temporaryVersion << __E__;
90 TableView* cfgView = table->getTemporaryView(temporaryVersion);
96 retVal = sourceTableAsIs ? 0 : cfgView->fillFromCSV(data, dataOffset, author);
100 __COUT__ <<
"Data was the same, but columns have changed!" << __E__;
101 __COUTV__(sourceTableAsIs);
102 __COUTV__(lookForEquivalent);
105 cfgView->setURIEncodedComment(comment);
106 __COUT__ <<
"Table comment was set to:\n\t" << cfgView->getComment() << __E__;
110 __COUT__ <<
"Caught error while editing. Erasing temporary version." << __E__;
111 table->eraseView(temporaryVersion);
121 if(retVal < 0 && (!version.isTemporaryVersion() || makeTemporary) && ConfigurationInterface::isVersionTrackingEnabled())
123 if(!version.isInvalid() &&
125 !version.isScratchVersion())
128 __SS__ <<
"No rows were modified! No reason to fill a view with same content." << __E__;
129 __COUT_ERR__ <<
"\n" << ss.str();
131 table->eraseView(temporaryVersion);
134 else if(version.isInvalid())
135 __COUT__ <<
"This was interpreted as an attempt to create a blank table." << __E__;
136 else if(version.isScratchVersion())
137 __COUT__ <<
"This was interpreted as an attempt to make a persistent "
138 "version of the scratch table."
143 __THROW__(ss.str() +
"impossible!");
146 else if(retVal < 0 && (version.isTemporaryVersion() && !makeTemporary))
148 __COUT__ <<
"Allowing the static data because this is converting from "
149 "temporary to persistent version."
152 else if(retVal < 0 && !ConfigurationInterface::isVersionTrackingEnabled())
154 __COUT__ <<
"Allowing the static data because version tracking is OFF." << __E__;
158 __SS__ <<
"This should not be possible! Fatal error." << __E__;
160 table->eraseView(temporaryVersion);
165 ConfigurationSupervisorBase::saveModifiedVersionXML(xmlOut,
173 lookForEquivalent || sourceTableAsIs );
175 catch(std::runtime_error& e)
177 __COUT__ <<
"Error detected!\n\n " << e.what() << __E__;
178 xmlOut.addTextElementToData(
"Error",
"Error saving new view!\n " + std::string(e.what()));
182 __COUT__ <<
"Error detected!\n\n " << __E__;
183 xmlOut.addTextElementToData(
"Error",
"Error saving new view! ");
193 const std::string& tableName,
198 bool ignoreDuplicates,
199 bool lookForEquivalent)
201 bool foundEquivalent;
202 TableVersion newAssignedVersion = cfgMgr->saveModifiedVersion(
203 tableName, originalVersion, makeTemporary, table, temporaryModifiedVersion, ignoreDuplicates, lookForEquivalent, &foundEquivalent);
205 xmlOut.addTextElementToData(
"savedName", tableName);
206 xmlOut.addTextElementToData(
"savedVersion", newAssignedVersion.toString());
212 xmlOut.addTextElementToData(
"foundEquivalentVersion",
"1");
213 xmlOut.addTextElementToData(tableName +
"_foundEquivalentVersion",
"1");
215 return newAssignedVersion;
358 void ConfigurationSupervisorBase::handleCreateTableGroupXML(
HttpXmlDocument& xmlOut,
360 const std::string& groupName,
361 const std::string& tableList,
362 bool allowDuplicates,
364 const std::string& groupComment,
365 bool lookForEquivalent)
try
367 __COUT__ <<
"handleCreateTableGroupXML \n";
369 xmlOut.addTextElementToData(
"AttemptedNewGroupName", groupName);
373 std::string accumulatedWarnings;
374 const std::map<std::string, TableInfo>& allTableInfo = cfgMgr->getAllTableInfo(
true, &accumulatedWarnings);
375 __COUT_WARN__ <<
"Ignoring these errors: " << accumulatedWarnings << __E__;
376 cfgMgr->loadConfigurationBackbone();
378 std::map<std::string , std::map<std::string ,
TableVersion >> versionAliases = cfgMgr->getVersionAliases();
385 std::map<std::string , std::string > groupAliases;
387 std::string name, versionStr, alias;
389 auto c = tableList.find(
',', 0);
392 while(c < tableList.length())
395 name = tableList.substr(i, c - i);
397 c = tableList.find(
',', i);
398 if(c == std::string::npos)
400 __SS__ <<
"Incomplete Table Name-Version pair!" << __E__;
401 __COUT_ERR__ <<
"\n" << ss.str();
402 xmlOut.addTextElementToData(
"Error", ss.str());
406 versionStr = tableList.substr(i, c - i);
408 c = tableList.find(
',', i);
414 if(versionStr.find(ConfigurationManager::ALIAS_VERSION_PREAMBLE) == 0)
416 alias = versionStr.substr(ConfigurationManager::ALIAS_VERSION_PREAMBLE.size());
418 __COUT__ <<
"Found alias " << name <<
" " << versionStr << __E__;
421 if(versionAliases.find(name) != versionAliases.end() && versionAliases[name].find(alias) != versionAliases[name].end())
423 version = versionAliases[name][alias];
424 __COUT__ <<
"version alias '" << alias <<
"'translated to: " << version << __E__;
426 groupAliases[name] = alias;
430 __SS__ <<
"version alias '" << versionStr.substr(ConfigurationManager::ALIAS_VERSION_PREAMBLE.size())
431 <<
"' was not found in active version aliases!" << __E__;
432 __COUT_ERR__ <<
"\n" << ss.str();
433 xmlOut.addTextElementToData(
"Error", ss.str());
440 if(version.isTemporaryVersion())
442 __SS__ <<
"Groups can not be created using temporary member tables. "
443 <<
"Table member '" << name <<
"' with temporary version '" << version <<
"' is illegal." << __E__;
444 xmlOut.addTextElementToData(
"Error", ss.str());
449 if(allTableInfo.find(name) == allTableInfo.end())
451 __SS__ <<
"Groups can not be created using mock-up member tables of "
453 <<
"Table member '" << name <<
"' is not defined." << __E__;
454 xmlOut.addTextElementToData(
"Error", ss.str());
458 if(version.isMockupVersion())
461 TableBase* table = cfgMgr->getTableByName(name);
463 TableVersion temporaryVersion = table->createTemporaryView();
464 __COUT__ <<
"\t\ttemporaryVersion: " << temporaryVersion << __E__;
467 __COUT__ <<
"Creating version from mock-up for name: " << name <<
" inputVersionStr: " << versionStr << __E__;
470 table->getTemporaryView(temporaryVersion)->setComment(
"Auto-generated from mock-up.");
473 version = ConfigurationSupervisorBase::saveModifiedVersionXML(xmlOut,
483 __COUT__ <<
"Using mockup version: " << version << __E__;
487 groupMembers[name] = version;
490 __COUTV__(StringMacros::mapToString(groupAliases));
494 __COUT__ <<
"Checking for duplicate groups..." << __E__;
495 TableGroupKey foundKey = cfgMgr->findTableGroup(groupName, groupMembers, groupAliases);
497 if(!foundKey.isInvalid())
500 xmlOut.addTextElementToData(
"TableGroupName", groupName);
501 xmlOut.addTextElementToData(
"TableGroupKey", foundKey.toString());
503 if(lookForEquivalent)
505 __COUT__ <<
"Found equivalent group key (" << foundKey <<
") for " << groupName <<
"." << __E__;
507 xmlOut.addTextElementToData(
"foundEquivalentKey",
"1");
510 handleGetTableGroupXML(xmlOut, cfgMgr, groupName, foundKey, ignoreWarnings);
515 __COUT__ <<
"Treating duplicate group as error." << __E__;
516 __SS__ << (
"Failed to create table group: " + groupName +
". It is a duplicate of an existing group key (" + foundKey.toString() +
")");
517 __COUT_ERR__ << ss.str() << __E__;
518 xmlOut.addTextElementToData(
"Error", ss.str());
523 __COUT__ <<
"Check for duplicate groups complete." << __E__;
529 cfgMgr->loadMemberMap(groupMembers);
531 std::string accumulateErrors =
"";
532 for(
auto& groupMemberPair : groupMembers)
534 TableView* cfgViewPtr = cfgMgr->getTableByName(groupMemberPair.first)->getViewP();
535 if(cfgViewPtr->getDataColumnSize() != cfgViewPtr->getNumberOfColumns() ||
536 cfgViewPtr->getSourceColumnMismatch() != 0)
538 const std::set<std::string> srcColNames = cfgViewPtr->getSourceColumnNames();
539 __SS__ <<
"\n\nThere were errors found in loading a member table " << groupMemberPair.first <<
":v" << cfgViewPtr->getVersion()
540 <<
". Please see the details below:\n\n"
541 <<
"The source column size was found to be " << srcColNames.size() <<
", and the current number of columns for this table is "
542 << cfgViewPtr->getNumberOfColumns() <<
". This resulted in a count of " << cfgViewPtr->getSourceColumnMismatch()
543 <<
" source column mismatches, and a count of " << cfgViewPtr->getSourceColumnMissing() <<
" table entries missing in "
544 << cfgViewPtr->getNumberOfRows() <<
" row(s) of data." << __E__;
546 ss <<
"\n\nSource column names were as follows:\n";
548 for(
auto& srcColName : srcColNames)
549 ss <<
"\n\t" << index++ <<
". " << srcColName;
552 std::set<std::string> destColNames = cfgViewPtr->getColumnStorageNames();
553 ss <<
"\n\nCurrent table column names are as follows:\n";
555 for(
auto& destColName : destColNames)
556 ss <<
"\n\t" << index++ <<
". " << destColName;
559 __COUT_ERR__ <<
"\n" << ss.str();
560 xmlOut.addTextElementToData(
"Error", ss.str());
565 catch(std::runtime_error& e)
567 __SS__ <<
"Failed to create table group: " << groupName <<
".\nThere were problems loading the chosen members:\n\n" << e.what() << __E__;
568 __COUT_ERR__ <<
"\n" << ss.str();
569 xmlOut.addTextElementToData(
"Error", ss.str());
574 __SS__ <<
"Failed to create table group: " << groupName << __E__;
575 __COUT_ERR__ <<
"\n" << ss.str();
576 xmlOut.addTextElementToData(
"Error", ss.str());
581 std::string accumulateTreeErrs;
582 cfgMgr->getChildren(&groupMembers, &accumulateTreeErrs);
583 if(accumulateTreeErrs !=
"")
585 __COUT_WARN__ <<
"\n" << accumulateTreeErrs << __E__;
588 xmlOut.addTextElementToData(
"TreeErrors", accumulateTreeErrs);
596 __COUT__ <<
"Saving new group..." << __E__;
597 newKey = cfgMgr->saveNewTableGroup(groupName, groupMembers, groupComment, &groupAliases);
599 catch(std::runtime_error& e)
601 __COUT_ERR__ <<
"Failed to create table group: " << groupName << __E__;
602 __COUT_ERR__ <<
"\n\n" << e.what() << __E__;
603 xmlOut.addTextElementToData(
"Error",
"Failed to create table group: " + groupName +
".\n\n" + e.what());
608 __COUT_ERR__ <<
"Failed to create table group: " << groupName << __E__;
609 xmlOut.addTextElementToData(
"Error",
"Failed to create table group: " + groupName);
614 __COUT__ <<
"Loading new table group..." << __E__;
615 handleGetTableGroupXML(xmlOut, cfgMgr, groupName, newKey, ignoreWarnings);
618 catch(std::runtime_error& e)
620 __COUT__ <<
"Error detected!\n\n " << e.what() << __E__;
621 xmlOut.addTextElementToData(
"Error",
"Error saving table group! " + std::string(e.what()));
625 __COUT__ <<
"Unknown Error detected!\n\n " << __E__;
626 xmlOut.addTextElementToData(
"Error",
"Error saving table group! ");
652 void ConfigurationSupervisorBase::handleGetTableGroupXML(
656 xercesc::DOMElement *parentEl, *configEl;
679 const GroupInfo& groupInfo = cfgMgr->getGroupInfo(groupName);
680 const std::set<TableGroupKey>& sortedKeys = groupInfo.keys_;
682 if(groupKey.isInvalid() ||
683 sortedKeys.find(groupKey) == sortedKeys.end())
686 if(!groupKey.isInvalid())
689 std::string accumulatedWarnings;
690 cfgMgr->getAllTableInfo(
true, &accumulatedWarnings);
691 __COUT_WARN__ <<
"Attempting info refresh. Ignoring these errors: " << accumulatedWarnings << __E__;
693 __SS__ <<
"Group key " << groupKey <<
" was not found for group '" << groupName <<
"!'" << __E__;
696 ss <<
"Found keys: " << __E__;
697 for(
auto& key : sortedKeys)
698 ss <<
"\t" << key << __E__;
699 __COUT__ << ss.str() << __E__;
703 if(sortedKeys.size())
704 groupKey = *sortedKeys.rbegin();
705 __COUT__ <<
"Group key requested was invalid or not found, going with latest " << groupKey << __E__;
709 xmlOut.addTextElementToData(
"TableGroupName", groupName);
710 xmlOut.addTextElementToData(
"TableGroupKey", groupKey.toString());
713 for(
auto& keyInOrder : sortedKeys)
714 xmlOut.addTextElementToData(
"HistoricalTableGroupKey", keyInOrder.toString());
716 parentEl = xmlOut.addTextElementToData(
"TableGroupMembers",
"");
720 std::map<std::string , std::string > groupMemberAliases;
722 __COUT__ <<
"groupName=" << groupName << __E__;
723 __COUT__ <<
"groupKey=" << groupKey << __E__;
725 const std::map<std::string, TableInfo>& allTableInfo = cfgMgr->getAllTableInfo();
726 std::map<std::string, TableInfo>::const_iterator it;
732 std::string groupAuthor, groupComment, groupCreationTime, groupTypeString;
733 std::string accumulateTreeErrors;
735 __COUTV__(ignoreWarnings);
736 cfgMgr->loadTableGroup(groupName,
742 &accumulateTreeErrors,
748 &groupMemberAliases);
750 if(accumulateTreeErrors !=
"")
752 __COUTV__(accumulateTreeErrors);
753 xmlOut.addTextElementToData(
"TreeErrors", accumulateTreeErrors);
756 xmlOut.addTextElementToData(
"TableGroupAuthor", groupAuthor);
757 xmlOut.addTextElementToData(
"TableGroupComment", groupComment);
758 xmlOut.addTextElementToData(
"TableGroupCreationTime", groupCreationTime);
759 xmlOut.addTextElementToData(
"TableGroupType", groupTypeString);
761 catch(
const std::runtime_error& e)
763 __SS__ <<
"Table group \"" + groupName +
"(" + groupKey.toString() +
")" +
"\" members can not be loaded!\n\n" + e.what() << __E__;
764 __COUT_ERR__ << ss.str();
765 xmlOut.addTextElementToData(
"Error", ss.str());
770 __SS__ <<
"Table group \"" + groupName +
"(" + groupKey.toString() +
")" +
"\" members can not be loaded!" << __E__;
771 __COUT_ERR__ << ss.str();
772 xmlOut.addTextElementToData(
"Error", ss.str());
776 __COUTV__(StringMacros::mapToString(groupMemberAliases));
778 std::map<std::string, std::map<std::string, TableVersion>> versionAliases = cfgMgr->getVersionAliases();
780 __COUT__ <<
"# of table version aliases: " << versionAliases.size() << __E__;
783 for(
auto& memberPair : memberMap)
785 xmlOut.addTextElementToParent(
"MemberName", memberPair.first, parentEl);
788 if(groupMemberAliases.find(memberPair.first) != groupMemberAliases.end())
790 xmlOut.addTextElementToParent(
"MemberVersion",
791 ConfigurationManager::ALIAS_VERSION_PREAMBLE + groupMemberAliases[memberPair.first],
794 configEl = xmlOut.addTextElementToParent(
"MemberVersion", memberPair.second.toString(), parentEl);
796 it = allTableInfo.find(memberPair.first);
797 if(it == allTableInfo.end())
799 xmlOut.addTextElementToData(
"Error",
"Table \"" + memberPair.first +
"\" can not be retrieved!");
803 if(versionAliases.find(it->first) != versionAliases.end())
804 for(
auto& aliasVersion : versionAliases[it->first])
805 xmlOut.addTextElementToParent(
"TableExistingVersion", ConfigurationManager::ALIAS_VERSION_PREAMBLE + aliasVersion.first, configEl);
807 for(
auto& version : it->second.versions_)
810 xmlOut.addTextElementToParent(
"TableExistingVersion", version.toString(), configEl);
813 for(
auto& memberPair : memberMap)
820 xmlOut.addTextElementToParent(
"MemberComment", allTableInfo.at(memberPair.first).tablePtr_->getView().getComment(), parentEl);
856 catch(std::runtime_error& e)
858 __SS__ << (
"Error!\n\n" + std::string(e.what())) << __E__;
859 __COUT_ERR__ <<
"\n" << ss.str();
860 xmlOut.addTextElementToData(
"Error", ss.str());
864 __SS__ << (
"Error!\n\n") << __E__;
865 __COUT_ERR__ <<
"\n" << ss.str();
866 xmlOut.addTextElementToData(
"Error", ss.str());
870 bool ConfigurationSupervisorBase::handleAddDesktopIconXML(
HttpXmlDocument& xmlOut,
872 const std::string& iconCaption,
873 const std::string& iconAltText,
874 const std::string& iconFolderPath,
875 const std::string& iconImageURL,
876 const std::string& iconWindowURL,
877 const std::string& iconPermissions,
878 std::string windowLinkedApp ,
879 unsigned int windowLinkedAppLID ,
880 bool enforceOneWindowInstance ,
881 const std::string& windowParameters )
try
883 cfgMgr->getAllTableInfo(
true );
885 const std::string& author = cfgMgr->getUsername();
888 __COUTV__(iconCaption);
889 __COUTV__(iconAltText);
890 __COUTV__(iconFolderPath);
891 __COUTV__(iconImageURL);
892 __COUTV__(iconWindowURL);
893 __COUTV__(iconPermissions);
894 __COUTV__(windowLinkedApp);
895 __COUTV__(windowLinkedAppLID);
896 __COUTV__(enforceOneWindowInstance);
898 __COUTV__(windowParameters);
910 cfgMgr->restoreActiveTableGroups(
true ,
"" ,
true
913 const std::string backboneGroupName = cfgMgr->getActiveGroupName(ConfigurationManager::GroupType::BACKBONE_TYPE);
915 GroupEditStruct contextGroupEdit(ConfigurationManager::GroupType::CONTEXT_TYPE, cfgMgr);
924 TableEditStruct& iconTable = contextGroupEdit.getTableEditStruct(DesktopIconTable::ICON_TABLE,
true );
925 TableEditStruct& parameterTable = contextGroupEdit.getTableEditStruct(DesktopIconTable::PARAMETER_TABLE,
true );
926 TableEditStruct& appTable = contextGroupEdit.getTableEditStruct(ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME);
935 row = iconTable.tableView_->addRow(author,
true ,
"generatedIcon");
936 iconUID = iconTable.tableView_->getDataView()[row][iconTable.tableView_->getColUID()];
942 iconTable.tableView_->setValueAsString(
"1", row, iconTable.tableView_->getColStatus());
945 iconTable.tableView_->setURIEncodedValue(iconCaption, row, iconTable.tableView_->findCol(DesktopIconTable::COL_CAPTION));
947 iconTable.tableView_->setURIEncodedValue(iconAltText, row, iconTable.tableView_->findCol(DesktopIconTable::COL_ALTERNATE_TEXT));
949 iconTable.tableView_->setValueAsString(
950 enforceOneWindowInstance ?
"1" :
"0", row, iconTable.tableView_->findCol(DesktopIconTable::COL_FORCE_ONLY_ONE_INSTANCE));
952 iconTable.tableView_->setURIEncodedValue(iconPermissions, row, iconTable.tableView_->findCol(DesktopIconTable::COL_PERMISSIONS));
954 iconTable.tableView_->setURIEncodedValue(iconImageURL, row, iconTable.tableView_->findCol(DesktopIconTable::COL_IMAGE_URL));
956 iconTable.tableView_->setURIEncodedValue(iconWindowURL, row, iconTable.tableView_->findCol(DesktopIconTable::COL_WINDOW_CONTENT_URL));
958 iconTable.tableView_->setURIEncodedValue(iconFolderPath, row, iconTable.tableView_->findCol(DesktopIconTable::COL_FOLDER_PATH));
961 if(windowLinkedAppLID > 0)
963 __COUTV__(windowLinkedAppLID);
965 int appRow = appTable.tableView_->findRow(appTable.tableView_->findCol(XDAQContextTable::colApplication_.colId_), windowLinkedAppLID);
966 windowLinkedApp = appTable.tableView_->getDataView()[appRow][appTable.tableView_->getColUID()];
967 __COUT__ <<
"Found app by LID: " << windowLinkedApp << __E__;
970 if(windowLinkedApp !=
"" && windowLinkedApp !=
"undefined" && windowLinkedApp != TableViewColumnInfo::DATATYPE_STRING_DEFAULT)
975 __COUTV__(windowLinkedApp);
977 if(!windowLinkedAppLID)
981 windowLinkedApp = StringMacros::decodeURIComponent(windowLinkedApp);
982 appTable.tableView_->findRow(appTable.tableView_->getColUID(), windowLinkedApp);
984 catch(
const std::runtime_error& e)
989 int appRow = appTable.tableView_->findRow(appTable.tableView_->findCol(XDAQContextTable::colApplication_.colClass_), windowLinkedApp);
990 windowLinkedApp = appTable.tableView_->getDataView()[appRow][appTable.tableView_->getColUID()];
995 __SS__ <<
"Failed to create an icon linking to app '" << windowLinkedApp <<
".' The following error occurred: " << e.what() << __E__;
996 appTable.tableView_->print(ss);
1001 __COUTV__(windowLinkedApp);
1003 iconTable.tableView_->setValueAsString(
1004 ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME, row, iconTable.tableView_->findCol(DesktopIconTable::COL_APP_LINK));
1005 iconTable.tableView_->setValueAsString(windowLinkedApp, row, iconTable.tableView_->findCol(DesktopIconTable::COL_APP_LINK_UID));
1009 std::map<std::string, std::string> parameters;
1011 __COUTV__(windowParameters);
1012 StringMacros::getMapFromString(windowParameters, parameters);
1015 if(parameters.size())
1018 iconTable.tableView_->setValueAsString(DesktopIconTable::PARAMETER_TABLE, row, iconTable.tableView_->findCol(DesktopIconTable::COL_PARAMETER_LINK));
1020 iconTable.tableView_->setValueAsString(iconUID +
"_Parameters", row, iconTable.tableView_->findCol(DesktopIconTable::COL_PARAMETER_LINK_GID));
1022 __COUTV__(StringMacros::mapToString(parameters));
1024 unsigned int gidCol = parameterTable.tableView_->findCol(DesktopIconTable::COL_PARAMETER_GID);
1027 std::vector<
unsigned int > rowsInGroup = parameterTable.tableView_->getGroupRows(gidCol, iconUID +
"_Parameters" );
1029 __COUTV__(StringMacros::vectorToString(rowsInGroup));
1032 for(
unsigned int r = rowsInGroup.size() - 1; r < rowsInGroup.size(); --r)
1033 parameterTable.tableView_->removeRowFromGroup(rowsInGroup[r], gidCol, iconUID +
"_Parameters" ,
true );
1036 for(
const auto& parameter : parameters)
1039 row = parameterTable.tableView_->addRow(author,
true ,
"generatedParameter");
1042 parameterTable.tableView_->setValueAsString(
"1", row, parameterTable.tableView_->getColStatus());
1044 parameterTable.tableView_->setValueAsString(iconUID +
"_Parameters", row, gidCol);
1046 parameterTable.tableView_->setURIEncodedValue(parameter.first, row, parameterTable.tableView_->findCol(DesktopIconTable::COL_PARAMETER_KEY));
1048 parameterTable.tableView_->setURIEncodedValue(parameter.second, row, parameterTable.tableView_->findCol(DesktopIconTable::COL_PARAMETER_VALUE));
1051 std::stringstream ss;
1052 parameterTable.tableView_->print(ss);
1053 __COUT__ << ss.str();
1055 parameterTable.tableView_->init();
1059 std::stringstream ss;
1060 iconTable.tableView_->print(ss);
1061 __COUT__ << ss.str();
1063 iconTable.tableView_->init();
1067 __COUT__ <<
"Icon table errors while saving. Erasing all newly "
1068 "created table versions."
1074 __COUT__ <<
"Edits complete for new desktop icon, now making persistent tables." << __E__;
1087 bool foundEquivalentContextKey;
1089 bool foundEquivalentBackboneKey;
1091 contextGroupEdit.saveChanges(contextGroupEdit.originalGroupName_,
1093 &foundEquivalentContextKey,
1098 &foundEquivalentBackboneKey);
1100 xmlOut.addTextElementToData(
"contextGroupName", contextGroupEdit.originalGroupName_);
1101 xmlOut.addTextElementToData(
"contextGroupKey", newContextKey.toString());
1103 xmlOut.addTextElementToData(
"backboneGroupName", backboneGroupName);
1104 xmlOut.addTextElementToData(
"backboneGroupKey", newBackboneKey.toString());
1107 ConfigurationSupervisorBase::getConfigurationStatusXML(xmlOut, cfgMgr);
1115 std::map<std::string, TableVersion> contextGroupMembers;
1116 std::map<std::string, TableVersion> backboneGroupMembers;
1118 std::map<std::string, TableVersion> activeTables = cfgMgr->getActiveVersions();
1119 for(
auto& table : cfgMgr->getContextMemberNames())
1122 __COUT__ << table <<
" v" << activeTables.at(table) << __E__;
1123 contextGroupMembers[table] = activeTables.at(table);
1127 __SS__ <<
"Error! Could not find Context member table '" << table <<
".' All Context members must be present to add a desktop icon."
1131 for(
auto& table : cfgMgr->getBackboneMemberNames())
1134 __COUT__ << table <<
" v" << activeTables.at(table) << __E__;
1135 backboneGroupMembers[table] = activeTables.at(table);
1139 __SS__ <<
"Error! Could not find Backbone member table '" << table <<
".' All Backbone members must be present to add a desktop icon."
1145 const std::string contextGroupName = cfgMgr->getActiveGroupName(ConfigurationManager::GroupType::CONTEXT_TYPE);
1146 const TableGroupKey originalContextGroupKey = cfgMgr->getActiveGroupKey(ConfigurationManager::GroupType::CONTEXT_TYPE);
1147 const std::string backboneGroupName = cfgMgr->getActiveGroupName(ConfigurationManager::GroupType::BACKBONE_TYPE);
1148 const TableGroupKey originalBackboneGroupKey = cfgMgr->getActiveGroupKey(ConfigurationManager::GroupType::BACKBONE_TYPE);
1150 __COUTV__(contextGroupName);
1151 __COUTV__(originalContextGroupKey);
1152 __COUTV__(backboneGroupName);
1153 __COUTV__(originalBackboneGroupKey);
1155 if(contextGroupName ==
"" || originalContextGroupKey.isInvalid())
1157 __SS__ <<
"Error! No active Context group found. "
1158 "There must be an active Context group to add a Desktop Icon."
1174 TableEditStruct appTable(ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME,
1181 std::string iconUID;
1184 row = iconTable.tableView_->addRow(author,
true ,
"generatedIcon");
1185 iconUID = iconTable.tableView_->getDataView()[row][iconTable.tableView_->getColUID()];
1191 iconTable.tableView_->setValueAsString(
"1", row, iconTable.tableView_->getColStatus());
1194 iconTable.tableView_->setURIEncodedValue(iconCaption, row, iconTable.tableView_->findCol(DesktopIconTable::COL_CAPTION));
1196 iconTable.tableView_->setURIEncodedValue(iconAltText, row, iconTable.tableView_->findCol(DesktopIconTable::COL_ALTERNATE_TEXT));
1198 iconTable.tableView_->setValueAsString(
1199 enforceOneWindowInstance ?
"1" :
"0", row, iconTable.tableView_->findCol(DesktopIconTable::COL_FORCE_ONLY_ONE_INSTANCE));
1201 iconTable.tableView_->setURIEncodedValue(iconPermissions, row, iconTable.tableView_->findCol(DesktopIconTable::COL_PERMISSIONS));
1203 iconTable.tableView_->setURIEncodedValue(iconImageURL, row, iconTable.tableView_->findCol(DesktopIconTable::COL_IMAGE_URL));
1205 iconTable.tableView_->setURIEncodedValue(iconWindowURL, row, iconTable.tableView_->findCol(DesktopIconTable::COL_WINDOW_CONTENT_URL));
1207 iconTable.tableView_->setURIEncodedValue(iconFolderPath, row, iconTable.tableView_->findCol(DesktopIconTable::COL_FOLDER_PATH));
1210 if(windowLinkedAppLID > 0)
1212 __COUTV__(windowLinkedAppLID);
1214 int appRow = appTable.tableView_->findRow(appTable.tableView_->findCol(XDAQContextTable::colApplication_.colId_), windowLinkedAppLID);
1215 windowLinkedApp = appTable.tableView_->getDataView()[appRow][appTable.tableView_->getColUID()];
1216 __COUT__ <<
"Found app by LID: " << windowLinkedApp << __E__;
1219 if(windowLinkedApp !=
"" && windowLinkedApp !=
"undefined" && windowLinkedApp != TableViewColumnInfo::DATATYPE_STRING_DEFAULT)
1224 __COUTV__(windowLinkedApp);
1226 if(!windowLinkedAppLID)
1230 appTable.tableView_->findRow(appTable.tableView_->getColUID(), windowLinkedApp);
1232 catch(
const std::runtime_error& e)
1238 appTable.tableView_->findRow(appTable.tableView_->findCol(XDAQContextTable::colApplication_.colClass_), windowLinkedApp);
1239 windowLinkedApp = appTable.tableView_->getDataView()[appRow][appTable.tableView_->getColUID()];
1244 __SS__ <<
"Failed to create an icon linking to app '" << windowLinkedApp <<
".' The following error occurred: " << e.what()
1250 __COUTV__(windowLinkedApp);
1252 iconTable.tableView_->setValueAsString(
1253 ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME, row, iconTable.tableView_->findCol(DesktopIconTable::COL_APP_LINK));
1254 iconTable.tableView_->setValueAsString(windowLinkedApp, row, iconTable.tableView_->findCol(DesktopIconTable::COL_APP_LINK_UID));
1258 std::map<std::string, std::string> parameters;
1260 __COUTV__(windowParameters);
1261 StringMacros::getMapFromString(windowParameters, parameters);
1264 if(parameters.size())
1267 iconTable.tableView_->setValueAsString(
1268 DesktopIconTable::PARAMETER_TABLE, row, iconTable.tableView_->findCol(DesktopIconTable::COL_PARAMETER_LINK));
1270 iconTable.tableView_->setValueAsString(iconUID +
"_Parameters", row, iconTable.tableView_->findCol(DesktopIconTable::COL_PARAMETER_LINK_GID));
1272 __COUTV__(StringMacros::mapToString(parameters));
1274 for(
const auto& parameter : parameters)
1277 row = parameterTable.tableView_->addRow(author,
true ,
"generatedParameter");
1280 parameterTable.tableView_->setValueAsString(
"1", row, parameterTable.tableView_->getColStatus());
1282 parameterTable.tableView_->setValueAsString(
1283 iconUID +
"_Parameters", row, parameterTable.tableView_->findCol(DesktopIconTable::COL_PARAMETER_GID));
1285 parameterTable.tableView_->setURIEncodedValue(
1286 parameter.first, row, parameterTable.tableView_->findCol(DesktopIconTable::COL_PARAMETER_KEY));
1288 parameterTable.tableView_->setURIEncodedValue(
1289 parameter.second, row, parameterTable.tableView_->findCol(DesktopIconTable::COL_PARAMETER_VALUE));
1292 std::stringstream ss;
1293 parameterTable.tableView_->print(ss);
1294 __COUT__ << ss.str();
1296 parameterTable.tableView_->init();
1300 std::stringstream ss;
1301 iconTable.tableView_->print(ss);
1302 __COUT__ << ss.str();
1304 iconTable.tableView_->init();
1308 __COUT__ <<
"Icon table errors while saving. Erasing all newly "
1309 "created table versions."
1311 if(iconTable.createdTemporaryVersion_)
1313 __COUT__ <<
"Erasing temporary version " << iconTable.tableName_ <<
"-v" << iconTable.temporaryVersion_ << __E__;
1315 cfgMgr->eraseTemporaryVersion(iconTable.tableName_, iconTable.temporaryVersion_);
1318 if(parameterTable.createdTemporaryVersion_)
1320 __COUT__ <<
"Erasing temporary version " << parameterTable.tableName_ <<
"-v" << parameterTable.temporaryVersion_ << __E__;
1322 cfgMgr->eraseTemporaryVersion(parameterTable.tableName_, parameterTable.temporaryVersion_);
1325 if(appTable.createdTemporaryVersion_)
1327 __COUT__ <<
"Erasing temporary version " << appTable.tableName_ <<
"-v" << appTable.temporaryVersion_ << __E__;
1329 cfgMgr->eraseTemporaryVersion(appTable.tableName_, appTable.temporaryVersion_);
1335 __COUT__ <<
"Edits complete for new desktop icon, now making persistent tables." << __E__;
1347 __COUT__ <<
"Original version is " << iconTable.tableName_ <<
"-v" << iconTable.originalVersion_ << __E__;
1348 __COUT__ <<
"Original version is " << parameterTable.tableName_ <<
"-v" << parameterTable.originalVersion_ << __E__;
1350 contextGroupMembers[DesktopIconTable::ICON_TABLE] =
1351 ConfigurationSupervisorBase::saveModifiedVersionXML(xmlOut,
1353 iconTable.tableName_,
1354 iconTable.originalVersion_,
1357 iconTable.temporaryVersion_,
1359 contextGroupMembers[DesktopIconTable::PARAMETER_TABLE] =
1360 ConfigurationSupervisorBase::saveModifiedVersionXML(xmlOut,
1362 parameterTable.tableName_,
1363 parameterTable.originalVersion_,
1365 parameterTable.table_,
1366 parameterTable.temporaryVersion_,
1369 __COUT__ <<
"Temporary target version is " << iconTable.tableName_ <<
"-v" << contextGroupMembers[DesktopIconTable::ICON_TABLE] <<
"-v"
1370 << iconTable.temporaryVersion_ << __E__;
1371 __COUT__ <<
"Temporary target version is " << parameterTable.tableName_ <<
"-v" << contextGroupMembers[DesktopIconTable::PARAMETER_TABLE] <<
"-v"
1372 << parameterTable.temporaryVersion_ << __E__;
1374 contextGroupMembers[DesktopIconTable::ICON_TABLE] =
1375 ConfigurationSupervisorBase::saveModifiedVersionXML(xmlOut,
1377 iconTable.tableName_,
1378 iconTable.originalVersion_,
1381 iconTable.temporaryVersion_,
1384 contextGroupMembers[DesktopIconTable::PARAMETER_TABLE] =
1385 ConfigurationSupervisorBase::saveModifiedVersionXML(xmlOut,
1387 parameterTable.tableName_,
1388 parameterTable.originalVersion_,
1390 parameterTable.table_,
1391 parameterTable.temporaryVersion_,
1395 __COUT__ <<
"Final target version is " << iconTable.tableName_ <<
"-v" << contextGroupMembers[DesktopIconTable::ICON_TABLE] << __E__;
1396 __COUT__ <<
"Final target version is " << parameterTable.tableName_ <<
"-v" << contextGroupMembers[DesktopIconTable::PARAMETER_TABLE] << __E__;
1398 for(
auto& table : contextGroupMembers)
1400 __COUT__ << table.first <<
" v" << table.second << __E__;
1403 __COUT__ <<
"Checking for duplicate Context groups..." << __E__;
1404 TableGroupKey newContextKey = cfgMgr->findTableGroup(contextGroupName, contextGroupMembers);
1406 if(!newContextKey.isInvalid())
1408 __COUT__ <<
"Found equivalent group key (" << newContextKey <<
") for " << contextGroupName <<
"." << __E__;
1409 xmlOut.addTextElementToData(contextGroupName +
"_foundEquivalentKey",
1414 newContextKey = cfgMgr->saveNewTableGroup(contextGroupName, contextGroupMembers);
1415 __COUT__ <<
"Saved new Context group key (" << newContextKey <<
") for " << contextGroupName <<
"." << __E__;
1418 xmlOut.addTextElementToData(
"contextGroupName", contextGroupName);
1419 xmlOut.addTextElementToData(
"contextGroupKey", newContextKey.toString());
1423 __COUT__ <<
"Original version is " << iconTable.tableName_ <<
"-v" << iconTable.originalVersion_ << __E__;
1424 __COUT__ <<
"Original version is " << parameterTable.tableName_ <<
"-v" << parameterTable.originalVersion_ << __E__;
1426 bool groupAliasChange =
false;
1427 bool tableAliasChange =
false;
1432 TableBase* table = cfgMgr->getTableByName(ConfigurationManager::GROUP_ALIASES_TABLE_NAME);
1433 TableVersion originalVersion = backboneGroupMembers[ConfigurationManager::GROUP_ALIASES_TABLE_NAME];
1434 TableVersion temporaryVersion = table->createTemporaryView(originalVersion);
1435 TableView* tableView = table->getTemporaryView(temporaryVersion);
1438 unsigned int row = 0;
1440 std::vector<std::pair<std::string, ConfigurationTree>> aliasNodePairs =
1441 cfgMgr->getNode(ConfigurationManager::GROUP_ALIASES_TABLE_NAME).getChildren();
1442 std::string groupName, groupKey;
1443 for(
auto& aliasNodePair : aliasNodePairs)
1445 groupName = aliasNodePair.second.getNode(
"GroupName").getValueAsString();
1446 groupKey = aliasNodePair.second.getNode(
"GroupKey").getValueAsString();
1448 __COUT__ <<
"Group Alias: " << aliasNodePair.first <<
" => " << groupName <<
"(" << groupKey <<
"); row=" << row << __E__;
1450 if(groupName == contextGroupName &&
TableGroupKey(groupKey) == originalContextGroupKey)
1452 __COUT__ <<
"Found alias! Changing group key." << __E__;
1454 groupAliasChange =
true;
1456 tableView->setValueAsString(newContextKey.toString(), row, tableView->findCol(
"GroupKey"));
1462 if(groupAliasChange)
1464 std::stringstream ss;
1465 tableView->print(ss);
1466 __COUT__ << ss.str();
1469 backboneGroupMembers[ConfigurationManager::GROUP_ALIASES_TABLE_NAME] =
1470 ConfigurationSupervisorBase::saveModifiedVersionXML(xmlOut,
1472 table->getTableName(),
1480 __COUT__ <<
"Original version is " << table->getTableName() <<
"-v" << originalVersion <<
" and new version is v"
1481 << backboneGroupMembers[ConfigurationManager::GROUP_ALIASES_TABLE_NAME] << __E__;
1488 TableBase* table = cfgMgr->getTableByName(ConfigurationManager::VERSION_ALIASES_TABLE_NAME);
1489 TableVersion originalVersion = backboneGroupMembers[ConfigurationManager::VERSION_ALIASES_TABLE_NAME];
1490 TableVersion temporaryVersion = table->createTemporaryView(originalVersion);
1491 TableView* tableView = table->getTemporaryView(temporaryVersion);
1494 unsigned int row = 0;
1496 std::vector<std::pair<std::string, ConfigurationTree>> aliasNodePairs =
1497 cfgMgr->getNode(ConfigurationManager::VERSION_ALIASES_TABLE_NAME).getChildren();
1498 std::string tableName, tableVersion;
1499 for(
auto& aliasNodePair : aliasNodePairs)
1501 tableName = aliasNodePair.second.getNode(
"TableName").getValueAsString();
1502 tableVersion = aliasNodePair.second.getNode(
"Version").getValueAsString();
1504 __COUT__ <<
"Table Alias: " << aliasNodePair.first <<
" => " << tableName <<
"-v" << tableVersion <<
"" << __E__;
1506 if(tableName == DesktopIconTable::ICON_TABLE &&
TableVersion(tableVersion) == iconTable.originalVersion_)
1508 __COUT__ <<
"Found alias! Changing icon table version alias." << __E__;
1510 tableAliasChange =
true;
1512 tableView->setValueAsString(contextGroupMembers[DesktopIconTable::ICON_TABLE].toString(), row, tableView->findCol(
"Version"));
1514 else if(tableName == DesktopIconTable::PARAMETER_TABLE &&
TableVersion(tableVersion) == parameterTable.originalVersion_)
1516 __COUT__ <<
"Found alias! Changing icon parameter table version alias." << __E__;
1518 tableAliasChange =
true;
1520 tableView->setValueAsString(contextGroupMembers[DesktopIconTable::PARAMETER_TABLE].toString(), row, tableView->findCol(
"Version"));
1526 if(tableAliasChange)
1528 std::stringstream ss;
1529 tableView->print(ss);
1530 __COUT__ << ss.str();
1533 backboneGroupMembers[ConfigurationManager::VERSION_ALIASES_TABLE_NAME] =
1534 ConfigurationSupervisorBase::saveModifiedVersionXML(xmlOut,
1536 table->getTableName(),
1544 __COUT__ <<
"Original version is " << table->getTableName() <<
"-v" << originalVersion <<
" and new version is v"
1545 << backboneGroupMembers[ConfigurationManager::VERSION_ALIASES_TABLE_NAME] << __E__;
1551 if(groupAliasChange || tableAliasChange)
1553 for(
auto& table : backboneGroupMembers)
1555 __COUT__ << table.first <<
" v" << table.second << __E__;
1559 __COUT__ <<
"Checking for duplicate Backbone groups..." << __E__;
1560 TableGroupKey newBackboneKey = cfgMgr->findTableGroup(backboneGroupName, backboneGroupMembers);
1562 if(!newBackboneKey.isInvalid())
1564 __COUT__ <<
"Found equivalent group key (" << newBackboneKey <<
") for " << backboneGroupName <<
"." << __E__;
1565 xmlOut.addTextElementToData(backboneGroupName +
"_foundEquivalentKey",
"1" );
1569 newBackboneKey = cfgMgr->saveNewTableGroup(backboneGroupName, backboneGroupMembers);
1570 __COUT__ <<
"Saved new Backbone group key (" << newBackboneKey <<
") for " << backboneGroupName <<
"." << __E__;
1573 xmlOut.addTextElementToData(
"backboneGroupName", backboneGroupName);
1574 xmlOut.addTextElementToData(
"backboneGroupKey", newBackboneKey.toString());
1577 __COUT__ <<
"Activating Context group key (" << newContextKey <<
") for " << contextGroupName <<
"." << __E__;
1578 __COUT__ <<
"Activating Backbone group key (" << newBackboneKey <<
") for " << backboneGroupName <<
"." << __E__;
1582 cfgMgr->restoreActiveTableGroups(
false ,
"" ,
false
1586 cfgMgr->activateTableGroup(contextGroupName, newContextKey);
1587 cfgMgr->activateTableGroup(backboneGroupName, newBackboneKey);
1590 ConfigurationSupervisorBase::getConfigurationStatusXML(xmlOut, cfgMgr);
1594 catch(std::runtime_error& e)
1596 __COUT__ <<
"Error detected!\n\n " << e.what() << __E__;
1597 xmlOut.addTextElementToData(
"Error",
"Error adding Desktop Icon! " + std::string(e.what()));
1602 __COUT__ <<
"Unknown Error detected!\n\n " << __E__;
1603 xmlOut.addTextElementToData(
"Error",
"Error adding Desktop Icon! ");