added APIs related to account in OCAccountManager
authorJaewook Jung <jw0213.jung@samsung.com>
Tue, 9 Aug 2016 07:39:08 +0000 (16:39 +0900)
committerJee Hyeok Kim <jihyeok13.kim@samsung.com>
Tue, 9 Aug 2016 10:51:55 +0000 (10:51 +0000)
added 2 APIs related to account
: searchUser, deleteDevice

and modified signOut API due to the change of the specification
that signOut message has no more any payload but only login property.

Change-Id: Ida9abb953d1bed0dae0fb4f0cb2bed522bc8a3dd
Signed-off-by: Jaewook Jung <jw0213.jung@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/10171
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jee Hyeok Kim <jihyeok13.kim@samsung.com>
resource/csdk/stack/include/octypes.h
resource/include/IClientWrapper.h
resource/include/InProcClientWrapper.h
resource/include/OCAccountManager.h
resource/include/OutOfProcClientWrapper.h
resource/src/InProcClientWrapper.cpp
resource/src/OCAccountManager.cpp
resource/src/OCResource.cpp
resource/unittests/OCAccountManagerTest.cpp

index c2267a5..c31affd 100644 (file)
@@ -377,20 +377,23 @@ extern "C" {
 /** Defines auth code. */
 #define OC_RSRVD_AUTHCODE                  "authcode"
 
-/** Defines session. */
+/** Defines access token. */
 #define OC_RSRVD_ACCESS_TOKEN              "accesstoken"
 
-/** Defines status. */
+/** Defines login. */
 #define OC_RSRVD_LOGIN                     "login"
 
+/** Defines search. */
+#define OC_RSRVD_SEARCH                    "search"
+
 /** Defines grant type. */
 #define OC_RSRVD_GRANT_TYPE                "granttype"
 
 /** Defines refresh token. */
 #define OC_RSRVD_REFRESH_TOKEN             "refreshtoken"
 
-/** Defines user ID. */
-#define OC_RSRVD_USER_ID                   "uid"
+/** Defines user UUID. */
+#define OC_RSRVD_USER_UUID                 "uid"
 
 /** Defines options. */
 #define OC_RSRVD_OPTIONS                   "options"
index 2a958f5..41a3689 100644 (file)
@@ -63,6 +63,7 @@ namespace OC
                         const std::string& uri,
                         const QueryParamsMap& queryParams,
                         const HeaderOptions& headerOptions,
+                        OCConnectivityType connectivityType,
                         GetCallback& callback, QualityOfService QoS)=0;
 
         virtual OCStackResult PutResourceRepresentation(
@@ -84,6 +85,7 @@ namespace OC
                         const OCDevAddr& devAddr,
                         const std::string& uri,
                         const HeaderOptions& headerOptions,
+                        OCConnectivityType connectivityType,
                         DeleteCallback& callback, QualityOfService QoS) = 0;
 
         virtual OCStackResult ObserveResource(
index 2c90c90..f046c97 100644 (file)
@@ -136,6 +136,7 @@ namespace OC
             const OCDevAddr& devAddr,
             const std::string& uri,
             const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
+            OCConnectivityType connectivityType,
             GetCallback& callback, QualityOfService QoS);
 
         virtual OCStackResult PutResourceRepresentation(
@@ -155,6 +156,7 @@ namespace OC
             const OCDevAddr& devAddr,
             const std::string& uri,
             const HeaderOptions& headerOptions,
+            OCConnectivityType connectivityType,
             DeleteCallback& callback, QualityOfService QoS);
 
         virtual OCStackResult ObserveResource(
index 00f2b66..a5d3f40 100644 (file)
@@ -88,42 +88,72 @@ namespace OC
         /**
          * Function for sign-in to account server
          *
-         * @param userId Identifier of the user obtained by account registration.
+         * @param userUuid Identifier of the user obtained by account registration.
          * @param accessToken Identifier of the resource obtained by account registration.
          * @param cloudConnectHandler Callback function that will get the result of the operation.
          *
          * @return Returns ::OC_STACK_OK if success
          */
-        OCStackResult signIn(const std::string& userId,
+        OCStackResult signIn(const std::string& userUuid,
                              const std::string& accessToken,
                              PostCallback cloudConnectHandler);
 
         /**
          * Function for sign-out to account server
          *
-         * @param userId Identifier of the user obtained by account registration.
-         * @param accessToken Identifier of the resource obtained by account registration.
          * @param cloudConnectHandler Callback function that will get the result of the operation.
          *
          * @return Returns ::OC_STACK_OK if success
          */
-        OCStackResult signOut(const std::string& userId,
-                              const std::string& accessToken,
-                              PostCallback cloudConnectHandler);
+        OCStackResult signOut(PostCallback cloudConnectHandler);
 
         /**
          * Function for refresh access token to account server
          *
-         * @param userId Identifier of the user obtained by account registration.
+         * @param userUuid Identifier of the user obtained by account registration.
          * @param refreshToken Refresh token used for access token refresh.
          * @param cloudConnectHandler Callback function that will get the result of the operation.
          *
          * @return Returns ::OC_STACK_OK if success
          */
-        OCStackResult refreshAccessToken(const std::string& userId,
+        OCStackResult refreshAccessToken(const std::string& userUuid,
                                          const std::string& refreshToken,
                                          PostCallback cloudConnectHandler);
 
+        /**
+         * Function to get information of the user to account server
+         *
+         * @param userUuid Identifier of the user to get information.
+         * @param cloudConnectHandler Callback function that will get the result of the operation.
+         *
+         * @return Returns ::OC_STACK_OK if success
+         */
+        OCStackResult searchUser(const std::string& userUuid,
+                                 GetCallback cloudConnectHandler);
+
+        /**
+         * Overload
+         *
+         * @param queryParams Map which can have the query key and value for specific users.
+         *                    account server can response information of more than one user.
+         * @param cloudConnectHandler Callback function that will get the result of the operation.
+         *
+         * @return Returns ::OC_STACK_OK if success
+         */
+        OCStackResult searchUser(const QueryParamsMap& queryParams,
+                                 GetCallback cloudConnectHandler);
+
+        /**
+         * Function to delete the device registered on the account signed-in
+         *
+         * @param deviceId Device ID to delete.
+         * @param cloudConnectHandler Callback function that will get the result of the operation.
+         *
+         * @return Returns ::OC_STACK_OK if success
+         */
+        OCStackResult deleteDevice(const std::string& deviceId,
+                                   DeleteCallback cloudConnectHandler);
+
     private:
         std::weak_ptr<IClientWrapper> m_clientWrapper;
         std::string m_deviceID;
@@ -136,10 +166,14 @@ namespace OC
                          const std::string& host,
                          OCConnectivityType connectivityType);
 
-        OCStackResult signInOut(const std::string& userId,
+        OCStackResult signInOut(const std::string& userUuid,
                                 const std::string& accessToken,
                                 bool isSignIn,
                                 PostCallback cloudConnectHandler);
+
+        OCStackResult searchUser(const std::string& userUuid,
+                                 const QueryParamsMap& queryParams,
+                                 GetCallback cloudConnectHandler);
     };
 } // namespace OC
 
index 79c2d4e..e349508 100644 (file)
@@ -65,6 +65,7 @@ namespace OC
             const std::string& /*uri*/,
             const QueryParamsMap& /*queryParams*/,
             const HeaderOptions& /*headerOptions*/,
+            OCConnectivityType /*connectivityType*/,
             GetCallback& /*callback*/, QualityOfService /*QoS*/)
             {return OC_STACK_NOTIMPL;}
 
@@ -92,6 +93,7 @@ namespace OC
             const OCDevAddr& /*devAddr*/,
             const std::string& /*uri*/,
             const HeaderOptions& /*headerOptions*/,
+            OCConnectivityType /*connectivityType*/,
             DeleteCallback& /*callback*/, QualityOfService /*QoS*/)
             {return OC_STACK_NOTIMPL;}
 
index b41b7ac..2f223d9 100644 (file)
@@ -672,6 +672,7 @@ namespace OC
         const OCDevAddr& devAddr,
         const std::string& resourceUri,
         const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
+        OCConnectivityType connectivityType,
         GetCallback& callback, QualityOfService QoS)
     {
         if (!callback)
@@ -700,7 +701,7 @@ namespace OC
                                   nullptr, OC_REST_GET,
                                   uri.c_str(),
                                   &devAddr, nullptr,
-                                  CT_DEFAULT,
+                                  connectivityType,
                                   static_cast<OCQualityOfService>(QoS),
                                   &cbdata,
                                   assembleHeaderOptions(options, headerOptions),
@@ -957,6 +958,7 @@ namespace OC
         const OCDevAddr& devAddr,
         const std::string& uri,
         const HeaderOptions& headerOptions,
+        OCConnectivityType connectivityType,
         DeleteCallback& callback,
         QualityOfService /*QoS*/)
     {
@@ -984,7 +986,7 @@ namespace OC
             result = OCDoResource(nullptr, OC_REST_DELETE,
                                   uri.c_str(), &devAddr,
                                   nullptr,
-                                  CT_DEFAULT,
+                                  connectivityType,
                                   static_cast<OCQualityOfService>(m_cfg.QoS),
                                   &cbdata,
                                   assembleHeaderOptions(options, headerOptions),
index f83d9b1..ca73282 100644 (file)
@@ -97,21 +97,19 @@ OCStackResult OCAccountManager::signUp(const std::string& authProvider,
                          m_connType, cloudConnectHandler, m_defaultQos);
 }
 
-OCStackResult OCAccountManager::signIn(const std::string& userId,
+OCStackResult OCAccountManager::signIn(const std::string& userUuid,
                                        const std::string& accessToken,
                                        PostCallback cloudConnectHandler)
 {
-    return result_guard(signInOut(userId, accessToken, true, cloudConnectHandler));
+    return result_guard(signInOut(userUuid, accessToken, true, cloudConnectHandler));
 }
 
-OCStackResult OCAccountManager::signOut(const std::string& userId,
-                                        const std::string& accessToken,
-                                        PostCallback cloudConnectHandler)
+OCStackResult OCAccountManager::signOut(PostCallback cloudConnectHandler)
 {
-    return result_guard(signInOut(userId, accessToken, false, cloudConnectHandler));
+    return result_guard(signInOut("", "", false, cloudConnectHandler));
 }
 
-OCStackResult OCAccountManager::signInOut(const std::string& userId,
+OCStackResult OCAccountManager::signInOut(const std::string& userUuid,
                                           const std::string& accessToken,
                                           bool isSignIn,
                                           PostCallback cloudConnectHandler)
@@ -119,9 +117,12 @@ OCStackResult OCAccountManager::signInOut(const std::string& userId,
     std::string uri = m_host + OC_RSRVD_ACCOUNT_SESSION_URI;
 
     OCRepresentation rep;
-    rep.setValue(OC_RSRVD_USER_ID, userId);
-    rep.setValue(OC_RSRVD_DEVICE_ID, m_deviceID);
-    rep.setValue(OC_RSRVD_ACCESS_TOKEN, accessToken);
+    if (isSignIn)
+    {
+        rep.setValue(OC_RSRVD_USER_UUID, userUuid);
+        rep.setValue(OC_RSRVD_DEVICE_ID, m_deviceID);
+        rep.setValue(OC_RSRVD_ACCESS_TOKEN, accessToken);
+    }
     rep.setValue(OC_RSRVD_LOGIN, isSignIn);
 
     return checked_guard(m_clientWrapper.lock(), &IClientWrapper::PostResourceRepresentation,
@@ -129,14 +130,14 @@ OCStackResult OCAccountManager::signInOut(const std::string& userId,
                          m_connType, cloudConnectHandler, m_defaultQos);
 }
 
-OCStackResult OCAccountManager::refreshAccessToken(const std::string& userId,
+OCStackResult OCAccountManager::refreshAccessToken(const std::string& userUuid,
                                                    const std::string& refreshToken,
                                                    PostCallback cloudConnectHandler)
 {
     std::string uri = m_host + OC_RSRVD_ACCOUNT_TOKEN_REFRESH_URI;
 
     OCRepresentation rep;
-    rep.setValue(OC_RSRVD_USER_ID, userId);
+    rep.setValue(OC_RSRVD_USER_UUID, userUuid);
     rep.setValue(OC_RSRVD_DEVICE_ID, m_deviceID);
     rep.setValue(OC_RSRVD_GRANT_TYPE, OC_RSRVD_GRANT_TYPE_REFRESH_TOKEN);
     rep.setValue(OC_RSRVD_REFRESH_TOKEN, refreshToken);
@@ -145,4 +146,57 @@ OCStackResult OCAccountManager::refreshAccessToken(const std::string& userId,
                          OCDevAddr(), uri, rep, QueryParamsMap(), HeaderOptions(),
                          m_connType, cloudConnectHandler, m_defaultQos);
 }
+
+OCStackResult OCAccountManager::searchUser(const std::string& userUuid,
+                                           GetCallback cloudConnectHandler)
+{
+    return result_guard(searchUser(userUuid, QueryParamsMap(), cloudConnectHandler));
+}
+
+OCStackResult OCAccountManager::searchUser(const QueryParamsMap& queryParams,
+                                           GetCallback cloudConnectHandler)
+{
+    return result_guard(searchUser("", queryParams, cloudConnectHandler));
+}
+
+OCStackResult OCAccountManager::searchUser(const std::string& userUuid,
+                                           const QueryParamsMap& queryParams,
+                                           GetCallback cloudConnectHandler)
+{
+    std::string uri = m_host + OC_RSRVD_ACCOUNT_URI;
+
+    QueryParamsMap fullQuery = {};
+
+    if (!userUuid.empty())
+    {
+        fullQuery.insert(std::make_pair(OC_RSRVD_USER_UUID, userUuid));
+    }
+
+    if (!queryParams.empty())
+    {
+        std::string searchQuery;
+        for (auto iter : queryParams)
+        {
+            searchQuery.append(iter.first + ":" + iter.second + ",");
+        }
+        searchQuery.resize(searchQuery.size() - 1);
+        fullQuery.insert(std::make_pair(OC_RSRVD_SEARCH, searchQuery));
+    }
+
+    return checked_guard(m_clientWrapper.lock(), &IClientWrapper::GetResourceRepresentation,
+                         OCDevAddr(), uri, fullQuery, HeaderOptions(),
+                         m_connType, cloudConnectHandler, m_defaultQos);
+}
+
+OCStackResult OCAccountManager::deleteDevice(const std::string& deviceId,
+                                             DeleteCallback cloudConnectHandler)
+{
+    std::string uri = m_host + OC_RSRVD_ACCOUNT_URI
+                      + "?" + OC_RSRVD_DEVICE_ID + "=" + deviceId;
+
+    return checked_guard(m_clientWrapper.lock(), &IClientWrapper::DeleteResource,
+                         OCDevAddr(), uri, HeaderOptions(),
+                         m_connType, cloudConnectHandler, m_defaultQos);
+}
+
 } // namespace OC
index 12a9628..741629d 100644 (file)
@@ -280,7 +280,7 @@ OCStackResult OCResource::get(const QueryParamsMap& queryParametersMap,
     return checked_guard(m_clientWrapper.lock(),
                             &IClientWrapper::GetResourceRepresentation,
                             m_devAddr, m_uri,
-                            queryParametersMap, m_headerOptions,
+                            queryParametersMap, m_headerOptions, CT_DEFAULT,
                             attributeHandler, QoS);
 }
 
@@ -423,7 +423,7 @@ OCStackResult OCResource::post(const std::string& resourceType,
 OCStackResult OCResource::deleteResource(DeleteCallback deleteHandler, QualityOfService QoS)
 {
     return checked_guard(m_clientWrapper.lock(), &IClientWrapper::DeleteResource,
-                         m_devAddr, m_uri, m_headerOptions, deleteHandler, QoS);
+                         m_devAddr, m_uri, m_headerOptions, CT_DEFAULT, deleteHandler, QoS);
 }
 
 OCStackResult OCResource::deleteResource(DeleteCallback deleteHandler)
index df55bd2..09a8bae 100644 (file)
@@ -32,6 +32,10 @@ namespace OCAccountManagerTest
     {
     }
 
+    void deleteHandler(const HeaderOptions& /*headerOptions*/, const int /*eCode*/)
+    {
+    }
+
     // Helper method
     OCAccountManager::Ptr ConstructAccountManagerObject(std::string host)
     {
@@ -123,21 +127,17 @@ namespace OCAccountManagerTest
     TEST(SignOutTest, DISABLED_SignOutForValid)
     {
         std::string host("coap://192.168.1.2:5000");
-        std::string userId("AnyUserId");
-        std::string accessToken("AnyAccessToken");
         OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
         EXPECT_TRUE(NULL != accountManager);
-        EXPECT_EQ(OC_STACK_OK, accountManager->signOut(userId, accessToken, &accountHandler));
+        EXPECT_EQ(OC_STACK_OK, accountManager->signOut(&accountHandler));
     }
 
     TEST(SignOutTest, SignOutWithNullCallback)
     {
         std::string host("coap://192.168.1.2:5000");
-        std::string userId("AnyUserId");
-        std::string accessToken("AnyAccessToken");
         OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
         EXPECT_TRUE(NULL != accountManager);
-        EXPECT_ANY_THROW(accountManager->signOut(userId, accessToken, nullptr));
+        EXPECT_ANY_THROW(accountManager->signOut(nullptr));
     }
 
     // RefreshAccessToken Test
@@ -161,4 +161,54 @@ namespace OCAccountManagerTest
         EXPECT_TRUE(NULL != accountManager);
         EXPECT_ANY_THROW(accountManager->refreshAccessToken(userId, refreshToken, nullptr));
     }
+
+    // SearchUser Test
+    TEST(SearchUserTest, DISABLED_SearchUserWithUserUuidForValid)
+    {
+        std::string host("coap://192.168.1.2:5000");
+        std::string userId("AnyUserId");
+        OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
+        EXPECT_TRUE(NULL != accountManager);
+        EXPECT_EQ(OC_STACK_OK, accountManager->searchUser(userId, &accountHandler));
+    }
+
+    TEST(SearchUserTest, DISABLED_SearchUserWithQueryForValid)
+    {
+        std::string host("coap://192.168.1.2:5000");
+        std::string key("AnyKey");
+        std::string value("AnyValue");
+        QueryParamsMap query = {};
+        query.insert(std::pair<std::string, std::string>(key, value));
+        OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
+        EXPECT_TRUE(NULL != accountManager);
+        EXPECT_EQ(OC_STACK_OK, accountManager->searchUser(query, &accountHandler));
+    }
+
+    TEST(SearchUserTest, SearchUserWithNullCallback)
+    {
+        std::string host("coap://192.168.1.2:5000");
+        std::string userId("AnyUserId");
+        OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
+        EXPECT_TRUE(NULL != accountManager);
+        EXPECT_ANY_THROW(accountManager->searchUser(userId, nullptr));
+    }
+
+    // DeleteDevice Test
+    TEST(DeleteDeviceTest, DISABLED_DeleteDeviceForValid)
+    {
+        std::string host("coap://192.168.1.2:5000");
+        std::string deviceId("AnyDeviceId");
+        OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
+        EXPECT_TRUE(NULL != accountManager);
+        EXPECT_EQ(OC_STACK_OK, accountManager->deleteDevice(deviceId, &deleteHandler));
+    }
+
+    TEST(DeleteDeviceTest, DeleteDeviceWithNullCallback)
+    {
+        std::string host("coap://192.168.1.2:5000");
+        std::string deviceId("AnyDeviceId");
+        OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
+        EXPECT_TRUE(NULL != accountManager);
+        EXPECT_ANY_THROW(accountManager->deleteDevice(deviceId, nullptr));
+    }
 }