Latent defect issue solved in AS based on statistical analysis result
authoryeonghun.nam <yeonghun.nam@samsung.com>
Tue, 6 Dec 2016 04:50:15 +0000 (13:50 +0900)
committerJee Hyeok Kim <jihyeok13.kim@samsung.com>
Wed, 18 Jan 2017 05:38:41 +0000 (05:38 +0000)
Change-Id: Ib80244e04a16354a31efb667126124daeb81896f
Signed-off-by: yeonghun.nam <yeonghun.nam@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/15179
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jee Hyeok Kim <jihyeok13.kim@samsung.com>
(cherry picked from commit d39eed202efcd989dc4d971638b6e5713835c077)
Reviewed-on: https://gerrit.iotivity.org/gerrit/16089
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
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
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/id/AclResource.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/invite/InviteManager.java

index 1a005e7..79aa494 100644 (file)
@@ -567,6 +567,9 @@ public class GroupManager {
         if (groupTable == null) {
             throw new BadRequestException("group " + gid + " does not exist");
         }
+        if (groupTable.getMembers() == null) {
+            throw new BadRequestException("there are no members in the group");
+        }
         if (!groupTable.getMembers().contains(mid)) {
             throw new BadRequestException("uid is not a member of the group");
         }
index 5601ce3..a401cd1 100644 (file)
@@ -193,6 +193,9 @@ public class GroupResource extends Resource {
 
     private IResponse handleGroupPostRequest(IRequest request)
             throws ServerException {
+        if (request.getPayload() == null) {
+            throw new BadRequestException("payload is null");
+        }
         HashMap<String, Object> payloadData = mCbor
                 .parsePayloadFromCbor(request.getPayload(), HashMap.class);
 
@@ -400,6 +403,12 @@ public class GroupResource extends Resource {
                 Constants.KEYFIELD_GROUP_MEMBERS), queryMap);
 
         String uid = queryMap.get(Constants.REQ_UUID_ID).get(0);
+
+        if (uid == null || uid.isEmpty()) {
+            throw new BadRequestException(
+                    Constants.REQ_UUID_ID + " is null or empty");
+        }
+
         if (!uid.equals(
                 queryMap.get(Constants.KEYFIELD_GROUP_MEMBERS).get(0))) {
             throw new BadRequestException(
@@ -407,11 +416,6 @@ public class GroupResource extends Resource {
                             + Constants.KEYFIELD_GROUP_MEMBERS + "query value");
         }
 
-        if (uid == null || uid.isEmpty()) {
-            throw new BadRequestException(
-                    Constants.REQ_UUID_ID + " is null or empty");
-        }
-
         String gid = request.getUriPathSegments()
                 .get(getUriPathSegments().size());
 
@@ -444,6 +448,12 @@ public class GroupResource extends Resource {
                 Constants.KEYFIELD_GROUP_OWNER), queryMap);
 
         String uid = queryMap.get(Constants.REQ_UUID_ID).get(0);
+
+        if (uid == null || uid.isEmpty()) {
+            throw new BadRequestException(
+                    Constants.REQ_UUID_ID + " is null or empty");
+        }
+
         if (!uid.equals(queryMap.get(Constants.KEYFIELD_GROUP_OWNER).get(0))) {
             throw new BadRequestException(
                     Constants.REQ_UUID_ID + "query value should be equal to "
@@ -451,11 +461,6 @@ public class GroupResource extends Resource {
                             + "query value to delete group");
         }
 
-        if (uid == null || uid.isEmpty()) {
-            throw new BadRequestException(
-                    Constants.REQ_UUID_ID + " is null or empty");
-        }
-
         String gid = request.getUriPathSegments()
                 .get(getUriPathSegments().size());
 
index f212d62..8a0e91a 100644 (file)
@@ -107,37 +107,44 @@ public class AclResource extends Resource {
     }
 
     private IResponse handlePostRequest(IRequest request)
-        throws ServerException {
+            throws ServerException {
+
+        if (request.getPayload() == null) {
+            throw new BadRequestException("payload is null");
+        }
 
-            HashMap<String, Object> payloadData = mCbor
+        HashMap<String, Object> payloadData = mCbor
                 .parsePayloadFromCbor(request.getPayload(), HashMap.class);
 
-            if (null !=request.getUriQueryMap()) {
-                String aclid = request.getUriPathSegments().get(getUriPathSegments().size());
-                String aceid = request.getUriQueryMap().get(Constants.REQ_ACE_ID).get(0);
-                List<HashMap<String, Object>> aclist = (List<HashMap<String, Object>>) payloadData
+        if (null != request.getUriQueryMap()) {
+            String aclid = request.getUriPathSegments()
+                    .get(getUriPathSegments().size());
+            String aceid = request.getUriQueryMap().get(Constants.REQ_ACE_ID)
+                    .get(0);
+            List<HashMap<String, Object>> aclist = (List<HashMap<String, Object>>) payloadData
                     .get(Constants.REQ_ACL_LIST);
-                mAclManager.updateACE(aclid, aceid, aclist.get(0));
-                return MessageBuilder.createResponse(request, ResponseStatus.CHANGED);
+            mAclManager.updateACE(aclid, aceid, aclist.get(0));
+            return MessageBuilder.createResponse(request,
+                    ResponseStatus.CHANGED);
+        } else if (!getUriPathSegments()
+                .containsAll(request.getUriPathSegments())) {
+            String aclid = request.getUriPathSegments()
+                    .get(getUriPathSegments().size());
+
+            List<HashMap<String, Object>> aclist = null;
+            if (!payloadData.containsKey(Constants.REQ_ACL_LIST)) {
+                throw new BadRequestException("aclist not included in payload");
             }
-            else if (!getUriPathSegments().containsAll(request.getUriPathSegments())) {
-                String aclid = request.getUriPathSegments().get(getUriPathSegments().size());
-
-                List<HashMap<String, Object>> aclist = null;
-                if (!payloadData.containsKey(Constants.REQ_ACL_LIST)) {
-                    throw new BadRequestException("aclist not included in payload");
-                }
-                aclist = (List<HashMap<String, Object>>) payloadData
+            aclist = (List<HashMap<String, Object>>) payloadData
                     .get(Constants.REQ_ACL_LIST);
-                aclist= mAclManager.addAclACE(aclid, aclist);
-                payloadData.put(Constants.REQ_ACL_LIST, aclist);
-                return MessageBuilder.createResponse(request, ResponseStatus.CHANGED,
-                        ContentFormat.APPLICATION_CBOR,
-                        mCbor.encodingPayloadToCbor(payloadData));
-            }
-            throw new BadRequestException("uriPath is invalid");
+            aclist = mAclManager.addAclACE(aclid, aclist);
+            payloadData.put(Constants.REQ_ACL_LIST, aclist);
+            return MessageBuilder.createResponse(request,
+                    ResponseStatus.CHANGED, ContentFormat.APPLICATION_CBOR,
+                    mCbor.encodingPayloadToCbor(payloadData));
         }
-
+        throw new BadRequestException("uriPath is invalid");
+    }
 
     @SuppressWarnings("unchecked")
 
@@ -200,17 +207,14 @@ public class AclResource extends Resource {
             aclid = request.getUriPathSegments()
                     .get(getUriPathSegments().size());
 
-            if (request.getUriQueryMap() == null)
-            {
+            if (request.getUriQueryMap() == null) {
                 mAclManager.deleteAclAclist(aclid);
-            }
-            else if (request.getUriQueryMap()
+            } else if (request.getUriQueryMap()
                     .containsKey(Constants.REQ_ACE_ID)) {
-                String aceid = request.getUriQueryMap().get(Constants.REQ_ACE_ID)
-                        .get(0);
+                String aceid = request.getUriQueryMap()
+                        .get(Constants.REQ_ACE_ID).get(0);
                 mAclManager.deleteAclACE(aclid, aceid);
-            }
-            else {
+            } else {
                 throw new BadRequestException("uriPath is invalid");
             }
         }
index afcc6aa..11b398b 100644 (file)
@@ -110,6 +110,10 @@ public class InviteManager {
         List<HashMap<String, Object>> getInviteList = AccountDBManager
                 .getInstance().selectRecord(Constants.INVITE_TABLE, condition);
 
+        if (getInviteList == null || getInviteList.isEmpty()) {
+            throw new BadRequestException("mid or gid is not valid");
+        }
+
         ArrayList<String> uidList = new ArrayList<>();
         for (HashMap<String, Object> getInvite : getInviteList) {
             getInviteTable = mTypeInvite.convertMaptoObject(getInvite,
@@ -117,10 +121,6 @@ public class InviteManager {
             uidList.add(getInviteTable.getInviteUser());
         }
 
-        if (getInviteList == null || getInviteList.isEmpty()) {
-            throw new BadRequestException("mid or gid is not valid");
-        }
-
         AccountDBManager.getInstance().deleteRecord(Constants.INVITE_TABLE,
                 condition);