Remove code duplication in easy-setup service. 90/218790/1
authorSenthil Kumar G S <senthil.gs@samsung.com>
Tue, 19 Nov 2019 06:05:11 +0000 (11:35 +0530)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Thu, 28 Nov 2019 07:21:33 +0000 (16:21 +0900)
Code duplications in easy-setup service reported by Sonarqube
has been addressed in this patch.

https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/commit/ecf2f9ec396bddceaa59aa4daa84506d6ea32e92
(cherry-picked from ecf2f9ec396bddceaa59aa4daa84506d6ea32e92)

Change-Id: Id89ba0f0ea8a712dad2c60873f4c6896491a7cb9
Signed-off-by: Senthil Kumar G S <senthil.gs@samsung.com>
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
service/easy-setup/enrollee/src/resourcehandler.c
service/easy-setup/mediator/richsdk/inc/ESSCCommon.h

index 779354e5ce1c3bff6da45c50074f0b58b76dba2c..f33187d788d0c5245653f1bce1ead167f5a1a53f 100755 (executable)
@@ -559,6 +559,29 @@ void updateDevConfResource(OCRepPayload* input)
     OICFree(devConfData);
 }
 
+static OCRepPayload *constructPolicy(OCEntityHandlerRequest *ehRequest, OCResourceHandle handle)
+{
+    OCResourceProperty p = OCGetResourceProperties(handle);
+    OCRepPayload *policy = OCRepPayloadCreate();
+    if (!policy)
+    {
+        OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
+        return NULL;
+    }
+
+    OCRepPayloadSetPropInt(policy, OC_RSRVD_BITMAP,
+                            ((p & OC_DISCOVERABLE) | (p & OC_OBSERVABLE)));
+    if (p & OC_SECURE)
+    {
+        OCRepPayloadSetPropBool(policy, OC_RSRVD_SECURE, p & OC_SECURE);
+        uint16_t securePort = CAGetAssignedPortNumber(ehRequest->devAddr.adapter,
+                                                            ehRequest->devAddr.flags);
+        OCRepPayloadSetPropInt(policy, OC_RSRVD_HOSTING_PORT, securePort);
+    }
+
+    return policy;
+}
+
 OCRepPayload* constructResponseOfWiFiConf(char *interface)
 {
     OCRepPayload* payload = OCRepPayloadCreate();
@@ -865,24 +888,8 @@ OCRepPayload* constructResponseOfEasySetup(OCEntityHandlerRequest *ehRequest)
             OCRepPayloadSetStringArray(add, OC_RSRVD_INTERFACE,
                                             (const char **)resourceInterface, dimensions);
 
-            OCResourceProperty p = OCGetResourceProperties((OCResourceHandle *)g_ESWiFiConfResource.handle);
-            OCRepPayload *policy = OCRepPayloadCreate();
-            if (!policy)
-            {
-                OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
-                return NULL;
-            }
-
-            OCRepPayloadSetPropInt(policy, OC_RSRVD_BITMAP,
-                                    ((p & OC_DISCOVERABLE) | (p & OC_OBSERVABLE)));
-            if (p & OC_SECURE)
-            {
-                OCRepPayloadSetPropBool(policy, OC_RSRVD_SECURE, p & OC_SECURE);
-                uint16_t securePort = CAGetAssignedPortNumber(ehRequest->devAddr.adapter,
-                                                                    ehRequest->devAddr.flags);
-                OCRepPayloadSetPropInt(policy, OC_RSRVD_HOSTING_PORT, securePort);
-            }
-
+            OCRepPayload *policy = constructPolicy(ehRequest,
+                                            (OCResourceHandle *)g_ESWiFiConfResource.handle);
             OCRepPayloadSetPropObject(add, OC_RSRVD_POLICY, policy);
 
             arrayPayload[childResCnt++] = add;
@@ -919,24 +926,8 @@ OCRepPayload* constructResponseOfEasySetup(OCEntityHandlerRequest *ehRequest)
             OCRepPayloadSetStringArray(add, OC_RSRVD_INTERFACE,
                                             (const char **)resourceInterface, dimensions);
 
-            OCResourceProperty p = OCGetResourceProperties((OCResourceHandle *)g_ESDevConfResource.handle);
-            OCRepPayload *policy = OCRepPayloadCreate();
-            if (!policy)
-            {
-                OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
-                return NULL;
-            }
-
-            OCRepPayloadSetPropInt(policy, OC_RSRVD_BITMAP,
-                                    ((p & OC_DISCOVERABLE) | (p & OC_OBSERVABLE)));
-            if (p & OC_SECURE)
-            {
-                OCRepPayloadSetPropBool(policy, OC_RSRVD_SECURE, p & OC_SECURE);
-                uint16_t securePort = CAGetAssignedPortNumber(ehRequest->devAddr.adapter,
-                                                                    ehRequest->devAddr.flags);
-                OCRepPayloadSetPropInt(policy, OC_RSRVD_HOSTING_PORT, securePort);
-            }
-
+            OCRepPayload *policy = constructPolicy(ehRequest,
+                                            (OCResourceHandle *)g_ESDevConfResource.handle);
             OCRepPayloadSetPropObject(add, OC_RSRVD_POLICY, policy);
 
             arrayPayload[childResCnt++] = add;
index d52cd26797f6b9e4d26cdde553f620e143413f9c..65c6d4729053d735c8659e06b0ef08918c8671ca 100644 (file)
@@ -109,6 +109,68 @@ namespace OIC
             std::string bssid;
         } SCCandidateAPInfo;
 
+        static std::vector<SCCandidateAPInfo> getCandidateAPListHelper(OCRepresentation rep)
+        {
+            if (rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATEAPS))
+            {
+                std::vector<OC::OCRepresentation> candidateInfo =
+                                rep.getValue<std::vector<OC::OCRepresentation>>(SC_RSRVD_ES_VENDOR_CANDIDATEAPS);
+                std::vector<SCCandidateAPInfo> postcandidateInfo;
+                for(std::vector<OC::OCRepresentation>::iterator it = candidateInfo.begin();
+                          it != candidateInfo.end(); ++it)
+                {
+                    OC::OCRepresentation rep = *it;
+                    SCCandidateAPInfo candidateInfotemp;
+                    if (rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATE_SSID))
+                    {
+                        candidateInfotemp.ssid=rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_CANDIDATE_SSID);
+                    }
+                    if (rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATE_PASSPHRASE))
+                    {
+                        candidateInfotemp.passphrase=rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_CANDIDATE_PASSPHRASE);
+                    }
+                    if (rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATE_CHANNEL))
+                    {
+                        candidateInfotemp.channel=rep.getValue<int>(SC_RSRVD_ES_VENDOR_CANDIDATE_CHANNEL);
+                    }
+                    if (rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATE_BSSID))
+                    {
+                        candidateInfotemp.bssid=rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_CANDIDATE_BSSID);
+                    }
+                    postcandidateInfo.push_back(candidateInfotemp);
+                }
+                return postcandidateInfo;
+            }
+            return {};
+        }
+
+        static std::string getEasySetupPropHelper(OCRepresentation easySetupRep, std::string propName)
+        {
+            std::vector<OCRepresentation> children = easySetupRep.getChildren();
+            for(auto child = children.begin(); child != children.end(); ++child)
+            {
+                if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
+                {
+                    OCRepresentation rep;
+                    if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
+                    {
+                        rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
+                    }
+                    else
+                    {
+                        return std::string("");
+                    }
+
+                    if(rep.hasAttribute(propName))
+                    {
+                        return rep.getValue<std::string>(propName);
+                    }
+                }
+            }
+            return std::string("");
+        }
+
+
         /**
          * @brief Properties of provisioning resource. It includes a provisioning status and last
          *        error code.
@@ -433,38 +495,7 @@ namespace OIC
              */
             std::vector<SCCandidateAPInfo> getCandidateAPList()
             {
-                if (m_rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATEAPS))
-                {
-                    std::vector<OC::OCRepresentation> candidateInfo=
-                                m_rep.getValue<std::vector<OC::OCRepresentation>>(SC_RSRVD_ES_VENDOR_CANDIDATEAPS);
-                    std::vector<SCCandidateAPInfo> postcandidateInfo;
-                    for(std::vector<OC::OCRepresentation>::iterator it = candidateInfo.begin();
-                              it != candidateInfo.end(); ++it)
-                    {
-                        OC::OCRepresentation rep = *it;
-                        SCCandidateAPInfo candidateInfotemp;
-                        if (rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATE_SSID))
-                        {
-                            candidateInfotemp.ssid=rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_CANDIDATE_SSID);
-                        }
-                        if (rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATE_PASSPHRASE))
-                        {
-                            candidateInfotemp.passphrase=rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_CANDIDATE_PASSPHRASE);
-                        }
-                        if (rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATE_CHANNEL))
-                        {
-                            candidateInfotemp.channel=rep.getValue<int>(SC_RSRVD_ES_VENDOR_CANDIDATE_CHANNEL);
-
-                        }
-                        if (rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATE_BSSID))
-                        {
-                            candidateInfotemp.bssid=rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_CANDIDATE_BSSID);
-                        }
-                        postcandidateInfo.push_back(candidateInfotemp);
-                    }
-                    return postcandidateInfo;
-                }
-                return {};
+                return getCandidateAPListHelper(m_rep);
             }
 
             /**
@@ -828,28 +859,7 @@ namespace OIC
              */
             std::string getDeviceType() const
             {
-                std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
-                for(auto child = children.begin(); child != children.end(); ++child)
-                {
-                    if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
-                    {
-                        OCRepresentation rep;
-                        if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
-                        {
-                            rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
-                        }
-                        else
-                        {
-                            return std::string("");
-                        }
-
-                        if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_DEVICE_TYPE))
-                        {
-                            return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_DEVICE_TYPE);
-                        }
-                    }
-                }
-                return std::string("");
+                return getEasySetupPropHelper(m_EasySetupRep, SC_RSRVD_ES_VENDOR_DEVICE_TYPE);
             }
 
             /**
@@ -860,28 +870,7 @@ namespace OIC
              */
             std::string getDeviceSubType() const
             {
-                std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
-                for(auto child = children.begin(); child != children.end(); ++child)
-                {
-                    if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
-                    {
-                        OCRepresentation rep;
-                        if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
-                        {
-                            rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
-                        }
-                        else
-                        {
-                            return std::string("");
-                        }
-
-                        if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_DEVICE_SUBTYPE))
-                        {
-                            return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_DEVICE_SUBTYPE);
-                        }
-                    }
-                }
-                return std::string("");
+                return getEasySetupPropHelper(m_EasySetupRep, SC_RSRVD_ES_VENDOR_DEVICE_SUBTYPE);
             }
 
             /**
@@ -894,28 +883,7 @@ namespace OIC
              */
             std::string getRegisterSetDevice() const
             {
-                std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
-                for(auto child = children.begin(); child != children.end(); ++child)
-                {
-                    if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
-                    {
-                        OCRepresentation rep;
-                        if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
-                        {
-                            rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
-                        }
-                        else
-                        {
-                            return std::string("");
-                        }
-
-                        if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_REGISTER_SET_DEV))
-                        {
-                            return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_REGISTER_SET_DEV);
-                        }
-                    }
-                }
-                return std::string("");
+                return getEasySetupPropHelper(m_EasySetupRep, SC_RSRVD_ES_VENDOR_REGISTER_SET_DEV);
             }
 
             /**
@@ -926,45 +894,19 @@ namespace OIC
             std::vector<SCCandidateAPInfo> getCandidateAPList() const
             {
                 std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
-                for(auto child = children.begin(); child != children.end(); ++child)
+                for (auto child = children.begin(); child != children.end(); ++child)
                 {
-                    if(child->getUri().find(OC_RSRVD_ES_URI_WIFICONF) != std::string::npos)
+                    if (child->getUri().find(OC_RSRVD_ES_URI_WIFICONF) != std::string::npos)
                     {
                         OCRepresentation rep;
-                        if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
+                        if (child->hasAttribute(OC_RSRVD_REPRESENTATION))
                         {
                             rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
                         }
 
-                        if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATEAPS))
+                        if (rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATEAPS))
                         {
-                            std::vector<OC::OCRepresentation> candidateInfo=rep.getValue<std::vector<OC::OCRepresentation>>(SC_RSRVD_ES_VENDOR_CANDIDATEAPS);
-                            std::vector<SCCandidateAPInfo> postcandidateInfo;
-                            for(std::vector<OC::OCRepresentation>::iterator it = candidateInfo.begin();
-                                      it != candidateInfo.end(); ++it)
-                            {
-                                OC::OCRepresentation rep = *it;
-                                SCCandidateAPInfo candidateInfotemp;
-                                if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATE_SSID))
-                                {
-                                    candidateInfotemp.ssid=rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_CANDIDATE_SSID);
-                                }
-                                if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATE_PASSPHRASE))
-                                {
-                                    candidateInfotemp.passphrase=rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_CANDIDATE_PASSPHRASE);
-                                }
-                                if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATE_CHANNEL))
-                                {
-                                    candidateInfotemp.channel=rep.getValue<int>(SC_RSRVD_ES_VENDOR_CANDIDATE_CHANNEL);
-
-                                }
-                                if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATE_BSSID))
-                                {
-                                    candidateInfotemp.bssid=rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_CANDIDATE_BSSID);
-                                }
-                                postcandidateInfo.push_back(candidateInfotemp);
-                            }
-                            return postcandidateInfo;
+                            return getCandidateAPListHelper(rep);
                         }
                     }
                 }
@@ -982,28 +924,7 @@ namespace OIC
              */
             std::string getNetworkProvisioningInfo() const
             {
-                std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
-                for(auto child = children.begin(); child != children.end(); ++child)
-                {
-                    if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
-                    {
-                        OCRepresentation rep;
-                        if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
-                        {
-                            rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
-                        }
-                        else
-                        {
-                            return std::string("");
-                        }
-
-                        if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_NETWORK_PROV_INFO))
-                        {
-                            return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_NETWORK_PROV_INFO);
-                        }
-                    }
-                }
-                return std::string("");
+                return getEasySetupPropHelper(m_EasySetupRep, SC_RSRVD_ES_VENDOR_NETWORK_PROV_INFO);
             }
 
             /**
@@ -1016,28 +937,7 @@ namespace OIC
              */
             std::string getSSOList() const
             {
-                std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
-                for(auto child = children.begin(); child != children.end(); ++child)
-                {
-                    if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
-                    {
-                        OCRepresentation rep;
-                        if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
-                        {
-                            rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
-                        }
-                        else
-                        {
-                            return std::string("");
-                        }
-
-                        if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_SSO_LIST))
-                        {
-                            return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_SSO_LIST);
-                        }
-                    }
-                }
-                return std::string("");
+                return getEasySetupPropHelper(m_EasySetupRep, SC_RSRVD_ES_VENDOR_SSO_LIST);
             }
 
             /**
@@ -1077,28 +977,7 @@ namespace OIC
              */
             std::string getTCHeader()
             {
-                std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
-                for(auto child = children.begin(); child != children.end(); ++child)
-                {
-                    if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
-                    {
-                        OCRepresentation rep;
-                        if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
-                        {
-                            rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
-                        }
-                        else
-                        {
-                            return std::string("");
-                        }
-
-                        if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_TC_HEADER))
-                        {
-                            return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_TC_HEADER);
-                        }
-                    }
-                }
-                return std::string("");
+                return getEasySetupPropHelper(m_EasySetupRep, SC_RSRVD_ES_VENDOR_TC_HEADER);
             }
 
             /**
@@ -1108,28 +987,7 @@ namespace OIC
              */
             std::string getTCVersion()
             {
-                std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
-                for(auto child = children.begin(); child != children.end(); ++child)
-                {
-                    if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
-                    {
-                        OCRepresentation rep;
-                        if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
-                        {
-                            rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
-                        }
-                        else
-                        {
-                            return std::string("");
-                        }
-
-                        if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_TC_VERSION))
-                        {
-                            return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_TC_VERSION);
-                        }
-                    }
-                }
-                return std::string("");
+                return getEasySetupPropHelper(m_EasySetupRep, SC_RSRVD_ES_VENDOR_TC_VERSION);
             }
 
             /**
@@ -1139,28 +997,7 @@ namespace OIC
              */
             std::string getPnpPin() const
             {
-                std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
-                for(auto child = children.begin(); child != children.end(); ++child)
-                {
-                    if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
-                    {
-                        OCRepresentation rep;
-                        if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
-                        {
-                            rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
-                        }
-                        else
-                        {
-                            return std::string("");
-                        }
-
-                        if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_PNP_PIN))
-                        {
-                            return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_PNP_PIN);
-                        }
-                    }
-                }
-                return std::string("");
+                return getEasySetupPropHelper(m_EasySetupRep, SC_RSRVD_ES_VENDOR_PNP_PIN);
             }
 
             /**
@@ -1227,28 +1064,7 @@ namespace OIC
              */
             std::string getUTCDatetime() const
             {
-                std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
-                for(auto child = children.begin(); child != children.end(); ++child)
-                {
-                    if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
-                    {
-                        OCRepresentation rep;
-                        if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
-                        {
-                            rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
-                        }
-                        else
-                        {
-                            return std::string("");
-                        }
-
-                        if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_UTC_DATE_TIME))
-                        {
-                            return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_UTC_DATE_TIME);
-                        }
-                    }
-                }
-                return {};
+                return getEasySetupPropHelper(m_EasySetupRep, SC_RSRVD_ES_VENDOR_UTC_DATE_TIME);
             }
 
             /**
@@ -1258,28 +1074,7 @@ namespace OIC
              */
             std::string getRegionalDatetime() const
             {
-                std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
-                for(auto child = children.begin(); child != children.end(); ++child)
-                {
-                    if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
-                    {
-                        OCRepresentation rep;
-                        if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
-                        {
-                            rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
-                        }
-                        else
-                        {
-                            return std::string("");
-                        }
-
-                        if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_REGIONAL_DATE_TIME))
-                        {
-                            return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_REGIONAL_DATE_TIME);
-                        }
-                    }
-                }
-                return {};
+                return getEasySetupPropHelper(m_EasySetupRep, SC_RSRVD_ES_VENDOR_REGIONAL_DATE_TIME);
             }
 
             /**
@@ -1294,28 +1089,7 @@ namespace OIC
              */
             std::string getESProtocolVersion() const
             {
-                std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
-                for(auto child = children.begin(); child != children.end(); ++child)
-                {
-                    if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
-                    {
-                        OCRepresentation rep;
-                        if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
-                        {
-                            rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
-                        }
-                        else
-                        {
-                            return std::string("");
-                        }
-
-                        if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_ES_PROTOCOL_VERSION))
-                        {
-                            return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_ES_PROTOCOL_VERSION);
-                        }
-                    }
-                }
-                return std::string("");
+                return getEasySetupPropHelper(m_EasySetupRep, SC_RSRVD_ES_VENDOR_ES_PROTOCOL_VERSION);
             }
 
             /**
@@ -1326,28 +1100,7 @@ namespace OIC
              */
             std::string getCountry() const
             {
-                std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
-                for(auto child = children.begin(); child != children.end(); ++child)
-                {
-                    if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
-                    {
-                        OCRepresentation rep;
-                        if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
-                        {
-                            rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
-                        }
-                        else
-                        {
-                            return std::string("");
-                        }
-
-                        if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_COUNTRY))
-                        {
-                            return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_COUNTRY);
-                        }
-                    }
-                }
-                return std::string("");
+                return getEasySetupPropHelper(m_EasySetupRep,  SC_RSRVD_ES_VENDOR_COUNTRY);
             }
 
             /**
@@ -1357,30 +1110,8 @@ namespace OIC
              */
             std::string getHubId() const
             {
-                std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
-                for(auto child = children.begin(); child != children.end(); ++child)
-                {
-                    if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
-                    {
-                        OCRepresentation rep;
-                        if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
-                        {
-                            rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
-                        }
-                        else
-                        {
-                            return std::string("");
-                        }
-
-                        if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_HUB_ID))
-                        {
-                            return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_HUB_ID);
-                        }
-                    }
-                }
-                return std::string("");
+                return getEasySetupPropHelper(m_EasySetupRep, SC_RSRVD_ES_VENDOR_HUB_ID);
             }
-
         };
     }
 }