datafieldmap.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2016 HPCC Systems.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #include "datafieldmap.hpp"
  14. static const char* const defaultLogSourcePath = "Source";
  15. void ensureInputString(const char* input, bool lowerCase, StringBuffer& outputStr, int code, const char* msg)
  16. {
  17. outputStr.set(input).trim();
  18. if (outputStr.isEmpty())
  19. throw MakeStringException(code, "%s", msg);
  20. if (lowerCase)
  21. outputStr.toLowerCase();
  22. }
  23. void readLogGroupCfg(IPropertyTree* cfg, StringAttr& defaultLogGroup, MapStringToMyClass<CLogGroup>& logGroups)
  24. {
  25. StringBuffer groupName;
  26. Owned<IPropertyTreeIterator> iter = cfg->getElements("LogGroup");
  27. ForEach(*iter)
  28. {
  29. ensureInputString(iter->query().queryProp("@name"), true, groupName, -1, "LogGroup @name required");
  30. Owned<CLogGroup> logGroup = new CLogGroup(groupName.str());
  31. logGroup->loadMappings(iter->query());
  32. logGroups.setValue(groupName.str(), logGroup);
  33. if (defaultLogGroup.isEmpty())
  34. defaultLogGroup.set(groupName.str());
  35. }
  36. }
  37. void readLogSourceCfg(IPropertyTree* cfg, unsigned& logSourceCount, StringAttr& logSourcePath, MapStringToMyClass<CLogSource>& logSources)
  38. {
  39. logSourceCount = 0;
  40. StringBuffer name, groupName, dbName;
  41. Owned<IPropertyTreeIterator> iter = cfg->getElements("LogSourceMap/LogSource");
  42. ForEach(*iter)
  43. {
  44. ensureInputString(iter->query().queryProp("@name"), false, name, -1, "LogSource @name required");
  45. ensureInputString(iter->query().queryProp("@maptologgroup"), true, groupName, -1, "LogSource @maptologgroup required");
  46. ensureInputString(iter->query().queryProp("@maptodb"), true, dbName, -1, "LogSource @maptodb required");
  47. Owned<CLogSource> logSource = new CLogSource(name.str(), groupName.str(), dbName.str());
  48. logSources.setValue(name.str(), logSource);
  49. logSourceCount++;
  50. }
  51. //xpath to read log source from log request
  52. logSourcePath.set(cfg->hasProp("LogSourcePath") ? cfg->queryProp("LogSourcePath") : defaultLogSourcePath);
  53. }
  54. void CLogTable::loadMappings(IPropertyTree& fieldList)
  55. {
  56. StringBuffer name, mapTo, fieldType, defaultValue;
  57. Owned<IPropertyTreeIterator> itr = fieldList.getElements("Field");
  58. ForEach(*itr)
  59. {
  60. IPropertyTree &map = itr->query();
  61. ensureInputString(map.queryProp("@name"), false, name, -1, "Field @name required");
  62. ensureInputString(map.queryProp("@mapto"), true, mapTo, -1, "Field @mapto required");
  63. ensureInputString(map.queryProp("@type"), true, fieldType, -1, "Field @type required");
  64. defaultValue = map.queryProp("@default");
  65. defaultValue.trim();
  66. Owned<CLogField> field = new CLogField(name.str(), mapTo.str(), fieldType.str());
  67. if (!defaultValue.isEmpty())
  68. field->setDefault(defaultValue.str());
  69. logFields.append(*field.getClear());
  70. }
  71. }
  72. void CLogGroup::loadMappings(IPropertyTree& fieldList)
  73. {
  74. StringBuffer tableName;
  75. Owned<IPropertyTreeIterator> itr = fieldList.getElements("Fieldmap");
  76. ForEach(*itr)
  77. {
  78. ensureInputString(itr->query().queryProp("@table"), true, tableName, -1, "Fieldmap @table required");
  79. Owned<CLogTable> table = new CLogTable(tableName.str());
  80. table->loadMappings(itr->query());
  81. CIArrayOf<CLogField>& logFields = table->getLogFields();
  82. if (logFields.length() < 1)
  83. throw MakeStringException(-1,"No Fieldmap for %s", tableName.str());
  84. logTables.append(*table.getClear());
  85. }
  86. }