relocate singleton object(getInstance) to GroupManager
authorJung Seungho <shonest.jung@samsung.com>
Thu, 1 Sep 2016 02:31:41 +0000 (11:31 +0900)
committerJee Hyeok Kim <jihyeok13.kim@samsung.com>
Mon, 19 Sep 2016 08:26:06 +0000 (08:26 +0000)
Change-Id: I3c263e0edd69e92d17fa4bf49e15d797054e7c8f
Signed-off-by: Jung Seungho <shonest.jung@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/11241
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jee Hyeok Kim <jihyeok13.kim@samsung.com>
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/account/AccountManager.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/group/Group.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/group/GroupManager.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/group/GroupResource.java

index a523f2d..de2d2be 100644 (file)
@@ -39,7 +39,7 @@ import org.iotivity.cloud.accountserver.db.AccountDBManager;
 import org.iotivity.cloud.accountserver.db.TokenTable;
 import org.iotivity.cloud.accountserver.db.UserTable;
 import org.iotivity.cloud.accountserver.oauth.OAuthProviderFactory;
-import org.iotivity.cloud.accountserver.resources.acl.group.GroupResource;
+import org.iotivity.cloud.accountserver.resources.acl.group.GroupManager;
 import org.iotivity.cloud.accountserver.util.TypeCastingManager;
 import org.iotivity.cloud.base.exception.ServerException.BadRequestException;
 import org.iotivity.cloud.base.exception.ServerException.InternalServerErrorException;
@@ -226,7 +226,7 @@ public class AccountManager {
                     castUserTableToMap(userInfo));
 
             // make my private group
-            GroupResource.getInstance().createGroup(userInfo.getUuid(),
+            GroupManager.getInstance().createGroup(userInfo.getUuid(),
                     Constants.REQ_GTYPE_PRIVATE);
         }
         tokenInfo.setUuid(userUuid);
@@ -567,7 +567,7 @@ public class AccountManager {
         AccountDBManager.getInstance().deleteRecord(Constants.TOKEN_TABLE,
                 condition);
         // delete device ID from all groups in the DB
-        GroupResource.getInstance().removeGroupDeviceinEveryGroup(uid, di);
+        GroupManager.getInstance().removeGroupDeviceinEveryGroup(uid, di);
 
         // TODO remove device record from the ACL table
     }
index 0aca7ab..57f8fd7 100644 (file)
@@ -120,7 +120,7 @@ public class Group {
             throw new InternalServerErrorException("group master is empty");
         }
         if (uuid.contains(groupTable.getGmid())) {
-            GroupResource.getInstance().deleteGroup(groupTable.getGmid(), mGid);
+            GroupManager.getInstance().deleteGroup(groupTable.getGmid(), mGid);
             notifyToSubscriber(getResponsePayload(false));
         } else {
             if (groupTable.getMidlist() == null) {
index 56d039e..c490756 100644 (file)
@@ -44,9 +44,17 @@ import org.iotivity.cloud.base.protocols.IRequest;
  */
 
 public class GroupManager {
+    private static GroupManager            mGrManager = new GroupManager();
     public HashMap<String, Group>          mGroups    = new HashMap<>();
     private TypeCastingManager<GroupTable> mTypeGroup = new TypeCastingManager<GroupTable>();
 
+    private GroupManager() {
+    }
+
+    public static GroupManager getInstance() {
+        return mGrManager;
+    }
+
     /**
      * API to create a public or private group
      * 
@@ -131,7 +139,7 @@ public class GroupManager {
     public void removeGroupDeviceinEveryGroup(String uid, String di) {
         // check if the device is the resource server (i.e., device ID exists in
         // the private group table
-        if (GroupResource.getInstance().verifyDeviceInGroup(uid, di)) {
+        if (verifyDeviceInGroup(uid, di)) {
             // token table search criteria
             HashMap<String, Object> condition = new HashMap<>();
             condition.put(Constants.REQ_DEVICE_ID_LIST, di);
@@ -144,7 +152,7 @@ public class GroupManager {
                 String gid = (String) record.get(Constants.KEYFIELD_GID);
                 HashSet<String> diSet = new HashSet<>();
                 diSet.add(di);
-                GroupResource.getInstance().removeGroupDevice(gid, diSet);
+                removeGroupDevice(gid, diSet);
             }
         }
     }
index be7f3a5..174620b 100644 (file)
@@ -40,20 +40,13 @@ import org.iotivity.cloud.base.resource.Resource;
 import org.iotivity.cloud.util.Cbor;
 
 public class GroupResource extends Resource {
-
-    private Cbor<HashMap<String, Object>> mCbor      = new Cbor<>();
-
-    private static GroupManager           mGrManager = new GroupManager();
+    private Cbor<HashMap<String, Object>> mCbor = new Cbor<>();
 
     public GroupResource() {
         super(Arrays.asList(Constants.PREFIX_OIC, Constants.ACL_URI,
                 Constants.GROUP_URI));
     }
 
-    public static GroupManager getInstance() {
-        return mGrManager;
-    }
-
     @Override
     public void onDefaultRequestReceived(Device srcDevice, IRequest request)
             throws ServerException {
@@ -102,8 +95,8 @@ public class GroupResource extends Resource {
             }
             return MessageBuilder.createResponse(request,
                     ResponseStatus.CHANGED, ContentFormat.APPLICATION_CBOR,
-                    mCbor.encodingPayloadToCbor(
-                            mGrManager.createGroup(uuid, gtype)));
+                    mCbor.encodingPayloadToCbor(GroupManager.getInstance()
+                            .createGroup(uuid, gtype)));
         } else {
             String gid = request.getUriPathSegments()
                     .get(getUriPathSegments().size());
@@ -115,7 +108,8 @@ public class GroupResource extends Resource {
                     throw new PreconditionFailedException(
                             "midList property is invalid");
                 }
-                mGrManager.addGroupMember(gid, new HashSet<String>(midList));
+                GroupManager.getInstance().addGroupMember(gid,
+                        new HashSet<String>(midList));
             }
 
             if (payloadData.containsKey(Constants.REQ_DEVICE_ID_LIST)) {
@@ -125,7 +119,8 @@ public class GroupResource extends Resource {
                     throw new PreconditionFailedException(
                             "diList property is invalid");
                 }
-                mGrManager.addGroupDevice(gid, new HashSet<String>(diList));
+                GroupManager.getInstance().addGroupDevice(gid,
+                        new HashSet<String>(diList));
             }
         }
         return MessageBuilder.createResponse(request, ResponseStatus.CHANGED);
@@ -144,21 +139,22 @@ public class GroupResource extends Resource {
         mid = request.getUriQueryMap().get(Constants.REQ_MEMBER).get(0);
 
         if (getUriPathSegments().containsAll(request.getUriPathSegments())) {
-            responsePayload = mGrManager.getGroupList(mid);
+            responsePayload = GroupManager.getInstance().getGroupList(mid);
         } else {
             String gid = request.getUriPathSegments()
                     .get(getUriPathSegments().size());
             switch (request.getObserve()) {
                 case NOTHING:
-                    responsePayload = mGrManager.getGroupInfo(gid, mid);
+                    responsePayload = GroupManager.getInstance()
+                            .getGroupInfo(gid, mid);
                     break;
                 case SUBSCRIBE:
-                    responsePayload = mGrManager.addGroupSubscriber(gid, mid,
-                            srcDevice, request);
+                    responsePayload = GroupManager.getInstance()
+                            .addGroupSubscriber(gid, mid, srcDevice, request);
                     break;
                 case UNSUBSCRIBE:
-                    responsePayload = mGrManager.removeGroupSubscriber(gid,
-                            mid);
+                    responsePayload = GroupManager.getInstance()
+                            .removeGroupSubscriber(gid, mid);
                     break;
                 default:
                     throw new BadRequestException(request.getObserve()
@@ -182,7 +178,7 @@ public class GroupResource extends Resource {
             String gid = request.getUriQueryMap().get(Constants.REQ_GROUP_ID)
                     .get(0);
 
-            mGrManager.deleteGroup(gmid, gid);
+            GroupManager.getInstance().deleteGroup(gmid, gid);
         } else {
             String gid = request.getUriPathSegments()
                     .get(getUriPathSegments().size());
@@ -194,7 +190,8 @@ public class GroupResource extends Resource {
                     throw new PreconditionFailedException(
                             "midList property is invalid");
                 }
-                mGrManager.removeGroupMember(gid, new HashSet<String>(midList));
+                GroupManager.getInstance().removeGroupMember(gid,
+                        new HashSet<String>(midList));
             }
             if (request.getUriQueryMap()
                     .containsKey(Constants.REQ_DEVICE_ID_LIST)) {
@@ -204,7 +201,8 @@ public class GroupResource extends Resource {
                     throw new PreconditionFailedException(
                             "diList property is invalid");
                 }
-                mGrManager.removeGroupDevice(gid, new HashSet<String>(diList));
+                GroupManager.getInstance().removeGroupDevice(gid,
+                        new HashSet<String>(diList));
             }
         }
         return MessageBuilder.createResponse(request, ResponseStatus.DELETED);