Implement acl/invite resource in cloud account server.
authorJung Seungho <shonest.jung@samsung.com>
Wed, 10 Aug 2016 09:52:35 +0000 (18:52 +0900)
committerJee Hyeok Kim <jihyeok13.kim@samsung.com>
Fri, 12 Aug 2016 06:03:43 +0000 (06:03 +0000)
Add invite feature to invite user

Change-Id: I7a4c1922de4b312afda92423338092423fa573c7
Signed-off-by: Minji Park <minjii.park@samsung.com>
Signed-off-by: Jung Seungho <shonest.jung@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/9975
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jee Hyeok Kim <jihyeok13.kim@samsung.com>
16 files changed:
cloud/account/src/main/java/org/iotivity/cloud/accountserver/AccountServer.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/Constants.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/db/AccountDBManager.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/db/InviteTable.java [new file with mode: 0644]
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/account/AccountResource.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/invite/InviteManager.java [new file with mode: 0644]
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/invite/InviteResource.java [new file with mode: 0644]
cloud/interface/src/main/java/org/iotivity/cloud/ciserver/CloudInterfaceServer.java
cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/proxy/account/Account.java
cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/proxy/account/AclGroup.java
cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/proxy/account/AclInvite.java [new file with mode: 0644]
cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/proxy/rd/DevicePresence.java
cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/proxy/rd/ResourceFind.java
cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/proxy/rd/ResourcePresence.java
cloud/stack/src/main/java/org/iotivity/cloud/base/OCFConstants.java
cloud/stack/src/main/java/org/iotivity/cloud/base/protocols/Message.java

index efcd4cd0c236d306cb46e4569b8f4ae223f74c5c..ae7a57759b5a4102c225b8991c3ebb28efddd747 100755 (executable)
@@ -28,6 +28,7 @@ import org.iotivity.cloud.accountserver.resources.account.AccountResource;
 import org.iotivity.cloud.accountserver.resources.account.session.SessionResource;
 import org.iotivity.cloud.accountserver.resources.account.tokenrefresh.TokenRefreshResource;
 import org.iotivity.cloud.accountserver.resources.acl.group.GroupResource;
+import org.iotivity.cloud.accountserver.resources.acl.invite.InviteResource;
 import org.iotivity.cloud.accountserver.resources.certificate.CertificateResource;
 import org.iotivity.cloud.base.ServerSystem;
 import org.iotivity.cloud.base.server.CoapServer;
@@ -62,8 +63,10 @@ public class AccountServer {
 
         serverSystem.addResource(new CertificateResource());
 
-        serverSystem.addServer(new CoapServer(
-                new InetSocketAddress(Integer.parseInt(args[0]))));
+        serverSystem.addResource(new InviteResource());
+
+        serverSystem.addServer(new CoapServer(new InetSocketAddress(Integer
+                .parseInt(args[0]))));
 
         boolean tlsMode = Integer.parseInt(args[1]) == 1;
 
index 6bb9db7adb582602a8347e9ebf89de56dfef023d..f53de46df2707a9f1e8b9cb86e2d993b743ac2ce 100755 (executable)
@@ -37,6 +37,8 @@ public class Constants extends OCFConstants {
 
     public static final String GROUP_TABLE           = "GROUP_TABLE";
 
+    public static final String INVITE_TABLE          = "INVITE_TABLE";
+
     public static final String DEVICE_TABLE          = "DEVICE_TABLE";
 
     public static final String ACL_TABLE             = "ACL_TABLE";
@@ -71,6 +73,10 @@ public class Constants extends OCFConstants {
 
     public static final String KEYFIELD_EXPIRED_TIME = "expiredtime";
 
+    public static final String KEYFIELD_INVITE_USER  = "inviteUser";
+
+    public static final String KEYFIELD_INVITED_USER = "invitedUser";
+
     // Request payload key
 
     public static final String REQ_DEVICE_ID         = "di";
@@ -109,7 +115,9 @@ public class Constants extends OCFConstants {
 
     public static final String REQ_GTYPE_PUBLIC      = "Public";
 
-    public static final String REQ_CSR             = "csr";
+    public static final String REQ_CSR               = "csr";
+
+    public static final String REQ_INVITE            = "invite";
 
     // Response payload key
 
@@ -135,11 +143,15 @@ public class Constants extends OCFConstants {
 
     public static final String RESP_USER_LIST        = "ulist";
 
-    public static final String RESP_DEVICE_ID      = "di";
+    public static final String RESP_DEVICE_ID        = "di";
+
+    public static final String RESP_CERT             = "cert";
+
+    public static final String RESP_CACERT           = "cacert";
+
+    public static final String RESP_INVITE           = "invite";
 
-    public static final String RESP_CERT           = "cert";
-    
-    public static final String RESP_CACERT         = "cacert";
+    public static final String RESP_INVITED          = "invited";
 
     // static token type
 
index f424f9c9e244a3a9f6f8f69d0e0ecf14c3f6b419..06f3e62a49bae54f7a043c96408457c4cf088f57 100644 (file)
@@ -69,6 +69,7 @@ public class AccountDBManager {
         mongoDB.createTable(Constants.USER_TABLE);
         mongoDB.createTable(Constants.TOKEN_TABLE);
         mongoDB.createTable(Constants.GROUP_TABLE);
+        mongoDB.createTable(Constants.INVITE_TABLE);
         mongoDB.createTable(Constants.DEVICE_TABLE);
         mongoDB.createTable(Constants.ACL_TABLE);
         mongoDB.createTable(Constants.ACLTEMPLATE_TABLE);
@@ -95,6 +96,14 @@ public class AccountDBManager {
         mongoDB.createIndex(Constants.GROUP_TABLE, keys);
         keyField.put(Constants.GROUP_TABLE, keys);
 
+        keys = new ArrayList<>();
+        keys.add(Constants.KEYFIELD_INVITE_USER);
+        keys.add(Constants.KEYFIELD_GID);
+        keys.add(Constants.KEYFIELD_INVITED_USER);
+
+        mongoDB.createIndex(Constants.INVITE_TABLE, keys);
+        keyField.put(Constants.INVITE_TABLE, keys);
+
         keys = new ArrayList<>();
         keys.add(Constants.KEYFIELD_UUID);
         keys.add(Constants.KEYFIELD_DID);
diff --git a/cloud/account/src/main/java/org/iotivity/cloud/accountserver/db/InviteTable.java b/cloud/account/src/main/java/org/iotivity/cloud/accountserver/db/InviteTable.java
new file mode 100644 (file)
index 0000000..151c56f
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * //******************************************************************
+ * //
+ * // Copyright 2016 Samsung Electronics All Rights Reserved.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ * //
+ * // Licensed under the Apache License, Version 2.0 (the "License");
+ * // you may not use this file except in compliance with the License.
+ * // You may obtain a copy of the License at
+ * //
+ * //      http://www.apache.org/licenses/LICENSE-2.0
+ * //
+ * // Unless required by applicable law or agreed to in writing, software
+ * // distributed under the License is distributed on an "AS IS" BASIS,
+ * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * // See the License for the specific language governing permissions and
+ * // limitations under the License.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+package org.iotivity.cloud.accountserver.db;
+
+public class InviteTable {
+
+    String gid;
+    String inviteUser;
+    String invitedUser;
+
+    public InviteTable() {
+    }
+
+    public InviteTable(String inviteUser, String gid, String invitedUser) {
+        this.inviteUser = inviteUser;
+        this.gid = gid;
+        this.invitedUser = invitedUser;
+    }
+
+    public String getGid() {
+        return gid;
+    }
+
+    public void setGid(String gid) {
+        this.gid = gid;
+    }
+
+    public String getInviteUser() {
+        return inviteUser;
+    }
+
+    public void setInviteUser(String inviteUser) {
+        this.inviteUser = inviteUser;
+    }
+
+    public String getInvitedUser() {
+        return invitedUser;
+    }
+
+    public void setInvitedUser(String invitedUser) {
+        this.invitedUser = invitedUser;
+    }
+
+}
\ No newline at end of file
index 4fb9501c8c2539d4bd239e4d151f9338f7658f76..12d80d5564178979115d1572258b063f10748aa8 100644 (file)
@@ -145,8 +145,7 @@ public class AccountResource extends Resource {
                     "uid and search query param are null");
         }
 
-
-        return MessageBuilder.createResponse(request, ResponseStatus.CHANGED,
+        return MessageBuilder.createResponse(request, ResponseStatus.CONTENT,
                 ContentFormat.APPLICATION_CBOR,
                 mCbor.encodingPayloadToCbor(responsePayload));
     }
diff --git a/cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/invite/InviteManager.java b/cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/invite/InviteManager.java
new file mode 100644 (file)
index 0000000..05d4b68
--- /dev/null
@@ -0,0 +1,209 @@
+/*
+ * //******************************************************************
+ * //
+ * // Copyright 2016 Samsung Electronics All Rights Reserved.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ * //
+ * // Licensed under the Apache License, Version 2.0 (the "License");
+ * // you may not use this file except in compliance with the License.
+ * // You may obtain a copy of the License at
+ * //
+ * //      http://www.apache.org/licenses/LICENSE-2.0
+ * //
+ * // Unless required by applicable law or agreed to in writing, software
+ * // distributed under the License is distributed on an "AS IS" BASIS,
+ * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * // See the License for the specific language governing permissions and
+ * // limitations under the License.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+package org.iotivity.cloud.accountserver.resources.acl.invite;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.iotivity.cloud.accountserver.Constants;
+import org.iotivity.cloud.accountserver.db.AccountDBManager;
+import org.iotivity.cloud.accountserver.db.InviteTable;
+import org.iotivity.cloud.accountserver.util.TypeCastingManager;
+import org.iotivity.cloud.base.device.Device;
+import org.iotivity.cloud.base.protocols.IRequest;
+import org.iotivity.cloud.base.protocols.MessageBuilder;
+import org.iotivity.cloud.base.protocols.enums.ContentFormat;
+import org.iotivity.cloud.base.protocols.enums.ResponseStatus;
+import org.iotivity.cloud.util.Cbor;
+
+public class InviteManager {
+
+    private TypeCastingManager<InviteTable> mTypeInvite = new TypeCastingManager<>();
+
+    private class InviteSubscriber {
+        InviteSubscriber(Device subscriber, IRequest request) {
+            mSubscriber = subscriber;
+            mRequest = request;
+        }
+
+        public Device   mSubscriber;
+        public IRequest mRequest;
+    }
+
+    private HashMap<String, InviteSubscriber> mSubscribers = new HashMap<>();
+
+    public void addInvitation(String uid, String gid, String mid) {
+
+        InviteTable newInviteTable = new InviteTable(uid, gid, mid);
+
+        HashMap<String, Object> condition = new HashMap<>();
+        condition.put(Constants.KEYFIELD_INVITE_USER, uid);
+        condition.put(Constants.KEYFIELD_GID, gid);
+        condition.put(Constants.KEYFIELD_INVITED_USER, mid);
+
+        if (AccountDBManager.getInstance()
+                .selectRecord(Constants.INVITE_TABLE, condition).isEmpty()) {
+            AccountDBManager.getInstance().insertRecord(Constants.INVITE_TABLE,
+                    mTypeInvite.convertObjectToMap(newInviteTable));
+            notifyToSubscriber(uid);
+            notifyToSubscriber(mid);
+        }
+    }
+
+    public void deleteInvitation(String mid, String gid) {
+        HashMap<String, Object> condition = new HashMap<>();
+        condition.put(Constants.REQ_GROUP_ID, gid);
+        condition.put(Constants.KEYFIELD_INVITED_USER, mid);
+
+        InviteTable getInviteTable = new InviteTable();
+
+        List<HashMap<String, Object>> getInviteList = AccountDBManager
+                .getInstance().selectRecord(Constants.INVITE_TABLE, condition);
+
+        ArrayList<String> uidList = new ArrayList<>();
+        for (HashMap<String, Object> getInvite : getInviteList) {
+            getInviteTable = mTypeInvite.convertMaptoObject(getInvite,
+                    getInviteTable);
+            uidList.add(getInviteTable.getInviteUser());
+        }
+
+        AccountDBManager.getInstance().deleteRecord(Constants.INVITE_TABLE,
+                condition);
+
+        notifyToSubscriber(mid);
+        for (String uid : uidList) {
+            notifyToSubscriber(uid);
+        }
+    }
+
+    public void cancelInvitation(String uid, String gid, String mid) {
+
+        HashMap<String, Object> condition = new HashMap<>();
+
+        condition.put(Constants.REQ_GROUP_ID, gid);
+        condition.put(Constants.KEYFIELD_INVITED_USER, mid);
+        condition.put(Constants.KEYFIELD_INVITE_USER, uid);
+
+        AccountDBManager.getInstance().deleteRecord(Constants.INVITE_TABLE,
+                condition);
+
+        notifyToSubscriber(uid);
+        notifyToSubscriber(mid);
+    }
+
+    public HashMap<String, Object> getInvitationInfo(String uid) {
+        HashMap<String, Object> responsePayload = new HashMap<>();
+
+        ArrayList<Object> invitePayloadData = null;
+        ArrayList<Object> invitedPayloadData = null;
+
+        List<InviteTable> inviteList = getInviteTableList(
+                Constants.KEYFIELD_INVITE_USER, uid);
+        if (inviteList != null) {
+            invitePayloadData = new ArrayList<>();
+            for (InviteTable invite : inviteList) {
+                HashMap<String, String> inviteElement = new HashMap<>();
+                inviteElement.put(Constants.REQ_GROUP_ID, invite.getGid());
+                inviteElement.put(Constants.REQ_MEMBER,
+                        invite.getInvitedUser());
+                invitePayloadData.add(inviteElement);
+            }
+        }
+
+        List<InviteTable> invitedList = getInviteTableList(
+                Constants.KEYFIELD_INVITED_USER, uid);
+        if (invitedList != null) {
+            invitedPayloadData = new ArrayList<>();
+            for (InviteTable invited : invitedList) {
+                HashMap<String, String> invitedElement = new HashMap<>();
+                invitedElement.put(Constants.REQ_GROUP_ID, invited.getGid());
+                invitedElement.put(Constants.REQ_MEMBER,
+                        invited.getInviteUser());
+                invitedPayloadData.add(invitedElement);
+            }
+        }
+
+        responsePayload.put(Constants.RESP_INVITE, invitePayloadData);
+        responsePayload.put(Constants.RESP_INVITED, invitedPayloadData);
+
+        return responsePayload;
+    }
+
+    public HashMap<String, Object> addSubscriber(String uid, Device subscriber,
+            IRequest request) {
+
+        InviteSubscriber newSubscriber = new InviteSubscriber(subscriber,
+                request);
+        mSubscribers.put(uid, newSubscriber);
+
+        return getInvitationInfo(uid);
+    }
+
+    public HashMap<String, Object> removeSubscriber(String uid) {
+
+        if (mSubscribers.containsKey(uid)) {
+            mSubscribers.remove(uid);
+        }
+
+        return getInvitationInfo(uid);
+    }
+
+    private void notifyToSubscriber(String id) {
+
+        synchronized (mSubscribers) {
+            if (!mSubscribers.containsKey(id)) {
+                return;
+            }
+            Cbor<HashMap<String, Object>> cbor = new Cbor<>();
+            mSubscribers.get(id).mSubscriber.sendResponse(
+                    MessageBuilder.createResponse(mSubscribers.get(id).mRequest,
+                            ResponseStatus.CONTENT,
+                            ContentFormat.APPLICATION_CBOR,
+                            cbor.encodingPayloadToCbor(getInvitationInfo(id))));
+        }
+    }
+
+    private List<InviteTable> getInviteTableList(String property, String uid) {
+
+        InviteTable getInviteTable = new InviteTable();
+        ArrayList<InviteTable> inviteList = null;
+
+        HashMap<String, Object> condition = new HashMap<>();
+        condition.put(property, uid);
+        ArrayList<HashMap<String, Object>> mapInviteList = AccountDBManager
+                .getInstance().selectRecord(Constants.INVITE_TABLE, condition);
+        if (!mapInviteList.isEmpty()) {
+            inviteList = new ArrayList<>();
+        }
+
+        for (HashMap<String, Object> mapInviteTable : mapInviteList) {
+
+            getInviteTable = mTypeInvite.convertMaptoObject(mapInviteTable,
+                    getInviteTable);
+            inviteList.add(getInviteTable);
+        }
+        return inviteList;
+
+    }
+
+}
diff --git a/cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/invite/InviteResource.java b/cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/invite/InviteResource.java
new file mode 100644 (file)
index 0000000..080eafe
--- /dev/null
@@ -0,0 +1,157 @@
+/*
+ * //******************************************************************
+ * //
+ * // Copyright 2016 Samsung Electronics All Rights Reserved.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ * //
+ * // Licensed under the Apache License, Version 2.0 (the "License");
+ * // you may not use this file except in compliance with the License.
+ * // You may obtain a copy of the License at
+ * //
+ * //      http://www.apache.org/licenses/LICENSE-2.0
+ * //
+ * // Unless required by applicable law or agreed to in writing, software
+ * // distributed under the License is distributed on an "AS IS" BASIS,
+ * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * // See the License for the specific language governing permissions and
+ * // limitations under the License.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+package org.iotivity.cloud.accountserver.resources.acl.invite;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+
+import org.iotivity.cloud.accountserver.Constants;
+import org.iotivity.cloud.base.device.Device;
+import org.iotivity.cloud.base.exception.ServerException;
+import org.iotivity.cloud.base.exception.ServerException.BadRequestException;
+import org.iotivity.cloud.base.exception.ServerException.PreconditionFailedException;
+import org.iotivity.cloud.base.protocols.IRequest;
+import org.iotivity.cloud.base.protocols.IResponse;
+import org.iotivity.cloud.base.protocols.MessageBuilder;
+import org.iotivity.cloud.base.protocols.enums.ContentFormat;
+import org.iotivity.cloud.base.protocols.enums.ResponseStatus;
+import org.iotivity.cloud.base.resource.Resource;
+import org.iotivity.cloud.util.Cbor;
+
+public class InviteResource extends Resource {
+
+    private InviteManager                 mInviteManager = new InviteManager();
+
+    private Cbor<HashMap<String, Object>> mCbor          = new Cbor<>();
+
+    public InviteResource() {
+        super(Arrays.asList(Constants.PREFIX_WELL_KNOWN, Constants.PREFIX_OCF,
+                Constants.ACL_URI, Constants.INVITE_URI));
+    }
+
+    @Override
+    public void onDefaultRequestReceived(Device srcDevice, IRequest request)
+            throws ServerException {
+
+        IResponse response = null;
+
+        switch (request.getMethod()) {
+            case GET:
+                response = handleGetRequest(srcDevice, request);
+                break;
+            case POST:
+                response = handlePostRequest(request);
+                break;
+            case DELETE:
+                response = handleDeleteRequest(request);
+                break;
+            default:
+                throw new BadRequestException(request.getMethod()
+                        + " request type is not supported");
+        }
+
+        srcDevice.sendResponse(response);
+    }
+
+    private IResponse handleGetRequest(Device srcDevice, IRequest request)
+            throws ServerException {
+
+        checkQueryException(Constants.REQ_UUID_ID, request.getUriQueryMap());
+
+        String uid = request.getUriQueryMap().get(Constants.REQ_UUID_ID).get(0);
+        HashMap<String, Object> responsePayload = null;
+
+        switch (request.getObserve()) {
+            case NOTHING:
+                responsePayload = mInviteManager.getInvitationInfo(uid);
+                break;
+            case SUBSCRIBE:
+                responsePayload = mInviteManager.addSubscriber(uid, srcDevice,
+                        request);
+                break;
+            case UNSUBSCRIBE:
+                responsePayload = mInviteManager.removeSubscriber(uid);
+                break;
+            default:
+                break;
+        }
+
+        return MessageBuilder.createResponse(request, ResponseStatus.CONTENT,
+                ContentFormat.APPLICATION_CBOR,
+                mCbor.encodingPayloadToCbor(responsePayload));
+    }
+
+    @SuppressWarnings("unchecked")
+    private IResponse handlePostRequest(IRequest request)
+            throws ServerException {
+
+        HashMap<String, Object> payload = mCbor.parsePayloadFromCbor(
+                request.getPayload(), HashMap.class);
+
+        checkPayloadException(
+                Arrays.asList(Constants.REQ_UUID_ID, Constants.REQ_INVITE),
+                payload);
+
+        String uid = (String) payload.get(Constants.REQ_UUID_ID);
+        ArrayList<HashMap<String, String>> inviteList = (ArrayList<HashMap<String, String>>) payload
+                .get(Constants.REQ_INVITE);
+
+        for (HashMap<String, String> invite : inviteList) {
+
+            String gid = invite.get(Constants.REQ_GROUP_ID);
+            String mid = invite.get(Constants.REQ_MEMBER);
+
+            if (gid == null || mid == null) {
+
+                throw new PreconditionFailedException(
+                        "value of invite property is invalid");
+            }
+
+            mInviteManager.addInvitation(uid, gid, mid);
+        }
+
+        return MessageBuilder.createResponse(request, ResponseStatus.CHANGED);
+    }
+
+    private IResponse handleDeleteRequest(IRequest request)
+            throws ServerException {
+
+        HashMap<String, List<String>> queryParams = request.getUriQueryMap();
+
+        checkQueryException(Constants.REQ_GROUP_ID, queryParams);
+
+        String gid = queryParams.get(Constants.REQ_GROUP_ID).get(0);
+        String uid = queryParams.get(Constants.REQ_UUID_ID).get(0);
+
+        if (queryParams.get(Constants.REQ_MEMBER) == null) {
+            mInviteManager.deleteInvitation(uid, gid);
+        } else {
+            String mid = queryParams.get(Constants.REQ_MEMBER).get(0);
+            mInviteManager.cancelInvitation(uid, gid, mid);
+        }
+
+        return MessageBuilder.createResponse(request, ResponseStatus.DELETED);
+    }
+
+}
\ No newline at end of file
index c2902eb15ec686a0a094c8248194a9a0b26946b3..41f0e830378e7c47835c75245bd5336566dea29f 100755 (executable)
@@ -33,12 +33,13 @@ import org.iotivity.cloud.ciserver.resources.proxy.account.Account;
 import org.iotivity.cloud.ciserver.resources.proxy.account.AccountSession;
 import org.iotivity.cloud.ciserver.resources.proxy.account.Acl;
 import org.iotivity.cloud.ciserver.resources.proxy.account.AclGroup;
+import org.iotivity.cloud.ciserver.resources.proxy.account.AclInvite;
+import org.iotivity.cloud.ciserver.resources.proxy.account.Certificate;
 import org.iotivity.cloud.ciserver.resources.proxy.mq.MessageQueue;
 import org.iotivity.cloud.ciserver.resources.proxy.rd.DevicePresence;
 import org.iotivity.cloud.ciserver.resources.proxy.rd.ResourceDirectory;
 import org.iotivity.cloud.ciserver.resources.proxy.rd.ResourceFind;
 import org.iotivity.cloud.ciserver.resources.proxy.rd.ResourcePresence;
-import org.iotivity.cloud.ciserver.resources.proxy.account.Certificate;
 import org.iotivity.cloud.util.Log;
 
 public class CloudInterfaceServer {
@@ -56,15 +57,12 @@ public class CloudInterfaceServer {
 
         boolean tlsMode = Integer.parseInt(args[7]) == 1;
 
-        ConnectorPool.addConnection("rd",
-                new InetSocketAddress(args[1], Integer.parseInt(args[2])),
-                tlsMode);
-        ConnectorPool.addConnection("account",
-                new InetSocketAddress(args[3], Integer.parseInt(args[4])),
-                tlsMode);
-        ConnectorPool.addConnection("mq",
-                new InetSocketAddress(args[5], Integer.parseInt(args[6])),
-                tlsMode);
+        ConnectorPool.addConnection("rd", new InetSocketAddress(args[1],
+                Integer.parseInt(args[2])), tlsMode);
+        ConnectorPool.addConnection("account", new InetSocketAddress(args[3],
+                Integer.parseInt(args[4])), tlsMode);
+        ConnectorPool.addConnection("mq", new InetSocketAddress(args[5],
+                Integer.parseInt(args[6])), tlsMode);
 
         DeviceServerSystem deviceServer = new DeviceServerSystem();
 
@@ -78,6 +76,7 @@ public class CloudInterfaceServer {
         Acl aclHandler = new Acl();
         AclGroup aclGroupHandler = new AclGroup();
         Certificate certHandler = new Certificate();
+        AclInvite aclInviteHandler = new AclInvite();
 
         CoapDevicePool devicePool = deviceServer.getDevicePool();
 
@@ -101,15 +100,17 @@ public class CloudInterfaceServer {
 
         deviceServer.addResource(certHandler);
 
-        KeepAliveResource resKeepAlive = new KeepAliveResource(
-                new int[] { 1, 2, 4, 8 });
+        deviceServer.addResource(aclInviteHandler);
+
+        KeepAliveResource resKeepAlive = new KeepAliveResource(new int[] { 1,
+                2, 4, 8 });
 
         deviceServer.addResource(resKeepAlive);
 
         deviceServer.addResource(new DiResource(devicePool));
 
-        deviceServer.addServer(new CoapServer(
-                new InetSocketAddress(Integer.parseInt(args[0]))));
+        deviceServer.addServer(new CoapServer(new InetSocketAddress(Integer
+                .parseInt(args[0]))));
 
         // deviceServer.addServer(new HttpServer(new InetSocketAddress(8080)));
 
index c0512c0b792a9e02ef490456bc5f50ae5508b162..dd651eeb812ce797e2a3fc2a6144ef613126e332 100644 (file)
@@ -47,15 +47,13 @@ public class Account extends Resource {
     public void onDefaultRequestReceived(Device srcDevice, IRequest request)
             throws ServerException {
         if (request.getMethod().equals(RequestMethod.DELETE)) {
-            String di = request.getUriQueryMap().get(Constants.REQ_DEVICE_ID)
-                    .get(0);
-            StringBuffer uriQuery = new StringBuffer();
-            uriQuery.append(Constants.REQ_DEVICE_ID + "=" + di);
-            uriQuery.append(";");
-            uriQuery.append(Constants.USER_ID + "=" + srcDevice.getUserId());
-
-            request = MessageBuilder.modifyRequest(request, null,
-                    uriQuery.toString(), null, null);
+            StringBuffer additionalQuery = new StringBuffer();
+            additionalQuery
+                    .append(Constants.USER_ID + "=" + srcDevice.getUserId());
+            String uriQuery = request.getUriQuery() + ";"
+                    + additionalQuery.toString();
+            request = MessageBuilder.modifyRequest(request, null, uriQuery,
+                    null, null);
         }
         mAuthServer.sendRequest(request, srcDevice);
     }
index a7a14fb7bb1e8b0b46e4575f8eb7481972d4062f..6168556ccd3c45ff0615820a24c2d5ba541e1369 100644 (file)
@@ -62,9 +62,7 @@ public class AclGroup extends Resource {
                     payloadData.put(Constants.REQ_GROUP_MASTER_ID,
                             srcDevice.getUserId());
                 } else {
-                    if (!payloadData.containsKey(Constants.REQ_DEVICE_LIST)
-                            && !payloadData
-                                    .containsKey(Constants.REQ_MEMBER_LIST)) {
+                    if (payloadData.isEmpty()) {
                         payloadData.put(Constants.REQ_MEMBER_LIST,
                                 Arrays.asList(srcDevice.getUserId()));
                     }
@@ -81,13 +79,12 @@ public class AclGroup extends Resource {
                         uriGetQuery.toString(), null, null);
                 break;
             case DELETE:
-                String uriDeleteQuery;
                 StringBuffer additionalQuery = new StringBuffer();
                 if (getUriPathSegments()
                         .containsAll(request.getUriPathSegments())) {
                     additionalQuery.append(Constants.REQ_GROUP_MASTER_ID + "="
                             + srcDevice.getUserId());
-                    uriDeleteQuery = request.getUriQuery() + ";"
+                    String uriDeleteQuery = request.getUriQuery() + ";"
                             + additionalQuery.toString();
                     request = MessageBuilder.modifyRequest(request, null,
                             uriDeleteQuery, null, null);
diff --git a/cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/proxy/account/AclInvite.java b/cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/proxy/account/AclInvite.java
new file mode 100644 (file)
index 0000000..46c28f5
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * //******************************************************************
+ * //
+ * // Copyright 2016 Samsung Electronics All Rights Reserved.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ * //
+ * // Licensed under the Apache License, Version 2.0 (the "License");
+ * // you may not use this file except in compliance with the License.
+ * // You may obtain a copy of the License at
+ * //
+ * //      http://www.apache.org/licenses/LICENSE-2.0
+ * //
+ * // Unless required by applicable law or agreed to in writing, software
+ * // distributed under the License is distributed on an "AS IS" BASIS,
+ * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * // See the License for the specific language governing permissions and
+ * // limitations under the License.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+package org.iotivity.cloud.ciserver.resources.proxy.account;
+
+import java.util.Arrays;
+import java.util.HashMap;
+
+import org.iotivity.cloud.base.connector.ConnectorPool;
+import org.iotivity.cloud.base.device.Device;
+import org.iotivity.cloud.base.device.IRequestChannel;
+import org.iotivity.cloud.base.exception.ServerException;
+import org.iotivity.cloud.base.protocols.IRequest;
+import org.iotivity.cloud.base.protocols.MessageBuilder;
+import org.iotivity.cloud.base.protocols.enums.ContentFormat;
+import org.iotivity.cloud.base.resource.Resource;
+import org.iotivity.cloud.ciserver.Constants;
+import org.iotivity.cloud.util.Cbor;
+
+public class AclInvite extends Resource {
+
+    IRequestChannel mAuthServer = null;
+
+    public AclInvite() {
+        super(Arrays.asList(Constants.PREFIX_WELL_KNOWN, Constants.PREFIX_OCF,
+                Constants.ACL_URI, Constants.INVITE_URI));
+
+        mAuthServer = ConnectorPool.getConnection("account");
+
+    }
+
+    @Override
+    public void onDefaultRequestReceived(Device srcDevice, IRequest request)
+            throws ServerException {
+
+        switch (request.getMethod()) {
+
+            case POST:
+
+                Cbor<HashMap<String, Object>> cbor = new Cbor<>();
+                HashMap<String, Object> payload = cbor.parsePayloadFromCbor(
+                        request.getPayload(), HashMap.class);
+
+                payload.put(Constants.USER_ID, srcDevice.getUserId());
+
+                request = MessageBuilder.modifyRequest(request, null, null,
+                        ContentFormat.APPLICATION_CBOR,
+                        cbor.encodingPayloadToCbor(payload));
+                break;
+
+            default:
+
+                StringBuffer additionalQuery = new StringBuffer();
+                additionalQuery.append(
+                        Constants.USER_ID + "=" + srcDevice.getUserId());
+
+                String uriQuery = additionalQuery.toString()
+                        + (request.getUriQuery() != null
+                                ? (";" + request.getUriQuery()) : "");
+                request = MessageBuilder.modifyRequest(request, null, uriQuery,
+                        null, null);
+
+                break;
+        }
+
+        mAuthServer.sendRequest(request, srcDevice);
+    }
+
+}
\ No newline at end of file
index 3b690deef9ed3046fc65c38a2f488c88402e039b..8f0fed75dcdfcb564638a8404ac8272101d95353 100644 (file)
@@ -30,13 +30,12 @@ import org.iotivity.cloud.base.device.Device;
 import org.iotivity.cloud.base.device.IRequestChannel;
 import org.iotivity.cloud.base.device.IResponseEventHandler;
 import org.iotivity.cloud.base.exception.ClientException;
-import org.iotivity.cloud.base.exception.ClientException.BadResponseException;
 import org.iotivity.cloud.base.exception.ServerException;
-import org.iotivity.cloud.base.exception.ServerException.UnAuthorizedException;
 import org.iotivity.cloud.base.protocols.IRequest;
 import org.iotivity.cloud.base.protocols.IResponse;
 import org.iotivity.cloud.base.protocols.MessageBuilder;
 import org.iotivity.cloud.base.protocols.enums.RequestMethod;
+import org.iotivity.cloud.base.protocols.enums.ResponseStatus;
 import org.iotivity.cloud.base.resource.Resource;
 import org.iotivity.cloud.ciserver.Constants;
 import org.iotivity.cloud.util.Cbor;
@@ -69,57 +68,74 @@ public class DevicePresence extends Resource {
                 throws ClientException {
             switch (response.getStatus()) {
                 case CONTENT:
-                    StringBuilder additionalQuery = new StringBuilder();
-
                     HashMap<String, Object> payloadData = mCbor
                             .parsePayloadFromCbor(response.getPayload(),
                                     HashMap.class);
-                    List<String> deviceList = (List<String>) payloadData
-                            .get(Constants.REQ_DEVICE_LIST);
-                    if (deviceList != null) {
-                        int index = deviceList.size();
-                        if (mRequest.getUriQuery() == null) {
-                            for (String device : deviceList) {
-                                if (!device.equals(mSrcDevice.getDeviceId())) {
-                                    additionalQuery
-                                            .append(Constants.REQ_DEVICE_ID
-                                                    + "=" + device);
-                                    if (--index > 0) {
-                                        additionalQuery.append(";");
-                                    }
-                                }
-                            }
-                            String uriQuery = (mRequest.getUriQuery() == null
-                                    ? "" : mRequest.getUriQuery()) + ";"
-                                    + additionalQuery.toString();
-                            mRequest = MessageBuilder.modifyRequest(mRequest,
-                                    null, uriQuery, null, null);
-                        } else {
-                            List<String> originDeviceList = mRequest
-                                    .getUriQueryMap()
-                                    .get(Constants.REQ_DEVICE_ID);
-                            if (originDeviceList == null) {
-                                throw new UnAuthorizedException(
-                                        "device is not include in group");
-                            }
-                            for (String device : originDeviceList) {
-                                if (!deviceList.contains(device)) {
-                                    throw new UnAuthorizedException(device
-                                            + " device is not include in group");
-                                }
-                            }
+
+                    if (mRequest.getUriQuery() != null
+                            && mRequest.getUriQueryMap()
+                                    .containsKey(Constants.REQ_DEVICE_ID)) {
+                        if (!getResponseDeviceList(payloadData)
+                                .containsAll(mRequest.getUriQueryMap()
+                                        .get(Constants.REQ_DEVICE_ID))) {
+                            mSrcDevice.sendResponse(
+                                    MessageBuilder.createResponse(mRequest,
+                                            ResponseStatus.BAD_REQUEST));
                         }
-                        mRDServer.sendRequest(mRequest, mSrcDevice);
-                    } else
-                        throw new UnAuthorizedException(
-                                "There is not device in group");
+                    } else {
+                        String additionalQuery = makeAdditionalQuery(
+                                payloadData, mSrcDevice.getDeviceId());
+                        if (additionalQuery == null) {
+                            mSrcDevice.sendResponse(
+                                    MessageBuilder.createResponse(mRequest,
+                                            ResponseStatus.BAD_REQUEST));
+                            return;
+                        }
+                        mRequest = MessageBuilder.modifyRequest(mRequest, null,
+                                additionalQuery
+                                        + (mRequest.getUriQuery() != null
+                                                ? ";" + mRequest.getUriQuery()
+                                                : ""),
+                                null, null);
+                    }
+
+                    mRDServer.sendRequest(mRequest, mSrcDevice);
                     break;
                 default:
-                    throw new BadResponseException(
-                            response.getStatus().toString()
-                                    + " response type is not supported");
+                    mSrcDevice.sendResponse(MessageBuilder.createResponse(
+                            mRequest, ResponseStatus.BAD_REQUEST));
             }
         }
+
+        private String makeAdditionalQuery(HashMap<String, Object> payloadData,
+                String did) {
+
+            StringBuilder additionalQuery = new StringBuilder();
+
+            List<String> deviceList = getResponseDeviceList(payloadData);
+
+            if (deviceList.isEmpty()) {
+                return null;
+            }
+
+            int index = deviceList.size();
+            for (String device : deviceList) {
+                additionalQuery.append(Constants.REQ_DEVICE_ID + "=" + device);
+                if (--index > 0) {
+                    additionalQuery.append(";");
+                }
+            }
+            return additionalQuery.toString();
+        }
+
+        @SuppressWarnings("unchecked")
+        private List<String> getResponseDeviceList(
+                HashMap<String, Object> payloadData) {
+            List<String> deviceList = (List<String>) payloadData
+                    .get(Constants.REQ_DEVICE_LIST);
+
+            return deviceList;
+        }
     }
 
     @Override
index 00312b5718f258f730e74dd49385ac08a7247d11..635a1b028bb731cc7a469988448b569b30de955b 100644 (file)
@@ -30,13 +30,12 @@ import org.iotivity.cloud.base.device.Device;
 import org.iotivity.cloud.base.device.IRequestChannel;
 import org.iotivity.cloud.base.device.IResponseEventHandler;
 import org.iotivity.cloud.base.exception.ClientException;
-import org.iotivity.cloud.base.exception.ClientException.BadResponseException;
 import org.iotivity.cloud.base.exception.ServerException;
-import org.iotivity.cloud.base.exception.ServerException.UnAuthorizedException;
 import org.iotivity.cloud.base.protocols.IRequest;
 import org.iotivity.cloud.base.protocols.IResponse;
 import org.iotivity.cloud.base.protocols.MessageBuilder;
 import org.iotivity.cloud.base.protocols.enums.RequestMethod;
+import org.iotivity.cloud.base.protocols.enums.ResponseStatus;
 import org.iotivity.cloud.base.resource.Resource;
 import org.iotivity.cloud.ciserver.Constants;
 import org.iotivity.cloud.util.Cbor;
@@ -68,57 +67,74 @@ public class ResourceFind extends Resource {
                 throws ClientException {
             switch (response.getStatus()) {
                 case CONTENT:
-                    StringBuilder additionalQuery = new StringBuilder();
-
                     HashMap<String, Object> payloadData = mCbor
                             .parsePayloadFromCbor(response.getPayload(),
                                     HashMap.class);
-                    List<String> deviceList = (List<String>) payloadData
-                            .get(Constants.REQ_DEVICE_LIST);
-                    if (deviceList != null) {
-                        int index = deviceList.size();
-                        if (mRequest.getUriQuery() == null) {
-                            for (String device : deviceList) {
-                                if (!device.equals(mSrcDevice.getDeviceId())) {
-                                    additionalQuery
-                                            .append(Constants.REQ_DEVICE_ID
-                                                    + "=" + device);
-                                    if (--index > 0) {
-                                        additionalQuery.append(";");
-                                    }
-                                }
-                            }
-                            String uriQuery = (mRequest.getUriQuery() == null
-                                    ? "" : mRequest.getUriQuery()) + ";"
-                                    + additionalQuery.toString();
-                            mRequest = MessageBuilder.modifyRequest(mRequest,
-                                    null, uriQuery, null, null);
-                        } else {
-                            List<String> originDeviceList = mRequest
-                                    .getUriQueryMap()
-                                    .get(Constants.REQ_DEVICE_ID);
-                            if (originDeviceList == null) {
-                                throw new UnAuthorizedException(
-                                        "device is not include in group");
-                            }
-                            for (String device : originDeviceList) {
-                                if (!deviceList.contains(device)) {
-                                    throw new UnAuthorizedException(device
-                                            + " device is not include in group");
-                                }
-                            }
+
+                    if (mRequest.getUriQuery() != null
+                            && mRequest.getUriQueryMap()
+                                    .containsKey(Constants.REQ_DEVICE_ID)) {
+                        if (!getResponseDeviceList(payloadData)
+                                .containsAll(mRequest.getUriQueryMap()
+                                        .get(Constants.REQ_DEVICE_ID))) {
+                            mSrcDevice.sendResponse(
+                                    MessageBuilder.createResponse(mRequest,
+                                            ResponseStatus.BAD_REQUEST));
                         }
-                        mRDServer.sendRequest(mRequest, mSrcDevice);
-                    } else
-                        throw new UnAuthorizedException(
-                                "There is not device in group");
+                    } else {
+                        String additionalQuery = makeAdditionalQuery(
+                                payloadData, mSrcDevice.getDeviceId());
+                        if (additionalQuery == null) {
+                            mSrcDevice.sendResponse(
+                                    MessageBuilder.createResponse(mRequest,
+                                            ResponseStatus.BAD_REQUEST));
+                            return;
+                        }
+                        mRequest = MessageBuilder.modifyRequest(mRequest, null,
+                                additionalQuery
+                                        + (mRequest.getUriQuery() != null
+                                                ? ";" + mRequest.getUriQuery()
+                                                : ""),
+                                null, null);
+                    }
+
+                    mRDServer.sendRequest(mRequest, mSrcDevice);
                     break;
                 default:
-                    throw new BadResponseException(
-                            response.getStatus().toString()
-                                    + " response type is not supported");
+                    mSrcDevice.sendResponse(MessageBuilder.createResponse(
+                            mRequest, ResponseStatus.BAD_REQUEST));
             }
         }
+
+        private String makeAdditionalQuery(HashMap<String, Object> payloadData,
+                String did) {
+
+            StringBuilder additionalQuery = new StringBuilder();
+
+            List<String> deviceList = getResponseDeviceList(payloadData);
+
+            if (deviceList.isEmpty()) {
+                return null;
+            }
+
+            int index = deviceList.size();
+            for (String device : deviceList) {
+                additionalQuery.append(Constants.REQ_DEVICE_ID + "=" + device);
+                if (--index > 0) {
+                    additionalQuery.append(";");
+                }
+            }
+            return additionalQuery.toString();
+        }
+
+        @SuppressWarnings("unchecked")
+        private List<String> getResponseDeviceList(
+                HashMap<String, Object> payloadData) {
+            List<String> deviceList = (List<String>) payloadData
+                    .get(Constants.REQ_DEVICE_LIST);
+
+            return deviceList;
+        }
     }
 
     @Override
index 53708e549e4336b2b25de7f202d0bb89def3f8ea..e87da65c5155fb5297dee16588146c411f23048d 100644 (file)
@@ -30,13 +30,12 @@ import org.iotivity.cloud.base.device.Device;
 import org.iotivity.cloud.base.device.IRequestChannel;
 import org.iotivity.cloud.base.device.IResponseEventHandler;
 import org.iotivity.cloud.base.exception.ClientException;
-import org.iotivity.cloud.base.exception.ClientException.BadResponseException;
 import org.iotivity.cloud.base.exception.ServerException;
-import org.iotivity.cloud.base.exception.ServerException.UnAuthorizedException;
 import org.iotivity.cloud.base.protocols.IRequest;
 import org.iotivity.cloud.base.protocols.IResponse;
 import org.iotivity.cloud.base.protocols.MessageBuilder;
 import org.iotivity.cloud.base.protocols.enums.RequestMethod;
+import org.iotivity.cloud.base.protocols.enums.ResponseStatus;
 import org.iotivity.cloud.base.resource.Resource;
 import org.iotivity.cloud.ciserver.Constants;
 import org.iotivity.cloud.util.Cbor;
@@ -68,57 +67,74 @@ public class ResourcePresence extends Resource {
                 throws ClientException {
             switch (response.getStatus()) {
                 case CONTENT:
-                    StringBuilder additionalQuery = new StringBuilder();
-
                     HashMap<String, Object> payloadData = mCbor
                             .parsePayloadFromCbor(response.getPayload(),
                                     HashMap.class);
-                    List<String> deviceList = (List<String>) payloadData
-                            .get(Constants.REQ_DEVICE_LIST);
-                    if (deviceList != null) {
-                        int index = deviceList.size();
-                        if (mRequest.getUriQuery() == null) {
-                            for (String device : deviceList) {
-                                if (!device.equals(mSrcDevice.getDeviceId())) {
-                                    additionalQuery
-                                            .append(Constants.REQ_DEVICE_ID
-                                                    + "=" + device);
-                                    if (--index > 0) {
-                                        additionalQuery.append(";");
-                                    }
-                                }
-                            }
-                            String uriQuery = (mRequest.getUriQuery() == null
-                                    ? "" : mRequest.getUriQuery()) + ";"
-                                    + additionalQuery.toString();
-                            mRequest = MessageBuilder.modifyRequest(mRequest,
-                                    null, uriQuery, null, null);
-                        } else {
-                            List<String> originDeviceList = mRequest
-                                    .getUriQueryMap()
-                                    .get(Constants.REQ_DEVICE_ID);
-                            if (originDeviceList == null) {
-                                throw new UnAuthorizedException(
-                                        "device is not include in group");
-                            }
-                            for (String device : originDeviceList) {
-                                if (!deviceList.contains(device)) {
-                                    throw new UnAuthorizedException(device
-                                            + " device is not include in group");
-                                }
-                            }
+
+                    if (mRequest.getUriQuery() != null
+                            && mRequest.getUriQueryMap()
+                                    .containsKey(Constants.REQ_DEVICE_ID)) {
+                        if (!getResponseDeviceList(payloadData)
+                                .containsAll(mRequest.getUriQueryMap()
+                                        .get(Constants.REQ_DEVICE_ID))) {
+                            mSrcDevice.sendResponse(
+                                    MessageBuilder.createResponse(mRequest,
+                                            ResponseStatus.BAD_REQUEST));
                         }
-                        mRDServer.sendRequest(mRequest, mSrcDevice);
-                    } else
-                        throw new UnAuthorizedException(
-                                "There is not device in group");
+                    } else {
+                        String additionalQuery = makeAdditionalQuery(
+                                payloadData, mSrcDevice.getDeviceId());
+                        if (additionalQuery == null) {
+                            mSrcDevice.sendResponse(
+                                    MessageBuilder.createResponse(mRequest,
+                                            ResponseStatus.BAD_REQUEST));
+                            return;
+                        }
+                        mRequest = MessageBuilder.modifyRequest(mRequest, null,
+                                additionalQuery
+                                        + (mRequest.getUriQuery() != null
+                                                ? ";" + mRequest.getUriQuery()
+                                                : ""),
+                                null, null);
+                    }
+
+                    mRDServer.sendRequest(mRequest, mSrcDevice);
                     break;
                 default:
-                    throw new BadResponseException(
-                            response.getStatus().toString()
-                                    + " response type is not supported");
+                    mSrcDevice.sendResponse(MessageBuilder.createResponse(
+                            mRequest, ResponseStatus.BAD_REQUEST));
             }
         }
+
+        private String makeAdditionalQuery(HashMap<String, Object> payloadData,
+                String did) {
+
+            StringBuilder additionalQuery = new StringBuilder();
+
+            List<String> deviceList = getResponseDeviceList(payloadData);
+
+            if (deviceList.isEmpty()) {
+                return null;
+            }
+
+            int index = deviceList.size();
+            for (String device : deviceList) {
+                additionalQuery.append(Constants.REQ_DEVICE_ID + "=" + device);
+                if (--index > 0) {
+                    additionalQuery.append(";");
+                }
+            }
+            return additionalQuery.toString();
+        }
+
+        @SuppressWarnings("unchecked")
+        private List<String> getResponseDeviceList(
+                HashMap<String, Object> payloadData) {
+            List<String> deviceList = (List<String>) payloadData
+                    .get(Constants.REQ_DEVICE_LIST);
+
+            return deviceList;
+        }
     }
 
     @Override
index da358acd2b5a69caa63304ebba581cbc669aab02..da0232da964364f2b847607ce64b8526b88adf39 100755 (executable)
@@ -23,31 +23,31 @@ package org.iotivity.cloud.base;
 
 public class OCFConstants {
     /* resource Interface for keep-alive */
-    public static final String DEFAULT_INTERFACE = "oic.if.baseline";
+    public static final String DEFAULT_INTERFACE   = "oic.if.baseline";
 
-    public static final String LINK_INTERFACE = "oic.if.ll";
+    public static final String LINK_INTERFACE      = "oic.if.ll";
 
-    public static final String PREFIX_WELL_KNOWN = ".well-known";
+    public static final String PREFIX_WELL_KNOWN   = ".well-known";
 
-    public static final String PREFIX_OCF = "ocf";
+    public static final String PREFIX_OCF          = "ocf";
 
-    public static final String PREFIX_OIC = "oic";
+    public static final String PREFIX_OIC          = "oic";
 
-    public static final String RS_INTERFACE = "if";
+    public static final String RS_INTERFACE        = "if";
 
     /* resource url for account */
-    public static final String ACCOUNT_URI = "account";
+    public static final String ACCOUNT_URI         = "account";
 
-    public static final String SESSION_URI = "session";
+    public static final String SESSION_URI         = "session";
 
-    public static final String DEVICE_URI = "device";
+    public static final String DEVICE_URI          = "device";
 
-    public static final String TOKEN_REFRESH_URI = "tokenrefresh";
+    public static final String TOKEN_REFRESH_URI   = "tokenrefresh";
 
     /* resource url for acl */
-    public static final String CREDPROV_URI = "credprov";
+    public static final String CREDPROV_URI        = "credprov";
 
-    public static final String CERT_URI = "cert";
+    public static final String CERT_URI            = "cert";
 
     /* resource url for acl */
     public static final String ACL_URI             = "acl";
@@ -58,31 +58,32 @@ public class OCFConstants {
 
     public static final String ID_URI              = "id";
 
+    public static final String INVITE_URI          = "invite";
+
     /* resource uri to publish, update, delete resource info */
-    public static final String RD_URI = "rd";
+    public static final String RD_URI              = "rd";
 
     /* resource uri for keep-alive */
-    public static final String KEEP_ALIVE_URI = "ping";
+    public static final String KEEP_ALIVE_URI      = "ping";
 
     /* resource uri to discover resource info */
-    public static final String WELL_KNOWN_URI = "res";
+    public static final String WELL_KNOWN_URI      = "res";
 
     /* resource uri for resource presence */
-    public static final String RES_PRESENCE_URI = "ad";
+    public static final String RES_PRESENCE_URI    = "ad";
 
     /* resource uri for device presence */
     public static final String DEVICE_PRESENCE_URI = "prs";
 
     /* resource uri for message queue */
-    public static final String MQ_BROKER_URI = "ps";
-    public static final String MQ_BROKER_RT = "oic.wk.ps";
+    public static final String MQ_BROKER_URI       = "ps";
 
     /* file path for tls communication - Modify filePath to yours */
-    public static final String ROOT_CERT_FILE = "./rootca.crt";
+    public static final String ROOT_CERT_FILE      = "./rootca.crt";
 
-    public static final String CLOUD_CERT_FILE = "./iotivitycloud.crt";
+    public static final String CLOUD_CERT_FILE     = "./iotivitycloud.crt";
 
-    public static final String CLOUD_KEY_FILE = "./iotivitycloud.key";
+    public static final String CLOUD_KEY_FILE      = "./iotivitycloud.key";
 
     /* cloud uuid */
     public static final String CLOUD_UUID          = "2a6085d1-815d-4277-baba-4e4e4df91308";
index 91e3df8e031f70039a790c55c3716df8f03943bc..9e2a503a4a2b2f62c107f6878e22775c773b640e 100644 (file)
@@ -72,7 +72,7 @@ public abstract class Message implements IRequest, IResponse {
         for (byte[] querySegment : uri_query) {
             uriQuery.append(new String(querySegment, StandardCharsets.UTF_8));
             if (--nItem > 0) {
-                uriQuery.append('&');
+                uriQuery.append(';');
             }
         }
         return uriQuery.toString();