test.cpp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <memory.h>
  4. #include <string>
  5. #include <exception>
  6. #include <iostream>
  7. #include "Exceptions.hpp"
  8. //#include "libxml/parser.h"
  9. //#include "libxml/tree.h"
  10. // namespace pt = boost::property_tree;
  11. const std::string c_path = "configfiles/"; ///opt/HPCCSystems/componentfiles/config2xml/";
  12. // void parseComponentXSD(pt::ptree &xsdTree);
  13. // void parseIncludes(pt::ptree &xsdTree);
  14. #include "SchemaItem.hpp"
  15. #include "XSDSchemaParser.hpp"
  16. #include "XMLEnvironmentMgr.hpp"
  17. int main()
  18. {
  19. try
  20. {
  21. //std::shared_ptr<ConfigItem> pConfig = std::make_shared<ConfigItem>("root");
  22. //ConfigParser *pCfgParser = new XSDConfigParser("", pConfig);
  23. //std::string fpath = c_path + "types.xsd"; //dafilesrv.xsd";
  24. // std::shared_ptr<ConfigParser> pCfgParser = std::make_shared<XSDConfigParser>("");
  25. // std::shared_ptr<ConfigItem> pNull;
  26. // std::shared_ptr<ConfigItem> pConfig = std::make_shared<ConfigItem>("myconfig", pNull);
  27. //pCfgParser->parseEnvironmentConfig("newenv.xsd", "");
  28. EnvironmentMgr *pEnvMgr = getEnvironmentMgrInstance("XML");
  29. std::vector<std::string> cfgParms;
  30. cfgParms.push_back("buildset.xml"); // not used right now
  31. pEnvMgr->loadSchema(c_path, "newenv.xsd", cfgParms);
  32. pEnvMgr->loadEnvironment(c_path + "/environment.xml");
  33. // 158
  34. //auto pNode = envMgr.getNodeFromPath("158");
  35. // auto pNode = pEnvMgr->getEnvironmentNode("74"); // 29 is Hardware/Computer
  36. auto pNode = pEnvMgr->getEnvironmentNode("35");
  37. //auto x = pNode->getAllFieldValues("name");
  38. auto list = pNode->getInsertableItems();
  39. Status status;
  40. auto pNewNode = pEnvMgr->addNewEnvironmentNode("35", "ws_ecl", status);
  41. auto newList = pNewNode->getInsertableItems();
  42. pEnvMgr->addNewEnvironmentNode("35", "ws_ecl", status);
  43. pEnvMgr->addNewEnvironmentNode("35", "ws_ecl", status);
  44. /*auto attributes = pNode->getAttributes();
  45. for (auto it = attributes.begin(); it != attributes.end(); ++it)
  46. {
  47. if ((*it)->getName() == "service")
  48. {
  49. std::shared_ptr<EnvironmentValue> pEnvValue = *it;
  50. const std::shared_ptr<ConfigValue> &pCfgValue = pEnvValue->getCfgValue();
  51. auto values = pCfgValue->getAllowedValues(pEnvValue.get());
  52. int i = 3;
  53. }
  54. }*/
  55. // keyref needs to look local first, then search the config tree, but field is ALWAYS local
  56. // Used during validation.
  57. //
  58. // Validate the environment
  59. //
  60. // Value set test
  61. //std::vector<EnvironmentMgr::NameValue> newValues;
  62. //newValues.push_back({ "name", "namehasbeenchanged" });
  63. //pEnvMgr->setAttributeValues("158", newValues, "", false);
  64. //pEnvMgr->saveEnvironment("testout.xml", status);
  65. auto results = pEnvMgr->getEnvironmentNode(".");
  66. }
  67. catch (ParseException &e)
  68. {
  69. std::cout << "Error: " << e.what() << "\n";
  70. }
  71. //pt::ptree xsdTree;
  72. // try
  73. // {
  74. // std::string fpath = c_path + "types.xsd"; //dafilesrv.xsd";
  75. // pt::read_xml(fpath, xsdTree);
  76. // // throw(ParseException("exception throw test"));
  77. // parseComponentXSD(xsdTree);
  78. //
  79. // Let's try iterating
  80. // for (pt::ptree::const_iterator it=xsdTree.begin(); it!=xsdTree.end(); ++it)
  81. // {
  82. // std::cout << "here: " << it->first << std::endl;
  83. // }
  84. // auto it = xsdTree.find("xs:schema");
  85. // bool isEnd = (it == xsdTree.not_found());
  86. // std::cout << "here " << it->first << " " << it->second.get_value<std::string>() << std::endl;
  87. // parseIncludes(it->second);
  88. // const pt::ptree &attributes = it->second.get_child("<xmlattr>", pt::ptree());
  89. // for (auto attrIt=attributes.begin(); attrIt!=attributes.end(); ++attrIt)
  90. // {
  91. // std::cout << "attr = " << attrIt->first.data() << " second = " << attrIt->second.get_value<std::string>() << std::endl;
  92. // }
  93. // std::cout << "First level keys: " << std::endl;
  94. // const pt::ptree &keys = it->second.get_child("", pt::ptree());
  95. // std::string val = it->second.get_value<std::string>("xs:include.<xmlattr>.schemaLocation");
  96. // std::cout << "value: " << val << std::endl;
  97. // for (auto keyIt=keys.begin(); keyIt!=keys.end(); ++keyIt)
  98. // {
  99. // std::cout << "key = >>" << keyIt->first << "<< " << std::endl;
  100. // if (keyIt->first == "xs:include")
  101. // {
  102. // int i = 5;
  103. // std::string val = keyIt->second.get("<xmlattr>.schemaLocation", "not found");
  104. // std::cout << " schema Location = " << val << std::endl;
  105. // }
  106. // //if (keyIt->first.get_value())
  107. // }
  108. std::cout << "Success\n";
  109. // std::cout << std::endl << "Using Boost "
  110. // << BOOST_VERSION / 100000 << "." // major version
  111. // << BOOST_VERSION / 100 % 1000 << "." // minor version
  112. // << BOOST_VERSION % 100 // patch level
  113. // << std::endl;
  114. // }
  115. // catch (const ParseException &e)
  116. // {
  117. // std::cout << "Error: " << e.what() << "\n";
  118. // }
  119. // catch (std::exception &e)
  120. // {
  121. // std::cout << "Error: " << e.what() << "\n";
  122. // }
  123. // return 0;
  124. }
  125. // void parseComponentXSD(pt::ptree &xsdTree)
  126. // {
  127. // //
  128. // // Get to the schema
  129. // auto schemaIt = xsdTree.find("xs:schema");
  130. // //
  131. // // Since we only support includes for a component schema at the top level, look for includes first and process them.
  132. // // Note that these includes may NOT define elements or anything like that. Only types, attribute groups, keyrefs
  133. // const pt::ptree &keys = schemaIt->second.get_child("", pt::ptree());
  134. // for (auto it=keys.begin(); it!=keys.end(); ++it)
  135. // {
  136. // if (it->first == "xs:include")
  137. // {
  138. // std::string schema = it->second.get("<xmlattr>.schemaLocation", "not found");
  139. // std::cout << "Parsing found include: " << schema << std::endl;
  140. // }
  141. // }
  142. // std::vector<std::string> vec;
  143. // vec.push_back("Hello");
  144. // vec.push_back("There");
  145. //
  146. // Now look for any special sections we support
  147. // for (auto it=keys.begin(); it!=keys.end(); ++it)
  148. // {
  149. // if (it->first == "xs:attributeGroup")
  150. // {
  151. // std::string groupName = it->second.get("<xmlattr>.name", "not found");
  152. // std::cout << "Attribute group name: " << groupName << std::endl;
  153. // //
  154. // // Lets parse the attributes now
  155. // const pt::ptree &attrs = it->second.get_child("", pt::ptree());
  156. // for (auto attributeIt = attrs.begin(); attributeIt != attrs.end(); ++attributeIt)
  157. // {
  158. // auto ss = attributeIt->first;
  159. // if (attributeIt->first == "xs:attribute")
  160. // {
  161. // std::cout << "found attribute" << groupName << std::endl;
  162. // XSDAttribute attr;
  163. // attr.parse(attributeIt->second);
  164. // }
  165. // }
  166. // // }
  167. // if (it->first == "xs:simpleType")
  168. // {
  169. // //std::string typeName = it->second.get("<xmlattr>.name", "not found");
  170. // //int i = 4;
  171. // std::shared_ptr<CfgType> pType = XSDTypeParser::parseSimpleType(it->second);
  172. // }
  173. // }
  174. // }
  175. // void parseIncludes(pt::ptree &xsdTree)
  176. // {
  177. // const pt::ptree &keys = xsdTree.get_child("", pt::ptree());
  178. // for (auto it=keys.begin(); it!=keys.end(); ++it)
  179. // {
  180. // if (it->first == "xs:include")
  181. // {
  182. // std::string schema = it->second.get("<xmlattr>.schemaLocation", "not found");
  183. // std::cout << "Parsing found include: " << schema << std::endl;
  184. // }
  185. // }
  186. // }