DescribeCommandsResult.cc 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright 2009-2017 Alibaba Cloud All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <alibabacloud/swas-open/model/DescribeCommandsResult.h>
  17. #include <json/json.h>
  18. using namespace AlibabaCloud::SWAS_OPEN;
  19. using namespace AlibabaCloud::SWAS_OPEN::Model;
  20. DescribeCommandsResult::DescribeCommandsResult() :
  21. ServiceResult()
  22. {}
  23. DescribeCommandsResult::DescribeCommandsResult(const std::string &payload) :
  24. ServiceResult()
  25. {
  26. parse(payload);
  27. }
  28. DescribeCommandsResult::~DescribeCommandsResult()
  29. {}
  30. void DescribeCommandsResult::parse(const std::string &payload)
  31. {
  32. Json::Reader reader;
  33. Json::Value value;
  34. reader.parse(payload, value);
  35. setRequestId(value["RequestId"].asString());
  36. auto allCommandsNode = value["Commands"]["command"];
  37. for (auto valueCommandscommand : allCommandsNode)
  38. {
  39. Command commandsObject;
  40. if(!valueCommandscommand["CommandId"].isNull())
  41. commandsObject.commandId = valueCommandscommand["CommandId"].asString();
  42. if(!valueCommandscommand["CreationTime"].isNull())
  43. commandsObject.creationTime = valueCommandscommand["CreationTime"].asString();
  44. if(!valueCommandscommand["Name"].isNull())
  45. commandsObject.name = valueCommandscommand["Name"].asString();
  46. if(!valueCommandscommand["Provider"].isNull())
  47. commandsObject.provider = valueCommandscommand["Provider"].asString();
  48. if(!valueCommandscommand["Type"].isNull())
  49. commandsObject.type = valueCommandscommand["Type"].asString();
  50. if(!valueCommandscommand["Timeout"].isNull())
  51. commandsObject.timeout = std::stol(valueCommandscommand["Timeout"].asString());
  52. if(!valueCommandscommand["Description"].isNull())
  53. commandsObject.description = valueCommandscommand["Description"].asString();
  54. if(!valueCommandscommand["WorkingDir"].isNull())
  55. commandsObject.workingDir = valueCommandscommand["WorkingDir"].asString();
  56. if(!valueCommandscommand["CommandContent"].isNull())
  57. commandsObject.commandContent = valueCommandscommand["CommandContent"].asString();
  58. if(!valueCommandscommand["EnableParameter"].isNull())
  59. commandsObject.enableParameter = valueCommandscommand["EnableParameter"].asString() == "true";
  60. auto allTagsNode = valueCommandscommand["Tags"]["tag"];
  61. for (auto valueCommandscommandTagstag : allTagsNode)
  62. {
  63. Command::Tag tagsObject;
  64. if(!valueCommandscommandTagstag["Key"].isNull())
  65. tagsObject.key = valueCommandscommandTagstag["Key"].asString();
  66. if(!valueCommandscommandTagstag["Value"].isNull())
  67. tagsObject.value = valueCommandscommandTagstag["Value"].asString();
  68. commandsObject.tags.push_back(tagsObject);
  69. }
  70. auto allParameterDefinitionsNode = valueCommandscommand["ParameterDefinitions"]["parameterDefinition"];
  71. for (auto valueCommandscommandParameterDefinitionsparameterDefinition : allParameterDefinitionsNode)
  72. {
  73. Command::ParameterDefinition parameterDefinitionsObject;
  74. if(!valueCommandscommandParameterDefinitionsparameterDefinition["Required"].isNull())
  75. parameterDefinitionsObject.required = valueCommandscommandParameterDefinitionsparameterDefinition["Required"].asString() == "true";
  76. if(!valueCommandscommandParameterDefinitionsparameterDefinition["Description"].isNull())
  77. parameterDefinitionsObject.description = valueCommandscommandParameterDefinitionsparameterDefinition["Description"].asString();
  78. if(!valueCommandscommandParameterDefinitionsparameterDefinition["DefaultValue"].isNull())
  79. parameterDefinitionsObject.defaultValue = valueCommandscommandParameterDefinitionsparameterDefinition["DefaultValue"].asString();
  80. if(!valueCommandscommandParameterDefinitionsparameterDefinition["ParameterName"].isNull())
  81. parameterDefinitionsObject.parameterName = valueCommandscommandParameterDefinitionsparameterDefinition["ParameterName"].asString();
  82. auto allPossibleValues = value["PossibleValues"]["possibleValue"];
  83. for (auto value : allPossibleValues)
  84. parameterDefinitionsObject.possibleValues.push_back(value.asString());
  85. commandsObject.parameterDefinitions.push_back(parameterDefinitionsObject);
  86. }
  87. auto allParameterNames = value["ParameterNames"]["parameterName"];
  88. for (auto value : allParameterNames)
  89. commandsObject.parameterNames.push_back(value.asString());
  90. commands_.push_back(commandsObject);
  91. }
  92. if(!value["TotalCount"].isNull())
  93. totalCount_ = std::stoi(value["TotalCount"].asString());
  94. if(!value["PageNumber"].isNull())
  95. pageNumber_ = std::stoi(value["PageNumber"].asString());
  96. if(!value["PageSize"].isNull())
  97. pageSize_ = std::stoi(value["PageSize"].asString());
  98. }
  99. int DescribeCommandsResult::getTotalCount()const
  100. {
  101. return totalCount_;
  102. }
  103. int DescribeCommandsResult::getPageSize()const
  104. {
  105. return pageSize_;
  106. }
  107. int DescribeCommandsResult::getPageNumber()const
  108. {
  109. return pageNumber_;
  110. }
  111. std::vector<DescribeCommandsResult::Command> DescribeCommandsResult::getCommands()const
  112. {
  113. return commands_;
  114. }