From efaafcd011db4feb4b94955b32bc594e70cb4e2f Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=A9dric=20Aguerre?= Date: Mon, 31 Aug 2015 14:21:51 +0200 Subject: [PATCH] fix updateAttributeGroup --- projects/GDE_API_CPP/api/src/AttributesService.cpp | 11 ++++++----- projects/GDE_API_CPP/api/src/AttributesService.hpp | 2 +- projects/GDE_API_CPP/api/src/GDESession.cpp | 4 ++-- projects/GDE_API_CPP/api/src/GDESession.hpp | 2 +- projects/GDE_API_CPP/api/tests/AttributesTest.cpp | 3 ++- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/projects/GDE_API_CPP/api/src/AttributesService.cpp b/projects/GDE_API_CPP/api/src/AttributesService.cpp index 882d2d8..924b682 100644 --- a/projects/GDE_API_CPP/api/src/AttributesService.cpp +++ b/projects/GDE_API_CPP/api/src/AttributesService.cpp @@ -89,15 +89,16 @@ gde::AttributesService::readAttribute(int attributeId) } std::string -_buildAttributesJsonString(int attributeGroupId, const std::vector& attributes) +_buildAttributesJsonString(const gde::AttributeGroup& attributeGroup) { // Solution here is not very smart. Have tried using Poco to stringify attributes, // but stringification is too recursive, for example it produces: // "attributeCollection":"[ { \"id\" : 0, \"name\" : \"myAttribute\",... // instead of: // "attributeCollection":[{"id":0,"name":"myAttribute",... + const std::vector& attributes = attributeGroup.getAttributes(); std::string data = "{"; - data += gde::JsonFormatter::format("\"id\":", attributeGroupId); + data += gde::JsonFormatter::format("\"id\":", attributeGroup.getId()); data += ", \"attributeCollection\":["; for (std::vector::const_iterator itr = attributes.begin(); itr != attributes.end(); ++itr) { if (itr != attributes.begin()) @@ -111,7 +112,7 @@ _buildAttributesJsonString(int attributeGroupId, const std::vector& attributes) +gde::AttributesService::updateAttributeGroup(const gde::AttributeGroup& attributeGroup) { - std::string data = _buildAttributesJsonString(attributeGroup.getId(), attributes); + std::string data = _buildAttributesJsonString(attributeGroup); CommandTO cto(UPDATE_ATTRIBUTE_GROUP, data); const Credentials& credentials = _session.getCredentials(); diff --git a/projects/GDE_API_CPP/api/src/AttributesService.hpp b/projects/GDE_API_CPP/api/src/AttributesService.hpp index 413142f..c75f2a7 100644 --- a/projects/GDE_API_CPP/api/src/AttributesService.hpp +++ b/projects/GDE_API_CPP/api/src/AttributesService.hpp @@ -20,7 +20,7 @@ namespace gde { const AttributeGroup createAttributeGroup(const AttributeGroup&); bool deleteAttributeGroup(const AttributeGroup&); - const AttributeGroup updateAttributeGroup(const AttributeGroup&, const std::vector&); + const AttributeGroup updateAttributeGroup(const AttributeGroup&); const AttributeGroup readAttributeGroup(int); private: diff --git a/projects/GDE_API_CPP/api/src/GDESession.cpp b/projects/GDE_API_CPP/api/src/GDESession.cpp index 6f6bf6a..0376c7b 100644 --- a/projects/GDE_API_CPP/api/src/GDESession.cpp +++ b/projects/GDE_API_CPP/api/src/GDESession.cpp @@ -127,9 +127,9 @@ gde::GDESession::deleteAttributeGroup(const gde::AttributeGroup& attributeGroup) } const gde::AttributeGroup -gde::GDESession::updateAttributeGroup(const gde::AttributeGroup& attributeGroup, const std::vector& attributes) +gde::GDESession::updateAttributeGroup(const gde::AttributeGroup& attributeGroup) { - return gde::AttributesService(*this).updateAttributeGroup(attributeGroup, attributes); + return gde::AttributesService(*this).updateAttributeGroup(attributeGroup); } const gde::AttributeGroup diff --git a/projects/GDE_API_CPP/api/src/GDESession.hpp b/projects/GDE_API_CPP/api/src/GDESession.hpp index ec4975b..9571ad0 100644 --- a/projects/GDE_API_CPP/api/src/GDESession.hpp +++ b/projects/GDE_API_CPP/api/src/GDESession.hpp @@ -62,7 +62,7 @@ namespace gde { const AttributeGroup createAttributeGroup(const AttributeGroup& attributeGroup=AttributeGroup()); bool deleteAttributeGroup(const AttributeGroup&); - const AttributeGroup updateAttributeGroup(const AttributeGroup&, const std::vector&); + const AttributeGroup updateAttributeGroup(const AttributeGroup&); const AttributeGroup readAttributeGroup(int); private: diff --git a/projects/GDE_API_CPP/api/tests/AttributesTest.cpp b/projects/GDE_API_CPP/api/tests/AttributesTest.cpp index 146530a..f2754f2 100644 --- a/projects/GDE_API_CPP/api/tests/AttributesTest.cpp +++ b/projects/GDE_API_CPP/api/tests/AttributesTest.cpp @@ -100,7 +100,8 @@ AttributesTest::testUpdateAttributeGroup() attributes.push_back(attribute2); { - const gde::AttributeGroup& attrGrp = session.updateAttributeGroup(myAttributeGroup, attributes); + myAttributeGroup.setAttributes(attributes); + const gde::AttributeGroup& attrGrp = session.updateAttributeGroup(myAttributeGroup); CPPUNIT_ASSERT(attrGrp.getId() == myAttributeGroup.getId()); const std::vector& attrs = attrGrp.getAttributes(); CPPUNIT_ASSERT(attrs.size() == 2); -- 2.39.2