test.cpp 9.0 KB

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