QueryOTAJobResult.cc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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/iot/model/QueryOTAJobResult.h>
  17. #include <json/json.h>
  18. using namespace AlibabaCloud::Iot;
  19. using namespace AlibabaCloud::Iot::Model;
  20. QueryOTAJobResult::QueryOTAJobResult() :
  21. ServiceResult()
  22. {}
  23. QueryOTAJobResult::QueryOTAJobResult(const std::string &payload) :
  24. ServiceResult()
  25. {
  26. parse(payload);
  27. }
  28. QueryOTAJobResult::~QueryOTAJobResult()
  29. {}
  30. void QueryOTAJobResult::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 dataNode = value["Data"];
  37. if(!dataNode["JobId"].isNull())
  38. data_.jobId = dataNode["JobId"].asString();
  39. if(!dataNode["UtcCreate"].isNull())
  40. data_.utcCreate = dataNode["UtcCreate"].asString();
  41. if(!dataNode["UtcModified"].isNull())
  42. data_.utcModified = dataNode["UtcModified"].asString();
  43. if(!dataNode["ProductKey"].isNull())
  44. data_.productKey = dataNode["ProductKey"].asString();
  45. if(!dataNode["FirmwareId"].isNull())
  46. data_.firmwareId = dataNode["FirmwareId"].asString();
  47. if(!dataNode["UtcStartTime"].isNull())
  48. data_.utcStartTime = dataNode["UtcStartTime"].asString();
  49. if(!dataNode["UtcEndTime"].isNull())
  50. data_.utcEndTime = dataNode["UtcEndTime"].asString();
  51. if(!dataNode["JobStatus"].isNull())
  52. data_.jobStatus = dataNode["JobStatus"].asString();
  53. if(!dataNode["JobType"].isNull())
  54. data_.jobType = dataNode["JobType"].asString();
  55. if(!dataNode["JobDesc"].isNull())
  56. data_.jobDesc = dataNode["JobDesc"].asString();
  57. if(!dataNode["Name"].isNull())
  58. data_.name = dataNode["Name"].asString();
  59. if(!dataNode["UtcScheduleTime"].isNull())
  60. data_.utcScheduleTime = dataNode["UtcScheduleTime"].asString();
  61. if(!dataNode["RetryInterval"].isNull())
  62. data_.retryInterval = std::stoi(dataNode["RetryInterval"].asString());
  63. if(!dataNode["RetryCount"].isNull())
  64. data_.retryCount = std::stoi(dataNode["RetryCount"].asString());
  65. if(!dataNode["TimeoutInMinutes"].isNull())
  66. data_.timeoutInMinutes = std::stoi(dataNode["TimeoutInMinutes"].asString());
  67. if(!dataNode["TargetSelection"].isNull())
  68. data_.targetSelection = dataNode["TargetSelection"].asString();
  69. if(!dataNode["SelectionType"].isNull())
  70. data_.selectionType = dataNode["SelectionType"].asString();
  71. if(!dataNode["GrayPercent"].isNull())
  72. data_.grayPercent = dataNode["GrayPercent"].asString();
  73. if(!dataNode["MaximumPerMinute"].isNull())
  74. data_.maximumPerMinute = std::stoi(dataNode["MaximumPerMinute"].asString());
  75. if(!dataNode["DestVersion"].isNull())
  76. data_.destVersion = dataNode["DestVersion"].asString();
  77. if(!dataNode["UtcScheduleFinishTime"].isNull())
  78. data_.utcScheduleFinishTime = dataNode["UtcScheduleFinishTime"].asString();
  79. if(!dataNode["OverwriteMode"].isNull())
  80. data_.overwriteMode = std::stoi(dataNode["OverwriteMode"].asString());
  81. if(!dataNode["DynamicMode"].isNull())
  82. data_.dynamicMode = std::stoi(dataNode["DynamicMode"].asString());
  83. if(!dataNode["NeedPush"].isNull())
  84. data_.needPush = dataNode["NeedPush"].asString() == "true";
  85. if(!dataNode["NeedConfirm"].isNull())
  86. data_.needConfirm = dataNode["NeedConfirm"].asString() == "true";
  87. if(!dataNode["GroupId"].isNull())
  88. data_.groupId = dataNode["GroupId"].asString();
  89. if(!dataNode["GroupName"].isNull())
  90. data_.groupName = dataNode["GroupName"].asString();
  91. if(!dataNode["DownloadProtocol"].isNull())
  92. data_.downloadProtocol = dataNode["DownloadProtocol"].asString();
  93. auto allTagsNode = dataNode["Tags"]["OtaTagDTO"];
  94. for (auto dataNodeTagsOtaTagDTO : allTagsNode)
  95. {
  96. Data::OtaTagDTO otaTagDTOObject;
  97. if(!dataNodeTagsOtaTagDTO["Key"].isNull())
  98. otaTagDTOObject.key = dataNodeTagsOtaTagDTO["Key"].asString();
  99. if(!dataNodeTagsOtaTagDTO["Value"].isNull())
  100. otaTagDTOObject.value = dataNodeTagsOtaTagDTO["Value"].asString();
  101. data_.tags.push_back(otaTagDTOObject);
  102. }
  103. auto allSrcVersions = dataNode["SrcVersions"]["SrcVersion"];
  104. for (auto value : allSrcVersions)
  105. data_.srcVersions.push_back(value.asString());
  106. if(!value["Success"].isNull())
  107. success_ = value["Success"].asString() == "true";
  108. if(!value["Code"].isNull())
  109. code_ = value["Code"].asString();
  110. if(!value["ErrorMessage"].isNull())
  111. errorMessage_ = value["ErrorMessage"].asString();
  112. }
  113. QueryOTAJobResult::Data QueryOTAJobResult::getData()const
  114. {
  115. return data_;
  116. }
  117. std::string QueryOTAJobResult::getErrorMessage()const
  118. {
  119. return errorMessage_;
  120. }
  121. std::string QueryOTAJobResult::getCode()const
  122. {
  123. return code_;
  124. }
  125. bool QueryOTAJobResult::getSuccess()const
  126. {
  127. return success_;
  128. }