00001 #include "otsdaq-utilities/ConfigurationGUI/ConfigurationGUISupervisor.h"
00002 #include "otsdaq-core/ConfigurationPluginDataFormats/IterateConfiguration.h"
00003 #include "otsdaq-core/MessageFacility/MessageFacility.h"
00004 #include "otsdaq-core/Macros/CoutMacros.h"
00005 #include "otsdaq-core/CgiDataUtilities/CgiDataUtilities.h"
00006 #include "otsdaq-core/XmlUtilities/HttpXmlDocument.h"
00007
00008 #if MESSAGEFACILITY_HEX_VERSION > 0x20100
00009 #include <boost/stacktrace.hpp>
00010 #endif
00011
00012 #include "otsdaq-core/ConfigurationPluginDataFormats/XDAQContextConfiguration.h"
00013
00014 #include <xdaq/NamespaceURI.h>
00015
00016 #include <iostream>
00017 #include <map>
00018 #include <utility>
00019
00020
00021
00022 using namespace ots;
00023
00024 #undef __MF_SUBJECT__
00025 #define __MF_SUBJECT__ "CfgGUI"
00026
00027 #define CONFIG_INFO_PATH std::string(getenv("CONFIGURATION_INFO_PATH")) + "/"
00028 #define CONFIG_INFO_EXT std::string("Info.xml")
00029
00031 xdaq::Application * ConfigurationGUISupervisor::instantiate(xdaq::ApplicationStub * stub )
00032 {
00033 return new ConfigurationGUISupervisor(stub);
00034 }
00035
00036
00037
00038
00039
00040 ConfigurationGUISupervisor::ConfigurationGUISupervisor(xdaq::ApplicationStub* stub)
00041 : CoreSupervisorBase (stub)
00042 {
00043 __SUP_COUT__ << "Constructor started." << __E__;
00044
00045 INIT_MF("ConfigurationGUI");
00046
00047 init();
00048 __SUP_COUT__ << "Constructor complete." << __E__;
00049 }
00050
00051
00052 ConfigurationGUISupervisor::~ConfigurationGUISupervisor(void)
00053 {
00054 destroy();
00055 }
00056
00057
00058 void ConfigurationGUISupervisor::init(void)
00059 {
00060 __SUP_COUT__ << "Initializing..." << std::endl;
00061
00062 __SUP_COUT__ << "Activating saved context, which may prepare for normal mode..." << std::endl;
00063 try
00064 {
00065 testXDAQContext();
00066 }
00067 catch(...)
00068 {
00069 __COUT_WARN__ << "Failed test context group activation. otsdaq, in Normal mode, will not launch when this test fails. " <<
00070 "Check the active context group from within Wizard Mode." << __E__;
00071 }
00072 }
00073
00074
00075
00076 void ConfigurationGUISupervisor::destroy(void)
00077 {
00078
00079 for (std::map<std::string, ConfigurationManagerRW* > ::iterator it=userConfigurationManagers_.begin(); it!=userConfigurationManagers_.end(); ++it)
00080 {
00081 delete it->second;
00082 it->second = 0;
00083 }
00084 userConfigurationManagers_.clear();
00085
00086
00087 if( ConfigurationInterface::getInstance(true) != 0 )
00088 delete ConfigurationInterface::getInstance(true);
00089 }
00090
00091
00092 void ConfigurationGUISupervisor::defaultPage(xgi::Input* in, xgi::Output* out )
00093 {
00094 cgicc::Cgicc cgiIn(in);
00095 std::string configName = CgiDataUtilities::getData(cgiIn,"configWindowName");
00096 if(configName == "tableEditor")
00097 *out << "<!DOCTYPE HTML><html lang='en'><frameset col='100%' row='100%'><frame src='/WebPath/html/ConfigurationTableEditor.html?urn=" <<
00098 this->getApplicationDescriptor()->getLocalId() <<"'></frameset></html>";
00099 if(configName == "iterate")
00100 *out << "<!DOCTYPE HTML><html lang='en'><frameset col='100%' row='100%'><frame src='/WebPath/html/Iterate.html?urn=" <<
00101 this->getApplicationDescriptor()->getLocalId() <<"'></frameset></html>";
00102 else
00103 *out << "<!DOCTYPE HTML><html lang='en'><frameset col='100%' row='100%'><frame src='/WebPath/html/ConfigurationGUI.html?urn=" <<
00104 this->getApplicationDescriptor()->getLocalId() <<"'></frameset></html>";
00105 }
00106
00107
00108
00109
00110
00111 void ConfigurationGUISupervisor::setSupervisorPropertyDefaults(void)
00112 {
00113 CorePropertySupervisorBase::setSupervisorProperty(CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.UserPermissionsThreshold,
00114 "*=10 | deleteTreeNodeRecords=255 | saveConfigurationInfo=255 | deleteConfigurationInfo=255");
00115 CorePropertySupervisorBase::setSupervisorProperty(CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.RequireUserLockRequestTypes,
00116 "*");
00117 }
00118
00119
00120
00121
00122 void ConfigurationGUISupervisor::forceSupervisorPropertyValues()
00123 {
00124 CorePropertySupervisorBase::setSupervisorProperty(CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.AutomatedRequestTypes,
00125 "");
00126 CorePropertySupervisorBase::setSupervisorProperty(CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.CheckUserLockRequestTypes,
00127 "*");
00128 }
00129
00130
00131 void ConfigurationGUISupervisor::request(const std::string& requestType, cgicc::Cgicc& cgiIn,
00132 HttpXmlDocument& xmlOut, const WebUsers::RequestUserInfo& userInfo)
00133 try
00134 {
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188 std::string refresh = CgiDataUtilities::getData(cgiIn,"refresh");
00189
00190
00191
00192 ConfigurationManagerRW* cfgMgr = refreshUserSession(userInfo.username_,
00193 userInfo.activeUserSessionIndex_,
00194 (refresh == "1") );
00195
00196 if(requestType == "saveConfigurationInfo")
00197 {
00198 std::string configName = CgiDataUtilities::getData (cgiIn,"configName");
00199 std::string columnCSV = CgiDataUtilities::postData(cgiIn,"columnCSV");
00200 std::string allowOverwrite = CgiDataUtilities::getData (cgiIn,"allowOverwrite");
00201 std::string tableDescription = CgiDataUtilities::postData(cgiIn,"tableDescription");
00202 std::string columnChoicesCSV = CgiDataUtilities::postData(cgiIn,"columnChoicesCSV");
00203
00204
00205
00206
00207 __SUP_COUT__ << "configName: " << configName << std::endl;
00208 __SUP_COUT__ << "columnCSV: " << columnCSV << std::endl;
00209 __SUP_COUT__ << "tableDescription: " << tableDescription << std::endl;
00210 __SUP_COUT__ << "columnChoicesCSV: " << columnChoicesCSV << std::endl;
00211 __SUP_COUT__ << "allowOverwrite: " << allowOverwrite << std::endl;
00212
00213 if(!allSupervisorInfo_.isWizardMode())
00214 {
00215 __SUP_SS__ << "Improper permissions for saving configuration info." << std::endl;
00216 xmlOut.addTextElementToData("Error", ss.str());
00217 }
00218 else
00219 handleSaveConfigurationInfoXML(xmlOut,cfgMgr,configName,columnCSV,tableDescription,
00220 columnChoicesCSV,allowOverwrite=="1");
00221 }
00222 else if(requestType == "deleteConfigurationInfo")
00223 {
00224 std::string configName = CgiDataUtilities::getData(cgiIn,"configName");
00225 __SUP_COUT__ << "configName: " << configName << std::endl;
00226 handleDeleteConfigurationInfoXML(xmlOut,cfgMgr,configName);
00227 }
00228 else if(requestType == "gatewayLaunchOTS" || requestType == "gatewayLaunchWiz" ||
00229 requestType == "flattenToSystemAliases")
00230 {
00231
00232 __SUP_COUT_WARN__ << requestType << " command received! " << std::endl;
00233 __MOUT_WARN__ << requestType << " command received! " << std::endl;
00234
00235
00236 __SUP_COUT_INFO__ << "Launching... " << std::endl;
00237
00238 __SUP_COUT__ << "Extracting target context hostnames... " << std::endl;
00239 std::vector<std::string> hostnames;
00240 try
00241 {
00242 cfgMgr->init();
00243
00244 const XDAQContextConfiguration* contextConfiguration = cfgMgr->__GET_CONFIG__(XDAQContextConfiguration);
00245
00246 auto contexts = contextConfiguration->getContexts();
00247 unsigned int i,j;
00248 for(const auto& context: contexts)
00249 {
00250 if(!context.status_) continue;
00251
00252
00253 j=0;
00254 for(i=0;i<context.address_.size();++i)
00255 if(context.address_[i] == '/')
00256 j = i+1;
00257 hostnames.push_back(context.address_.substr(j));
00258 __SUP_COUT__ << "hostname = " << hostnames.back() << std::endl;
00259 }
00260 }
00261 catch(...)
00262 {
00263 __SUP_SS__ << "\nTransition to Configuring interrupted! " <<
00264 "The Configuration Manager could not be initialized." << std::endl;
00265
00266 __SUP_COUT_ERR__ << "\n" << ss.str();
00267 return;
00268 }
00269
00270 for(const auto& hostname: hostnames)
00271 {
00272 std::string fn = (std::string(getenv("SERVICE_DATA_PATH")) +
00273 "/StartOTS_action_" + hostname + ".cmd");
00274 FILE* fp = fopen(fn.c_str(),"w");
00275 if(fp)
00276 {
00277 if(requestType == "gatewayLaunchOTS")
00278 fprintf(fp,"LAUNCH_OTS");
00279 else if(requestType == "gatewayLaunchWiz")
00280 fprintf(fp,"LAUNCH_WIZ");
00281 else if(requestType == "flattenToSystemAliases")
00282 {
00283 fprintf(fp,"FLATTEN_TO_SYSTEM_ALIASES");
00284 fclose(fp);
00285 break;
00286 }
00287
00288 fclose(fp);
00289 }
00290 else
00291 __SUP_COUT_ERR__ << "Unable to open command file: " << fn << std::endl;
00292 }
00293
00294 }
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340 else if(requestType == "versionTracking")
00341 {
00342 std::string type = CgiDataUtilities::getData(cgiIn,"Type");
00343 __SUP_COUT__ << "type: " << type << std::endl;
00344
00345 if(type == "Get")
00346 xmlOut.addTextElementToData("versionTrackingStatus",
00347 ConfigurationInterface::isVersionTrackingEnabled()?"ON":"OFF");
00348 else if(type == "ON")
00349 {
00350 ConfigurationInterface::setVersionTrackingEnabled(true);
00351 xmlOut.addTextElementToData("versionTrackingStatus",
00352 ConfigurationInterface::isVersionTrackingEnabled()?"ON":"OFF");
00353 }
00354 else if(type == "OFF")
00355 {
00356 ConfigurationInterface::setVersionTrackingEnabled(false);
00357 xmlOut.addTextElementToData("versionTrackingStatus",
00358 ConfigurationInterface::isVersionTrackingEnabled()?"ON":"OFF");
00359 }
00360 }
00361 else if(requestType == "getColumnTypes")
00362 {
00363
00364 std::vector<std::string> allTypes = ViewColumnInfo::getAllTypesForGUI();
00365 std::vector<std::string> allDataTypes = ViewColumnInfo::getAllDataTypesForGUI();
00366 std::map<std::pair<std::string,std::string>,std::string> allDefaults =
00367 ViewColumnInfo::getAllDefaultsForGUI();
00368
00369 for(const auto& type:allTypes)
00370 xmlOut.addTextElementToData("columnTypeForGUI",
00371 type);
00372 for(const auto& dataType:allDataTypes)
00373 xmlOut.addTextElementToData("columnDataTypeForGUI",
00374 dataType);
00375
00376 for(const auto& colDefault:allDefaults)
00377 {
00378 xmlOut.addTextElementToData("columnDefaultDataType",
00379 colDefault.first.first);
00380 xmlOut.addTextElementToData("columnDefaultTypeFilter",
00381 colDefault.first.second);
00382 xmlOut.addTextElementToData("columnDefaultValue",
00383 colDefault.second);
00384 }
00385 }
00386 else if(requestType == "getGroupAliases")
00387 {
00388
00389
00390 bool reloadActive = 1 == CgiDataUtilities::getDataAsInt(cgiIn,"reloadActiveGroups");
00391
00392 __SUP_COUT__ << "reloadActive: " << reloadActive << std::endl;
00393 bool wasError = false;
00394 if(reloadActive)
00395 {
00396 try
00397 {
00398 cfgMgr->clearAllCachedVersions();
00399 cfgMgr->restoreActiveConfigurationGroups(true);
00400 }
00401 catch(std::runtime_error& e)
00402 {
00403 __SUP_SS__ << ("Error loading active groups!\n\n" + std::string(e.what())) << std::endl;
00404 __SUP_COUT_ERR__ << "\n" << ss.str();
00405 xmlOut.addTextElementToData("Error", ss.str());
00406 wasError = true;
00407 }
00408 catch(...)
00409 {
00410 __SUP_SS__ << ("Error loading active groups!\n\n") << std::endl;
00411 __SUP_COUT_ERR__ << "\n" << ss.str();
00412 xmlOut.addTextElementToData("Error", ss.str());
00413 wasError = true;
00414 }
00415
00416 }
00417
00418
00419 handleGroupAliasesXML(xmlOut,cfgMgr);
00420 }
00421 else if(requestType == "setGroupAliasInActiveBackbone")
00422 {
00423 std::string groupAlias = CgiDataUtilities::getData(cgiIn,"groupAlias");
00424 std::string groupName = CgiDataUtilities::getData(cgiIn,"groupName");
00425 std::string groupKey = CgiDataUtilities::getData(cgiIn,"groupKey");
00426
00427 __SUP_COUT__ << "groupAlias: " << groupAlias << std::endl;
00428 __SUP_COUT__ << "groupName: " << groupName << std::endl;
00429 __SUP_COUT__ << "groupKey: " << groupKey << std::endl;
00430
00431 handleSetGroupAliasInBackboneXML(xmlOut,cfgMgr,groupAlias,groupName,
00432 ConfigurationGroupKey(groupKey),userInfo.username_);
00433 }
00434 else if(requestType == "setVersionAliasInActiveBackbone")
00435 {
00436 std::string versionAlias = CgiDataUtilities::getData(cgiIn,"versionAlias");
00437 std::string configName = CgiDataUtilities::getData(cgiIn,"configName");
00438 std::string version = CgiDataUtilities::getData(cgiIn,"version");
00439
00440 __SUP_COUT__ << "versionAlias: " << versionAlias << std::endl;
00441 __SUP_COUT__ << "configName: " << configName << std::endl;
00442 __SUP_COUT__ << "version: " << version << std::endl;
00443
00444 handleSetVersionAliasInBackboneXML(xmlOut,cfgMgr,versionAlias,
00445 configName,
00446 ConfigurationVersion(version),userInfo.username_);
00447 }
00448 else if(requestType == "setAliasOfGroupMembers")
00449 {
00450 std::string versionAlias = CgiDataUtilities::getData(cgiIn,"versionAlias");
00451 std::string groupName = CgiDataUtilities::getData(cgiIn,"groupName");
00452 std::string groupKey = CgiDataUtilities::getData(cgiIn,"groupKey");
00453
00454 __SUP_COUT__ << "versionAlias: " << versionAlias << std::endl;
00455 __SUP_COUT__ << "groupName: " << groupName << std::endl;
00456 __SUP_COUT__ << "groupKey: " << groupKey << std::endl;
00457
00458 handleAliasGroupMembersInBackboneXML(xmlOut,cfgMgr,versionAlias,
00459 groupName,
00460 ConfigurationGroupKey(groupKey),userInfo.username_);
00461 }
00462 else if(requestType == "getVersionAliases")
00463 {
00464 handleVersionAliasesXML(xmlOut,cfgMgr);
00465 }
00466 else if(requestType == "getConfigurationGroups")
00467 {
00468 bool doNotReturnMembers = CgiDataUtilities::getDataAsInt(cgiIn,"doNotReturnMembers") == 1?true:false;
00469
00470 __SUP_COUT__ << "doNotReturnMembers: " << doNotReturnMembers << std::endl;
00471 handleConfigurationGroupsXML(xmlOut,cfgMgr,!doNotReturnMembers);
00472 }
00473 else if(requestType == "getConfigurationGroupType")
00474 {
00475 std::string configList = CgiDataUtilities::postData(cgiIn,"configList");
00476 __SUP_COUT__ << "configList: " << configList << std::endl;
00477
00478 handleGetConfigurationGroupTypeXML(xmlOut,cfgMgr,configList);
00479 }
00480 else if(requestType == "getConfigurations")
00481 {
00482 std::string allowIllegalColumns = CgiDataUtilities::getData(cgiIn,"allowIllegalColumns");
00483
00484 __SUP_COUT__ << "allowIllegalColumns: " << allowIllegalColumns << std::endl;
00485
00486 handleConfigurationsXML(xmlOut,cfgMgr, allowIllegalColumns == "1");
00487 }
00488 else if(requestType == "getContextMemberNames")
00489 {
00490 std::set<std::string> members = cfgMgr->getContextMemberNames();
00491
00492 for(auto& member:members)
00493 xmlOut.addTextElementToData("ContextMember", member);
00494 }
00495 else if(requestType == "getBackboneMemberNames")
00496 {
00497 std::set<std::string> members = cfgMgr->getBackboneMemberNames();
00498
00499 for(auto& member:members)
00500 xmlOut.addTextElementToData("BackboneMember", member);
00501 }
00502 else if(requestType == "getIterateMemberNames")
00503 {
00504 std::set<std::string> members = cfgMgr->getIterateMemberNames();
00505
00506 for(auto& member:members)
00507 xmlOut.addTextElementToData("IterateMember", member);
00508 }
00509 else if(requestType == "getSpecificConfigurationGroup")
00510 {
00511 std::string groupName = CgiDataUtilities::getData (cgiIn,"groupName");
00512 std::string groupKey = CgiDataUtilities::getData (cgiIn,"groupKey");
00513
00514 __SUP_COUT__ << "groupName: " << groupName << std::endl;
00515 __SUP_COUT__ << "groupKey: " << groupKey << std::endl;
00516
00517 handleGetConfigurationGroupXML(xmlOut,cfgMgr,groupName,ConfigurationGroupKey(groupKey));
00518 }
00519 else if(requestType == "saveNewConfigurationGroup")
00520 {
00521 std::string groupName = CgiDataUtilities::getData (cgiIn,"groupName");
00522 bool ignoreWarnings = CgiDataUtilities::getDataAsInt(cgiIn,"ignoreWarnings");
00523 bool allowDuplicates = CgiDataUtilities::getDataAsInt(cgiIn,"allowDuplicates");
00524 bool lookForEquivalent = CgiDataUtilities::getDataAsInt(cgiIn,"lookForEquivalent");
00525 std::string configList = CgiDataUtilities::postData (cgiIn,"configList");
00526 std::string comment = CgiDataUtilities::getData (cgiIn,"groupComment");
00527
00528 __SUP_COUT__ << "saveNewConfigurationGroup: " << groupName << std::endl;
00529 __SUP_COUT__ << "configList: " << configList << std::endl;
00530 __SUP_COUT__ << "ignoreWarnings: " << ignoreWarnings << std::endl;
00531 __SUP_COUT__ << "allowDuplicates: " << allowDuplicates << std::endl;
00532 __SUP_COUT__ << "lookForEquivalent: " << lookForEquivalent << std::endl;
00533 __SUP_COUT__ << "comment: " << comment << std::endl;
00534
00535 handleCreateConfigurationGroupXML(xmlOut,cfgMgr,groupName,configList,
00536 allowDuplicates,ignoreWarnings,comment,lookForEquivalent);
00537 }
00538 else if(requestType == "getSpecificConfiguration")
00539 {
00540 std::string configName = CgiDataUtilities::getData (cgiIn,"configName");
00541 std::string versionStr = CgiDataUtilities::getData (cgiIn,"version");
00542 int dataOffset = CgiDataUtilities::getDataAsInt (cgiIn,"dataOffset");
00543 int chunkSize = CgiDataUtilities::getDataAsInt (cgiIn,"chunkSize");
00544
00545 std::string allowIllegalColumns = CgiDataUtilities::getData(cgiIn,"allowIllegalColumns");
00546 __SUP_COUT__ << "allowIllegalColumns: " << (allowIllegalColumns=="1") << std::endl;
00547
00548 __SUP_COUT__ << "getSpecificConfiguration: " << configName << " versionStr: " << versionStr
00549 << " chunkSize: " << chunkSize << " dataOffset: " << dataOffset << std::endl;
00550
00551 ConfigurationVersion version;
00552 const std::map<std::string, ConfigurationInfo>& allCfgInfo = cfgMgr->getAllConfigurationInfo();
00553 std::string versionAlias;
00554
00555 if(allCfgInfo.find(configName) != allCfgInfo.end())
00556 {
00557 if(versionStr == "" &&
00558 allCfgInfo.at(configName).versions_.size())
00559 version =* (allCfgInfo.at(configName).versions_.rbegin());
00560 else if(versionStr.find(ConfigurationManager::ALIAS_VERSION_PREAMBLE) == 0)
00561 {
00562
00563 std::map<std::string , std::map<
00564 std::string ,ConfigurationVersion> > versionAliases =
00565 cfgMgr->getVersionAliases();
00566
00567 versionAlias = versionStr.substr(ConfigurationManager::ALIAS_VERSION_PREAMBLE.size());
00568
00569
00570
00571
00572
00573
00574 if(versionAliases.find(configName) != versionAliases.end() &&
00575 versionAliases[configName].find(versionStr.substr(
00576 ConfigurationManager::ALIAS_VERSION_PREAMBLE.size())) !=
00577 versionAliases[configName].end())
00578 {
00579 version = versionAliases[configName][versionStr.substr(
00580 ConfigurationManager::ALIAS_VERSION_PREAMBLE.size())];
00581 __SUP_COUT__ << "version alias translated to: " << version << std::endl;
00582 }
00583 else
00584 __SUP_COUT_WARN__ << "version alias '" << versionStr.substr(
00585 ConfigurationManager::ALIAS_VERSION_PREAMBLE.size()) <<
00586 "'was not found in active version aliases!" << std::endl;
00587 }
00588 else
00589 version = atoi(versionStr.c_str());
00590 }
00591
00592 __SUP_COUT__ << "version: " << version << std::endl;
00593
00594 handleGetConfigurationXML(xmlOut,cfgMgr,configName,ConfigurationVersion(version),
00595 (allowIllegalColumns=="1"));
00596
00597 xmlOut.addTextElementToData("DefaultRowValue", userInfo.username_);
00598 }
00599 else if(requestType == "saveSpecificConfiguration")
00600 {
00601 std::string configName = CgiDataUtilities::getData (cgiIn,"configName");
00602 int version = CgiDataUtilities::getDataAsInt(cgiIn,"version");
00603 int dataOffset = CgiDataUtilities::getDataAsInt(cgiIn,"dataOffset");
00604 bool sourceTableAsIs = CgiDataUtilities::getDataAsInt(cgiIn,"sourceTableAsIs");
00605 bool lookForEquivalent = CgiDataUtilities::getDataAsInt(cgiIn,"lookForEquivalent");
00606 int temporary = CgiDataUtilities::getDataAsInt(cgiIn,"temporary");
00607 std::string comment = CgiDataUtilities::getData (cgiIn,"tableComment");
00608
00609 std::string data = CgiDataUtilities::postData(cgiIn,"data");
00610
00611
00612
00613 __SUP_COUT__ << "configName: " << configName << " version: " << version
00614 << " temporary: " << temporary << " dataOffset: " << dataOffset << std::endl;
00615 __SUP_COUT__ << "comment: " << comment << std::endl;
00616 __SUP_COUT__ << "data: " << data << std::endl;
00617 __SUP_COUT__ << "sourceTableAsIs: " << sourceTableAsIs << std::endl;
00618 __SUP_COUT__ << "lookForEquivalent: " << lookForEquivalent << std::endl;
00619
00620 handleCreateConfigurationXML(xmlOut,cfgMgr,configName,ConfigurationVersion(version),
00621 temporary,data,dataOffset,userInfo.username_,comment,sourceTableAsIs,lookForEquivalent);
00622 }
00623 else if(requestType == "clearConfigurationTemporaryVersions")
00624 {
00625 std::string configName = CgiDataUtilities::getData (cgiIn,"configName");
00626 __SUP_COUT__ << "configName: " << configName << std::endl;
00627
00628 try { cfgMgr->eraseTemporaryVersion(configName);}
00629 catch(std::runtime_error& e)
00630 {
00631 __SUP_COUT__ << "Error detected!\n\n " << e.what() << std::endl;
00632 xmlOut.addTextElementToData("Error", "Error clearing temporary views!\n " +
00633 std::string(e.what()));
00634 }
00635 catch(...)
00636 {
00637 __SUP_COUT__ << "Error detected!\n\n "<< std::endl;
00638 xmlOut.addTextElementToData("Error", "Error clearing temporary views! ");
00639 }
00640 }
00641 else if(requestType == "clearConfigurationCachedVersions")
00642 {
00643 std::string configName = CgiDataUtilities::getData (cgiIn,"configName");
00644 __SUP_COUT__ << "configName: " << configName << std::endl;
00645
00646 try { cfgMgr->clearCachedVersions(configName);}
00647 catch(std::runtime_error& e)
00648 {
00649 __SUP_COUT__ << "Error detected!\n\n " << e.what() << std::endl;
00650 xmlOut.addTextElementToData("Error", "Error clearing cached views!\n " +
00651 std::string(e.what()));
00652 }
00653 catch(...)
00654 {
00655 __SUP_COUT__ << "Error detected!\n\n "<< std::endl;
00656 xmlOut.addTextElementToData("Error", "Error clearing cached views! ");
00657 }
00658 }
00659 else if(requestType == "getTreeView")
00660 {
00661 std::string configGroup = CgiDataUtilities::getData(cgiIn,"configGroup");
00662 std::string configGroupKey = CgiDataUtilities::getData(cgiIn,"configGroupKey");
00663 std::string startPath = CgiDataUtilities::postData(cgiIn,"startPath");
00664 std::string modifiedTables = CgiDataUtilities::postData(cgiIn,"modifiedTables");
00665 std::string filterList = CgiDataUtilities::postData(cgiIn,"filterList");
00666 int depth = CgiDataUtilities::getDataAsInt(cgiIn,"depth");
00667 bool hideStatusFalse = CgiDataUtilities::getDataAsInt(cgiIn,"hideStatusFalse");
00668
00669 __SUP_COUT__ << "configGroup: " << configGroup << std::endl;
00670 __SUP_COUT__ << "configGroupKey: " << configGroupKey << std::endl;
00671 __SUP_COUT__ << "startPath: " << startPath << std::endl;
00672 __SUP_COUT__ << "depth: " << depth << std::endl;
00673 __SUP_COUT__ << "hideStatusFalse: " << hideStatusFalse << std::endl;
00674 __SUP_COUT__ << "modifiedTables: " << modifiedTables << std::endl;
00675 __SUP_COUT__ << "filterList: " << filterList << std::endl;
00676
00677 handleFillTreeViewXML(xmlOut,cfgMgr,configGroup,ConfigurationGroupKey(configGroupKey),
00678 startPath,depth,hideStatusFalse,modifiedTables,filterList);
00679 }
00680 else if(requestType == "getTreeNodeCommonFields")
00681 {
00682 std::string configGroup = CgiDataUtilities::getData(cgiIn,"configGroup");
00683 std::string configGroupKey = CgiDataUtilities::getData(cgiIn,"configGroupKey");
00684 std::string startPath = CgiDataUtilities::postData(cgiIn,"startPath");
00685 std::string modifiedTables = CgiDataUtilities::postData(cgiIn,"modifiedTables");
00686 std::string fieldList = CgiDataUtilities::postData(cgiIn,"fieldList");
00687 std::string recordList = CgiDataUtilities::postData(cgiIn,"recordList");
00688 int depth = CgiDataUtilities::getDataAsInt(cgiIn,"depth");
00689
00690 __SUP_COUT__ << "configGroup: " << configGroup << std::endl;
00691 __SUP_COUT__ << "configGroupKey: " << configGroupKey << std::endl;
00692 __SUP_COUT__ << "startPath: " << startPath << std::endl;
00693 __SUP_COUT__ << "depth: " << depth << std::endl;
00694 __SUP_COUT__ << "fieldList: " << fieldList << std::endl;
00695 __SUP_COUT__ << "recordList: " << recordList << std::endl;
00696 __SUP_COUT__ << "modifiedTables: " << modifiedTables << std::endl;
00697
00698 handleFillTreeNodeCommonFieldsXML(xmlOut,cfgMgr,configGroup,ConfigurationGroupKey(configGroupKey),
00699 startPath,depth,modifiedTables,recordList,fieldList);
00700
00701 }
00702 else if(requestType == "getUniqueFieldValuesForRecords")
00703 {
00704 std::string configGroup = CgiDataUtilities::getData(cgiIn,"configGroup");
00705 std::string configGroupKey = CgiDataUtilities::getData(cgiIn,"configGroupKey");
00706 std::string startPath = CgiDataUtilities::postData(cgiIn,"startPath");
00707 std::string modifiedTables = CgiDataUtilities::postData(cgiIn,"modifiedTables");
00708 std::string fieldList = CgiDataUtilities::postData(cgiIn,"fieldList");
00709 std::string recordList = CgiDataUtilities::postData(cgiIn,"recordList");
00710
00711 __SUP_COUT__ << "configGroup: " << configGroup << std::endl;
00712 __SUP_COUT__ << "configGroupKey: " << configGroupKey << std::endl;
00713 __SUP_COUT__ << "startPath: " << startPath << std::endl;
00714 __SUP_COUT__ << "fieldList: " << fieldList << std::endl;
00715 __SUP_COUT__ << "recordList: " << recordList << std::endl;
00716 __SUP_COUT__ << "modifiedTables: " << modifiedTables << std::endl;
00717
00718 handleFillUniqueFieldValuesForRecordsXML(xmlOut,cfgMgr,configGroup,ConfigurationGroupKey(configGroupKey),
00719 startPath,modifiedTables,recordList,fieldList);
00720
00721 }
00722 else if(requestType == "getTreeNodeFieldValues")
00723 {
00724 std::string configGroup = CgiDataUtilities::getData(cgiIn,"configGroup");
00725 std::string configGroupKey = CgiDataUtilities::getData(cgiIn,"configGroupKey");
00726 std::string startPath = CgiDataUtilities::postData(cgiIn,"startPath");
00727 std::string modifiedTables = CgiDataUtilities::postData(cgiIn,"modifiedTables");
00728 std::string fieldList = CgiDataUtilities::postData(cgiIn,"fieldList");
00729 std::string recordList = CgiDataUtilities::postData(cgiIn,"recordList");
00730
00731 __SUP_COUT__ << "configGroup: " << configGroup << std::endl;
00732 __SUP_COUT__ << "configGroupKey: " << configGroupKey << std::endl;
00733 __SUP_COUT__ << "startPath: " << startPath << std::endl;
00734 __SUP_COUT__ << "fieldList: " << fieldList << std::endl;
00735 __SUP_COUT__ << "recordList: " << recordList << std::endl;
00736 __SUP_COUT__ << "modifiedTables: " << modifiedTables << std::endl;
00737
00738 handleFillGetTreeNodeFieldValuesXML(xmlOut,cfgMgr,configGroup,ConfigurationGroupKey(configGroupKey),
00739 startPath,modifiedTables,recordList,fieldList);
00740 }
00741 else if(requestType == "setTreeNodeFieldValues")
00742 {
00743 std::string configGroup = CgiDataUtilities::getData(cgiIn,"configGroup");
00744 std::string configGroupKey = CgiDataUtilities::getData(cgiIn,"configGroupKey");
00745 std::string startPath = CgiDataUtilities::postData(cgiIn,"startPath");
00746 std::string modifiedTables = CgiDataUtilities::postData(cgiIn,"modifiedTables");
00747 std::string fieldList = CgiDataUtilities::postData(cgiIn,"fieldList");
00748 std::string recordList = CgiDataUtilities::postData(cgiIn,"recordList");
00749 std::string valueList = CgiDataUtilities::postData(cgiIn,"valueList");
00750
00751 __SUP_COUT__ << "configGroup: " << configGroup << std::endl;
00752 __SUP_COUT__ << "configGroupKey: " << configGroupKey << std::endl;
00753 __SUP_COUT__ << "startPath: " << startPath << std::endl;
00754 __SUP_COUT__ << "fieldList: " << fieldList << std::endl;
00755 __SUP_COUT__ << "valueList: " << valueList << std::endl;
00756 __SUP_COUT__ << "recordList: " << recordList << std::endl;
00757 __SUP_COUT__ << "modifiedTables: " << modifiedTables << std::endl;
00758
00759 handleFillSetTreeNodeFieldValuesXML(xmlOut,cfgMgr,configGroup,ConfigurationGroupKey(configGroupKey),
00760 startPath,modifiedTables,recordList,fieldList,valueList,userInfo.username_);
00761
00762 }
00763 else if(requestType == "addTreeNodeRecords")
00764 {
00765 std::string configGroup = CgiDataUtilities::getData(cgiIn,"configGroup");
00766 std::string configGroupKey = CgiDataUtilities::getData(cgiIn,"configGroupKey");
00767 std::string startPath = CgiDataUtilities::postData(cgiIn,"startPath");
00768 std::string modifiedTables = CgiDataUtilities::postData(cgiIn,"modifiedTables");
00769 std::string recordList = CgiDataUtilities::postData(cgiIn,"recordList");
00770
00771 __SUP_COUT__ << "configGroup: " << configGroup << std::endl;
00772 __SUP_COUT__ << "configGroupKey: " << configGroupKey << std::endl;
00773 __SUP_COUT__ << "startPath: " << startPath << std::endl;
00774 __SUP_COUT__ << "recordList: " << recordList << std::endl;
00775 __SUP_COUT__ << "modifiedTables: " << modifiedTables << std::endl;
00776
00777 handleFillCreateTreeNodeRecordsXML(xmlOut,cfgMgr,configGroup,ConfigurationGroupKey(configGroupKey),
00778 startPath,modifiedTables,recordList,userInfo.username_);
00779 }
00780 else if(requestType == "deleteTreeNodeRecords")
00781 {
00782 std::string configGroup = CgiDataUtilities::getData(cgiIn,"configGroup");
00783 std::string configGroupKey = CgiDataUtilities::getData(cgiIn,"configGroupKey");
00784 std::string startPath = CgiDataUtilities::postData(cgiIn,"startPath");
00785 std::string modifiedTables = CgiDataUtilities::postData(cgiIn,"modifiedTables");
00786 std::string recordList = CgiDataUtilities::postData(cgiIn,"recordList");
00787
00788 __SUP_COUT__ << "configGroup: " << configGroup << std::endl;
00789 __SUP_COUT__ << "configGroupKey: " << configGroupKey << std::endl;
00790 __SUP_COUT__ << "startPath: " << startPath << std::endl;
00791 __SUP_COUT__ << "recordList: " << recordList << std::endl;
00792 __SUP_COUT__ << "modifiedTables: " << modifiedTables << std::endl;
00793
00794 handleFillDeleteTreeNodeRecordsXML(xmlOut,cfgMgr,configGroup,ConfigurationGroupKey(configGroupKey),
00795 startPath,modifiedTables,recordList);
00796 }
00797 else if(requestType == "getAffectedActiveGroups")
00798 {
00799 std::string groupName = CgiDataUtilities::getData(cgiIn,"groupName");
00800 std::string groupKey = CgiDataUtilities::getData(cgiIn,"groupKey");
00801 std::string modifiedTables = CgiDataUtilities::postData(cgiIn,"modifiedTables");
00802 __SUP_COUT__ << "modifiedTables: " << modifiedTables << std::endl;
00803 __SUP_COUT__ << "groupName: " << groupName << std::endl;
00804 __SUP_COUT__ << "groupKey: " << groupKey << std::endl;
00805
00806 handleGetAffectedGroupsXML(xmlOut,cfgMgr,groupName,ConfigurationGroupKey(groupKey),
00807 modifiedTables);
00808 }
00809 else if(requestType == "saveTreeNodeEdit")
00810 {
00811 std::string editNodeType = CgiDataUtilities::getData(cgiIn,"editNodeType");
00812 std::string targetTable = CgiDataUtilities::getData(cgiIn,"targetTable");
00813 std::string targetTableVersion = CgiDataUtilities::getData(cgiIn,"targetTableVersion");
00814 std::string targetUID = CgiDataUtilities::getData(cgiIn,"targetUID");
00815 std::string targetColumn = CgiDataUtilities::getData(cgiIn,"targetColumn");
00816 std::string newValue = CgiDataUtilities::postData(cgiIn,"newValue");
00817
00818 __SUP_COUT__ << "editNodeType: " << editNodeType << std::endl;
00819 __SUP_COUT__ << "targetTable: " << targetTable << std::endl;
00820 __SUP_COUT__ << "targetTableVersion: " << targetTableVersion << std::endl;
00821 __SUP_COUT__ << "targetUID: " << targetUID << std::endl;
00822 __SUP_COUT__ << "targetColumn: " << targetColumn << std::endl;
00823 __SUP_COUT__ << "newValue: " << newValue << std::endl;
00824
00825 handleSaveTreeNodeEditXML(xmlOut,cfgMgr,targetTable,ConfigurationVersion(targetTableVersion),
00826 editNodeType,
00827 CgiDataUtilities::decodeURIComponent(targetUID),
00828 CgiDataUtilities::decodeURIComponent(targetColumn),
00829 newValue,userInfo.username_);
00830 }
00831 else if(requestType == "getLinkToChoices")
00832 {
00833 std::string linkToTableName = CgiDataUtilities::getData(cgiIn,"linkToTableName");
00834 std::string linkToTableVersion = CgiDataUtilities::getData(cgiIn,"linkToTableVersion");
00835 std::string linkIdType = CgiDataUtilities::getData(cgiIn,"linkIdType");
00836 std::string linkIndex = CgiDataUtilities::getData(cgiIn,"linkIndex");
00837 std::string linkInitId = CgiDataUtilities::getData(cgiIn,"linkInitId");
00838
00839 __SUP_COUT__ << "linkToTableName: " << linkToTableName << std::endl;
00840 __SUP_COUT__ << "linkToTableVersion: " << linkToTableVersion << std::endl;
00841 __SUP_COUT__ << "linkIdType: " << linkIdType << std::endl;
00842 __SUP_COUT__ << "linkIndex: " << linkIndex << std::endl;
00843 __SUP_COUT__ << "linkInitId: " << linkInitId << std::endl;
00844
00845 handleGetLinkToChoicesXML(xmlOut,cfgMgr,linkToTableName,
00846 ConfigurationVersion(linkToTableVersion),linkIdType,linkIndex,linkInitId);
00847 }
00848 else if(requestType == "activateConfigGroup")
00849 {
00850 std::string groupName = CgiDataUtilities::getData(cgiIn,"groupName");
00851 std::string groupKey = CgiDataUtilities::getData(cgiIn,"groupKey");
00852 bool ignoreWarnings = CgiDataUtilities::getDataAsInt(cgiIn,"ignoreWarnings");
00853
00854 __SUP_COUT__ << "Activating config: " << groupName <<
00855 "(" << groupKey << ")" << std::endl;
00856 __SUP_COUT__ << "ignoreWarnings: " << ignoreWarnings << std::endl;
00857
00858
00859 xmlOut.addTextElementToData("AttemptedGroupActivation","1");
00860 xmlOut.addTextElementToData("AttemptedGroupActivationName",groupName);
00861 xmlOut.addTextElementToData("AttemptedGroupActivationKey",groupKey);
00862
00863 std::string accumulatedTreeErrors;
00864 try
00865 {
00866 cfgMgr->activateConfigurationGroup(groupName, ConfigurationGroupKey(groupKey),
00867 ignoreWarnings?0:&accumulatedTreeErrors);
00868 }
00869 catch(std::runtime_error& e)
00870 {
00871
00872
00873
00874 __SUP_COUT__ << "Error detected!\n\n " << e.what() << std::endl;
00875 xmlOut.addTextElementToData("Error", "Error activating config group '" +
00876 groupName + "(" + groupKey + ")" + ".' Please see details below:\n\n" +
00877 std::string(e.what()));
00878 __SUP_COUT_ERR__ << "Errors detected so de-activating group: " <<
00879 groupName << " (" << groupKey << ")" << std::endl;
00880 try
00881 { cfgMgr->destroyConfigurationGroup(groupName,true); }
00882 catch(...){}
00883 }
00884 catch(cet::exception& e)
00885 {
00886
00887
00888
00889
00890 __SUP_COUT__ << "Error detected!\n\n " << e.what() << std::endl;
00891 xmlOut.addTextElementToData("Error", "Error activating config group '" +
00892 groupName + "(" + groupKey + ")" + "!'\n\n" +
00893 std::string(e.what()));
00894 __SUP_COUT_ERR__ << "Errors detected so de-activating group: " <<
00895 groupName << " (" << groupKey << ")" << std::endl;
00896 try
00897 { cfgMgr->destroyConfigurationGroup(groupName,true); }
00898 catch(...){}
00899 }
00900 catch(...)
00901 {
00902 __SUP_COUT__ << "Error detected!" << std::endl;
00903 throw;
00904 }
00905
00906 if(accumulatedTreeErrors != "")
00907 xmlOut.addTextElementToData("Error", "Warnings were found when activating group '" +
00908 groupName + "(" + groupKey + ")" + "'! Please see details below:\n\n" +
00909 accumulatedTreeErrors);
00910 }
00911 else if(requestType == "getActiveConfigGroups");
00912 else if(requestType == "copyViewToCurrentColumns")
00913 {
00914 std::string configName = CgiDataUtilities::getData(cgiIn,"configName");
00915 std::string sourceVersion = CgiDataUtilities::getData(cgiIn,"sourceVersion");
00916
00917 __SUP_COUT__ << "configName: " << configName << std::endl;
00918 __SUP_COUT__ << "sourceVersion: " << sourceVersion << std::endl;
00919 __SUP_COUT__ << "userInfo.username_: " << userInfo.username_ << std::endl;
00920
00921
00922 ConfigurationVersion newTemporaryVersion;
00923 try
00924 {
00925
00926 newTemporaryVersion = cfgMgr->copyViewToCurrentColumns(configName,
00927 ConfigurationVersion(sourceVersion));
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940 __SUP_COUT__ << "New temporary version = " << newTemporaryVersion << std::endl;
00941 }
00942 catch(std::runtime_error& e)
00943 {
00944 __SUP_COUT__ << "Error detected!\n\n " << e.what() << std::endl;
00945 xmlOut.addTextElementToData("Error", "Error copying view from '" +
00946 configName + "_v" + sourceVersion + "'! " +
00947 std::string(e.what()));
00948 }
00949 catch(...)
00950 {
00951 __SUP_COUT__ << "Error detected!\n\n " << std::endl;
00952 xmlOut.addTextElementToData("Error", "Error copying view from '" +
00953 configName + "_v" + sourceVersion + "'! ");
00954 }
00955
00956 handleGetConfigurationXML(xmlOut,cfgMgr,configName,newTemporaryVersion);
00957 }
00958 else if(requestType == "getLastConfigGroups")
00959 {
00960 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* gatewaySupervisor =
00961 allSupervisorInfo_.isWizardMode()?
00962 allSupervisorInfo_.getWizardDescriptor():
00963 allSupervisorInfo_.getGatewayDescriptor();
00964
00965 std::string timeString;
00966 std::pair<std::string , ConfigurationGroupKey> theGroup =
00967 theRemoteWebUsers_.getLastConfigGroup(gatewaySupervisor,
00968 "Configured",timeString);
00969 xmlOut.addTextElementToData("LastConfiguredGroupName",theGroup.first);
00970 xmlOut.addTextElementToData("LastConfiguredGroupKey",theGroup.second.toString());
00971 xmlOut.addTextElementToData("LastConfiguredGroupTime",timeString);
00972 theGroup = theRemoteWebUsers_.getLastConfigGroup(gatewaySupervisor,
00973 "Started",timeString);
00974 xmlOut.addTextElementToData("LastStartedGroupName",theGroup.first);
00975 xmlOut.addTextElementToData("LastStartedGroupKey",theGroup.second.toString());
00976 xmlOut.addTextElementToData("LastStartedGroupTime",timeString);
00977 }
00978 else if(requestType == "savePlanCommandSequence")
00979 {
00980 std::string planName = CgiDataUtilities::getData(cgiIn,"planName");
00981 std::string commands = CgiDataUtilities::postData(cgiIn,"commands");
00982 std::string modifiedTables = CgiDataUtilities::postData(cgiIn,"modifiedTables");
00983 std::string groupName = CgiDataUtilities::getData(cgiIn,"groupName");
00984 std::string groupKey = CgiDataUtilities::getData(cgiIn,"groupKey");
00985
00986 __SUP_COUT__ << "modifiedTables: " << modifiedTables << std::endl;
00987 __SUP_COUT__ << "planName: " << planName << std::endl;
00988 __SUP_COUT__ << "commands: " << commands << std::endl;
00989 __SUP_COUT__ << "groupName: " << groupName << std::endl;
00990 __SUP_COUT__ << "groupKey: " << groupKey << std::endl;
00991
00992 handleSavePlanCommandSequenceXML(xmlOut,cfgMgr,groupName,ConfigurationGroupKey(groupKey),
00993 modifiedTables,userInfo.username_,planName,commands);
00994 }
00995 else if(requestType == "mergeGroups")
00996 {
00997 std::string groupANameContext = CgiDataUtilities::getData(cgiIn,"groupANameContext");
00998 std::string groupAKeyContext = CgiDataUtilities::getData(cgiIn,"groupAKeyContext");
00999 std::string groupBNameContext = CgiDataUtilities::getData(cgiIn,"groupBNameContext");
01000 std::string groupBKeyContext = CgiDataUtilities::getData(cgiIn,"groupBKeyContext");
01001 std::string groupANameConfig = CgiDataUtilities::getData(cgiIn,"groupANameConfig");
01002 std::string groupAKeyConfig = CgiDataUtilities::getData(cgiIn,"groupAKeyConfig");
01003 std::string groupBNameConfig = CgiDataUtilities::getData(cgiIn,"groupBNameConfig");
01004 std::string groupBKeyConfig = CgiDataUtilities::getData(cgiIn,"groupBKeyConfig");
01005 std::string mergeApproach = CgiDataUtilities::getData(cgiIn,"mergeApproach");
01006
01007 __SUP_COUTV__(groupANameContext);
01008 __SUP_COUTV__(groupAKeyContext);
01009 __SUP_COUTV__(groupBNameContext);
01010 __SUP_COUTV__(groupBKeyContext);
01011 __SUP_COUTV__(groupANameConfig);
01012 __SUP_COUTV__(groupAKeyConfig);
01013 __SUP_COUTV__(groupBNameConfig);
01014 __SUP_COUTV__(groupBKeyConfig);
01015 __SUP_COUTV__(mergeApproach);
01016
01017 handleMergeGroupsXML(xmlOut,cfgMgr,
01018 groupANameContext,ConfigurationGroupKey(groupAKeyContext),
01019 groupBNameContext,ConfigurationGroupKey(groupBKeyContext),
01020 groupANameConfig,ConfigurationGroupKey(groupAKeyConfig),
01021 groupBNameConfig,ConfigurationGroupKey(groupBKeyConfig),
01022 userInfo.username_,mergeApproach);
01023 }
01024 else
01025 {
01026 __SUP_SS__ << "requestType '" << requestType << "' request not recognized." << std::endl;
01027 __SUP_COUT__ << "\n" << ss.str();
01028 xmlOut.addTextElementToData("Error", ss.str());
01029 }
01030
01031
01032
01033
01034 std::map<std::string ,
01035 std::pair<
01036 std::string ,
01037 ConfigurationGroupKey> > activeGroupMap =
01038 cfgMgr->getActiveConfigurationGroups();
01039
01040 for(auto& type:activeGroupMap)
01041 {
01042 xmlOut.addTextElementToData(type.first + "-ActiveGroupName",
01043 type.second.first);
01044 xmlOut.addTextElementToData(type.first + "-ActiveGroupKey",
01045 type.second.second.toString());
01046
01047 }
01048
01049
01050 xmlOut.addTextElementToData("versionTracking",
01051 ConfigurationInterface::isVersionTrackingEnabled()?"ON":"OFF");
01052
01053
01054
01055
01056
01057 }
01058 catch(const std::runtime_error& e)
01059 {
01060 __SS__ << "A fatal error occurred while handling the request '" <<
01061 requestType << ".' Error: " <<
01062 e.what() << __E__;
01063 __COUT_ERR__ << "\n" << ss.str();
01064 xmlOut.addTextElementToData("Error", ss.str());
01065
01066 try
01067 {
01068
01069 xmlOut.addTextElementToData("versionTracking",
01070 ConfigurationInterface::isVersionTrackingEnabled()?"ON":"OFF");
01071 }
01072 catch(...)
01073 {
01074 __COUT_ERR__ << "Error getting version tracking status!" << __E__;
01075 }
01076 }
01077 catch(...)
01078 {
01079 __SS__ << "A fatal error occurred while handling the request '" <<
01080 requestType << ".'" << __E__;
01081 __COUT_ERR__ << "\n" << ss.str();
01082 xmlOut.addTextElementToData("Error", ss.str());
01083
01084 try
01085 {
01086
01087 xmlOut.addTextElementToData("versionTracking",
01088 ConfigurationInterface::isVersionTrackingEnabled()?"ON":"OFF");
01089 }
01090 catch(...)
01091 {
01092 __COUT_ERR__ << "Error getting version tracking status!" << __E__;
01093 }
01094 }
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105 void ConfigurationGUISupervisor::handleGetAffectedGroupsXML(HttpXmlDocument& xmlOut,
01106 ConfigurationManagerRW* cfgMgr,
01107 const std::string& rootGroupName, const ConfigurationGroupKey& rootGroupKey,
01108 const std::string& modifiedTables)
01109 try
01110 {
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121 std::map<std::string, std::pair<std::string, ConfigurationGroupKey>> consideredGroups =
01122 cfgMgr->getActiveConfigurationGroups();
01123
01124
01125
01126 if(consideredGroups[ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT].second.isInvalid())
01127 {
01128 __SUP_COUT__ << "Finding a context group to consider..." << __E__;
01129 if(cfgMgr->getFailedConfigurationGroups().find(
01130 ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT) !=
01131 cfgMgr->getFailedConfigurationGroups().end())
01132 {
01133 consideredGroups[ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT] =
01134 cfgMgr->getFailedConfigurationGroups().at(ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT);
01135 }
01136 else if(cfgMgr->getFailedConfigurationGroups().find(
01137 ConfigurationManager::ACTIVE_GROUP_NAME_UNKNOWN) !=
01138 cfgMgr->getFailedConfigurationGroups().end())
01139 {
01140 consideredGroups[ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT] =
01141 cfgMgr->getFailedConfigurationGroups().at(ConfigurationManager::ACTIVE_GROUP_NAME_UNKNOWN);
01142 }
01143 }
01144 if(consideredGroups[ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION].second.isInvalid())
01145 {
01146 __SUP_COUT__ << "Finding a configuration group to consider..." << __E__;
01147 if(cfgMgr->getFailedConfigurationGroups().find(
01148 ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION) !=
01149 cfgMgr->getFailedConfigurationGroups().end())
01150 {
01151 consideredGroups[ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION] =
01152 cfgMgr->getFailedConfigurationGroups().at(ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION);
01153 }
01154 else if(cfgMgr->getFailedConfigurationGroups().find(
01155 ConfigurationManager::ACTIVE_GROUP_NAME_UNKNOWN) !=
01156 cfgMgr->getFailedConfigurationGroups().end())
01157 {
01158 consideredGroups[ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION] =
01159 cfgMgr->getFailedConfigurationGroups().at(ConfigurationManager::ACTIVE_GROUP_NAME_UNKNOWN);
01160 }
01161 }
01162
01163 __SUP_COUTV__(StringMacros::mapToString(consideredGroups));
01164
01165
01166
01167 try
01168 {
01169 std::map<std::string , ConfigurationVersion > rootGroupMemberMap;
01170
01171 cfgMgr->loadConfigurationGroup(rootGroupName,rootGroupKey,
01172 0,&rootGroupMemberMap,0,0,0,0,0,
01173 true);
01174
01175 const std::string& groupType = cfgMgr->getTypeNameOfGroup(rootGroupMemberMap);
01176
01177 consideredGroups[groupType] = std::pair<std::string, ConfigurationGroupKey>(
01178 rootGroupName,rootGroupKey);
01179 }
01180 catch(const std::runtime_error& e)
01181 {
01182
01183 if(rootGroupName.size())
01184 {
01185 __SUP_SS__ << "Failed to determine type of configuration group for " << rootGroupName << "(" <<
01186 rootGroupKey << ")! " << e.what() << std::endl;
01187 __SUP_COUT_ERR__ << "\n" << ss.str();
01188 __SS_THROW__;
01189 }
01190
01191
01192 __SUP_COUT__ << "Did not modify considered active groups due to empty root group name - assuming this was intentional." << std::endl;
01193 }
01194 catch(...)
01195 {
01196
01197 if(rootGroupName.size())
01198 {
01199 __SUP_COUT_ERR__ << "Failed to determine type of configuration group for " << rootGroupName << "(" <<
01200 rootGroupKey << ")!" << std::endl;
01201 throw;
01202 }
01203
01204
01205 __SUP_COUT__ << "Did not modify considered active groups due to empty root group name - assuming this was intentional." << std::endl;
01206 }
01207
01208
01209 std::map<std::string , ConfigurationVersion > modifiedTablesMap;
01210 std::map<std::string , ConfigurationVersion >::iterator modifiedTablesMapIt;
01211 {
01212 std::istringstream f(modifiedTables);
01213 std::string table,version;
01214 while (getline(f, table, ','))
01215 {
01216 getline(f, version, ',');
01217 modifiedTablesMap.insert(
01218 std::pair<std::string ,
01219 ConfigurationVersion >(
01220 table, ConfigurationVersion(version)));
01221 }
01222 __SUP_COUT__ << modifiedTables << std::endl;
01223 for(auto& pair:modifiedTablesMap)
01224 __SUP_COUT__ << "modified table " <<
01225 pair.first << ":" <<
01226 pair.second << std::endl;
01227 }
01228
01229 bool affected;
01230 DOMElement* parentEl;
01231 std::string groupComment;
01232 for(auto group : consideredGroups)
01233 {
01234 if(group.second.second.isInvalid()) continue;
01235
01236 __SUP_COUT__ << "Considering " << group.first << " group " <<
01237 group.second.first << " (" << group.second.second << ")" << std::endl;
01238
01239 affected = false;
01240
01241 std::map<std::string , ConfigurationVersion > memberMap;
01242 cfgMgr->loadConfigurationGroup(group.second.first,group.second.second,
01243 0,&memberMap,0,0,&groupComment,0,0,
01244 true );
01245
01246 __SUP_COUT__ << "groupComment = " << groupComment << std::endl;
01247
01248 for(auto& table: memberMap)
01249 {
01250 if((modifiedTablesMapIt = modifiedTablesMap.find(table.first)) !=
01251 modifiedTablesMap.end() &&
01252 table.second != (*modifiedTablesMapIt).second)
01253 {
01254 __SUP_COUT__ << "Affected by " <<
01255 (*modifiedTablesMapIt).first << ":" <<
01256 (*modifiedTablesMapIt).second << std::endl;
01257 affected = true;
01258 memberMap[table.first] = (*modifiedTablesMapIt).second;
01259 }
01260 }
01261
01262 if(affected)
01263 {
01264
01265 parentEl = xmlOut.addTextElementToData("AffectedActiveGroup", "");
01266 xmlOut.addTextElementToParent("GroupName", group.second.first, parentEl);
01267 xmlOut.addTextElementToParent("GroupKey",
01268 group.second.second.toString(), parentEl);
01269 xmlOut.addTextElementToParent("GroupComment", groupComment, parentEl);
01270
01271
01272 for(auto& table: memberMap)
01273 {
01274 xmlOut.addTextElementToParent("MemberName",
01275 table.first, parentEl);
01276 xmlOut.addTextElementToParent("MemberVersion",
01277 table.second.toString(), parentEl);
01278 }
01279 }
01280 }
01281 }
01282 catch(std::runtime_error& e)
01283 {
01284 __SUP_COUT__ << "Error detected!\n\n " << e.what() << std::endl;
01285 xmlOut.addTextElementToData("Error", "Error getting affected groups! " + std::string(e.what()));
01286 }
01287 catch(...)
01288 {
01289 __SUP_COUT__ << "Error detected!\n\n "<< std::endl;
01290 xmlOut.addTextElementToData("Error", "Error getting affected groups! ");
01291 }
01292
01293
01294
01295
01296
01297
01298
01299
01300
01301
01302 void ConfigurationGUISupervisor::setupActiveTablesXML(
01303 HttpXmlDocument& xmlOut,
01304 ConfigurationManagerRW* cfgMgr,
01305 const std::string& groupName, const ConfigurationGroupKey& groupKey,
01306 const std::string& modifiedTables,
01307 bool refreshAll, bool doGetGroupInfo,
01308 std::map<std::string /*name*/, ConfigurationVersion /*version*/>* returnMemberMap,
01309 bool outputActiveTables,
01310 std::string* accumulatedErrors)
01311 try
01312 {
01313 if(accumulatedErrors)* accumulatedErrors = "";
01314
01315 xmlOut.addTextElementToData("configGroup", groupName);
01316 xmlOut.addTextElementToData("configGroupKey", groupKey.toString());
01317
01318 bool usingActiveGroups = (groupName == "" || groupKey.isInvalid());
01319
01320
01321 if(usingActiveGroups || refreshAll)
01322 cfgMgr->getAllConfigurationInfo(true,accumulatedErrors);
01323
01324 const std::map<std::string, ConfigurationInfo>& allCfgInfo = cfgMgr->getAllConfigurationInfo(false);
01325
01326 std::map<std::string , ConfigurationVersion > modifiedTablesMap;
01327 std::map<std::string , ConfigurationVersion >::iterator modifiedTablesMapIt;
01328
01329 if(usingActiveGroups)
01330 {
01331
01332 __SUP_COUT__ << "Using active groups." << std::endl;
01333 }
01334 else
01335 {
01336 __SUP_COUT__ << "Loading group '" << groupName <<
01337 "(" << groupKey << ")'" << std::endl;
01338
01339 std::string groupComment, groupAuthor, configGroupCreationTime;
01340
01341
01342 cfgMgr->loadConfigurationGroup(groupName,groupKey,
01343 false ,
01344 returnMemberMap,0 ,
01345 accumulatedErrors,
01346 doGetGroupInfo?&groupComment:0,
01347 doGetGroupInfo?&groupAuthor:0,
01348 doGetGroupInfo?&configGroupCreationTime:0);
01349
01350 if(doGetGroupInfo)
01351 {
01352 xmlOut.addTextElementToData("configGroupComment", groupComment);
01353 xmlOut.addTextElementToData("configGroupAuthor", groupAuthor);
01354 xmlOut.addTextElementToData("configGroupCreationTime", configGroupCreationTime);
01355 }
01356 }
01357
01358
01359 {
01360 std::istringstream f(modifiedTables);
01361 std::string table,version;
01362 while (getline(f, table, ','))
01363 {
01364 getline(f, version, ',');
01365 modifiedTablesMap.insert(
01366 std::pair<std::string ,
01367 ConfigurationVersion >(
01368 table, ConfigurationVersion(version)));
01369 }
01370
01371 for(auto& pair:modifiedTablesMap)
01372 __SUP_COUT__ << "modified table " <<
01373 pair.first << ":" <<
01374 pair.second << std::endl;
01375 }
01376
01377
01378 std::map<std::string, ConfigurationVersion> allActivePairs = cfgMgr->getActiveVersions();
01379 xmlOut.addTextElementToData("DefaultNoLink", ViewColumnInfo::DATATYPE_LINK_DEFAULT);
01380 for(auto& activePair: allActivePairs)
01381 {
01382 if(outputActiveTables)
01383 xmlOut.addTextElementToData("ActiveTableName", activePair.first);
01384
01385
01386
01387 if((modifiedTablesMapIt = modifiedTablesMap.find(activePair.first)) !=
01388 modifiedTablesMap.end())
01389 {
01390 __SUP_COUT__ << "Found modified table " <<
01391 (*modifiedTablesMapIt).first << ": trying... " <<
01392 (*modifiedTablesMapIt).second << std::endl;
01393
01394 try
01395 {
01396 allCfgInfo.at(activePair.first).configurationPtr_->setActiveView(
01397 (*modifiedTablesMapIt).second);
01398 }
01399 catch(...)
01400 {
01401 __SUP_SS__ << "Modified table version v" << (*modifiedTablesMapIt).second <<
01402 " failed. Reverting to v" <<
01403 allCfgInfo.at(activePair.first).configurationPtr_->getView().getVersion() <<
01404 "." <<
01405 std::endl;
01406 __SUP_COUT_WARN__ << "Warning detected!\n\n " << ss.str() << std::endl;
01407 xmlOut.addTextElementToData("Warning", "Error setting up active tables!\n\n" +
01408 std::string(ss.str()));
01409 }
01410 }
01411
01412 if(outputActiveTables)
01413 {
01414 xmlOut.addTextElementToData("ActiveTableVersion",
01415 allCfgInfo.at(activePair.first).configurationPtr_->getView().getVersion().toString());
01416 xmlOut.addTextElementToData("ActiveTableComment",
01417 allCfgInfo.at(activePair.first).configurationPtr_->getView().getComment());
01418 }
01419
01420
01421
01422
01423 }
01424
01425 }
01426 catch(std::runtime_error& e)
01427 {
01428 __SUP_SS__ << ("Error setting up active tables!\n\n" + std::string(e.what())) << std::endl;
01429 __SUP_COUT_ERR__ << "\n" << ss.str();
01430 xmlOut.addTextElementToData("Error", ss.str());
01431 }
01432 catch(...)
01433 {
01434 __SUP_SS__ << ("Error setting up active tables!\n\n") << std::endl;
01435 __SUP_COUT_ERR__ << "\n" << ss.str();
01436 xmlOut.addTextElementToData("Error", ss.str());
01437 }
01438
01439
01440
01441
01442
01443
01444
01445
01446
01447
01448
01449
01450
01451
01452
01453
01454
01455 void ConfigurationGUISupervisor::handleFillCreateTreeNodeRecordsXML(HttpXmlDocument& xmlOut,
01456 ConfigurationManagerRW* cfgMgr,
01457 const std::string& groupName, const ConfigurationGroupKey& groupKey,
01458 const std::string& startPath,
01459 const std::string& modifiedTables, const std::string& recordList,
01460 const std::string& author)
01461 {
01462
01463 setupActiveTablesXML(
01464 xmlOut,
01465 cfgMgr,
01466 groupName, groupKey,
01467 modifiedTables,
01468 true , false ,
01469 0 , false );
01470
01471 try
01472 {
01473
01474 ConfigurationTree targetNode =
01475 cfgMgr->getNode(startPath);
01476 ConfigurationBase* config = cfgMgr->getConfigurationByName(
01477 targetNode.getConfigurationName());
01478
01479 __SUP_COUT__ << config->getConfigurationName() << std::endl;
01480 ConfigurationVersion temporaryVersion;
01481
01482
01483
01484
01485
01486
01487
01488
01489 bool firstSave = true;
01490
01491
01492
01493 ConfigurationView backupView;
01494
01495
01496
01497 {
01498 std::istringstream f(recordList);
01499 std::string recordUID;
01500 unsigned int i;
01501
01502 while (getline(f, recordUID, ','))
01503 {
01504 recordUID = StringMacros::decodeURIComponent(recordUID);
01505
01506 __SUP_COUT__ << "recordUID " <<
01507 recordUID << std::endl;
01508
01509 if(firstSave)
01510 {
01511 if(!(temporaryVersion =
01512 targetNode.getConfigurationVersion()).isTemporaryVersion())
01513 {
01514 __SUP_COUT__ << "Start version " << temporaryVersion << std::endl;
01515
01516 temporaryVersion = config->createTemporaryView(temporaryVersion);
01517 cfgMgr->saveNewConfiguration(
01518 targetNode.getConfigurationName(),
01519 temporaryVersion, true);
01520
01521 __SUP_COUT__ << "Created temporary version " << temporaryVersion << std::endl;
01522 }
01523 else
01524 __SUP_COUT__ << "Using temporary version " << temporaryVersion << std::endl;
01525
01526 firstSave = false;
01527
01528
01529 backupView.copy(config->getView(),temporaryVersion,author);
01530 }
01531
01532
01533
01534
01535
01536
01537 unsigned int row = config->getViewP()->addRow(author,
01538 true );
01539
01540
01541 try
01542 {
01543 unsigned int col = config->getViewP()->getColStatus();
01544 config->getViewP()->setURIEncodedValue("1",row,col);
01545 }
01546 catch(...) {}
01547
01548
01549 config->getViewP()->setURIEncodedValue(recordUID,row,
01550 config->getViewP()->getColUID());
01551
01552 }
01553 }
01554
01555 if(!firstSave)
01556 {
01557 try
01558 {
01559 config->getViewP()->init();
01560 }
01561 catch(...)
01562 {
01563 __SUP_COUT_INFO__ << "Reverting to original view." << __E__;
01564 __SUP_COUT__ << "Before:" << __E__;
01565 config->getViewP()->print();
01566 config->getViewP()->copy(backupView,temporaryVersion,author);
01567 __SUP_COUT__ << "After:" << __E__;
01568 config->getViewP()->print();
01569
01570 throw;
01571 }
01572 }
01573
01574 handleFillModifiedTablesXML(xmlOut,cfgMgr);
01575 }
01576 catch(std::runtime_error& e)
01577 {
01578 __SUP_SS__ << ("Error creating new record(s)!\n\n" + std::string(e.what())) << std::endl;
01579 __SUP_COUT_ERR__ << "\n" << ss.str();
01580 xmlOut.addTextElementToData("Error", ss.str());
01581 }
01582 catch(...)
01583 {
01584 __SUP_SS__ << ("Error creating new record(s)!\n\n") << std::endl;
01585 __SUP_COUT_ERR__ << "\n" << ss.str();
01586 xmlOut.addTextElementToData("Error", ss.str());
01587 }
01588 }
01589
01590
01591
01592
01593 void ConfigurationGUISupervisor::handleFillModifiedTablesXML(HttpXmlDocument& xmlOut,
01594 ConfigurationManagerRW* cfgMgr)
01595 try
01596 {
01597
01598 const std::map<std::string, ConfigurationInfo>& allCfgInfo = cfgMgr->getAllConfigurationInfo();
01599 std::map<std::string, ConfigurationVersion> allActivePairs = cfgMgr->getActiveVersions();
01600 for(auto& activePair: allActivePairs)
01601 {
01602 xmlOut.addTextElementToData("NewActiveTableName", activePair.first);
01603 xmlOut.addTextElementToData("NewActiveTableVersion",
01604 allCfgInfo.at(activePair.first).configurationPtr_->getView().getVersion().toString());
01605 xmlOut.addTextElementToData("NewActiveTableComment",
01606 allCfgInfo.at(activePair.first).configurationPtr_->getView().getComment());
01607 }
01608 }
01609 catch(std::runtime_error& e)
01610 {
01611 __SUP_SS__ << ("Error!\n\n" + std::string(e.what())) << std::endl;
01612 __SUP_COUT_ERR__ << "\n" << ss.str();
01613 xmlOut.addTextElementToData("Error", ss.str());
01614 }
01615 catch(...)
01616 {
01617 __SUP_SS__ << ("Error!\n\n") << std::endl;
01618 __SUP_COUT_ERR__ << "\n" << ss.str();
01619 xmlOut.addTextElementToData("Error", ss.str());
01620 }
01621
01622
01623
01624
01625
01626
01627
01628
01629
01630
01631
01632
01633
01634
01635
01636
01637 void ConfigurationGUISupervisor::handleFillDeleteTreeNodeRecordsXML(HttpXmlDocument& xmlOut,
01638 ConfigurationManagerRW* cfgMgr,
01639 const std::string& groupName, const ConfigurationGroupKey& groupKey,
01640 const std::string& startPath,
01641 const std::string& modifiedTables, const std::string& recordList)
01642 {
01643
01644 setupActiveTablesXML(
01645 xmlOut,
01646 cfgMgr,
01647 groupName, groupKey,
01648 modifiedTables,
01649 true , false ,
01650 0 , false );
01651
01652 try
01653 {
01654
01655 ConfigurationTree targetNode =
01656 cfgMgr->getNode(startPath);
01657 ConfigurationBase* config = cfgMgr->getConfigurationByName(
01658 targetNode.getConfigurationName());
01659
01660 __SUP_COUT__ << config->getConfigurationName() << std::endl;
01661 ConfigurationVersion temporaryVersion;
01662
01663
01664
01665
01666
01667
01668
01669
01670 bool firstSave = true;
01671
01672
01673
01674
01675 {
01676 std::istringstream f(recordList);
01677 std::string recordUID;
01678 unsigned int i;
01679
01680 while (getline(f, recordUID, ','))
01681 {
01682 recordUID = StringMacros::decodeURIComponent(recordUID);
01683
01684 __SUP_COUT__ << "recordUID " <<
01685 recordUID << std::endl;
01686
01687 if(firstSave)
01688 {
01689 if(!(temporaryVersion =
01690 targetNode.getConfigurationVersion()).isTemporaryVersion())
01691 {
01692 __SUP_COUT__ << "Start version " << temporaryVersion << std::endl;
01693
01694 temporaryVersion = config->createTemporaryView(temporaryVersion);
01695 cfgMgr->saveNewConfiguration(
01696 targetNode.getConfigurationName(),
01697 temporaryVersion, true);
01698
01699 __SUP_COUT__ << "Created temporary version " << temporaryVersion << std::endl;
01700 }
01701 else
01702 __SUP_COUT__ << "Using temporary version " << temporaryVersion << std::endl;
01703
01704 firstSave = false;
01705 }
01706
01707
01708
01709
01710 unsigned int row = config->getViewP()->findRow(
01711 config->getViewP()->getColUID(),
01712 recordUID
01713 );
01714 config->getViewP()->deleteRow(row);
01715 }
01716 }
01717
01718 if(!firstSave)
01719 config->getViewP()->init();
01720
01721 handleFillModifiedTablesXML(xmlOut,cfgMgr);
01722 }
01723 catch(std::runtime_error& e)
01724 {
01725 __SUP_SS__ << ("Error removing record(s)!\n\n" + std::string(e.what())) << std::endl;
01726 __SUP_COUT_ERR__ << "\n" << ss.str();
01727 xmlOut.addTextElementToData("Error", ss.str());
01728 }
01729 catch(...)
01730 {
01731 __SUP_SS__ << ("Error removing record(s)!\n\n") << std::endl;
01732 __SUP_COUT_ERR__ << "\n" << ss.str();
01733 xmlOut.addTextElementToData("Error", ss.str());
01734 }
01735 }
01736
01737
01738
01739
01740
01741
01742
01743
01744
01745
01746
01747
01748
01749
01750
01751
01752
01753
01754
01755 void ConfigurationGUISupervisor::handleFillSetTreeNodeFieldValuesXML(HttpXmlDocument& xmlOut,
01756 ConfigurationManagerRW* cfgMgr,
01757 const std::string& groupName, const ConfigurationGroupKey& groupKey,
01758 const std::string& startPath,
01759 const std::string& modifiedTables, const std::string& recordList,
01760 const std::string& fieldList, const std::string& valueList,
01761 const std::string& author)
01762 {
01763
01764 setupActiveTablesXML(
01765 xmlOut,
01766 cfgMgr,
01767 groupName, groupKey,
01768 modifiedTables,
01769 true , false ,
01770 0 , false );
01771
01772
01773
01774
01775 try
01776 {
01777 std::vector<std::string > fieldPaths;
01778
01779 {
01780 std::istringstream f(fieldList);
01781 std::string fieldPath;
01782 while (getline(f, fieldPath, ','))
01783 {
01784 fieldPaths.push_back(
01785 StringMacros::decodeURIComponent(fieldPath));
01786 }
01787 __SUP_COUT__ << fieldList << std::endl;
01788 for(const auto& field:fieldPaths)
01789 __SUP_COUT__ << "fieldPath " <<
01790 field << std::endl;
01791 }
01792
01793 std::vector<std::string > fieldValues;
01794
01795 {
01796 std::istringstream f(valueList);
01797 std::string fieldValue;
01798 while (getline(f, fieldValue, ','))
01799 {
01800 fieldValues.push_back(fieldValue);
01801
01802 }
01803
01804
01805 if(valueList.size() &&
01806 valueList[valueList.size()-1] == ',')
01807 fieldValues.push_back("");
01808
01809 __SUP_COUT__ << valueList << std::endl;
01810 for(const auto& value:fieldValues)
01811 __SUP_COUT__ << "fieldValue " <<
01812 value << std::endl;
01813 }
01814
01815 if(fieldPaths.size() != fieldValues.size())
01816 {__SUP_SS__; __THROW__(ss.str()+"Mismatch in fields and values array size!");}
01817
01818
01819 {
01820 ConfigurationBase* config;
01821 ConfigurationVersion temporaryVersion;
01822 std::istringstream f(recordList);
01823 std::string recordUID;
01824 unsigned int i;
01825
01826 while (getline(f, recordUID, ','))
01827 {
01828 recordUID = StringMacros::decodeURIComponent(recordUID);
01829
01830
01831
01832 DOMElement* parentEl = xmlOut.addTextElementToData("fieldValues", recordUID);
01833
01834
01835 for(i=0;i<fieldPaths.size();++i)
01836 {
01837 __SUP_COUT__ << "fieldPath " << fieldPaths[i] << std::endl;
01838 __SUP_COUT__ << "fieldValue " << fieldValues[i] << std::endl;
01839
01840
01841 ConfigurationTree targetNode =
01842 cfgMgr->getNode(startPath + "/" + recordUID + "/" + fieldPaths[i],
01843 true );
01844
01845
01846
01847
01848
01849
01850
01851
01852
01853
01854
01855
01856
01857
01858
01859
01860
01861
01862
01863
01864
01865
01866
01867
01868
01869
01870
01871
01872
01873
01874
01875
01876 __SUP_COUT__ << "Getting table " <<
01877 targetNode.getFieldConfigurationName() << std::endl;
01878
01879
01880 config = cfgMgr->getConfigurationByName(
01881 targetNode.getFieldConfigurationName());
01882 if(!(temporaryVersion =
01883 config->getViewP()->getVersion()).isTemporaryVersion())
01884 {
01885
01886 temporaryVersion = config->createTemporaryView(
01887 config->getViewP()->getVersion());
01888 cfgMgr->saveNewConfiguration(
01889 config->getConfigurationName(),
01890 temporaryVersion, true);
01891
01892 __SUP_COUT__ << "Created temporary version " <<
01893 config->getConfigurationName() << "-v" << temporaryVersion << std::endl;
01894 }
01895
01896 __SUP_COUT__ << "Using temporary version " <<
01897 config->getConfigurationName() << "-v" << temporaryVersion << std::endl;
01898
01899
01900 config->getViewP()->setURIEncodedValue(
01901 fieldValues[i],
01902 targetNode.getFieldRow(),
01903 targetNode.getFieldColumn(),
01904 author);
01905
01906 config->getViewP()->init();
01907 }
01908 }
01909 }
01910
01911 handleFillModifiedTablesXML(xmlOut,cfgMgr);
01912
01913 }
01914 catch(std::runtime_error& e)
01915 {
01916 __SUP_SS__ << ("Error setting field values!\n\n" + std::string(e.what())) << std::endl;
01917 __SUP_COUT_ERR__ << "\n" << ss.str();
01918 xmlOut.addTextElementToData("Error", ss.str());
01919 }
01920 catch(...)
01921 {
01922 __SUP_SS__ << ("Error setting field values!\n\n") << std::endl;
01923 __SUP_COUT_ERR__ << "\n" << ss.str();
01924 xmlOut.addTextElementToData("Error", ss.str());
01925 }
01926 }
01927
01928
01929
01930
01931
01932
01933
01934
01935
01936
01937
01938
01939
01940
01941
01942
01943 void ConfigurationGUISupervisor::handleFillGetTreeNodeFieldValuesXML(HttpXmlDocument& xmlOut, ConfigurationManagerRW* cfgMgr,
01944 const std::string& groupName, const ConfigurationGroupKey& groupKey,
01945 const std::string& startPath,
01946 const std::string& modifiedTables, const std::string& recordList,
01947 const std::string& fieldList)
01948 {
01949
01950 setupActiveTablesXML(
01951 xmlOut,
01952 cfgMgr,
01953 groupName, groupKey,
01954 modifiedTables);
01955
01956
01957
01958
01959 try
01960 {
01961 std::vector<std::string > fieldPaths;
01962
01963 {
01964 std::istringstream f(fieldList);
01965 std::string fieldPath;
01966 while (getline(f, fieldPath, ','))
01967 {
01968 fieldPaths.push_back(
01969 StringMacros::decodeURIComponent(fieldPath));
01970 }
01971 __SUP_COUT__ << fieldList << std::endl;
01972 for(auto& field:fieldPaths)
01973 __SUP_COUT__ << "fieldPath " <<
01974 field << std::endl;
01975 }
01976
01977
01978 {
01979 std::istringstream f(recordList);
01980 std::string recordUID;
01981 while (getline(f, recordUID, ','))
01982 {
01983 recordUID = StringMacros::decodeURIComponent(recordUID);
01984
01985 __SUP_COUT__ << "recordUID " <<
01986 recordUID << std::endl;
01987
01988 DOMElement* parentEl = xmlOut.addTextElementToData("fieldValues", recordUID);
01989
01990
01991 for(const auto& fieldPath:fieldPaths)
01992 {
01993 __SUP_COUT__ << "fieldPath " << fieldPath << std::endl;
01994
01995 xmlOut.addTextElementToParent("FieldPath",
01996 fieldPath,
01997 parentEl);
01998 xmlOut.addTextElementToParent("FieldValue",
01999 cfgMgr->getNode(startPath + "/" + recordUID + "/" + fieldPath).getValueAsString(),
02000 parentEl);
02001 }
02002 }
02003 }
02004 }
02005 catch(std::runtime_error& e)
02006 {
02007 __SUP_SS__ << ("Error getting field values!\n\n" + std::string(e.what())) << std::endl;
02008 __SUP_COUT_ERR__ << "\n" << ss.str();
02009 xmlOut.addTextElementToData("Error", ss.str());
02010 }
02011 catch(...)
02012 {
02013 __SUP_SS__ << ("Error getting field values!\n\n") << std::endl;
02014 __SUP_COUT_ERR__ << "\n" << ss.str();
02015 xmlOut.addTextElementToData("Error", ss.str());
02016 }
02017 }
02018
02019
02020
02021
02022
02023
02024
02025
02026
02027
02028
02029
02030
02031
02032
02033
02034
02035
02036
02037 void ConfigurationGUISupervisor::handleFillTreeNodeCommonFieldsXML(HttpXmlDocument& xmlOut,
02038 ConfigurationManagerRW* cfgMgr,
02039 const std::string& groupName, const ConfigurationGroupKey& groupKey,
02040 const std::string& startPath, unsigned int depth,
02041 const std::string& modifiedTables, const std::string& recordList,
02042 const std::string& fieldList)
02043 {
02044
02045 setupActiveTablesXML(
02046 xmlOut,
02047 cfgMgr,
02048 groupName, groupKey,
02049 modifiedTables);
02050
02051
02052 try
02053 {
02054 DOMElement* parentEl = xmlOut.addTextElementToData("fields", startPath);
02055
02056 if(depth == 0)
02057 {
02058 __SUP_SS__ << "Depth of search must be greater than 0." << __E__;
02059 __SUP_COUT__ << ss.str();
02060 __SS_THROW__;
02061 }
02062
02063
02064
02065
02066
02067
02068 std::vector<ConfigurationTree::RecordField> retFieldList;
02069
02070
02071 {
02072 ConfigurationTree startNode = cfgMgr->getNode(startPath);
02073 if(startNode.isLinkNode() && startNode.isDisconnected())
02074 {
02075 __SUP_SS__ << "Start path was a disconnected link node!" << std::endl;
02076 __SUP_COUT_ERR__ << "\n" << ss.str();
02077 __SS_THROW__;
02078 return;
02079
02080 }
02081
02082 std::vector<std::string > fieldAcceptList, fieldRejectList;
02083 if(fieldList != "")
02084 {
02085
02086 {
02087 std::istringstream f(fieldList);
02088 std::string fieldPath, decodedFieldPath;
02089 while (getline(f, fieldPath, ','))
02090 {
02091 decodedFieldPath = StringMacros::decodeURIComponent(fieldPath);
02092
02093 if(decodedFieldPath[0] == '!')
02094 fieldRejectList.push_back(decodedFieldPath.substr(1));
02095 else
02096 fieldAcceptList.push_back(decodedFieldPath);
02097 }
02098 __SUP_COUT__ << fieldList << std::endl;
02099 for(auto& field:fieldAcceptList)
02100 __SUP_COUT__ << "fieldAcceptList " <<
02101 field << std::endl;
02102 for(auto& field:fieldRejectList)
02103 __SUP_COUT__ << "fieldRejectList " <<
02104 field << std::endl;
02105 }
02106 }
02107
02108 std::vector<std::string > records;
02109 if(recordList == "*")
02110 {
02111 records.clear();
02112 records = startNode.getChildrenNames();
02113 __SUP_COUT__ << "Translating wildcard..." << __E__;
02114 for(auto& record:records)
02115 __SUP_COUT__ << "recordList " <<
02116 record << std::endl;
02117 }
02118 else if(recordList != "")
02119 {
02120
02121 {
02122 std::istringstream f(recordList);
02123 std::string recordStr;
02124 while (getline(f, recordStr, ','))
02125 {
02126 records.push_back(
02127 StringMacros::decodeURIComponent(recordStr));
02128 }
02129 __SUP_COUT__ << recordList << std::endl;
02130 for(auto& record:records)
02131 __SUP_COUT__ << "recordList " <<
02132 record << std::endl;
02133 }
02134 }
02135
02136 retFieldList = startNode.getCommonFields(
02137 records,fieldAcceptList,fieldRejectList,depth);
02138 }
02139
02140 DOMElement* parentTypeEl;
02141 for(const auto& fieldInfo:retFieldList)
02142 {
02143 xmlOut.addTextElementToParent("FieldTableName",
02144 fieldInfo.tableName_,
02145 parentEl);
02146 xmlOut.addTextElementToParent("FieldColumnName",
02147 fieldInfo.columnName_,
02148 parentEl);
02149 xmlOut.addTextElementToParent("FieldRelativePath",
02150 fieldInfo.relativePath_,
02151 parentEl);
02152 xmlOut.addTextElementToParent("FieldColumnType",
02153 fieldInfo.columnInfo_->getType(),
02154 parentEl);
02155 xmlOut.addTextElementToParent("FieldColumnDataType",
02156 fieldInfo.columnInfo_->getDataType(),
02157 parentEl);
02158 xmlOut.addTextElementToParent("FieldColumnDefaultValue",
02159 fieldInfo.columnInfo_->getDefaultValue(),
02160 parentEl);
02161
02162 parentTypeEl = xmlOut.addTextElementToParent("FieldColumnDataChoices",
02163 "", parentEl);
02164
02165
02166 auto dataChoices = fieldInfo.columnInfo_->getDataChoices();
02167 xmlOut.addTextElementToParent("FieldColumnDataChoice",
02168 fieldInfo.columnInfo_->getDefaultValue(),
02169 parentTypeEl);
02170 for(const auto& dataChoice : dataChoices)
02171 xmlOut.addTextElementToParent("FieldColumnDataChoice",
02172 dataChoice,
02173 parentTypeEl);
02174 }
02175 }
02176 catch(std::runtime_error& e)
02177 {
02178 __SUP_SS__ << ("Error getting common fields!\n\n" + std::string(e.what())) << std::endl;
02179 __SUP_COUT_ERR__ << "\n" << ss.str();
02180 xmlOut.addTextElementToData("Error", ss.str());
02181 }
02182 catch(...)
02183 {
02184 __SUP_SS__ << ("Error getting common fields!\n\n") << std::endl;
02185 __SUP_COUT_ERR__ << "\n" << ss.str();
02186 xmlOut.addTextElementToData("Error", ss.str());
02187 }
02188
02189 }
02190
02191
02192
02193
02194
02195
02196
02197
02198
02199
02200
02201
02202
02203
02204
02205
02206
02207
02208
02209
02210
02211
02212
02213
02214
02215
02216 void ConfigurationGUISupervisor::handleFillUniqueFieldValuesForRecordsXML(HttpXmlDocument& xmlOut,
02217 ConfigurationManagerRW* cfgMgr,
02218 const std::string& groupName, const ConfigurationGroupKey& groupKey,
02219 const std::string& startPath,
02220 const std::string& modifiedTables, const std::string& recordList,
02221 const std::string& fieldList)
02222 {
02223
02224 setupActiveTablesXML(
02225 xmlOut,
02226 cfgMgr,
02227 groupName, groupKey,
02228 modifiedTables);
02229
02230
02231 try
02232 {
02233
02234
02235 if(startPath == "/")
02236 return;
02237
02238 std::vector<std::string > fieldsToGet;
02239 if(fieldList != "")
02240 {
02241
02242 {
02243 std::istringstream f(fieldList);
02244 std::string fieldPath;
02245 while (getline(f, fieldPath, ','))
02246 {
02247 fieldsToGet.push_back(
02248 StringMacros::decodeURIComponent(fieldPath));
02249 }
02250 __SUP_COUT__ << fieldList << std::endl;
02251 for(auto& field:fieldsToGet)
02252 __SUP_COUT__ << "fieldsToGet " <<
02253 field << std::endl;
02254 }
02255 }
02256
02257
02258
02259 ConfigurationTree startNode = cfgMgr->getNode(startPath);
02260 if(startNode.isLinkNode() && startNode.isDisconnected())
02261 {
02262 __SUP_SS__ << "Start path was a disconnected link node!" << std::endl;
02263 __SUP_COUT_ERR__ << "\n" << ss.str();
02264 __SS_THROW__;
02265 }
02266
02267 std::vector<std::string > records;
02268 if(recordList == "*")
02269 {
02270 records.clear();
02271 records = startNode.getChildrenNames();
02272 __SUP_COUT__ << "Translating wildcard..." << __E__;
02273 for(auto& record:records)
02274 __SUP_COUT__ << "recordList " <<
02275 record << std::endl;
02276 }
02277 else if(recordList != "")
02278 {
02279
02280 {
02281 std::istringstream f(recordList);
02282 std::string recordStr;
02283 while (getline(f, recordStr, ','))
02284 {
02285 records.push_back(
02286 StringMacros::decodeURIComponent(recordStr));
02287 }
02288 __SUP_COUT__ << recordList << std::endl;
02289 for(auto& record:records)
02290 __SUP_COUT__ << "recordList " <<
02291 record << std::endl;
02292 }
02293 }
02294
02295
02296
02297
02298 for(auto& field:fieldsToGet)
02299 {
02300 __SUP_COUT__ << "fieldsToGet " <<
02301 field << std::endl;
02302
02303 DOMElement* parentEl = xmlOut.addTextElementToData("field", field);
02304
02305
02306
02307 std::set<std::string > uniqueValues;
02308
02309 uniqueValues = cfgMgr->getNode(startPath).getUniqueValuesForField(
02310 records,field);
02311
02312 for(auto& uniqueValue:uniqueValues)
02313 {
02314 __SUP_COUT__ << "uniqueValue " <<
02315 uniqueValue << std::endl;
02316
02317 xmlOut.addTextElementToParent("uniqueValue",
02318 uniqueValue,
02319 parentEl);
02320 }
02321 }
02322 }
02323 catch(std::runtime_error& e)
02324 {
02325 __SUP_SS__ << ("Error getting common fields!\n\n" + std::string(e.what())) << std::endl;
02326 __SUP_COUT_ERR__ << "\n" << ss.str();
02327 xmlOut.addTextElementToData("Error", ss.str());
02328 }
02329 catch(...)
02330 {
02331 __SUP_SS__ << ("Error getting common fields!\n\n") << std::endl;
02332 __SUP_COUT_ERR__ << "\n" << ss.str();
02333 xmlOut.addTextElementToData("Error", ss.str());
02334 }
02335
02336 }
02337
02338
02339
02340
02341
02342
02343
02344
02345
02346
02347
02348
02349
02350
02351
02352
02353
02354
02355
02356
02357 void ConfigurationGUISupervisor::handleFillTreeViewXML(HttpXmlDocument& xmlOut, ConfigurationManagerRW* cfgMgr,
02358 const std::string& groupName, const ConfigurationGroupKey& groupKey,
02359 const std::string& startPath, unsigned int depth, bool hideStatusFalse,
02360 const std::string& modifiedTables, const std::string& filterList)
02361 {
02362
02363
02364
02365
02366
02367
02368
02369
02370
02371
02372
02373
02374
02375
02376
02377
02378
02379
02380
02381
02382
02383
02384
02385
02386
02387
02388
02389
02390
02391
02392
02393
02394 bool usingActiveGroups = (groupName == "" || groupKey.isInvalid());
02395 std::map<std::string , ConfigurationVersion > memberMap;
02396
02397 std::string accumulatedErrors;
02398 setupActiveTablesXML(
02399 xmlOut,
02400 cfgMgr,
02401 groupName, groupKey,
02402 modifiedTables,
02403 (startPath == "/"),
02404 (startPath == "/"),
02405 &memberMap,
02406 true,
02407 &accumulatedErrors
02408 );
02409 if(accumulatedErrors != "")
02410 xmlOut.addTextElementToData("Warning",
02411 accumulatedErrors);
02412
02413 __SUP_COUT__ << "Active tables are setup. Warning string: '" << accumulatedErrors << "'" << std::endl;
02414
02415 try
02416 {
02417 DOMElement* parentEl = xmlOut.addTextElementToData("tree", startPath);
02418
02419 if(depth == 0) return;
02420
02421 std::vector<std::pair<std::string,ConfigurationTree> > rootMap;
02422
02423 if(startPath == "/")
02424 {
02425
02426
02427 std::string accumulateTreeErrs;
02428
02429 if(usingActiveGroups)
02430 rootMap = cfgMgr->getChildren(0,&accumulateTreeErrs);
02431 else
02432 rootMap = cfgMgr->getChildren(&memberMap,&accumulateTreeErrs);
02433
02434 __SUP_COUT__ << "accumulateTreeErrs = " << accumulateTreeErrs << std::endl;
02435 if(accumulateTreeErrs != "")
02436 xmlOut.addTextElementToData("TreeErrors",
02437 accumulateTreeErrs);
02438 }
02439 else
02440 {
02441 ConfigurationTree startNode = cfgMgr->getNode(startPath,
02442 true );
02443 if(startNode.isLinkNode() && startNode.isDisconnected())
02444 {
02445 xmlOut.addTextElementToData("DisconnectedStartNode","1");
02446 return;
02447
02448 }
02449
02450 std::map<std::string , std::string > filterMap;
02451 StringMacros::getMapFromString(filterList,filterMap,
02452 std::set<char>({';'}),
02453 std::set<char>({'='}));
02454
02455 __COUTV__(StringMacros::mapToString(filterMap));
02456
02457 rootMap = cfgMgr->getNode(startPath).getChildren(filterMap);
02458 }
02459
02460 for(auto& treePair:rootMap)
02461 recursiveTreeToXML(treePair.second,depth-1,xmlOut,parentEl,hideStatusFalse);
02462 }
02463 catch(std::runtime_error& e)
02464 {
02465 __SUP_SS__ << "Error detected generating XML tree!\n\n " << e.what() << std::endl;
02466 __SUP_COUT_ERR__ << "\n" << ss.str();
02467 xmlOut.addTextElementToData("Error", ss.str());
02468 }
02469 catch(...)
02470 {
02471 __SUP_SS__ << "Error detected generating XML tree!" << std::endl;
02472 __SUP_COUT_ERR__ << "\n" << ss.str();
02473 xmlOut.addTextElementToData("Error", ss.str());
02474 }
02475 }
02476
02477
02478
02479
02480
02481
02482
02483 void ConfigurationGUISupervisor::recursiveTreeToXML(const ConfigurationTree& t, unsigned int depth, HttpXmlDocument& xmlOut,
02484 DOMElement* parentEl, bool hideStatusFalse)
02485 {
02486
02487
02488 if(t.isValueNode())
02489 {
02490 parentEl = xmlOut.addTextElementToParent("node", t.getValueName(), parentEl);
02491 xmlOut.addTextElementToParent("value", t.getValueAsString(), parentEl);
02492 parentEl = xmlOut.addTextElementToParent("valueType", t.getValueType(), parentEl);
02493
02494
02495
02496 if(t.getValueType() == ViewColumnInfo::TYPE_FIXED_CHOICE_DATA ||
02497 t.getValueType() == ViewColumnInfo::TYPE_BITMAP_DATA)
02498 {
02499
02500
02501 std::vector<std::string> choices = t.getFixedChoices();
02502 for(const auto& choice:choices)
02503 xmlOut.addTextElementToParent("fixedChoice", choice, parentEl);
02504 }
02505 }
02506 else
02507 {
02508 if(t.isLinkNode())
02509 {
02510
02511
02512
02513 parentEl = xmlOut.addTextElementToParent("node", t.getValueName(), parentEl);
02514
02515 if(t.isDisconnected())
02516 {
02517 __COUT__ << t.getValueName() << std::endl;
02518
02519
02520
02521
02522 xmlOut.addTextElementToParent("valueType", t.getValueType(), parentEl);
02523
02524
02525 xmlOut.addTextElementToParent(
02526 (t.isGroupLinkNode()?"Group":"U") + std::string("ID"),
02527 t.getDisconnectedLinkID(),
02528 parentEl);
02529 xmlOut.addTextElementToParent("LinkConfigurationName",
02530 t.getDisconnectedTableName(),
02531 parentEl);
02532 xmlOut.addTextElementToParent("LinkIndex",
02533 t.getChildLinkIndex(),
02534 parentEl);
02535
02536
02537
02538 DOMElement* choicesParentEl = xmlOut.addTextElementToParent("fixedChoices", "",
02539 parentEl);
02540
02541
02542
02543 std::vector<std::string> choices = t.getFixedChoices();
02544 __COUT__ << "choices.size() " << choices.size() << std::endl;
02545
02546 for(const auto& choice:choices)
02547 xmlOut.addTextElementToParent("fixedChoice", choice, choicesParentEl);
02548
02549
02550
02551
02552
02553
02554 return;
02555 }
02556
02557
02558
02559 xmlOut.addTextElementToParent(
02560 (t.isGroupLinkNode()?"Group":"U") + std::string("ID"),
02561 t.getValueAsString(), parentEl);
02562
02563 xmlOut.addTextElementToParent("LinkConfigurationName", t.getConfigurationName(),
02564 parentEl);
02565
02566 xmlOut.addTextElementToParent("LinkIndex", t.getChildLinkIndex(),
02567 parentEl);
02568
02569
02570 {
02571 DOMElement* choicesParentEl = xmlOut.addTextElementToParent("fixedChoices", "", parentEl);
02572 std::vector<std::string> choices = t.getFixedChoices();
02573
02574
02575
02576 for(const auto& choice:choices)
02577 xmlOut.addTextElementToParent("fixedChoice", choice, choicesParentEl);
02578 }
02579 }
02580 else
02581 {
02582 bool returnNode = true;
02583
02584 if(hideStatusFalse)
02585 {
02586 try
02587 {
02588 t.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue(returnNode);
02589 } catch(...) {}
02590 }
02591
02592 if(returnNode)
02593 parentEl = xmlOut.addTextElementToParent("node", t.getValueAsString(), parentEl);
02594 else
02595 return;
02596 }
02597
02598
02599
02600 if(depth >= 1)
02601 {
02602 auto C = t.getChildren();
02603 for(auto& c:C)
02604 recursiveTreeToXML(c.second,depth-1,xmlOut,parentEl,hideStatusFalse);
02605 }
02606 }
02607 }
02608
02609
02610
02611
02612
02613
02614
02615
02616
02617
02618 void ConfigurationGUISupervisor::handleGetLinkToChoicesXML(HttpXmlDocument& xmlOut,
02619 ConfigurationManagerRW* cfgMgr, const std::string& linkToTableName,
02620 const ConfigurationVersion& linkToTableVersion,
02621 const std::string& linkIdType, const std::string& linkIndex,
02622 const std::string& linkInitId)
02623 try
02624 {
02625
02626
02627
02628
02629
02630
02631
02632
02633
02634
02635
02636 const std::string& configName = linkToTableName;
02637 const ConfigurationVersion& version = linkToTableVersion;
02638 ConfigurationBase* config = cfgMgr->getConfigurationByName(configName);
02639 try
02640 {
02641 config->setActiveView(version);
02642 }
02643 catch(...)
02644 {
02645 __SUP_COUT__ << "Failed to find stored version, so attempting to load version: " <<
02646 version << std::endl;
02647 cfgMgr->getVersionedConfigurationByName(
02648 configName, version);
02649 }
02650
02651 if(version != config->getViewVersion())
02652 {
02653 __SUP_SS__ << "Target table version (" << version <<
02654 ") is not the currently active version (" << config->getViewVersion()
02655 << ". Try refreshing the tree." << std::endl;
02656 __SUP_COUT_WARN__ << ss.str();
02657 __SS_THROW__;
02658 }
02659
02660 __SUP_COUT__ << "Active version is " << config->getViewVersion() << std::endl;
02661
02662 if(linkIdType == "UID")
02663 {
02664
02665 unsigned int col = config->getView().getColUID();
02666 for(unsigned int row = 0; row < config->getView().getNumberOfRows(); ++row)
02667 xmlOut.addTextElementToData("linkToChoice",
02668 config->getView().getDataView()[row][col]);
02669 }
02670 else if(linkIdType == "GroupID")
02671 {
02672
02673
02674
02675
02676 std::set<std::string> setOfGroupIDs =
02677 config->getView().getSetOfGroupIDs(linkIndex);
02678
02679
02680
02681
02682 bool foundInitId = false;
02683 for(const auto& groupID : setOfGroupIDs)
02684 {
02685 if(!foundInitId &&
02686 linkInitId == groupID)
02687 foundInitId = true;
02688
02689 xmlOut.addTextElementToData("linkToChoice",
02690 groupID);
02691 }
02692
02693 if(!foundInitId)
02694 xmlOut.addTextElementToData("linkToChoice",
02695 linkInitId);
02696
02697
02698 unsigned int col = config->getView().getColUID();
02699 for(unsigned int row = 0; row < config->getView().getNumberOfRows(); ++row)
02700 {
02701 xmlOut.addTextElementToData("groupChoice",
02702 config->getView().getDataView()[row][col]);
02703 if(config->getView().isEntryInGroup(row,linkIndex,linkInitId))
02704 xmlOut.addTextElementToData("groupMember",
02705 config->getView().getDataView()[row][col]);
02706 }
02707 }
02708 else
02709 {
02710 __SUP_SS__ << "Unrecognized linkIdType '" << linkIdType
02711 << ".'" << std::endl;
02712 __SS_THROW__;
02713 }
02714
02715
02716 }
02717 catch(std::runtime_error& e)
02718 {
02719 __SUP_SS__ << "Error detected saving tree node!\n\n " << e.what() << std::endl;
02720 __SUP_COUT_ERR__ << "\n" << ss.str() << std::endl;
02721 xmlOut.addTextElementToData("Error", ss.str());
02722 }
02723 catch(...)
02724 {
02725 __SUP_SS__ << "Error detected saving tree node!\n\n "<< std::endl;
02726 __SUP_COUT_ERR__ << "\n" << ss.str() << std::endl;
02727 xmlOut.addTextElementToData("Error", ss.str());
02728 }
02729
02730
02731
02732
02733 void ConfigurationGUISupervisor::handleMergeGroupsXML(HttpXmlDocument& xmlOut,
02734 ConfigurationManagerRW* cfgMgr,
02735 const std::string& groupANameContext, const ConfigurationGroupKey& groupAKeyContext,
02736 const std::string& groupBNameContext, const ConfigurationGroupKey& groupBKeyContext,
02737 const std::string& groupANameConfig, const ConfigurationGroupKey& groupAKeyConfig,
02738 const std::string& groupBNameConfig, const ConfigurationGroupKey& groupBKeyConfig,
02739 const std::string& author, const std::string& mergeApproach)
02740 try
02741 {
02742 __SUP_COUT__ << "Merging context group pair " <<
02743 groupANameContext << " (" << groupAKeyContext << ") & " <<
02744 groupBNameContext << " (" << groupBKeyContext << ") and config group pair " <<
02745 groupANameConfig << " (" << groupAKeyConfig << ") & " <<
02746 groupBNameConfig << " (" << groupBKeyConfig << ") with approach '" <<
02747 mergeApproach << __E__;
02748
02749
02750
02751
02752
02753
02754
02755
02756
02757
02758
02759
02760
02761 if(!(mergeApproach == "Rename" || mergeApproach == "Replace" || mergeApproach == "Skip"))
02762 {
02763 __SS__ << "Error! Invalid merge approach '" << mergeApproach << ".'" << __E__;
02764 __SS_THROW__;
02765 }
02766
02767 std::map<std::string , ConfigurationVersion > memberMapAContext, memberMapBContext,
02768 memberMapAConfig, memberMapBConfig;
02769
02770
02771
02772 bool skippingContextPair = false;
02773 bool skippingConfigPair = false;
02774 if(groupANameContext.size() == 0 || groupANameContext[0] == ' ' ||
02775 groupBNameContext.size() == 0 || groupBNameContext[0] == ' ')
02776 {
02777 skippingContextPair = true;
02778 __SUP_COUTV__(skippingContextPair);
02779 }
02780 if(groupANameConfig.size() == 0 || groupANameConfig[0] == ' ' ||
02781 groupBNameConfig.size() == 0 || groupBNameConfig[0] == ' ')
02782 {
02783 skippingConfigPair = true;
02784 __SUP_COUTV__(skippingConfigPair);
02785 }
02786
02787
02788 if(!skippingContextPair)
02789 {
02790 cfgMgr->loadConfigurationGroup(groupANameContext,groupAKeyContext,
02791 false ,&memberMapAContext,0 ,0 ,
02792 0 , 0 , 0 ,
02793 false , 0
02794 );
02795 __SUP_COUTV__(StringMacros::mapToString(memberMapAContext));
02796
02797 cfgMgr->loadConfigurationGroup(groupBNameContext,groupBKeyContext,
02798 false ,&memberMapBContext,0 ,0 ,
02799 0 , 0 , 0 ,
02800 false , 0
02801 );
02802
02803 __SUP_COUTV__(StringMacros::mapToString(memberMapBContext));
02804 }
02805
02806
02807 if(!skippingConfigPair)
02808 {
02809 cfgMgr->loadConfigurationGroup(groupANameConfig,groupAKeyConfig,
02810 false ,&memberMapAConfig,0 ,0 ,
02811 0 , 0 , 0 ,
02812 false , 0
02813 );
02814 __SUP_COUTV__(StringMacros::mapToString(memberMapAConfig));
02815
02816 cfgMgr->loadConfigurationGroup(groupBNameConfig,groupBKeyConfig,
02817 false ,&memberMapBConfig,0 ,0 ,
02818 0 , 0 , 0 ,
02819 false , 0
02820 );
02821
02822 __SUP_COUTV__(StringMacros::mapToString(memberMapBConfig));
02823 }
02824
02825
02826
02827
02828
02829 std::map< std::pair<std::string ,std::string >,
02830 std::string > uidConversionMap;
02831 std::map< std::pair<std::string ,std::pair<std::string ,std::string >>,
02832 std::string > groupidConversionMap;
02833
02834
02835 for(unsigned int i=0;i<2;++i)
02836 {
02837 if(i==0 && mergeApproach != "Rename") continue;
02838
02839
02840 for(unsigned int j=0;j<2;++j)
02841 {
02842 if(j == 0 && skippingContextPair)
02843 {
02844 __COUT__ << "Skipping context pair..." << __E__;
02845 continue;
02846 }
02847 else if(j == 1 && skippingConfigPair)
02848 {
02849 __COUT__ << "Skipping config pair..." << __E__;
02850 continue;
02851 }
02852
02853 std::map<std::string , ConfigurationVersion >& memberMapAref =
02854 j == 0?memberMapAContext:memberMapAConfig;
02855
02856 std::map<std::string , ConfigurationVersion >& memberMapBref =
02857 j == 0?memberMapBContext:memberMapBConfig;
02858
02859 if(j == 0)
02860 __COUT__ << "Context pair..." << __E__;
02861 else
02862 __COUT__ << "Config pair..." << __E__;
02863
02864 __COUT__ << "Starting member map B scan." << __E__;
02865 for(const auto bkey : memberMapBref)
02866 {
02867 __SUP_COUTV__(bkey.first);
02868
02869 if(memberMapAref.find(bkey.first) == memberMapAref.end())
02870 {
02871
02872 memberMapAref[bkey.first] = bkey.second;
02873 }
02874 else if(memberMapAref[bkey.first] != bkey.second)
02875 {
02876
02877 __SUP_COUTV__(memberMapAref[bkey.first]);
02878 __SUP_COUTV__(bkey.second);
02879
02880
02881 ConfigurationBase* config = cfgMgr->getConfigurationByName(bkey.first);
02882
02883 __SUP_COUT__ << "Got configuration." << __E__;
02884
02885 ConfigurationVersion newVersion = config->mergeViews(
02886 cfgMgr->getVersionedConfigurationByName(bkey.first,
02887 memberMapAref[bkey.first])->getView(),
02888 cfgMgr->getVersionedConfigurationByName(bkey.first,bkey.second)->getView(),
02889 ConfigurationVersion() ,
02890 author,
02891 mergeApproach ,
02892 uidConversionMap, groupidConversionMap,
02893 i==0 ,
02894 i==1 ,
02895 config->getConfigurationName() ==
02896 ConfigurationManager::XDAQ_APPLICATION_CONFIG_NAME
02897 );
02898
02899 if(i==1)
02900 {
02901 __SUP_COUTV__(newVersion);
02902
02903 try
02904 {
02905
02906
02907 newVersion = saveModifiedVersionXML(xmlOut,cfgMgr,
02908 bkey.first,
02909 ConfigurationVersion() ,
02910 false ,
02911 config,
02912 newVersion ,
02913 false ,
02914 true );
02915 }
02916 catch(std::runtime_error& e)
02917 {
02918 __SUP_SS__ << "There was an error saving the '" <<
02919 config->getConfigurationName() << "' merge result to a persistent table version. " <<
02920 "Perhaps you can modify this table in one of the groups to resolve this issue, and then re-merge." <<
02921 __E__ << e.what();
02922 __SS_THROW__;
02923 }
02924
02925 __SUP_COUTV__(newVersion);
02926
02927
02928 memberMapAref[bkey.first] = newVersion;
02929 }
02930 }
02931 }
02932 }
02933 }
02934
02935
02936
02937 if(!skippingContextPair)
02938 {
02939 __SUP_COUT__ << "New context member map complete." << __E__;
02940 __SUP_COUTV__(StringMacros::mapToString(memberMapAContext));
02941
02942
02943 ConfigurationGroupKey newKeyContext =
02944 cfgMgr->saveNewConfigurationGroup(groupANameContext,memberMapAContext,
02945 "Merger of group " + groupANameContext + " (" + groupAKeyContext.toString() + ") and " +
02946 groupBNameContext + " (" + groupBKeyContext.toString() + ").");
02947
02948
02949 xmlOut.addTextElementToData("ContextGroupName", groupANameContext);
02950 xmlOut.addTextElementToData("ContextGroupKey", newKeyContext.toString());
02951 }
02952 if(!skippingConfigPair)
02953 {
02954 __SUP_COUT__ << "New config member map complete." << __E__;
02955 __SUP_COUTV__(StringMacros::mapToString(memberMapAConfig));
02956
02957 ConfigurationGroupKey newKeyConfig =
02958 cfgMgr->saveNewConfigurationGroup(groupANameConfig,memberMapAConfig,
02959 "Merger of group " + groupANameConfig + " (" + groupAKeyConfig.toString() + ") and " +
02960 groupBNameConfig + " (" + groupBKeyConfig.toString() + ").");
02961
02962
02963 xmlOut.addTextElementToData("ConfigGroupName", groupANameConfig);
02964 xmlOut.addTextElementToData("ConfigGroupKey", newKeyConfig.toString());
02965 }
02966
02967
02968
02969 }
02970 catch(std::runtime_error& e)
02971 {
02972 __SUP_SS__ << "Error merging context group pair " <<
02973 groupANameContext << " (" << groupAKeyContext << ") & " <<
02974 groupBNameContext << " (" << groupBKeyContext << ") and config group pair " <<
02975 groupANameConfig << " (" << groupAKeyConfig << ") & " <<
02976 groupBNameConfig << " (" << groupBKeyConfig << ") with approach '" <<
02977 mergeApproach << "': \n\n" <<
02978 e.what() << std::endl;
02979 __SUP_COUT_ERR__ << "\n" << ss.str() << std::endl;
02980 xmlOut.addTextElementToData("Error", ss.str());
02981 }
02982 catch(...)
02983 {
02984 __SUP_SS__ << "Unknown error merging context group pair " <<
02985 groupANameContext << " (" << groupAKeyContext << ") & " <<
02986 groupBNameContext << " (" << groupBKeyContext << ") and config group pair " <<
02987 groupANameConfig << " (" << groupAKeyConfig << ") & " <<
02988 groupBNameConfig << " (" << groupBKeyConfig << ") with approach '" <<
02989 mergeApproach << ".' \n\n";
02990 __SUP_COUT_ERR__ << "\n" << ss.str() << std::endl;
02991 xmlOut.addTextElementToData("Error", ss.str());
02992 }
02993
02994
02995
02996 void ConfigurationGUISupervisor::handleSavePlanCommandSequenceXML(HttpXmlDocument& xmlOut,
02997 ConfigurationManagerRW* cfgMgr,
02998 const std::string& groupName, const ConfigurationGroupKey& groupKey,
02999 const std::string& modifiedTables, const std::string& author,
03000 const std::string& planName,
03001 const std::string& commandString)
03002 try
03003 {
03004 __MOUT__ << "handleSavePlanCommandSequenceXML" << std::endl;
03005
03006
03007 setupActiveTablesXML(
03008 xmlOut,
03009 cfgMgr,
03010 groupName, groupKey,
03011 modifiedTables,
03012 true , false ,
03013 0 , false );
03014
03015
03016
03017 TableEditStruct planTable(IterateConfiguration::PLAN_TABLE,cfgMgr);
03018 TableEditStruct targetTable(IterateConfiguration::TARGET_TABLE,cfgMgr);
03019
03020
03021 std::map<std::string, TableEditStruct> commandTypeToCommandTableMap;
03022 for(const auto& commandPair : IterateConfiguration::commandToTableMap_)
03023 if(commandPair.second != "")
03024 commandTypeToCommandTableMap.emplace(std::pair<std::string,TableEditStruct>(
03025 commandPair.first,
03026 TableEditStruct(commandPair.second,cfgMgr)));
03027
03028
03029
03030
03031 try
03032 {
03033
03034
03035
03036
03037
03038
03039
03040
03041
03042
03043
03044 std::string groupName = planName + "-Plan";
03045 __SUP_COUT__ << "Handling commands for group " << groupName << std::endl;
03046
03047 unsigned int groupIdCol = planTable.cfgView_->findCol(IterateConfiguration::planTableCols_.GroupID_);
03048 unsigned int cmdTypeCol = planTable.cfgView_->findCol(IterateConfiguration::planTableCols_.CommandType_);
03049
03050
03051 unsigned int targetGroupIdCol = targetTable.cfgView_->findCol(IterateConfiguration::targetCols_.GroupID_);
03052 unsigned int targetTableCol = targetTable.cfgView_->findCol(IterateConfiguration::targetCols_.TargetLink_);
03053 unsigned int targetUIDCol = targetTable.cfgView_->findCol(IterateConfiguration::targetCols_.TargetLinkUID_);
03054
03055 std::string groupLinkIndex = planTable.cfgView_->getColumnInfo(groupIdCol).getChildLinkIndex();
03056 __SUP_COUT__ << "groupLinkIndex: " << groupLinkIndex << std::endl;
03057
03058 std::pair<unsigned int , unsigned int > commandUidLink;
03059 {
03060 bool isGroup;
03061 planTable.cfgView_->getChildLink(
03062 planTable.cfgView_->findCol(
03063 IterateConfiguration::planTableCols_.CommandLink_),
03064 isGroup,commandUidLink);
03065 }
03066
03067 unsigned int cmdRow, cmdCol;
03068 std::string targetGroupName;
03069
03070
03071 {
03072 std::string targetUID, cmdType;
03073
03074 for(unsigned int row=0;row < planTable.cfgView_->getNumberOfRows(); ++row)
03075 {
03076 targetUID = planTable.cfgView_->getDataView()[row][planTable.cfgView_->getColUID()];
03077 __SUP_COUT__ << "targetUID: " << targetUID << std::endl;
03078
03079
03080 if(planTable.cfgView_->isEntryInGroup(row,
03081 groupLinkIndex,groupName))
03082 {
03083 __SUP_COUT__ << "Removing." << std::endl;
03084
03085
03086
03087
03088 cmdType = planTable.cfgView_->getDataView()[row][cmdTypeCol];
03089 if(commandTypeToCommandTableMap.find(cmdType) !=
03090 commandTypeToCommandTableMap.end())
03091 {
03092 cmdRow = commandTypeToCommandTableMap[cmdType].cfgView_->findRow(
03093 commandTypeToCommandTableMap[cmdType].cfgView_->getColUID(),
03094 planTable.cfgView_->getDataView()[row][commandUidLink.second]);
03095
03096
03097
03098
03099 try
03100 {
03101 cmdCol = commandTypeToCommandTableMap[cmdType].cfgView_->findCol(
03102 IterateConfiguration::commandTargetCols_.TargetsLinkGroupID_);
03103 targetGroupName =
03104 commandTypeToCommandTableMap[cmdType].cfgView_->getDataView()
03105 [cmdRow][cmdCol];
03106
03107
03108 for(unsigned int trow=0;
03109 trow < targetTable.cfgView_->getNumberOfRows();
03110 ++trow)
03111 {
03112
03113 if(targetTable.cfgView_->isEntryInGroup(
03114 trow,
03115 commandTypeToCommandTableMap[cmdType].cfgView_->getColumnInfo(cmdCol).getChildLinkIndex(),
03116 targetGroupName))
03117 {
03118 __SUP_COUT__ << "Removing target." << std::endl;
03119
03120 if(targetTable.cfgView_->removeRowFromGroup(trow,
03121 targetGroupIdCol,
03122 targetGroupName,true ))
03123 --trow;
03124 }
03125 }
03126 }
03127 catch(...)
03128 {
03129 __SUP_COUT__ << "No targets." << std::endl;
03130 }
03131
03132
03133
03134 commandTypeToCommandTableMap[cmdType].cfgView_->deleteRow(cmdRow);
03135
03136 commandTypeToCommandTableMap[cmdType].modified_ = true;
03137 }
03138
03139
03140 if(planTable.cfgView_->removeRowFromGroup(row,groupIdCol,
03141 groupName,true ))
03142 --row;
03143 }
03144 }
03145 }
03146
03147
03148
03149
03150
03151 std::vector<IterateConfiguration::Command> commands;
03152
03153
03154
03155 {
03156 std::istringstream f(commandString);
03157 std::string commandSubString, paramSubString, paramValue;
03158 int i;
03159 while (getline(f, commandSubString, ';'))
03160 {
03161
03162 std::istringstream g(commandSubString);
03163
03164 i = 0;
03165 while (getline(g, paramSubString, ','))
03166 {
03167
03168 if(i == 0)
03169 {
03170 if(paramSubString != "type")
03171 {
03172 __SUP_SS__ << "Invalid command sequence" << std::endl;
03173 __SS_THROW__;
03174 }
03175
03176 commands.push_back(IterateConfiguration::Command());
03177
03178 getline(g, paramValue, ','); ++i;
03179
03180 commands.back().type_ = paramValue;
03181 }
03182 else
03183 {
03184 getline(g, paramValue, ','); ++i;
03185
03186
03187 commands.back().params_.emplace(
03188 std::pair<
03189 std::string ,
03190 std::string > (
03191 paramSubString,
03192 StringMacros::decodeURIComponent(paramValue)
03193 ));
03194 }
03195
03196 ++i;
03197 }
03198 }
03199
03200 }
03201
03202 __SUP_COUT__ << "commands size " << commands.size() << std::endl;
03203
03204
03205
03206
03207
03208
03209
03210 unsigned int row, tgtRow;
03211 unsigned int targetIndex;
03212 std::string targetStr, cmdUID;
03213
03214 for(auto& command:commands)
03215 {
03216
03217 __SUP_COUT__ << "command " <<
03218 command.type_ << std::endl;
03219 __SUP_COUT__ << "table " <<
03220 IterateConfiguration::commandToTableMap_.at(command.type_) << std::endl;
03221
03222
03223 row = planTable.cfgView_->addRow(author,"planCommand");
03224 planTable.cfgView_->addRowToGroup(row,groupIdCol,groupName);
03225
03226
03227 planTable.cfgView_->setURIEncodedValue(
03228 command.type_,
03229 row,
03230 cmdTypeCol);
03231
03232
03233 planTable.cfgView_->setValueAsString(
03234 "1",
03235 row,
03236 planTable.cfgView_->getColStatus());
03237
03238
03239 if(commandTypeToCommandTableMap.find(command.type_) !=
03240 commandTypeToCommandTableMap.end())
03241 {
03242 __SUP_COUT__ << "table " << commandTypeToCommandTableMap[command.type_].configName_ << std::endl;
03243
03244
03245
03246
03247 cmdRow = commandTypeToCommandTableMap[command.type_].cfgView_->addRow(
03248 author,true ,command.type_ + "_COMMAND_");
03249
03250
03251
03252
03253
03254
03255 for(auto& param:command.params_)
03256 {
03257 __SUP_COUT__ << "\t param " <<
03258 param.first << " : " <<
03259 param.second << std::endl;
03260
03261 if(param.first ==
03262 IterateConfiguration::targetParams_.Tables_)
03263 {
03264 __SUP_COUT__ << "\t\t found target tables" << __E__;
03265 std::istringstream f(param.second);
03266
03267 targetIndex = 0;
03268 while (getline(f, targetStr, '='))
03269 {
03270 __SUP_COUT__ << "\t\t targetStr = " << targetStr << __E__;
03271 if(!command.targets_.size() ||
03272 command.targets_.back().table_ != "")
03273 {
03274 __SUP_COUT__ << "\t\t make targetStr = " << targetStr << __E__;
03275
03276 command.addTarget();
03277 command.targets_.back().table_ = targetStr;
03278 }
03279 else
03280 command.targets_[targetIndex++].table_ = targetStr;
03281 }
03282
03283 continue;
03284 }
03285
03286 if(param.first ==
03287 IterateConfiguration::targetParams_.UIDs_)
03288 {
03289 __SUP_COUT__ << "\t\t found target UIDs" << __E__;
03290 std::istringstream f(param.second);
03291
03292 targetIndex = 0;
03293 while (getline(f, targetStr, '='))
03294 {
03295 __SUP_COUT__ << "\t\t targetStr = " << targetStr << __E__;
03296 if(!command.targets_.size() ||
03297 command.targets_.back().UID_ != "")
03298 {
03299 __SUP_COUT__ << "\t\t make targetStr = " << targetStr << __E__;
03300
03301 command.addTarget();
03302 command.targets_.back().UID_ = targetStr;
03303 }
03304 else
03305 command.targets_[targetIndex++].UID_ = targetStr;
03306 }
03307 continue;
03308 }
03309
03310 cmdCol = commandTypeToCommandTableMap[command.type_].cfgView_->findCol(
03311 param.first);
03312
03313 __SUP_COUT__ << "param col " << cmdCol << std::endl;
03314
03315 commandTypeToCommandTableMap[command.type_].cfgView_->setURIEncodedValue(
03316 param.second,cmdRow,cmdCol);
03317 }
03318
03319 cmdUID = commandTypeToCommandTableMap[command.type_].cfgView_->getDataView()
03320 [cmdRow][commandTypeToCommandTableMap[command.type_].cfgView_->getColUID()];
03321
03322 if(command.targets_.size())
03323 {
03324
03325
03326 __SUP_COUT__ << "targets found for command UID=" << cmdUID << __E__;
03327
03328
03329 cmdCol = commandTypeToCommandTableMap[command.type_].cfgView_->findCol(
03330 IterateConfiguration::commandTargetCols_.TargetsLink_);
03331 commandTypeToCommandTableMap[command.type_].cfgView_->setValueAsString(
03332 IterateConfiguration::TARGET_TABLE,
03333 cmdRow,
03334 cmdCol);
03335
03336 cmdCol = commandTypeToCommandTableMap[command.type_].cfgView_->findCol(
03337 IterateConfiguration::commandTargetCols_.TargetsLinkGroupID_);
03338 commandTypeToCommandTableMap[command.type_].cfgView_->setValueAsString(
03339 cmdUID + "_Targets",
03340 cmdRow,
03341 cmdCol);
03342
03343
03344
03345 for(const auto& target:command.targets_)
03346 {
03347 __SUP_COUT__ << target.table_ << " " << target.UID_ << __E__;
03348
03349
03350 tgtRow = targetTable.cfgView_->addRow(author,"commandTarget");
03351 targetTable.cfgView_->addRowToGroup(
03352 tgtRow,
03353 targetGroupIdCol,
03354 cmdUID + "_Targets");
03355
03356
03357 targetTable.cfgView_->setValueAsString(
03358 target.table_,
03359 tgtRow,
03360 targetTableCol);
03361
03362
03363 targetTable.cfgView_->setValueAsString(
03364 target.UID_,
03365 tgtRow,
03366 targetUIDCol);
03367 }
03368 }
03369
03370
03371
03372 planTable.cfgView_->setValueAsString(
03373 commandTypeToCommandTableMap[command.type_].configName_,
03374 row,
03375 commandUidLink.first);
03376 planTable.cfgView_->setValueAsString(
03377 cmdUID,
03378 row,
03379 commandUidLink.second);
03380
03381 __SUP_COUT__ << "linked to uid = " <<
03382 cmdUID << std::endl;
03383
03384 commandTypeToCommandTableMap[command.type_].modified_ = true;
03385 }
03386
03387 }
03388
03389
03390
03391
03392
03393 planTable.cfgView_->print();
03394 planTable.cfgView_->init();
03395
03396 __SUP_COUT__ << "requestType tables:" << std::endl;
03397
03398 for(auto& modifiedConfig : commandTypeToCommandTableMap)
03399 {
03400 modifiedConfig.second.cfgView_->print();
03401 modifiedConfig.second.cfgView_->init();
03402 }
03403
03404 targetTable.cfgView_->print();
03405 targetTable.cfgView_->init();
03406
03407 }
03408 catch(...)
03409 {
03410 __SUP_COUT__ << "Handling command table errors while saving. Erasing all newly created versions." << std::endl;
03411
03412
03413
03414 if(planTable.createdTemporaryVersion_)
03415 {
03416 __SUP_COUT__ << "Erasing temporary version " << planTable.configName_ <<
03417 "-v" << planTable.temporaryVersion_ << std::endl;
03418
03419 cfgMgr->eraseTemporaryVersion(planTable.configName_,planTable.temporaryVersion_);
03420 }
03421
03422 if(targetTable.createdTemporaryVersion_)
03423 {
03424 __SUP_COUT__ << "Erasing temporary version " << targetTable.configName_ <<
03425 "-v" << targetTable.temporaryVersion_ << std::endl;
03426
03427 cfgMgr->eraseTemporaryVersion(targetTable.configName_,targetTable.temporaryVersion_);
03428 }
03429
03430 for(auto& modifiedConfig : commandTypeToCommandTableMap)
03431 {
03432 if(modifiedConfig.second.createdTemporaryVersion_)
03433 {
03434 __SUP_COUT__ << "Erasing temporary version " << modifiedConfig.second.configName_ <<
03435 "-v" << modifiedConfig.second.temporaryVersion_ << std::endl;
03436
03437 cfgMgr->eraseTemporaryVersion(modifiedConfig.second.configName_,
03438 modifiedConfig.second.temporaryVersion_);
03439 }
03440 }
03441
03442 throw;
03443 }
03444
03445
03446
03447
03448
03449 ConfigurationVersion finalVersion = saveModifiedVersionXML(xmlOut,cfgMgr,
03450 planTable.configName_,
03451 planTable.originalVersion_,true ,
03452 planTable.config_,planTable.temporaryVersion_,true );
03453
03454 __SUP_COUT__ << "Final plan version is " << planTable.configName_ << "-v" <<
03455 finalVersion << std::endl;
03456
03457 finalVersion = saveModifiedVersionXML(xmlOut,cfgMgr,
03458 targetTable.configName_,
03459 targetTable.originalVersion_,true ,
03460 targetTable.config_,targetTable.temporaryVersion_,true );
03461
03462 __SUP_COUT__ << "Final target version is " << targetTable.configName_ << "-v" <<
03463 finalVersion << std::endl;
03464
03465 for(auto& modifiedConfig : commandTypeToCommandTableMap)
03466 {
03467 if(!modifiedConfig.second.modified_)
03468 {
03469 if(modifiedConfig.second.createdTemporaryVersion_)
03470 {
03471 __SUP_COUT__ << "Erasing unmodified temporary version " << modifiedConfig.second.configName_ <<
03472 "-v" << modifiedConfig.second.temporaryVersion_ << std::endl;
03473
03474 cfgMgr->eraseTemporaryVersion(modifiedConfig.second.configName_,
03475 modifiedConfig.second.temporaryVersion_);
03476 }
03477 continue;
03478 }
03479
03480 finalVersion = saveModifiedVersionXML(xmlOut,cfgMgr,
03481 modifiedConfig.second.configName_,
03482 modifiedConfig.second.originalVersion_,true ,
03483 modifiedConfig.second.config_,
03484 modifiedConfig.second.temporaryVersion_,true );
03485
03486 __SUP_COUT__ << "Final version is " << modifiedConfig.second.configName_ << "-v" <<
03487 finalVersion << std::endl;
03488 }
03489
03490 handleFillModifiedTablesXML(xmlOut,cfgMgr);
03491 }
03492 catch(std::runtime_error& e)
03493 {
03494 __SUP_SS__ << "Error detected saving Iteration Plan!\n\n " << e.what() << std::endl;
03495 __SUP_COUT_ERR__ << "\n" << ss.str() << std::endl;
03496 xmlOut.addTextElementToData("Error", ss.str());
03497 }
03498 catch(...)
03499 {
03500 __SUP_SS__ << "Error detected saving Iteration Plan!\n\n "<< std::endl;
03501 __SUP_COUT_ERR__ << "\n" << ss.str() << std::endl;
03502 xmlOut.addTextElementToData("Error", ss.str());
03503 }
03504
03505
03506
03507
03508
03509
03510
03511
03512
03513
03514
03515 void ConfigurationGUISupervisor::handleSaveTreeNodeEditXML(HttpXmlDocument& xmlOut,
03516 ConfigurationManagerRW* cfgMgr, const std::string& configName,
03517 ConfigurationVersion version, const std::string& type,
03518 const std::string& uid, const std::string& colName, const std::string& newValue,
03519 const std::string& author)
03520 try
03521 {
03522 __SUP_COUT__ << "table " <<
03523 configName << "(" << version << ")" << std::endl;
03524
03525
03526
03527
03528
03529
03530
03531
03532 ConfigurationBase* config = cfgMgr->getConfigurationByName(configName);
03533 try
03534 {
03535 config->setActiveView(version);
03536 }
03537 catch(...)
03538 {
03539 __SUP_COUT__ << "Failed to find stored version, so attempting to load version: " <<
03540 version << std::endl;
03541 cfgMgr->getVersionedConfigurationByName(
03542 configName, version);
03543 }
03544
03545 __SUP_COUT__ << "Active version is " << config->getViewVersion() << std::endl;
03546
03547 if(version != config->getViewVersion())
03548 {
03549 __SUP_SS__ << "Target table version (" << version <<
03550 ") is not the currently active version (" << config->getViewVersion()
03551 << ". Try refreshing the tree." << std::endl;
03552 __SS_THROW__;
03553 }
03554
03555 unsigned int col = -1;
03556 if(type == "uid" || type == "delete-uid")
03557 col = config->getView().getColUID();
03558 else if(
03559 type == "link-UID" ||
03560 type == "link-GroupID" ||
03561 type == "value" ||
03562 type == "value-groupid" ||
03563 type == "value-bool"||
03564 type == "value-bitmap")
03565 col = config->getView().findCol(colName);
03566 else if(
03567 type == "table" ||
03568 type == "link-comment" ||
03569 type == "table-newGroupRow" ||
03570 type == "table-newUIDRow" ||
03571 type == "table-newRow");
03572 else
03573 {
03574 __SUP_SS__ << "Impossible! Unrecognized edit type: " << type << std::endl;
03575 __SS_THROW__;
03576 }
03577
03578
03579 if(type == "table" ||
03580 type == "link-comment")
03581 {
03582
03583 if(config->getView().isURIEncodedCommentTheSame(newValue))
03584 {
03585 __SUP_SS__ << "Comment '" << newValue <<
03586 "' is the same as the current comment. No need to save change." <<
03587 std::endl;
03588 __SS_THROW__;
03589 }
03590
03591 }
03592
03593
03594
03595
03596
03597
03598
03599
03600
03601
03602
03603
03604 ConfigurationVersion temporaryVersion = config->createTemporaryView(version);
03605
03606 __SUP_COUT__ << "Created temporary version " << temporaryVersion << std::endl;
03607
03608 ConfigurationView* cfgView = config->getTemporaryView(temporaryVersion);
03609
03610
03611 try
03612 {
03613
03614 if(type == "table" ||
03615 type == "link-comment")
03616 {
03617
03618 cfgView->setURIEncodedComment(newValue);
03619 }
03620 else if(type == "table-newRow" ||
03621 type == "table-newUIDRow")
03622 {
03623
03624 unsigned int row = cfgView->addRow(author,true );
03625
03626
03627 try
03628 {
03629 col = cfgView->getColStatus();
03630 cfgView->setValueAsString("1",row,col);
03631 }
03632 catch(...) {}
03633
03634
03635 cfgView->setURIEncodedValue(newValue,row,cfgView->getColUID());
03636 }
03637 else if(type == "table-newGroupRow")
03638 {
03639
03640 unsigned int row = cfgView->addRow(author,true );
03641
03642
03643 unsigned int csvIndex = newValue.find(',');
03644
03645 std::string linkIndex = newValue.substr(0,csvIndex);
03646 std::string groupId = newValue.substr(csvIndex+1);
03647
03648
03649 csvIndex = groupId.find(',');
03650 std::string newRowUID = groupId.substr(csvIndex+1);
03651 groupId = groupId.substr(0,csvIndex);
03652
03653 __SUP_COUT__ << "newValue " << linkIndex << "," <<
03654 groupId << "," <<
03655 newRowUID << std::endl;
03656
03657
03658 cfgView->setURIEncodedValue(newRowUID,row,cfgView->getColUID());
03659
03660
03661 col = cfgView->getColLinkGroupID(linkIndex);
03662
03663
03664 cfgView->setURIEncodedValue(groupId,row,col);
03665
03666
03667 try
03668 {
03669 col = cfgView->getColStatus();
03670 cfgView->setValueAsString("1",row,col);
03671 }
03672 catch(...) {}
03673
03674 }
03675 else if(type == "delete-uid")
03676 {
03677
03678 unsigned int row = cfgView->findRow(col,uid);
03679 cfgView->deleteRow(row);
03680 }
03681 else if(type == "uid" ||
03682 type == "value" ||
03683 type == "value-groupid" ||
03684 type == "value-bool" ||
03685 type == "value-bitmap")
03686 {
03687 unsigned int row = cfgView->findRow(cfgView->getColUID(),uid);
03688 if(!cfgView->setURIEncodedValue(newValue,row,col,author))
03689 {
03690
03691 __SUP_SS__ << "Value '" << newValue <<
03692 "' is the same as the current value. No need to save change to tree node." <<
03693 std::endl;
03694 __SS_THROW__;
03695 }
03696 }
03697 else if(type == "link-UID" || type == "link-GroupID")
03698 {
03699 bool isGroup;
03700 std::pair<unsigned int , unsigned int > linkPair;
03701 if(!cfgView->getChildLink(col,isGroup,linkPair))
03702 {
03703
03704 __SUP_SS__ << "Col '" << colName <<
03705 "' is not a link column." <<
03706 std::endl;
03707 __SS_THROW__;
03708 }
03709
03710 __SUP_COUT__ << "linkPair " << linkPair.first << "," <<
03711 linkPair.second << std::endl;
03712
03713 std::string linkIndex = cfgView->getColumnInfo(col).getChildLinkIndex();
03714
03715 __SUP_COUT__ << "linkIndex " << linkIndex << std::endl;
03716
03717
03718 unsigned int csvIndexStart = 0,csvIndex = newValue.find(',');
03719
03720 std::string newTable = newValue.substr(csvIndexStart,csvIndex);
03721 csvIndexStart = csvIndex + 1;
03722 csvIndex = newValue.find(',',csvIndexStart);
03723 std::string newLinkId =
03724 newValue.substr(csvIndexStart,csvIndex-csvIndexStart);
03725
03726 __SUP_COUT__ << "newValue " << newTable << "," <<
03727 newLinkId << std::endl;
03728
03729
03730 unsigned int row = cfgView->findRow(cfgView->getColUID(),uid);
03731 bool changed = false;
03732 if(!cfgView->setURIEncodedValue(newTable,row,
03733 linkPair.first,author))
03734 {
03735
03736 __SUP_COUT__ << "Value '" << newTable <<
03737 "' is the same as the current value." <<
03738 std::endl;
03739 }
03740 else
03741 changed = true;
03742
03743 if(!cfgView->setURIEncodedValue(newLinkId,row,
03744 linkPair.second,author))
03745 {
03746
03747 __SUP_COUT__ << "Value '" << newLinkId <<
03748 "' is the same as the current value." <<
03749 std::endl;
03750 }
03751 else
03752 changed = true;
03753
03754
03755
03756
03757
03758
03759 if(type == "link-GroupID")
03760 {
03761 bool secondaryChanged = false;
03762
03763
03764 if(!changed)
03765 {
03766 __SUP_COUT__ << "No changes to primary view. Erasing temporary table." << std::endl;
03767 config->eraseView(temporaryVersion);
03768 }
03769 else
03770 {
03771 try
03772 {
03773 cfgView->init();
03774
03775 saveModifiedVersionXML(xmlOut,cfgMgr,configName,version,true ,
03776 config,temporaryVersion, true );
03777 }
03778 catch(std::runtime_error& e)
03779 {
03780 __SUP_COUT__ << "Caught error while editing main table. Erasing temporary version." << std::endl;
03781 config->eraseView(temporaryVersion);
03782 changed = false;
03783
03784
03785 xmlOut.addTextElementToData("Warning", "Error saving primary tree node! " + std::string(e.what()));
03786 }
03787 }
03788
03789
03790
03791
03792
03793
03794
03795 csvIndexStart = csvIndex + 1;
03796 csvIndex = newValue.find(',',csvIndexStart);
03797 version = ConfigurationVersion(
03798 newValue.substr(csvIndexStart,csvIndex-csvIndexStart));
03799
03800
03801 if(newTable == ViewColumnInfo::DATATYPE_LINK_DEFAULT)
03802 {
03803
03804
03805 return;
03806 }
03807
03808
03809 config = cfgMgr->getConfigurationByName(newTable);
03810 try
03811 {
03812 config->setActiveView(version);
03813 }
03814 catch(...)
03815 {
03816 __SUP_COUT__ << "Failed to find stored version, so attempting to load version: " <<
03817 version << std::endl;
03818 cfgMgr->getVersionedConfigurationByName(
03819 newTable, version);
03820 }
03821
03822 __SUP_COUT__ << "Active version is " << config->getViewVersion() << std::endl;
03823
03824 if(version != config->getViewVersion())
03825 {
03826 __SUP_SS__ << "Target table version (" << version <<
03827 ") is not the currently active version (" << config->getViewVersion()
03828 << ". Try refreshing the tree." << std::endl;
03829 __SS_THROW__;
03830 }
03831
03832
03833
03834 temporaryVersion = config->createTemporaryView(version);
03835
03836 __SUP_COUT__ << "Created temporary version " << temporaryVersion << std::endl;
03837
03838 cfgView = config->getTemporaryView(temporaryVersion);
03839
03840 col = cfgView->getColLinkGroupID(linkIndex);
03841
03842 __SUP_COUT__ << "target col " << col << std::endl;
03843
03844
03845
03846 std::vector<std::string> memberUIDs;
03847 do
03848 {
03849 csvIndexStart = csvIndex + 1;
03850 csvIndex = newValue.find(',',csvIndexStart);
03851 memberUIDs.push_back(newValue.substr(csvIndexStart,csvIndex-csvIndexStart));
03852 __SUP_COUT__ << "memberUIDs: " << memberUIDs.back() << std::endl;
03853 } while(csvIndex != (unsigned int)std::string::npos);
03854
03855
03856
03857
03858
03859
03860
03861
03862
03863
03864 std::string targetUID;
03865 bool shouldBeInGroup;
03866 bool defaultIsInGroup = false;
03867 bool isInGroup;
03868
03869 for(unsigned int row=0;row<cfgView->getNumberOfRows();++row)
03870 {
03871 targetUID = cfgView->getDataView()[row][cfgView->getColUID()];
03872 __SUP_COUT__ << "targetUID: " << targetUID << std::endl;
03873
03874 shouldBeInGroup = false;
03875 for(unsigned int i=0;i<memberUIDs.size();++i)
03876 if(targetUID == memberUIDs[i])
03877 {
03878
03879 shouldBeInGroup = true;
03880 break;
03881 }
03882
03883 isInGroup = cfgView->isEntryInGroup(row,linkIndex,newLinkId);
03884
03885
03886 if(shouldBeInGroup && !isInGroup)
03887 {
03888
03889 __SUP_COUT__ << "Changed YES: " << row << std::endl;
03890 secondaryChanged = true;
03891
03892 cfgView->addRowToGroup(row,col,newLinkId);
03893
03894 }
03895 else if(!shouldBeInGroup && isInGroup)
03896 {
03897
03898 __SUP_COUT__ << "Changed NO: " << row << std::endl;
03899 secondaryChanged = true;
03900
03901 cfgView->removeRowFromGroup(row,col,newLinkId);
03902 }
03903 else if(targetUID ==
03904 cfgView->getDefaultRowValues()[cfgView->getColUID()] &&
03905 isInGroup)
03906 {
03907
03908 defaultIsInGroup = true;
03909 }
03910 }
03911
03912
03913
03914 if(!secondaryChanged)
03915 {
03916 __SUP_COUT__ << "No changes to secondary view. Erasing temporary table." << std::endl;
03917 config->eraseView(temporaryVersion);
03918 }
03919 else
03920 {
03921 try
03922 {
03923 cfgView->init();
03924
03925 saveModifiedVersionXML(xmlOut,cfgMgr,newTable,version,true ,
03926 config,temporaryVersion,true );
03927 }
03928 catch(std::runtime_error& e)
03929 {
03930 __SUP_COUT__ << "Caught error while editing secondary table. Erasing temporary version." << std::endl;
03931 config->eraseView(temporaryVersion);
03932 secondaryChanged = false;
03933
03934
03935 xmlOut.addTextElementToData("Warning", "Error saving secondary tree node! " + std::string(e.what()));
03936 }
03937 }
03938
03939
03940
03941 if(0 && !changed && !secondaryChanged && !defaultIsInGroup)
03942 {
03943 __SUP_SS__ << "Link to table '" << newTable <<
03944 "', linkID '" << newLinkId <<
03945 "', and selected group members are the same as the current value. " <<
03946 "No need to save changes to tree." <<
03947 std::endl;
03948 __SS_THROW__;
03949 }
03950
03951 return;
03952 }
03953 else if(0 && !changed)
03954 {
03955 __SUP_SS__ << "Link to table '" << newTable <<
03956 "' and linkID '" << newLinkId <<
03957 "' are the same as the current values. No need to save change to tree node." <<
03958 std::endl;
03959 __SS_THROW__;
03960 }
03961 }
03962
03963 cfgView->init();
03964 }
03965 catch(...)
03966 {
03967 __SUP_COUT__ << "Caught error while editing. Erasing temporary version." << std::endl;
03968 config->eraseView(temporaryVersion);
03969 throw;
03970 }
03971
03972 saveModifiedVersionXML(xmlOut,cfgMgr,configName,version,true ,
03973 config,temporaryVersion,true );
03974 }
03975 catch(std::runtime_error& e)
03976 {
03977 __SUP_SS__ << "Error saving tree node! " << std::string(e.what()) << std::endl;
03978 __SUP_COUT_ERR__ << "\n" << ss.str() << std::endl;
03979 xmlOut.addTextElementToData("Error", ss.str());
03980 }
03981 catch(...)
03982 {
03983 __SUP_SS__ << "Error saving tree node! " << std::endl;
03984 __SUP_COUT_ERR__ << "\n" << ss.str() << std::endl;
03985 xmlOut.addTextElementToData("Error", ss.str());
03986 }
03987
03988
03989
03990
03991
03992
03993
03994
03995
03996
03997
03998
03999
04000
04001
04002
04003
04004
04005
04006
04007
04008
04009
04010
04011 void ConfigurationGUISupervisor::handleGetConfigurationGroupXML(HttpXmlDocument& xmlOut,
04012 ConfigurationManagerRW* cfgMgr, const std::string& groupName,
04013 ConfigurationGroupKey groupKey)
04014 try
04015 {
04016 char tmpIntStr[100];
04017 DOMElement* parentEl,* configEl;
04018
04019
04020
04021
04022
04023
04024
04025
04026
04027
04028
04029
04030
04031
04032
04033
04034
04035
04036
04037
04038
04039
04040
04041 const GroupInfo& groupInfo = cfgMgr->getGroupInfo(groupName);
04042 const std::set<ConfigurationGroupKey>& sortedKeys = groupInfo.keys_;
04043
04044 if(groupKey.isInvalid() ||
04045 sortedKeys.find(groupKey) == sortedKeys.end())
04046 {
04047 if(sortedKeys.size())
04048 groupKey =* sortedKeys.rbegin();
04049 __SUP_COUT__ << "Group key requested was invalid or not found, going with latest " <<
04050 groupKey << std::endl;
04051 }
04052
04053
04054
04055 xmlOut.addTextElementToData("ConfigurationGroupName", groupName);
04056 xmlOut.addTextElementToData("ConfigurationGroupKey", groupKey.toString());
04057
04058
04059 for(auto& keyInOrder:sortedKeys)
04060 xmlOut.addTextElementToData("HistoricalConfigurationGroupKey", keyInOrder.toString());
04061
04062
04063 parentEl = xmlOut.addTextElementToData("ConfigurationGroupMembers", "");
04064
04065
04066
04067 std::map<std::string , ConfigurationVersion > memberMap;
04068 std::map<std::string , std::string > groupMemberAliases;
04069
04070 __SUP_COUT__ << "groupName=" << groupName << std::endl;
04071 __SUP_COUT__ << "groupKey=" << groupKey << std::endl;
04072
04073 const std::map<std::string, ConfigurationInfo>& allCfgInfo = cfgMgr->getAllConfigurationInfo();
04074 std::map<std::string, ConfigurationInfo>::const_iterator it;
04075
04076
04077
04078 try
04079 {
04080 std::string groupAuthor, groupComment, groupCreationTime, groupTypeString;
04081 std::string accumulateErrors;
04082
04083 cfgMgr->loadConfigurationGroup(groupName,groupKey,
04084 false ,&memberMap,0 ,
04085 &accumulateErrors ,
04086 &groupComment, &groupAuthor, &groupCreationTime,
04087 false , &groupTypeString, &groupMemberAliases);
04088
04089 if(accumulateErrors != "")
04090 {
04091 __SUP_SS__ << accumulateErrors;
04092 __SUP_SS_THROW__;
04093 }
04094
04095 xmlOut.addTextElementToData("ConfigurationGroupAuthor", groupAuthor);
04096 xmlOut.addTextElementToData("ConfigurationGroupComment", groupComment);
04097 xmlOut.addTextElementToData("ConfigurationGroupCreationTime", groupCreationTime);
04098 xmlOut.addTextElementToData("ConfigurationGroupType", groupTypeString);
04099 }
04100 catch(const std::runtime_error& e)
04101 {
04102 __SUP_SS__ <<"Configuration group \"" +
04103 groupName + "(" + groupKey.toString() + ")" +
04104 "\" members can not be loaded!\n\n" + e.what();
04105 __SUP_COUT_ERR__ << ss.str();
04106 xmlOut.addTextElementToData("Error",ss.str());
04107
04108 }
04109 catch(...)
04110 {
04111 __SUP_SS__ << "Configuration group \"" +
04112 groupName + "(" + groupKey.toString() + ")" +
04113 "\" members can not be loaded!" << __E__;
04114 __SUP_COUT_ERR__ << ss.str();
04115 xmlOut.addTextElementToData("Error",ss.str());
04116
04117 }
04118
04119 __COUTV__(StringMacros::mapToString(groupMemberAliases));
04120
04121 std::map<std::string,std::map<std::string,ConfigurationVersion> > versionAliases =
04122 cfgMgr->getVersionAliases();
04123
04124 __SUP_COUT__ << "# of table version aliases: " << versionAliases.size() << std::endl;
04125
04126
04127
04128
04129 for(auto& memberPair:memberMap)
04130 {
04131 xmlOut.addTextElementToParent("MemberName", memberPair.first, parentEl);
04132
04133
04134 if(groupMemberAliases.find(memberPair.first) != groupMemberAliases.end())
04135 configEl = xmlOut.addTextElementToParent("MemberVersion",
04136 ConfigurationManager::ALIAS_VERSION_PREAMBLE +
04137 groupMemberAliases[memberPair.first],
04138 parentEl);
04139 else
04140 configEl = xmlOut.addTextElementToParent("MemberVersion", memberPair.second.toString(),
04141 parentEl);
04142
04143 it = allCfgInfo.find(memberPair.first);
04144 if(it == allCfgInfo.end())
04145 {
04146 xmlOut.addTextElementToData("Error","Configuration \"" +
04147 memberPair.first +
04148 "\" can not be retrieved!");
04149 continue;
04150 }
04151
04152 if(versionAliases.find(it->first) != versionAliases.end())
04153 for (auto& aliasVersion:versionAliases[it->first])
04154 xmlOut.addTextElementToParent("ConfigurationExistingVersion",
04155 ConfigurationManager::ALIAS_VERSION_PREAMBLE + aliasVersion.first,
04156 configEl);
04157
04158 for (auto& version:it->second.versions_)
04159
04160
04161 xmlOut.addTextElementToParent("ConfigurationExistingVersion", version.toString(), configEl);
04162 }
04163
04164 for(auto& memberPair:memberMap)
04165 {
04166
04167
04168
04169
04170
04171 xmlOut.addTextElementToParent("MemberComment",
04172 allCfgInfo.at(memberPair.first).configurationPtr_->getView().getComment(),
04173 parentEl);
04174
04175
04176
04177
04178
04179
04180
04181
04182
04183
04184
04185
04186
04187
04188
04189
04190
04191
04192
04193
04194
04195
04196
04197
04198
04199
04200
04201
04202
04203
04204 }
04205
04206
04207 return;
04208 }
04209 catch(std::runtime_error& e)
04210 {
04211 __SUP_SS__ << ("Error!\n\n" + std::string(e.what())) << std::endl;
04212 __SUP_COUT_ERR__ << "\n" << ss.str();
04213 xmlOut.addTextElementToData("Error", ss.str());
04214 }
04215 catch(...)
04216 {
04217 __SUP_SS__ << ("Error!\n\n") << std::endl;
04218 __SUP_COUT_ERR__ << "\n" << ss.str();
04219 xmlOut.addTextElementToData("Error", ss.str());
04220 }
04221
04222
04223
04224
04225
04226
04227
04228
04229
04230
04231
04232
04233
04234
04235
04236
04237
04238
04239
04240
04241
04242
04243
04244
04245
04246
04247
04248
04249
04250
04251
04252
04253
04254
04255
04256
04257
04258
04259
04260
04261
04262 void ConfigurationGUISupervisor::handleGetConfigurationXML(HttpXmlDocument& xmlOut,
04263 ConfigurationManagerRW* cfgMgr, const std::string& tableName,
04264 ConfigurationVersion version, bool allowIllegalColumns)
04265 try
04266 {
04267 char tmpIntStr[100];
04268 DOMElement *parentEl, *subparentEl;
04269
04270 std::string accumulatedErrors = "";
04271
04272 const std::map<std::string, ConfigurationInfo>& allCfgInfo =
04273 cfgMgr->getAllConfigurationInfo(allowIllegalColumns,
04274 allowIllegalColumns?&accumulatedErrors:0,tableName);
04275
04276 ConfigurationBase* config = cfgMgr->getConfigurationByName(tableName);
04277
04278
04279
04280 xmlOut.addTextElementToData("ExistingConfigurationNames", ViewColumnInfo::DATATYPE_LINK_DEFAULT);
04281 for(auto& configPair:allCfgInfo)
04282 {
04283 xmlOut.addTextElementToData("ExistingConfigurationNames",
04284 configPair.first);
04285 if(configPair.first == tableName &&
04286 configPair.second.versions_.find(version) ==
04287 configPair.second.versions_.end())
04288 {
04289 __SUP_COUT__ << "Version not found, so using mockup." << std::endl;
04290 version = ConfigurationVersion();
04291 }
04292 }
04293
04294 xmlOut.addTextElementToData("ConfigurationName", tableName);
04295 xmlOut.addTextElementToData("ConfigurationDescription",
04296 config->getConfigurationDescription());
04297
04298
04299
04300 {
04301
04302 std::map<std::string ,std::map<
04303 std::string ,ConfigurationVersion > > versionAliases;
04304 try
04305 {
04306
04307 versionAliases = cfgMgr->getVersionAliases();
04308 for(const auto& aliases:versionAliases)
04309 for(const auto& alias:aliases.second)
04310 __SUP_COUT__ << "ALIAS: " << aliases.first << " " << alias.first << " ==> " << alias.second << std::endl;
04311 }
04312 catch(const std::runtime_error& e)
04313 {
04314 __SUP_COUT__ << "Could not get backbone information for version aliases: " << e.what() << __E__;
04315 }
04316
04317 auto tableIterator = versionAliases.find(tableName);
04318
04319 parentEl = xmlOut.addTextElementToData("ConfigurationVersions", "");
04320 for(const ConfigurationVersion& v:allCfgInfo.at(tableName).versions_)
04321 {
04322 subparentEl = xmlOut.addTextElementToParent("Version", v.toString(), parentEl);
04323
04324 if(tableIterator != versionAliases.end())
04325 {
04326
04327 for(const auto& aliasPair : tableIterator->second)
04328 {
04329
04330
04331 if(v == aliasPair.second)
04332 {
04333 __SUP_COUT__ << "Found Alias " << aliasPair.second << " --> " <<
04334 aliasPair.first << __E__;
04335 xmlOut.addTextElementToParent("VersionAlias", aliasPair.first, subparentEl);
04336 }
04337 }
04338 }
04339
04340 }
04341 }
04342
04343
04344
04345
04346 ConfigurationView* cfgViewPtr;
04347 if(version.isInvalid())
04348 {
04349 cfgViewPtr = config->getMockupViewP();
04350 }
04351 else
04352 {
04353 try
04354 {
04355 cfgViewPtr = cfgMgr->getVersionedConfigurationByName(tableName,version)->getViewP();
04356 }
04357 catch(std::runtime_error& e)
04358 {
04359 __SUP_SS__ << "Failed to get table " << tableName <<
04360 " version " << version <<
04361 "... defaulting to mock-up! " <<
04362 std::endl;
04363 ss << "\n\n...Here is why it failed:\n\n" << e.what() << std::endl;
04364
04365 __SUP_COUT_ERR__ << "\n" << ss.str();
04366 version = ConfigurationVersion();
04367 cfgViewPtr = config->getMockupViewP();
04368
04369 xmlOut.addTextElementToData("Error", "Error getting view! " + ss.str());
04370 }
04371 catch(...)
04372 {
04373 __SUP_SS__ << "Failed to get table " << tableName <<
04374 " version: " << version <<
04375 "... defaulting to mock-up! " <<
04376 "(You may want to try again to see what was partially loaded into cache before failure. " <<
04377 "If you think, the failure is due to a column name change, " <<
04378 "you can also try to Copy the failing view to the new column names using " <<
04379 "'Copy and Move' functionality.)" <<
04380 std::endl;
04381
04382 __SUP_COUT_ERR__ << "\n" << ss.str();
04383 version = ConfigurationVersion();
04384 cfgViewPtr = config->getMockupViewP();
04385
04386 xmlOut.addTextElementToData("Error", "Error getting view! " + ss.str());
04387 }
04388 }
04389 xmlOut.addTextElementToData("ConfigurationVersion", version.toString());
04390
04391
04392 DOMElement* choicesParentEl;
04393 parentEl = xmlOut.addTextElementToData("CurrentVersionColumnHeaders", "");
04394
04395 std::vector<ViewColumnInfo> colInfo = cfgViewPtr->getColumnsInfo();
04396
04397 for(int i=0;i<(int)colInfo.size();++i)
04398 {
04399
04400
04401
04402
04403 xmlOut.addTextElementToParent("ColumnHeader", colInfo[i].getName(), parentEl);
04404 xmlOut.addTextElementToParent("ColumnType", colInfo[i].getType(), parentEl);
04405 xmlOut.addTextElementToParent("ColumnDataType", colInfo[i].getDataType(), parentEl);
04406
04407 choicesParentEl =
04408 xmlOut.addTextElementToParent("ColumnChoices", "", parentEl);
04409
04410 if(colInfo[i].getType() == ViewColumnInfo::TYPE_FIXED_CHOICE_DATA ||
04411 colInfo[i].getType() == ViewColumnInfo::TYPE_BITMAP_DATA ||
04412 colInfo[i].isChildLink())
04413 {
04414 for(auto& choice:colInfo[i].getDataChoices())
04415 xmlOut.addTextElementToParent("ColumnChoice", choice, choicesParentEl);
04416 }
04417 }
04418
04419
04420 try
04421 {
04422 if(version.isInvalid())
04423 cfgViewPtr->init();
04424 }
04425 catch(std::runtime_error& e)
04426 {
04427
04428 __THROW__(e.what() + std::string("\n\n") + accumulatedErrors);
04429 }
04430 catch(...)
04431 {
04432 throw;
04433 }
04434
04435 parentEl = xmlOut.addTextElementToData("CurrentVersionRows", "");
04436
04437 for(int r=0;r<(int)cfgViewPtr->getNumberOfRows();++r)
04438 {
04439
04440
04441 sprintf(tmpIntStr,"%d",r);
04442 DOMElement* tmpParentEl = xmlOut.addTextElementToParent("Row", tmpIntStr, parentEl);
04443
04444 for(int c=0;c<(int)cfgViewPtr->getNumberOfColumns();++c)
04445 {
04446 if(colInfo[c].getDataType() == ViewColumnInfo::DATATYPE_TIME)
04447 {
04448 std::string timeAsString;
04449 cfgViewPtr->getValue(timeAsString,r,c);
04450 xmlOut.addTextElementToParent("Entry", timeAsString, tmpParentEl);
04451 }
04452 else
04453 xmlOut.addTextElementToParent("Entry", cfgViewPtr->getDataView()[r][c], tmpParentEl);
04454 }
04455 }
04456
04457
04458 xmlOut.addTextElementToData("TableComment", cfgViewPtr->getComment());
04459 xmlOut.addTextElementToData("TableAuthor", cfgViewPtr->getAuthor());
04460 xmlOut.addTextElementToData("TableCreationTime", std::to_string(cfgViewPtr->getCreationTime()));
04461 xmlOut.addTextElementToData("TableLastAccessTime", std::to_string(cfgViewPtr->getLastAccessTime()));
04462
04463
04464 std::vector<std::string> defaultRowValues =
04465 cfgViewPtr->getDefaultRowValues();
04466
04467 for(unsigned int c = 0; c<defaultRowValues.size()-2; ++c)
04468 {
04469
04470
04471
04472 xmlOut.addTextElementToData("DefaultRowValue", defaultRowValues[c]);
04473 }
04474
04475
04476 if(accumulatedErrors != "")
04477 {
04478 __SUP_SS__ << (std::string("Column errors were allowed for this request, so maybe you can ignore this, ") +
04479 "but please note the following errors:\n" + accumulatedErrors) << std::endl;
04480 __SUP_COUT_ERR__ << ss.str();
04481 xmlOut.addTextElementToData("Error", ss.str());
04482 }
04483 else if(!version.isTemporaryVersion() &&
04484 (cfgViewPtr->getDataColumnSize() !=
04485 cfgViewPtr->getNumberOfColumns() ||
04486 cfgViewPtr->getSourceColumnMismatch() != 0))
04487 {
04488 __SUP_SS__ << "\n\nThere were warnings found when loading the table " <<
04489 tableName << ":v" << version << ". Please see the details below:\n\n" <<
04490 "The source column size was found to be " << cfgViewPtr->getDataColumnSize() <<
04491 ", and the current number of columns for this table is " <<
04492 cfgViewPtr->getNumberOfColumns() << ". This resulted in a count of " <<
04493 cfgViewPtr->getSourceColumnMismatch() << " source column mismatches, and a count of " <<
04494 cfgViewPtr->getSourceColumnMissing() << " table entries missing in " <<
04495 cfgViewPtr->getNumberOfRows() << " row(s) of data." << std::endl;
04496
04497
04498
04499 const std::set<std::string> srcColNames = cfgViewPtr->getSourceColumnNames();
04500 ss << "\n\nSource column names in ALPHABETICAL order were as follows:\n";
04501 char index = 'a';
04502 std::string preIndexStr = "";
04503 for(auto& srcColName:srcColNames)
04504 {
04505 ss << "\n\t" << preIndexStr << index << ". " << srcColName;
04506 if(index == 'z')
04507 {
04508 preIndexStr += 'a';
04509 index = 'a';
04510 }
04511 else
04512 ++index;
04513 }
04514 ss << std::endl;
04515
04516 std::set<std::string> destColNames = cfgViewPtr->getColumnStorageNames();
04517 ss << "\n\nCurrent table column names in ALPHABETICAL order are as follows:\n";
04518 index = 'a';
04519 preIndexStr = "";
04520 for(auto& destColName:destColNames)
04521 {
04522 ss << "\n\t" << preIndexStr << index << ". " << destColName;
04523 if(index == 'z')
04524 {
04525 preIndexStr += 'a';
04526 index = 'a';
04527 }
04528 else
04529 ++index;
04530 }
04531 ss << std::endl;
04532
04533 __SUP_COUT__ << "\n" << ss.str();
04534 xmlOut.addTextElementToData("TableWarnings",ss.str());
04535 }
04536 }
04537 catch(std::runtime_error& e)
04538 {
04539 __SUP_COUT__ << "Error detected!\n\n " << e.what() << std::endl;
04540 xmlOut.addTextElementToData("Error", "Error getting view! " + std::string(e.what()));
04541 }
04542 catch(...)
04543 {
04544 __SUP_COUT__ << "Error detected!\n\n "<< std::endl;
04545 xmlOut.addTextElementToData("Error", "Error getting view! ");
04546 }
04547
04548
04549
04550
04551
04552
04553
04554 ConfigurationVersion ConfigurationGUISupervisor::saveModifiedVersionXML(HttpXmlDocument& xmlOut,
04555 ConfigurationManagerRW* cfgMgr, const std::string& configName,
04556 ConfigurationVersion originalVersion,
04557 bool makeTemporary,
04558 ConfigurationBase* config,
04559 ConfigurationVersion temporaryModifiedVersion,
04560 bool ignoreDuplicates,
04561 bool lookForEquivalent)
04562 {
04563 bool needToEraseTemporarySource = (originalVersion.isTemporaryVersion() && !makeTemporary);
04564
04565
04566
04567 if(!ignoreDuplicates)
04568 {
04569 __SUP_COUT__ << "Checking for duplicate tables..." << std::endl;
04570
04571 ConfigurationVersion duplicateVersion;
04572
04573 {
04574
04575
04576
04577 const std::map<std::string, ConfigurationInfo>& allCfgInfo =
04578 cfgMgr->getAllConfigurationInfo();
04579
04580 auto versionReverseIterator = allCfgInfo.at(configName).versions_.rbegin();
04581 __SUP_COUT__ << "Filling up cached from " <<
04582 config->getNumberOfStoredViews() <<
04583 " to max count of " << config->MAX_VIEWS_IN_CACHE << std::endl;
04584 for(;config->getNumberOfStoredViews() < config->MAX_VIEWS_IN_CACHE &&
04585 versionReverseIterator != allCfgInfo.at(configName).versions_.rend();++versionReverseIterator)
04586 {
04587 __SUP_COUT__ << "Versions in reverse order " << *versionReverseIterator << std::endl;
04588 try
04589 {
04590 cfgMgr->getVersionedConfigurationByName(configName,*versionReverseIterator);
04591 }
04592 catch(const std::runtime_error& e)
04593 {
04594 __SUP_COUT__ << "Error loadiing historical version, but ignoring: " << e.what() << __E__;
04595 }
04596 }
04597 }
04598
04599 __SUP_COUT__ << "Checking duplicate..." << std::endl;
04600
04601
04602 duplicateVersion = config->checkForDuplicate(temporaryModifiedVersion,
04603 (!originalVersion.isTemporaryVersion() && !makeTemporary)?
04604 ConfigurationVersion():
04605 originalVersion);
04606
04607 if(lookForEquivalent && !duplicateVersion.isInvalid())
04608 {
04609
04610 __SUP_COUT__ << "Equivalent table found in version v" << duplicateVersion << std::endl;
04611
04612
04613 if(duplicateVersion.isTemporaryVersion() && !makeTemporary)
04614 {
04615 __SUP_COUT__ << "Need persistent. Duplicate version was temporary. Abandoning duplicate." << __E__;
04616 duplicateVersion = ConfigurationVersion();
04617 }
04618 else
04619 {
04620
04621
04622
04623 cfgMgr->eraseTemporaryVersion(configName,temporaryModifiedVersion);
04624
04625
04626 if(needToEraseTemporarySource)
04627 cfgMgr->eraseTemporaryVersion(configName,originalVersion);
04628
04629 xmlOut.addTextElementToData("savedName", configName);
04630 xmlOut.addTextElementToData("savedVersion", duplicateVersion.toString());
04631 xmlOut.addTextElementToData("foundEquivalentVersion", "1");
04632
04633 __SUP_COUT__ << "\t\t equivalent AssignedVersion: " << duplicateVersion << std::endl;
04634
04635 return duplicateVersion;
04636 }
04637 }
04638
04639 if(!duplicateVersion.isInvalid())
04640 {
04641 __SUP_SS__ << "This version is identical to another version currently cached v" <<
04642 duplicateVersion << ". No reason to save a duplicate." << std::endl;
04643 __SUP_COUT_ERR__ << "\n" << ss.str();
04644
04645
04646 config->eraseView(temporaryModifiedVersion);
04647 __SS_THROW__;
04648 }
04649
04650 __SUP_COUT__ << "Check for duplicate tables complete." << std::endl;
04651 }
04652
04653
04654 if(makeTemporary)
04655 __SUP_COUT__ << "\t\t**************************** Save as temporary table version" << std::endl;
04656 else
04657 __SUP_COUT__ << "\t\t**************************** Save as new table version" << std::endl;
04658
04659
04660
04661 ConfigurationVersion newAssignedVersion =
04662 cfgMgr->saveNewConfiguration(configName,temporaryModifiedVersion,
04663 makeTemporary);
04664
04665 if(needToEraseTemporarySource)
04666 cfgMgr->eraseTemporaryVersion(configName,originalVersion);
04667
04668 xmlOut.addTextElementToData("savedName", configName);
04669 xmlOut.addTextElementToData("savedVersion", newAssignedVersion.toString());
04670
04671 __SUP_COUT__ << "\t\t newAssignedVersion: " << newAssignedVersion << std::endl;
04672 return newAssignedVersion;
04673 }
04674
04675
04676
04677
04678
04679
04680
04681
04682
04683 void ConfigurationGUISupervisor::handleCreateConfigurationXML(HttpXmlDocument& xmlOut,
04684 ConfigurationManagerRW* cfgMgr, const std::string& configName, ConfigurationVersion version,
04685 bool makeTemporary, const std::string& data, const int& dataOffset,
04686 const std::string& author, const std::string& comment,
04687 bool sourceTableAsIs, bool lookForEquivalent)
04688 try
04689 {
04690
04691
04692
04693
04694
04695
04696 if(!version.isInvalid())
04697 {
04698 try
04699 {
04700 cfgMgr->getVersionedConfigurationByName(configName,version);
04701 }
04702 catch(...)
04703 {
04704
04705 version = ConfigurationVersion();
04706 }
04707 }
04708
04709 ConfigurationBase* config = cfgMgr->getConfigurationByName(configName);
04710
04711
04712
04713 if(!version.isInvalid())
04714 {
04715
04716 if(config->getViewP()->getDataColumnSize() !=
04717 config->getMockupViewP()->getNumberOfColumns() ||
04718 config->getViewP()->getSourceColumnMismatch() != 0)
04719 {
04720 __SUP_COUT__ << "config->getViewP()->getNumberOfColumns() " << config->getViewP()->getNumberOfColumns() << std::endl;
04721 __SUP_COUT__ << "config->getMockupViewP()->getNumberOfColumns() " << config->getMockupViewP()->getNumberOfColumns() << std::endl;
04722 __SUP_COUT__ << "config->getViewP()->getSourceColumnMismatch() " << config->getViewP()->getSourceColumnMismatch() << std::endl;
04723 __SUP_COUT_INFO__ << "Source view v" << version <<
04724 " has a mismatch in the number of columns, so using mockup as source." << std::endl;
04725 version = ConfigurationVersion();
04726 }
04727 }
04728
04729
04730 ConfigurationVersion temporaryVersion = config->createTemporaryView(version);
04731
04732 __SUP_COUT__ << "\t\ttemporaryVersion: " << temporaryVersion << std::endl;
04733
04734 ConfigurationView* cfgView = config->getTemporaryView(temporaryVersion);
04735
04736 int retVal;
04737 try
04738 {
04739
04740 retVal = sourceTableAsIs?0:cfgView->fillFromCSV(data,dataOffset,author);
04741
04742 if(retVal == 1)
04743 {
04744 __SUP_COUT__ << "Data was the same, but columns have changed!" << __E__;
04745 __SUP_COUTV__(sourceTableAsIs);
04746 lookForEquivalent = false;
04747 }
04748
04749 cfgView->setURIEncodedComment(comment);
04750 __SUP_COUT__ << "Table comment was set to:\n\t" << cfgView->getComment() << std::endl;
04751
04752 }
04753 catch(...)
04754 {
04755 __SUP_COUT__ << "Caught error while editing. Erasing temporary version." << std::endl;
04756 config->eraseView(temporaryVersion);
04757 throw;
04758 }
04759
04760
04761
04762
04763
04764
04765
04766 if(retVal < 0 &&
04767 (!version.isTemporaryVersion() || makeTemporary) &&
04768 ConfigurationInterface::isVersionTrackingEnabled()
04769 )
04770 {
04771 if(!version.isInvalid() &&
04772 !version.isScratchVersion())
04773 {
04774 __SUP_SS__ << "No rows were modified! No reason to fill a view with same content." << std::endl;
04775 __SUP_COUT_ERR__ << "\n" << ss.str();
04776
04777 config->eraseView(temporaryVersion);
04778 __SS_THROW__;
04779 }
04780 else if(version.isInvalid())
04781 __SUP_COUT__ << "This was interpreted as an attempt to create a blank table." << std::endl;
04782 else if(version.isScratchVersion())
04783 __SUP_COUT__ << "This was interpreted as an attempt to make a persistent version of the scratch table." << std::endl;
04784 else
04785 {__SUP_SS__; __THROW__(ss.str()+"impossible!");}
04786 }
04787 else if(retVal < 0 &&
04788 (version.isTemporaryVersion() && !makeTemporary))
04789 {
04790 __SUP_COUT__ << "Allowing the static data because this is converting from temporary to persistent version." << std::endl;
04791 }
04792 else if(retVal < 0 &&
04793 !ConfigurationInterface::isVersionTrackingEnabled())
04794 {
04795 __SUP_COUT__ << "Allowing the static data because version tracking is OFF." << std::endl;
04796 }
04797 else if(retVal < 0)
04798 {
04799 __SUP_SS__ << "This should not be possible! Fatal error." << std::endl;
04800
04801 config->eraseView(temporaryVersion);
04802 __SS_THROW__;
04803 }
04804
04805
04806 saveModifiedVersionXML(xmlOut,cfgMgr,configName,version,makeTemporary,
04807 config,temporaryVersion,false ,
04808 lookForEquivalent || sourceTableAsIs );
04809 }
04810 catch(std::runtime_error& e)
04811 {
04812 __SUP_COUT__ << "Error detected!\n\n " << e.what() << std::endl;
04813 xmlOut.addTextElementToData("Error", "Error saving new view!\n " +
04814 std::string(e.what()));
04815 }
04816 catch(...)
04817 {
04818 __SUP_COUT__ << "Error detected!\n\n "<< std::endl;
04819 xmlOut.addTextElementToData("Error", "Error saving new view! ");
04820 }
04821
04822
04823
04824
04825
04826
04827
04828
04829
04830
04831
04832 ConfigurationManagerRW* ConfigurationGUISupervisor::refreshUserSession(std::string username,
04833 uint64_t activeSessionIndex, bool refresh)
04834
04835 {
04836 activeSessionIndex = 0;
04837
04838 std::stringstream ssMapKey;
04839 ssMapKey << username << ":" << activeSessionIndex;
04840 std::string mapKey = ssMapKey.str();
04841 __SUP_COUT__ << "Config Session: " << mapKey << " ... out of size: " << userConfigurationManagers_.size() << std::endl;
04842
04843 time_t now = time(0);
04844
04845
04846 if(userConfigurationManagers_.find(mapKey) == userConfigurationManagers_.end())
04847 {
04848 __SUP_COUT_INFO__ << "Creating new Configuration Manager." << std::endl;
04849 userConfigurationManagers_[mapKey] = new ConfigurationManagerRW(username);
04850
04851
04852
04853
04854 userConfigurationManagers_[mapKey]->getAllConfigurationInfo(true);
04855 }
04856 else if(userLastUseTime_.find(mapKey) == userLastUseTime_.end())
04857 {
04858 __SUP_SS__ << "Fatal error managing userLastUseTime_!" << std::endl;
04859 __SUP_COUT_ERR__ << "\n" << ss.str();
04860 __SS_THROW__;
04861 }
04862 else if(refresh || (now - userLastUseTime_[mapKey]) >
04863 CONFIGURATION_MANAGER_REFRESH_THRESHOLD)
04864 {
04865 __SUP_COUT_INFO__ << "Refreshing all configuration info." << std::endl;
04866 userConfigurationManagers_[mapKey]->getAllConfigurationInfo(true);
04867 }
04868
04869
04870
04871
04872
04873
04874 userLastUseTime_[mapKey] = now;
04875
04876
04877 for (std::map<std::string, time_t> ::iterator it=userLastUseTime_.begin(); it!=userLastUseTime_.end(); ++it)
04878 if(now - it->second > CONFIGURATION_MANAGER_EXPIRATION_TIME)
04879 {
04880 __SUP_COUT__ << now << ":" << it->second << " = " << now - it->second << std::endl;
04881 delete userConfigurationManagers_[it->first];
04882 if(!(userConfigurationManagers_.erase(it->first)))
04883 {
04884 __SUP_SS__ << "Fatal error erasing configuration manager by key!" << std::endl;
04885 __SUP_COUT_ERR__ << "\n" << ss.str();
04886 __SS_THROW__;
04887 }
04888 userLastUseTime_.erase(it);
04889
04890 it=userLastUseTime_.begin();
04891 }
04892
04893 return userConfigurationManagers_[mapKey];
04894 }
04895
04896
04897
04898
04899
04900
04901
04902
04903
04904
04905
04906
04907
04908
04909
04910
04911
04912
04913
04914 void ConfigurationGUISupervisor::handleCreateConfigurationGroupXML(
04915 HttpXmlDocument& xmlOut,
04916 ConfigurationManagerRW* cfgMgr, const std::string& groupName,
04917 const std::string& configList, bool allowDuplicates, bool ignoreWarnings,
04918 const std::string& groupComment, bool lookForEquivalent)
04919 try
04920 {
04921 __SUP_COUT__ << "handleCreateConfigurationGroupXML \n";
04922
04923 xmlOut.addTextElementToData("AttemptedNewGroupName",groupName);
04924
04925
04926
04927 const std::map<std::string, ConfigurationInfo>& allCfgInfo = cfgMgr->getAllConfigurationInfo(true);
04928 cfgMgr->loadConfigurationBackbone();
04929
04930 std::map<std::string ,
04931 std::map<std::string ,
04932 ConfigurationVersion > > versionAliases =
04933 cfgMgr->getVersionAliases();
04934 for(const auto& aliases:versionAliases)
04935 for(const auto& alias:aliases.second)
04936 __SUP_COUT__ << aliases.first << " " << alias.first << " " << alias.second << std::endl;
04937
04938 std::map<std::string , ConfigurationVersion > groupMembers;
04939 std::map<std::string , std::string > groupAliases;
04940
04941 std::string name, versionStr, alias;
04942 ConfigurationVersion version;
04943 auto c = configList.find(',',0);
04944 auto i = c; i = 0;
04945 while(c < configList.length())
04946 {
04947
04948 name = configList.substr(i,c-i);
04949 i = c+1;
04950 c = configList.find(',',i);
04951 if(c == std::string::npos)
04952 {
04953 __SUP_SS__ << "Incomplete Configuration-Version pair!" << std::endl;
04954 __SUP_COUT_ERR__ << "\n" << ss.str();
04955 xmlOut.addTextElementToData("Error", ss.str());
04956 return;
04957 }
04958
04959 versionStr = configList.substr(i,c-i);
04960 i = c+1;
04961 c = configList.find(',',i);
04962
04963
04964
04965
04966
04967 if(versionStr.find(ConfigurationManager::ALIAS_VERSION_PREAMBLE) == 0)
04968 {
04969 alias = versionStr.substr(
04970 ConfigurationManager::ALIAS_VERSION_PREAMBLE.size());
04971
04972 __SUP_COUT__ << "Found alias " << name << " " << versionStr << __E__;
04973
04974
04975 if(versionAliases.find(name) != versionAliases.end() &&
04976 versionAliases[name].find(alias) != versionAliases[name].end())
04977 {
04978
04979 version = versionAliases[name][alias];
04980 __SUP_COUT__ << "version alias '" << alias <<
04981 "'translated to: " << version << std::endl;
04982
04983 groupAliases[name] = alias;
04984 }
04985 else
04986 {
04987 __SUP_SS__ << "version alias '" << versionStr.substr(
04988 ConfigurationManager::ALIAS_VERSION_PREAMBLE.size()) <<
04989 "' was not found in active version aliases!" << std::endl;
04990 __SUP_COUT_ERR__ << "\n" << ss.str();
04991 xmlOut.addTextElementToData("Error",
04992 ss.str());
04993 return;
04994 }
04995 }
04996 else
04997 version = ConfigurationVersion(versionStr);
04998
04999 if(version.isTemporaryVersion())
05000 {
05001 __SUP_SS__ << "Groups can not be created using temporary member tables. " <<
05002 "Table member '" << name << "' with temporary version '" << version <<
05003 "' is illegal." << std::endl;
05004 xmlOut.addTextElementToData("Error", ss.str());
05005 return;
05006 }
05007
05008
05009 if(allCfgInfo.find(name) == allCfgInfo.end())
05010 {
05011 __SUP_SS__ << "Groups can not be created using mock-up member tables of undefined tables. " <<
05012 "Table member '" << name << "' is not defined." << std::endl;
05013 xmlOut.addTextElementToData("Error", ss.str());
05014 return;
05015 }
05016
05017 if(version.isMockupVersion())
05018 {
05019
05020 ConfigurationBase* config = cfgMgr->getConfigurationByName(name);
05021
05022 ConfigurationVersion temporaryVersion = config->createTemporaryView();
05023 __SUP_COUT__ << "\t\ttemporaryVersion: " << temporaryVersion << std::endl;
05024
05025
05026
05027 __SUP_COUT__ << "Creating version from mock-up for name: " << name <<
05028 " inputVersionStr: " << versionStr << std::endl;
05029
05030
05031 config->getTemporaryView(temporaryVersion)->setComment("Auto-generated from mock-up.");
05032
05033
05034 version = saveModifiedVersionXML(xmlOut,cfgMgr,name,
05035 ConfigurationVersion() ,
05036 false ,
05037 config,
05038 temporaryVersion ,
05039 false ,
05040 true );
05041
05042 __SUP_COUT__ << "Using mockup version: " << version << std::endl;
05043
05044 }
05045
05046
05047 groupMembers[name] = version;
05048 }
05049
05050 __COUTV__(StringMacros::mapToString(groupAliases));
05051
05052 if(!allowDuplicates)
05053 {
05054 __SUP_COUT__ << "Checking for duplicate groups..." << std::endl;
05055 ConfigurationGroupKey foundKey =
05056 cfgMgr->findConfigurationGroup(groupName,groupMembers,groupAliases);
05057
05058 if(!foundKey.isInvalid())
05059 {
05060
05061 xmlOut.addTextElementToData("ConfigurationGroupName",groupName);
05062 xmlOut.addTextElementToData("ConfigurationGroupKey",foundKey.toString());
05063
05064 if(lookForEquivalent)
05065 {
05066 __SUP_COUT__ << "Found equivalent group key (" << foundKey << ") for " <<
05067 groupName << "." << std::endl;
05068
05069 xmlOut.addTextElementToData("foundEquivalentKey","1");
05070
05071
05072 handleGetConfigurationGroupXML(xmlOut,cfgMgr,groupName,foundKey);
05073 return;
05074 }
05075 else
05076 {
05077 __SUP_COUT__ << "Treating duplicate group as error." << std::endl;
05078 __SUP_SS__ << ("Failed to create configuration group: " + groupName +
05079 ". It is a duplicate of an existing group key (" + foundKey.toString() + ")");
05080 __SUP_COUT_ERR__ << ss.str() << std::endl;
05081 xmlOut.addTextElementToData("Error",ss.str());
05082 return;
05083 }
05084 }
05085
05086 __SUP_COUT__ << "Check for duplicate groups complete." << std::endl;
05087 }
05088
05089
05090 try
05091 {
05092 cfgMgr->loadMemberMap(groupMembers);
05093
05094 std::string accumulateErrors = "";
05095 for(auto& groupMemberPair:groupMembers)
05096 {
05097 ConfigurationView* cfgViewPtr =
05098 cfgMgr->getConfigurationByName(groupMemberPair.first)->getViewP();
05099 if(cfgViewPtr->getDataColumnSize() !=
05100 cfgViewPtr->getNumberOfColumns() ||
05101 cfgViewPtr->getSourceColumnMismatch() != 0)
05102 {
05103 __SUP_SS__ << "\n\nThere were errors found in loading a member table " <<
05104 groupMemberPair.first << ":v" << cfgViewPtr->getVersion() <<
05105 ". Please see the details below:\n\n" <<
05106 "The source column size was found to be " <<
05107 cfgViewPtr->getDataColumnSize() <<
05108 ", and the current number of columns for this table is " <<
05109 cfgViewPtr->getNumberOfColumns() << ". This resulted in a count of " <<
05110 cfgViewPtr->getSourceColumnMismatch() << " source column mismatches, and a count of " <<
05111 cfgViewPtr->getSourceColumnMissing() << " table entries missing in " <<
05112 cfgViewPtr->getNumberOfRows() << " row(s) of data." <<
05113 std::endl;
05114
05115 const std::set<std::string> srcColNames = cfgViewPtr->getSourceColumnNames();
05116 ss << "\n\nSource column names were as follows:\n";
05117 char index = 'a';
05118 for(auto& srcColName:srcColNames)
05119 ss << "\n\t" <<index++ << ". " << srcColName;
05120 ss << std::endl;
05121
05122 std::set<std::string> destColNames = cfgViewPtr->getColumnStorageNames();
05123 ss << "\n\nCurrent table column names are as follows:\n";
05124 index = 'a';
05125 for(auto& destColName:destColNames)
05126 ss << "\n\t" << index++ << ". " << destColName;
05127 ss << std::endl;
05128
05129 __SUP_COUT_ERR__ << "\n" << ss.str();
05130 xmlOut.addTextElementToData("Error", ss.str());
05131 return;
05132 }
05133 }
05134 }
05135 catch(std::runtime_error& e)
05136 {
05137 __SUP_SS__ << "Failed to create config group: " << groupName <<
05138 ".\nThere were problems loading the chosen members:\n\n" <<
05139 e.what() << std::endl;
05140 __SUP_COUT_ERR__ << "\n" << ss.str();
05141 xmlOut.addTextElementToData("Error", ss.str());
05142 return;
05143 }
05144 catch(...)
05145 {
05146 __SUP_SS__ << "Failed to create config group: " << groupName << std::endl;
05147 __SUP_COUT_ERR__ << "\n" << ss.str();
05148 xmlOut.addTextElementToData("Error", ss.str());
05149 return;
05150 }
05151
05152
05153 std::string accumulateTreeErrs;
05154 cfgMgr->getChildren(&groupMembers,&accumulateTreeErrs);
05155 if(accumulateTreeErrs != "" )
05156 {
05157 __SUP_COUT_WARN__ << "\n" << accumulateTreeErrs << std::endl;
05158 if(!ignoreWarnings)
05159 {
05160 xmlOut.addTextElementToData("TreeErrors",
05161 accumulateTreeErrs);
05162 return;
05163 }
05164 }
05165
05166 ConfigurationGroupKey newKey;
05167 try
05168 {
05169 __COUT__ << "Saving new group..." << __E__;
05170 newKey = cfgMgr->saveNewConfigurationGroup(groupName,groupMembers,
05171 groupComment,&groupAliases);
05172 }
05173 catch(std::runtime_error& e)
05174 {
05175 __SUP_COUT_ERR__ << "Failed to create config group: " << groupName << std::endl;
05176 __SUP_COUT_ERR__ << "\n\n" << e.what() << std::endl;
05177 xmlOut.addTextElementToData("Error", "Failed to create configuration group: " + groupName +
05178 ".\n\n" + e.what());
05179 return;
05180 }
05181 catch(...)
05182 {
05183 __SUP_COUT_ERR__ << "Failed to create config group: " << groupName << std::endl;
05184 xmlOut.addTextElementToData("Error", "Failed to create configuration group: " + groupName);
05185 return;
05186 }
05187
05188
05189 __COUT__ << "Loading new group..." << __E__;
05190 handleGetConfigurationGroupXML(xmlOut,cfgMgr,groupName,newKey);
05191 }
05192 catch(std::runtime_error& e)
05193 {
05194 __SUP_COUT__ << "Error detected!\n\n " << e.what() << std::endl;
05195 xmlOut.addTextElementToData("Error", "Error saving group! " + std::string(e.what()));
05196 }
05197 catch(...)
05198 {
05199 __SUP_COUT__ << "Error detected!\n\n "<< std::endl;
05200 xmlOut.addTextElementToData("Error", "Error saving group! ");
05201 }
05202
05203
05204
05205
05206
05207
05208
05209 void ConfigurationGUISupervisor::handleDeleteConfigurationInfoXML(HttpXmlDocument& xmlOut,
05210 ConfigurationManagerRW* cfgMgr,
05211 std::string& configName)
05212 {
05213
05214 if ( 0 == rename( (CONFIG_INFO_PATH + configName + CONFIG_INFO_EXT).c_str() ,
05215 (CONFIG_INFO_PATH + configName + CONFIG_INFO_EXT + ".unused").c_str() ) )
05216 __SUP_COUT_INFO__ << ( "Table Info File successfully renamed: " +
05217 (CONFIG_INFO_PATH + configName + CONFIG_INFO_EXT + ".unused")) << std::endl;
05218 else
05219 {
05220 __SUP_COUT_ERR__ << ( "Error renaming file to " +
05221 (CONFIG_INFO_PATH + configName + CONFIG_INFO_EXT + ".unused")) << std::endl;
05222
05223 xmlOut.addTextElementToData("Error",
05224 ( "Error renaming Table Info File to " +
05225 (CONFIG_INFO_PATH + configName + CONFIG_INFO_EXT + ".unused")));
05226 return;
05227 }
05228
05229
05230 cfgMgr->getAllConfigurationInfo(true);
05231 }
05232
05233
05234
05235
05236
05237
05238
05239
05240 void ConfigurationGUISupervisor::handleSaveConfigurationInfoXML(HttpXmlDocument& xmlOut,
05241 ConfigurationManagerRW* cfgMgr,
05242 std::string& configName, const std::string& data,
05243 const std::string& tableDescription, const std::string& columnChoicesCSV,
05244 bool allowOverwrite)
05245 {
05246
05247
05248 std::string capsName;
05249 try
05250 {
05251 capsName = ConfigurationBase::convertToCaps(configName, true);
05252 }
05253 catch(std::runtime_error& e)
05254 {
05255 xmlOut.addTextElementToData("Error",e.what());
05256 return;
05257 }
05258
05259 if(!allowOverwrite)
05260 {
05261 FILE* fp = fopen((CONFIG_INFO_PATH + configName + CONFIG_INFO_EXT).c_str(), "r");
05262 if(fp)
05263 {
05264 fclose(fp);
05265 xmlOut.addTextElementToData("ConfigurationName",
05266 configName);
05267 xmlOut.addTextElementToData("OverwriteError",
05268 "1");
05269 xmlOut.addTextElementToData("Error",
05270 "File already exists! ('" +
05271 (CONFIG_INFO_PATH + configName + CONFIG_INFO_EXT) +
05272 "')");
05273 return;
05274 }
05275 }
05276
05277 __SUP_COUT__ << "capsName=" << capsName << std::endl;
05278 __SUP_COUT__ << "configName=" << configName << std::endl;
05279 __SUP_COUT__ << "tableDescription=" << tableDescription << std::endl;
05280 __SUP_COUT__ << "columnChoicesCSV=" << columnChoicesCSV << std::endl;
05281
05282
05283 std::stringstream outss;
05284
05285 outss << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>\n";
05286 outss << "\t<ROOT xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"ConfigurationInfo.xsd\">\n";
05287 outss << "\t\t<CONFIGURATION Name=\"" <<
05288 configName << "\">\n";
05289 outss << "\t\t\t<VIEW Name=\"" << capsName <<
05290 "\" Type=\"File,Database,DatabaseTest\" Description=\"" <<
05291 tableDescription << "\">\n";
05292
05293
05294
05295 int i = 0;
05296 int j = data.find(',',i);
05297 int k = data.find(';',i);
05298
05299
05300 std::istringstream columnChoicesISS(columnChoicesCSV);
05301 std::string columnChoicesString;
05302 std::string columnType;
05303
05304 while(k != (int)(std::string::npos))
05305 {
05306
05307 columnType = data.substr(i,j-i);
05308 outss << "\t\t\t\t<COLUMN Type=\"";
05309 outss << columnType;
05310
05311 i=j+1;
05312 j = data.find(',',i);
05313
05314
05315 outss << "\" \t Name=\"";
05316 capsName = data.substr(i,j-i);
05317 outss << capsName;
05318 outss << "\" \t StorageName=\"";
05319
05320 try
05321 {
05322 outss << ConfigurationBase::convertToCaps(capsName);
05323 }
05324 catch(std::runtime_error& e)
05325 {
05326 xmlOut.addTextElementToData("Error", std::string("For column name '") +
05327 data.substr(i,j-i) + "' - " + e.what());
05328 return;
05329 }
05330
05331 i=j+1;
05332 j = data.find(',',i);
05333
05334
05335 outss << "\" \t DataType=\"";
05336 outss << data.substr(i,k-i);
05337
05338
05339
05340 getline(columnChoicesISS, columnChoicesString, ';');
05341
05342 outss << "\" \t DataChoices=\"";
05343 outss << columnChoicesString;
05344
05345
05346
05347 outss << "\"/>\n";
05348
05349 i = k+1;
05350 j = data.find(',',i);
05351 k = data.find(';',i);
05352 }
05353
05354 outss << "\t\t\t</VIEW>\n";
05355 outss << "\t\t</CONFIGURATION>\n";
05356 outss << "\t</ROOT>\n";
05357
05358 __SUP_COUT__ << outss.str() << std::endl;
05359
05360 FILE* fp = fopen((CONFIG_INFO_PATH + configName + CONFIG_INFO_EXT).c_str(), "w");
05361 if(!fp)
05362 {
05363 xmlOut.addTextElementToData("Error", "Failed to open destination Configuration Info file:" +
05364 (CONFIG_INFO_PATH + configName + CONFIG_INFO_EXT));
05365 return;
05366 }
05367
05368 fprintf(fp,"%s",outss.str().c_str());
05369 fclose(fp);
05370
05371
05372
05373 std::string accumulatedErrors = "";
05374 cfgMgr->getAllConfigurationInfo(true,&accumulatedErrors,configName);
05375
05376
05377 if(accumulatedErrors != "")
05378 {
05379 __SUP_SS__ << ("The new version of the '" + configName + "' table column info was saved, however errors were detected reading back the configuration '" +
05380 configName +
05381 "' after the save attempt:\n\n" + accumulatedErrors) << std::endl;
05382
05383 __SUP_COUT_ERR__ << ss.str() << std::endl;
05384 xmlOut.addTextElementToData("Error", ss.str());
05385
05386
05387
05388
05389 if(0)
05390 {
05391
05392
05393
05394
05395 if ( 0 == rename( (CONFIG_INFO_PATH + configName + CONFIG_INFO_EXT).c_str() ,
05396 (CONFIG_INFO_PATH + configName + CONFIG_INFO_EXT + ".unused").c_str() ) )
05397 __SUP_COUT_INFO__ << ( "File successfully renamed: " +
05398 (CONFIG_INFO_PATH + configName + CONFIG_INFO_EXT + ".unused")) << std::endl;
05399 else
05400
05401
05402 __SUP_COUT_ERR__ << ( "Error renaming file to " +
05403 (CONFIG_INFO_PATH + configName + CONFIG_INFO_EXT + ".unused")) << std::endl;
05404
05405
05406 cfgMgr->getAllConfigurationInfo(true);
05407 }
05408 return;
05409 }
05410
05411
05412 handleGetConfigurationXML(xmlOut,cfgMgr,configName,ConfigurationVersion());
05413
05414
05415
05416 const std::map<std::string, ConfigurationInfo>& allCfgInfo = cfgMgr->getAllConfigurationInfo();
05417
05418
05419 __SUP_COUT_INFO__ << "Looking for errors in all configuration column info..." << std::endl;
05420 for(const auto& cfgInfo: allCfgInfo)
05421 {
05422 try
05423 {
05424 cfgMgr->getConfigurationByName(cfgInfo.first)->getMockupViewP()->init();
05425 }
05426 catch(std::runtime_error& e)
05427 {
05428 __SUP_COUT_WARN__ << "\n\n##############################################\n" <<
05429 "Error identified in column info of configuration '" <<
05430 cfgInfo.first << "':\n\n" <<
05431 e.what() << "\n\n" << std::endl;
05432 }
05433 }
05434 }
05435
05436
05437
05438
05439
05440
05441
05442
05443
05444 void ConfigurationGUISupervisor::handleSetGroupAliasInBackboneXML(HttpXmlDocument& xmlOut,
05445 ConfigurationManagerRW* cfgMgr, const std::string& groupAlias,
05446 const std::string& groupName, ConfigurationGroupKey groupKey,
05447 const std::string& author)
05448 try
05449 {
05450 cfgMgr->loadConfigurationBackbone();
05451 std::map<std::string, ConfigurationVersion> activeVersions = cfgMgr->getActiveVersions();
05452
05453 const std::string groupAliasesTableName = ConfigurationManager::GROUP_ALIASES_CONFIG_NAME;
05454 if(activeVersions.find(groupAliasesTableName) == activeVersions.end())
05455 {
05456 __SUP_SS__ << "Active version of " << groupAliasesTableName << " missing!" << std::endl;
05457 xmlOut.addTextElementToData("Error", ss.str());
05458 return;
05459 }
05460
05461
05462 const std::set<std::string> backboneMembers = cfgMgr->getBackboneMemberNames();
05463 for(auto& memberName: backboneMembers)
05464 {
05465 __SUP_COUT__ << "activeVersions[\"" << memberName << "\"]=" <<
05466 activeVersions[memberName] << std::endl;
05467
05468 xmlOut.addTextElementToData("oldBackboneName",
05469 memberName);
05470 xmlOut.addTextElementToData("oldBackboneVersion",
05471 activeVersions[memberName].toString());
05472 }
05473
05474
05475
05476
05477
05478 ConfigurationBase* config = cfgMgr->getConfigurationByName(groupAliasesTableName);
05479 ConfigurationVersion originalVersion = activeVersions[groupAliasesTableName];
05480 ConfigurationVersion temporaryVersion = config->createTemporaryView(originalVersion);
05481
05482 __SUP_COUT__ << "\t\t temporaryVersion: " << temporaryVersion << std::endl;
05483 bool isDifferent = false;
05484
05485 try
05486 {
05487 ConfigurationView* configView = config->getTemporaryView(temporaryVersion);
05488
05489 unsigned int col = configView->findCol("GroupKeyAlias");
05490
05491
05492
05493
05494 unsigned int row = -1;
05495
05496 try { row = configView->findRow(col,groupAlias); }
05497 catch (...) {}
05498 if(row == (unsigned int)-1)
05499 {
05500 isDifferent = true;
05501 row = configView->addRow();
05502
05503
05504 col = configView->findCol("CommentDescription");
05505 configView->setValue("This Group Alias was automatically setup by the server." ,
05506 row, col);
05507 col = configView->findCol("GroupKeyAlias");
05508 configView->setValue(groupAlias, row, col);
05509 }
05510
05511 __SUP_COUT__ << "\t\t row: " << row << std::endl;
05512
05513 col = configView->findCol("GroupName");
05514
05515 __SUP_COUT__ << "\t\t groupName: " << groupName << " vs " <<
05516 configView->getDataView()[row][col] << std::endl;
05517 if(groupName != configView->getDataView()[row][col])
05518 {
05519 configView->setValue(groupName, row, col);
05520 isDifferent = true;
05521 }
05522
05523 col = configView->findCol("GroupKey");
05524 __SUP_COUT__ << "\t\t groupKey: " << groupKey << " vs " <<
05525 configView->getDataView()[row][col] << std::endl;
05526 if(groupKey.toString() != configView->getDataView()[row][col])
05527 {
05528 configView->setValue(groupKey.toString(), row, col);
05529 isDifferent = true;
05530 }
05531
05532 if(isDifferent)
05533 {
05534 configView->setValue(author, row, configView->findCol("Author"));
05535 configView->setValue(time(0), row, configView->findCol("RecordInsertionTime"));
05536 }
05537 }
05538 catch(...)
05539 {
05540 __SUP_COUT_ERR__ << "Error editing Group Alias view!" << std::endl;
05541
05542
05543 config->eraseView(temporaryVersion);
05544 throw;
05545 }
05546
05547
05548 ConfigurationVersion newAssignedVersion;
05549 if(isDifferent)
05550 {
05551 __SUP_COUT__ << "\t\t**************************** Save as new table version" << std::endl;
05552
05553
05554
05555
05556
05557
05558 newAssignedVersion = saveModifiedVersionXML(xmlOut,cfgMgr,
05559 config->getConfigurationName(),originalVersion, false ,
05560 config,temporaryVersion,false ,true );
05561
05562 }
05563 else
05564 {
05565 __SUP_COUT__ << "\t\t**************************** Using the existing table version" << std::endl;
05566
05567
05568 config->eraseView(temporaryVersion);
05569 newAssignedVersion = activeVersions[groupAliasesTableName];
05570
05571 xmlOut.addTextElementToData("savedName", groupAliasesTableName);
05572 xmlOut.addTextElementToData("savedVersion", newAssignedVersion.toString());
05573 }
05574
05575 __SUP_COUT__ << "\t\t newAssignedVersion: " << newAssignedVersion << std::endl;
05576
05577
05578 }
05579 catch(std::runtime_error& e)
05580 {
05581 __SUP_COUT_ERR__ << "Error detected!\n\n " << e.what() << std::endl;
05582 xmlOut.addTextElementToData("Error", "Error saving new Group Alias view!\n " +
05583 std::string(e.what()));
05584 }
05585 catch(...)
05586 {
05587 __SUP_COUT_ERR__ << "Error detected!\n\n "<< std::endl;
05588 xmlOut.addTextElementToData("Error", "Error saving new Group Alias view! ");
05589 }
05590
05591
05592
05593
05594
05595
05596
05597
05598
05599 void ConfigurationGUISupervisor::handleSetVersionAliasInBackboneXML(HttpXmlDocument& xmlOut,
05600 ConfigurationManagerRW* cfgMgr,
05601 const std::string& versionAlias,
05602 const std::string& configName, ConfigurationVersion version, const std::string& author)
05603 try
05604 {
05605 cfgMgr->loadConfigurationBackbone();
05606 std::map<std::string, ConfigurationVersion> activeVersions = cfgMgr->getActiveVersions();
05607
05608 const std::string versionAliasesTableName = ConfigurationManager::VERSION_ALIASES_CONFIG_NAME;
05609 if(activeVersions.find(versionAliasesTableName) == activeVersions.end())
05610 {
05611 __SUP_SS__ << "Active version of " << versionAliasesTableName << " missing!" << std::endl;
05612 xmlOut.addTextElementToData("Error", ss.str());
05613 return;
05614 }
05615
05616
05617 const std::set<std::string> backboneMembers = cfgMgr->getBackboneMemberNames();
05618 for(auto& memberName: backboneMembers)
05619 {
05620 __SUP_COUT__ << "activeVersions[\"" << memberName << "\"]=" <<
05621 activeVersions[memberName] << std::endl;
05622
05623 xmlOut.addTextElementToData("oldBackboneName",
05624 memberName);
05625 xmlOut.addTextElementToData("oldBackboneVersion",
05626 activeVersions[memberName].toString());
05627 }
05628
05629
05630
05631
05632
05633 ConfigurationBase* config = cfgMgr->getConfigurationByName(versionAliasesTableName);
05634 ConfigurationVersion originalVersion = activeVersions[versionAliasesTableName];
05635 ConfigurationVersion temporaryVersion = config->createTemporaryView(originalVersion);
05636
05637 __SUP_COUT__ << "\t\t temporaryVersion: " << temporaryVersion << std::endl;
05638
05639 bool isDifferent = false;
05640
05641 try
05642 {
05643 ConfigurationView* configView = config->getTemporaryView(temporaryVersion);
05644
05645 unsigned int col;
05646 unsigned int col2 = configView->findCol("VersionAlias");
05647 unsigned int col3 = configView->findCol("ConfigurationName");
05648
05649
05650
05651
05652 unsigned int row = -1;
05653
05654
05655 try {
05656 unsigned int tmpRow = -1;
05657 do
05658 {
05659 tmpRow = configView->findRow(col3,configName,tmpRow+1);
05660 } while (configView->getDataView()[tmpRow][col2] != versionAlias);
05661
05662 row = tmpRow;
05663 }
05664 catch (...) {}
05665 if(row == (unsigned int)-1)
05666 {
05667 isDifferent = true;
05668 row = configView->addRow();
05669
05670
05671 col = configView->findCol("CommentDescription");
05672 configView->setValue(std::string("Entry was added by server in ") +
05673 "ConfigurationGUISupervisor::setVersionAliasInActiveBackbone()." ,
05674 row, col);
05675
05676 col = configView->findCol("VersionAliasUID");
05677 configView->setValue(configName.substr(0,configName.rfind("Configuration")) +
05678 versionAlias, row, col);
05679
05680 configView->setValue(versionAlias, row, col2);
05681 configView->setValue(configName, row, col3);
05682 }
05683
05684 __SUP_COUT__ << "\t\t row: " << row << std::endl;
05685
05686 col = configView->findCol("Version");
05687 __SUP_COUT__ << "\t\t version: " << version << " vs " <<
05688 configView->getDataView()[row][col] << std::endl;
05689 if(version.toString() != configView->getDataView()[row][col])
05690 {
05691 configView->setValue(version.toString(), row, col);
05692 isDifferent = true;
05693 }
05694
05695 if(isDifferent)
05696 {
05697 configView->setValue(author, row, configView->findCol("Author"));
05698 configView->setValue(time(0), row, configView->findCol("RecordInsertionTime"));
05699 }
05700 }
05701 catch(...)
05702 {
05703 __SUP_COUT_ERR__ << "Error editing Version Alias view!" << std::endl;
05704
05705
05706 config->eraseView(temporaryVersion);
05707 throw;
05708 }
05709
05710 ConfigurationVersion newAssignedVersion;
05711 if(isDifferent)
05712 {
05713 __SUP_COUT__ << "\t\t**************************** Save as new table version" << std::endl;
05714
05715
05716
05717
05718 newAssignedVersion = saveModifiedVersionXML(xmlOut,cfgMgr,
05719 config->getConfigurationName(),originalVersion, false ,
05720 config,temporaryVersion,false ,true );
05721 }
05722 else
05723 {
05724 __SUP_COUT__ << "\t\t**************************** Using existing table version" << std::endl;
05725
05726
05727 config->eraseView(temporaryVersion);
05728 newAssignedVersion = activeVersions[versionAliasesTableName];
05729
05730 xmlOut.addTextElementToData("savedAlias", versionAliasesTableName);
05731 xmlOut.addTextElementToData("savedVersion", newAssignedVersion.toString());
05732 }
05733
05734 __SUP_COUT__ << "\t\t newAssignedVersion: " << newAssignedVersion << std::endl;
05735 }
05736 catch(std::runtime_error& e)
05737 {
05738 __SUP_COUT__ << "Error detected!\n\n " << e.what() << std::endl;
05739 xmlOut.addTextElementToData("Error", "Error saving new Version Alias view!\n " +
05740 std::string(e.what()));
05741 }
05742 catch(...)
05743 {
05744 __SUP_COUT__ << "Error detected!\n\n "<< std::endl;
05745 xmlOut.addTextElementToData("Error", "Error saving new Version Alias view! ");
05746 }
05747
05748
05749
05750
05751
05752
05753
05754 void ConfigurationGUISupervisor::handleAliasGroupMembersInBackboneXML(HttpXmlDocument& xmlOut,
05755 ConfigurationManagerRW* cfgMgr,
05756 const std::string& versionAlias,
05757 const std::string& groupName, ConfigurationGroupKey groupKey, const std::string& author)
05758 try
05759 {
05760 cfgMgr->loadConfigurationBackbone();
05761 std::map<std::string, ConfigurationVersion> activeVersions = cfgMgr->getActiveVersions();
05762
05763 const std::string versionAliasesTableName = ConfigurationManager::VERSION_ALIASES_CONFIG_NAME;
05764 if(activeVersions.find(versionAliasesTableName) == activeVersions.end())
05765 {
05766 __SUP_SS__ << "Active version of " << versionAliasesTableName << " missing!" << std::endl;
05767 xmlOut.addTextElementToData("Error", ss.str());
05768 return;
05769 }
05770
05771
05772 const std::set<std::string> backboneMembers = cfgMgr->getBackboneMemberNames();
05773 for(auto& memberName: backboneMembers)
05774 {
05775 __SUP_COUT__ << "activeVersions[\"" << memberName << "\"]=" <<
05776 activeVersions[memberName] << std::endl;
05777
05778 xmlOut.addTextElementToData("oldBackboneName",
05779 memberName);
05780 xmlOut.addTextElementToData("oldBackboneVersion",
05781 activeVersions[memberName].toString());
05782 }
05783
05784
05785
05786
05787
05788
05789 ConfigurationBase* config = cfgMgr->getConfigurationByName(versionAliasesTableName);
05790 ConfigurationVersion temporaryVersion = config->
05791 createTemporaryView(activeVersions[versionAliasesTableName]);
05792
05793 __SUP_COUT__ << "\t\t temporaryVersion: " << temporaryVersion << std::endl;
05794
05795 ConfigurationView* configView = config->getTemporaryView(temporaryVersion);
05796
05797
05798
05799 bool isDifferent = false;
05800
05801
05802 std::map<std::string , ConfigurationVersion > memberMap;
05803 try
05804 {
05805 cfgMgr->loadConfigurationGroup(groupName,groupKey,
05806 false ,&memberMap,0,0,0,0,0,
05807 true );
05808 }
05809 catch(...)
05810 {
05811 xmlOut.addTextElementToData("Error","Configuration group \"" +
05812 ConfigurationGroupKey::getFullGroupString(groupName,groupKey) +
05813 "\" can not be retrieved!");
05814 return;
05815 }
05816
05817 unsigned int col;
05818 unsigned int col2 = configView->findCol("VersionAlias");
05819 unsigned int col3 = configView->findCol("ConfigurationName");
05820
05821 for(auto& memberPair:memberMap)
05822 {
05823 bool thisMemberIsDifferent = false;
05824 unsigned int row = -1;
05825
05826 __SUP_COUT__ << "Adding alias for " << memberPair.first <<
05827 "_v" << memberPair.second << std::endl;
05828
05829
05830
05831 try {
05832 unsigned int tmpRow = -1;
05833 do
05834 {
05835 tmpRow = configView->findRow(col3,memberPair.first,tmpRow+1);
05836 __SUP_COUT__ << configView->getDataView()[tmpRow][col2] << std::endl;
05837 } while (configView->getDataView()[tmpRow][col2] != versionAlias);
05838
05839 row = tmpRow;
05840 }
05841 catch (...) {}
05842 if(row == (unsigned int)-1)
05843 {
05844 thisMemberIsDifferent = true;
05845 row = configView->addRow();
05846
05847
05848 col = configView->findCol("CommentDescription");
05849 configView->setValue(std::string("Entry was added by server in ") +
05850 "ConfigurationGUISupervisor::setVersionAliasInActiveBackbone()." ,
05851 row, col);
05852
05853 col = configView->getColUID();
05854 configView->setValue(memberPair.first.substr(
05855 0,memberPair.first.rfind("Configuration")) +
05856 versionAlias, row, col);
05857
05858 configView->setValue(versionAlias, row, col2);
05859 configView->setValue(memberPair.first, row, col3);
05860 }
05861
05862 __SUP_COUT__ << "\t\t row: " << row << std::endl;
05863
05864 col = configView->findCol("Version");
05865 __SUP_COUT__ << "\t\t col: " << col << std::endl;
05866 __SUP_COUT__ << "\t\t version: " << memberPair.second << " vs " <<
05867 configView->getDataView()[row][col] << std::endl;
05868 if(memberPair.second.toString() !=
05869 configView->getDataView()[row][col])
05870 {
05871 configView->setValue(memberPair.second.toString(), row, col);
05872 thisMemberIsDifferent = true;
05873 }
05874
05875 if(thisMemberIsDifferent)
05876 {
05877 configView->setValue(author, row, configView->findCol("Author"));
05878 configView->setValue(time(0), row, configView->findCol("RecordInsertionTime"));
05879 }
05880
05881 if(thisMemberIsDifferent)
05882 isDifferent = true;
05883 }
05884
05885
05886
05887 ConfigurationVersion newAssignedVersion;
05888 if(isDifferent)
05889 {
05890 __SUP_COUT__ << "\t\t**************************** Save as new table version" << std::endl;
05891
05892 newAssignedVersion =
05893 cfgMgr->saveNewConfiguration(versionAliasesTableName,temporaryVersion);
05894 }
05895 else
05896 {
05897 __SUP_COUT__ << "\t\t**************************** Using existing table version" << std::endl;
05898
05899
05900 config->eraseView(temporaryVersion);
05901 newAssignedVersion = activeVersions[versionAliasesTableName];
05902 }
05903
05904 xmlOut.addTextElementToData("savedAlias", versionAliasesTableName);
05905 xmlOut.addTextElementToData("savedVersion", newAssignedVersion.toString());
05906 __SUP_COUT__ << "\t\t newAssignedVersion: " << newAssignedVersion << std::endl;
05907 }
05908 catch(std::runtime_error& e)
05909 {
05910 __SUP_COUT__ << "Error detected!\n\n " << e.what() << std::endl;
05911 xmlOut.addTextElementToData("Error", "Error saving new Version Alias view!\n " +
05912 std::string(e.what()));
05913 }
05914 catch(...)
05915 {
05916 __SUP_COUT__ << "Error detected!\n\n "<< std::endl;
05917 xmlOut.addTextElementToData("Error", "Error saving new Version Alias view! ");
05918 }
05919
05920
05921
05922
05923
05924
05925
05926
05927
05928
05929
05930
05931 void ConfigurationGUISupervisor::handleGroupAliasesXML(HttpXmlDocument& xmlOut,
05932 ConfigurationManagerRW* cfgMgr)
05933 {
05934 cfgMgr->loadConfigurationBackbone();
05935 std::map<std::string, ConfigurationVersion> activeVersions = cfgMgr->getActiveVersions();
05936
05937 std::string groupAliasesTableName = ConfigurationManager::GROUP_ALIASES_CONFIG_NAME;
05938 if(activeVersions.find(groupAliasesTableName) == activeVersions.end())
05939 {
05940 __SUP_SS__ << "\nActive version of " << groupAliasesTableName << " missing! " <<
05941 groupAliasesTableName << " is a required member of the Backbone configuration group." <<
05942 "\n\nLikely you need to activate a valid Backbone group." <<
05943 std::endl;
05944 xmlOut.addTextElementToData("Error", ss.str());
05945 return;
05946 }
05947 __SUP_COUT__ << "activeVersions[\"" << groupAliasesTableName << "\"]=" <<
05948 activeVersions[groupAliasesTableName] << std::endl;
05949 xmlOut.addTextElementToData("GroupAliasesConfigurationName",
05950 groupAliasesTableName);
05951 xmlOut.addTextElementToData("GroupAliasesConfigurationVersion",
05952 activeVersions[groupAliasesTableName].toString());
05953
05954 std::vector<std::pair<std::string,ConfigurationTree> > aliasNodePairs =
05955 cfgMgr->getNode(groupAliasesTableName).getChildren();
05956
05957 std::string groupName, groupKey, groupComment, groupType;
05958 for(auto& aliasNodePair:aliasNodePairs)
05959 {
05960 groupName = aliasNodePair.second.getNode("GroupName").getValueAsString();
05961 groupKey = aliasNodePair.second.getNode("GroupKey").getValueAsString();
05962
05963 xmlOut.addTextElementToData("GroupAlias", aliasNodePair.first);
05964 xmlOut.addTextElementToData("GroupName", groupName);
05965 xmlOut.addTextElementToData("GroupKey", groupKey);
05966 xmlOut.addTextElementToData("AliasComment",
05967 aliasNodePair.second.getNode("CommentDescription").getValueAsString());
05968
05969
05970 groupComment = "";
05971 groupType = "Invalid";
05972 try
05973 {
05974 cfgMgr->loadConfigurationGroup(groupName,ConfigurationGroupKey(groupKey),
05975 0,0,0,0,&groupComment,0,0,
05976 true ,&groupType);
05977 }
05978 catch(...)
05979 {
05980 __SUP_COUT_WARN__ << "Failed to load group '" << groupName << "(" << groupKey <<
05981 ")' to extract group comment and type." << std::endl;
05982 }
05983 xmlOut.addTextElementToData("GroupComment", groupComment);
05984 xmlOut.addTextElementToData("GroupType", groupType);
05985 }
05986 }
05987
05988
05989
05990
05991
05992
05993
05994
05995
05996
05997
05998
05999 void ConfigurationGUISupervisor::handleVersionAliasesXML(HttpXmlDocument& xmlOut,
06000 ConfigurationManagerRW* cfgMgr)
06001 {
06002 cfgMgr->loadConfigurationBackbone();
06003 std::map<std::string, ConfigurationVersion> activeVersions = cfgMgr->getActiveVersions();
06004
06005 std::string versionAliasesTableName = ConfigurationManager::VERSION_ALIASES_CONFIG_NAME;
06006 if(activeVersions.find(versionAliasesTableName) == activeVersions.end())
06007 {
06008 __SUP_SS__ << "Active version of VersionAliases missing!" <<
06009 "Make sure you have a valid active Backbone Group." << std::endl;
06010 xmlOut.addTextElementToData("Error", ss.str());
06011 return;
06012 }
06013 __SUP_COUT__ << "activeVersions[\"" << versionAliasesTableName << "\"]=" <<
06014 activeVersions[versionAliasesTableName] << std::endl;
06015 xmlOut.addTextElementToData("VersionAliasesVersion",
06016 activeVersions[versionAliasesTableName].toString());
06017
06018 std::vector<std::pair<std::string,ConfigurationTree> > aliasNodePairs =
06019 cfgMgr->getNode(versionAliasesTableName).getChildren();
06020
06021 for(auto& aliasNodePair:aliasNodePairs)
06022 {
06023
06024
06025 xmlOut.addTextElementToData("VersionAlias",
06026 aliasNodePair.second.getNode("VersionAlias").getValueAsString());
06027 xmlOut.addTextElementToData("ConfigurationName",
06028 aliasNodePair.second.getNode("ConfigurationName").getValueAsString());
06029 xmlOut.addTextElementToData("Version",
06030 aliasNodePair.second.getNode("Version").getValueAsString());
06031 xmlOut.addTextElementToData("Comment",
06032 aliasNodePair.second.getNode("CommentDescription").getValueAsString());
06033 }
06034 }
06035
06036
06037
06038
06039
06040
06041
06042 void ConfigurationGUISupervisor::handleGetConfigurationGroupTypeXML(HttpXmlDocument& xmlOut,
06043 ConfigurationManagerRW* cfgMgr,
06044 const std::string& configList)
06045 {
06046
06047 std::map<std::string , ConfigurationVersion > memberMap;
06048 std::string name, versionStr;
06049 auto c = configList.find(',',0);
06050 auto i = c; i = 0;
06051 while(c < configList.length())
06052 {
06053
06054 name = configList.substr(i,c-i);
06055 i = c+1;
06056 c = configList.find(',',i);
06057 if(c == std::string::npos)
06058 {
06059 __SUP_SS__ << "Incomplete Configuration-Version pair!" << std::endl;
06060 __SUP_COUT_ERR__ << "\n" << ss.str();
06061 xmlOut.addTextElementToData("Error", ss.str());
06062 return;
06063 }
06064
06065 versionStr = configList.substr(i,c-i);
06066 i = c+1;
06067 c = configList.find(',',i);
06068
06069 memberMap[name] = ConfigurationVersion(versionStr);
06070 }
06071
06072 std::string groupTypeString = "";
06073
06074 try
06075 {
06076
06077 groupTypeString = cfgMgr->getTypeNameOfGroup(memberMap);
06078 xmlOut.addTextElementToData("ConfigurationGroupType", groupTypeString);
06079 }
06080 catch(std::runtime_error& e)
06081 {
06082 __SUP_SS__ << "Configuration group has invalid type! " << e.what() << std::endl;
06083 __SUP_COUT__ << "\n" << ss.str();
06084 groupTypeString = "Invalid";
06085 xmlOut.addTextElementToData("ConfigurationGroupType", groupTypeString);
06086 }
06087 catch(...)
06088 {
06089 __SUP_SS__ << "Configuration group has invalid type! " << std::endl;
06090 __SUP_COUT__ << "\n" << ss.str();
06091 groupTypeString = "Invalid";
06092 xmlOut.addTextElementToData("ConfigurationGroupType", groupTypeString);
06093 }
06094 }
06095
06096
06097
06098
06099
06100
06101
06102
06103
06104
06105
06106
06107
06108
06109
06110
06111
06112 void ConfigurationGUISupervisor::handleConfigurationGroupsXML(HttpXmlDocument& xmlOut,
06113 ConfigurationManagerRW* cfgMgr, bool returnMembers)
06114 {
06115 DOMElement* parentEl;
06116
06117
06118
06119 if(!cfgMgr->getAllGroupInfo().size())
06120 {
06121 __SUP_COUT__ << "Cache is empty? Attempting to regenerate." << __E__;
06122 cfgMgr->getAllConfigurationInfo(true );
06123 }
06124
06125 const std::map<std::string, GroupInfo>& allGroupInfo = cfgMgr->getAllGroupInfo();
06126
06127
06128
06129
06130
06131
06132
06133
06134
06135
06136
06137
06138
06139
06140
06141
06142
06143
06144 ConfigurationGroupKey groupKey;
06145 std::string groupName;
06146 std::string groupString, groupTypeString, groupComment, groupCreationTime, groupAuthor;
06147 for(auto& groupInfo:allGroupInfo)
06148 {
06149 groupName = groupInfo.first;
06150 if(groupInfo.second.keys_.size() == 0)
06151 {
06152 __SUP_COUT__ << "Group name '" << groupName << "' found, but no keys so ignoring." << __E__;
06153 continue;
06154 }
06155
06156 groupKey = *(groupInfo.second.keys_.rbegin());
06157
06158 xmlOut.addTextElementToData("ConfigurationGroupName", groupName);
06159 xmlOut.addTextElementToData("ConfigurationGroupKey", groupKey.toString());
06160
06161
06162 xmlOut.addTextElementToData("ConfigurationGroupType", groupInfo.second.latestKeyGroupTypeString_);
06163 xmlOut.addTextElementToData("ConfigurationGroupComment", groupInfo.second.latestKeyGroupComment_);
06164 xmlOut.addTextElementToData("ConfigurationGroupAuthor", groupInfo.second.latestKeyGroupAuthor_);
06165 xmlOut.addTextElementToData("ConfigurationGroupCreationTime", groupInfo.second.latestKeyGroupCreationTime_);
06166
06167 if(returnMembers)
06168 {
06169
06170
06171
06172
06173
06174
06175
06176
06177
06178 parentEl = xmlOut.addTextElementToData("ConfigurationGroupMembers", "");
06179
06180
06181
06182
06183
06184
06185
06186
06187
06188
06189
06190
06191
06192
06193
06194
06195
06196
06197
06198
06199
06200
06201
06202
06203
06204
06205
06206
06207
06208
06209
06210
06211
06212
06213 for(auto& memberPair:groupInfo.second.latestKeyMemberMap_)
06214 {
06215
06216 xmlOut.addTextElementToParent("MemberName", memberPair.first, parentEl);
06217 xmlOut.addTextElementToParent("MemberVersion", memberPair.second.toString(), parentEl);
06218 }
06219 }
06220
06221
06222
06223
06224 for(auto& keyInSet: groupInfo.second.keys_)
06225 {
06226 if(keyInSet == groupKey) continue;
06227 xmlOut.addTextElementToData("ConfigurationGroupName", groupName);
06228 xmlOut.addTextElementToData("ConfigurationGroupKey", keyInSet.toString());
06229
06230
06231 xmlOut.addTextElementToData("ConfigurationGroupType", groupInfo.second.latestKeyGroupTypeString_);
06232 xmlOut.addTextElementToData("ConfigurationGroupComment", groupInfo.second.latestKeyGroupComment_);
06233 xmlOut.addTextElementToData("ConfigurationGroupAuthor", groupInfo.second.latestKeyGroupAuthor_);
06234 xmlOut.addTextElementToData("ConfigurationGroupCreationTime", groupInfo.second.latestKeyGroupCreationTime_);
06235
06236 if(returnMembers)
06237 {
06238 xmlOut.addTextElementToData("ConfigurationGroupMembers", "");
06239
06240
06241 bool loadingHistoricalInfo = false;
06242 if(loadingHistoricalInfo)
06243 {
06244
06245
06246 groupComment = "";
06247 try
06248 {
06249 cfgMgr->loadConfigurationGroup(groupName,keyInSet,
06250 0,0,0,0,&groupComment,0,0,
06251 true ,&groupTypeString);
06252 }
06253 catch(...)
06254 {
06255 groupTypeString = "Invalid";
06256 __SUP_COUT_WARN__ << "Failed to load group '" << groupName << "(" << keyInSet <<
06257 ")' to extract group comment and type." << std::endl;
06258 }
06259
06260 xmlOut.addTextElementToData("ConfigurationGroupType", groupTypeString);
06261 xmlOut.addTextElementToData("ConfigurationGroupComment", groupComment);
06262 xmlOut.addTextElementToData("ConfigurationGroupAuthor", groupAuthor);
06263 xmlOut.addTextElementToData("ConfigurationGroupCreationTime", groupCreationTime);
06264 }
06265 }
06266
06267 }
06268 }
06269
06270 }
06271
06272
06273
06274
06275
06276
06277
06278
06279
06280
06281
06282
06283
06284 void ConfigurationGUISupervisor::handleConfigurationsXML(HttpXmlDocument& xmlOut,
06285 ConfigurationManagerRW* cfgMgr,
06286 bool allowIllegalColumns)
06287 {
06288 DOMElement* parentEl;
06289
06290 std::string accumulatedErrors = "";
06291 const std::map<std::string, ConfigurationInfo>& allCfgInfo = cfgMgr->getAllConfigurationInfo(
06292 allowIllegalColumns,allowIllegalColumns?&accumulatedErrors:0);
06293 std::map<std::string, ConfigurationInfo>::const_iterator it = allCfgInfo.begin();
06294
06295 __SUP_COUT__ << "# of configuration tables found: " << allCfgInfo.size() << std::endl;
06296
06297 std::map<std::string,std::map<std::string,ConfigurationVersion> > versionAliases =
06298 cfgMgr->getVersionAliases();
06299
06300 __SUP_COUT__ << "# of configuration tables w/aliases: " << versionAliases.size() << std::endl;
06301
06302
06303 while(it != allCfgInfo.end())
06304 {
06305
06306
06307
06308
06309
06310
06311 xmlOut.addTextElementToData("ConfigurationName", it->first);
06312 parentEl = xmlOut.addTextElementToData("ConfigurationVersions", "");
06313
06314
06315 if(versionAliases.find(it->first) != versionAliases.end())
06316 for (auto& aliasVersion:versionAliases[it->first])
06317 if(it->second.versions_.find(aliasVersion.second) !=
06318 it->second.versions_.end())
06319
06320 xmlOut.addTextElementToParent("Version",
06321 ConfigurationManager::ALIAS_VERSION_PREAMBLE + aliasVersion.first,
06322 parentEl);
06323
06324
06325
06326
06327
06328
06329
06330
06331
06332
06333
06334
06335
06336 for (auto& version:it->second.versions_)
06337 if(!version.isScratchVersion())
06338 xmlOut.addTextElementToParent("Version", version.toString(), parentEl);
06339
06340 ++it;
06341 }
06342
06343 if(accumulatedErrors != "")
06344 xmlOut.addTextElementToData("Error", std::string("Column errors were allowed for this request, ") +
06345 "but please note the following errors:\n" + accumulatedErrors);
06346 }
06347
06348
06349
06350
06351 void ConfigurationGUISupervisor::testXDAQContext()
06352 {
06353
06354 try
06355 {
06356 __SUP_COUT__ << "Attempting test activation of the context group." << std::endl;
06357 ConfigurationManager cfgMgr;
06358 }
06359 catch(...)
06360 {
06361 __SUP_COUT_WARN__ << "The test activation of the context group failed. Ignoring." << std::endl;
06362 }
06363 return;
06364
06366
06367
06368
06369
06370
06371
06372
06373
06376
06377
06378
06379
06380
06381
06382
06383
06384
06385
06386
06387
06388
06389
06390
06391
06392
06393
06394
06395
06396
06397
06398
06399
06400
06401
06402
06403
06404
06405
06406
06407
06410
06411
06412 }
06413
06414
06415
06416
06417
06418