import org.iotivity.cloud.base.exception.ServerException.BadRequestException;
public class GroupTable {
- // TODO add doxygen
private String gid = null;
private String gname = null;
private String owner = null;
}
storeGroupInfo(uid, gid, gname, parent);
- return makePostResponse(gid, gname);
+ return makePostResponse(uid, gid, gname, parent);
}
- private HashMap<String, Object> makePostResponse(String gid, String gname) {
+ private HashMap<String, Object> makePostResponse(String uid, String gid,
+ String gname, String parent) {
HashMap<String, Object> response = new HashMap<>();
response.put(Constants.KEYFIELD_GID, gid);
response.put(Constants.KEYFIELD_GROUP_NAME, gname);
+ response.put(Constants.KEYFIELD_GROUP_OWNER, uid);
+ response.put(Constants.KEYFIELD_GROUP_MEMBERS, Arrays.asList(uid));
+ if (parent != null) {
+ response.put(Constants.KEYFIELD_GROUP_PARENT, parent);
+ }
Log.d("Group post response : " + response.toString());
* member uuid list
*/
public void deleteMembersFromGroup(String gid, ArrayList<String> members) {
- // delete devices owned by deleted members
GroupTable groupTable = getGroupTable(gid);
ArrayList<String> devices = groupTable.getDevices();
- ArrayList<String> deletedDevices = new ArrayList<String>();
- for (String device : devices) {
- if (members.contains(findDeviceOwner(device))) {
- deletedDevices.add(device);
+ if (devices != null) {
+ // delete devices owned by deleted members
+ ArrayList<String> deletedDevices = new ArrayList<String>();
+ for (String device : devices) {
+ if (members.contains(findDeviceOwner(device))) {
+ deletedDevices.add(device);
+ }
}
+ deleteDevicesFromGroup(gid, deletedDevices);
}
- deleteDevicesFromGroup(gid, deletedDevices);
-
deleteProperties(gid, Constants.KEYFIELD_GROUP_MEMBERS, members);
deleteProperties(gid, Constants.KEYFIELD_GROUP_MASTERS, members);
}
public <T> ArrayList<T> getAddPropertyValues(String gid, String property,
ArrayList<T> values) {
GroupTable groupTable = getGroupTable(gid);
+ if (groupTable == null) {
+ throw new BadRequestException("group " + gid + " does not exist");
+ }
ArrayList<T> propertyValues = groupTable.getPropertyValue(property);
ArrayList<T> addedValues = new ArrayList<>();
for (int i = 0; i < values.size(); i++) {
public <T> ArrayList<T> getDeletePropertyValues(String gid, String property,
ArrayList<T> values) {
GroupTable groupTable = getGroupTable(gid);
+ if (groupTable == null) {
+ throw new BadRequestException("group " + gid + " does not exist");
+ }
ArrayList<T> propertyValues = groupTable.getPropertyValue(property);
ArrayList<T> deletedValues = new ArrayList<>();
for (int i = 0; i < propertyValues.size(); i++) {
* user uuid
*/
public void verifyGetRequestAuthz(String gid, String mid) {
- verifyMemberExistanceInGroup(gid, mid);
+ verifyMemberExistenceInGroup(gid, mid);
}
/**
String parentGid = groupTable.getParent();
// delete subgroup ID of the parent group
if (parentGid != null && !parentGid.isEmpty()) {
- ArrayList<Object> gidList = new ArrayList<Object>();
- gidList.add(gid);
+ ArrayList<Object> gidList = new ArrayList<Object>(
+ Arrays.asList(gid));
deleteProperties(parentGid, Constants.KEYFIELD_GROUP_SUBGROUPS,
gidList);
}
}
}
- private void verifyMemberExistanceInGroup(String gid, String mid) {
+ private void verifyMemberExistenceInGroup(String gid, String mid) {
GroupTable groupTable = getGroupTable(gid);
+ if (groupTable == null) {
+ throw new BadRequestException("group " + gid + " does not exist");
+ }
if (!groupTable.getMembers().contains(mid)) {
throw new BadRequestException("uid is not a member of the group");
}
case Constants.KEYFIELD_GROUP_DEVICES:
verifyDeviceOwner(mid,
(ArrayList<String>) properties.get(key));
- verifyExistanceInParentGroup(gid, key,
+ verifyExistenceInParentGroup(gid, key,
(ArrayList<Object>) properties.get(key));
break;
case Constants.KEYFIELD_GROUP_RESOURCES:
verifyResourceOwner(mid,
(ArrayList<HashMap<String, Object>>) properties
.get(key));
- verifyExistanceInParentGroup(gid, key,
- filterResourceExistanceInParentGroupDeviceProperty(
+ verifyExistenceInParentGroup(gid, key,
+ filterResourceExistenceInParentGroupDeviceProperty(
gid,
(ArrayList<HashMap<String, Object>>) properties
.get(key)));
case Constants.KEYFIELD_GROUP_MASTERS:
// TODO verify if members are registered to the Account user
// DB
- verifyExistanceInParentGroup(gid,
+ verifyExistenceInParentGroup(gid,
Constants.KEYFIELD_GROUP_MEMBERS,
(ArrayList<Object>) properties.get(key));
break;
throw new BadRequestException("cannot remove owner Id");
}
case Constants.KEYFIELD_GROUP_MASTERS:
- verifyExistanceInParentGroup(gid, key,
+ verifyExistenceInParentGroup(gid, key,
(ArrayList<Object>) properties.get(key));
break;
default:
}
}
- private ArrayList<HashMap<String, Object>> filterResourceExistanceInParentGroupDeviceProperty(
+ private ArrayList<HashMap<String, Object>> filterResourceExistenceInParentGroupDeviceProperty(
String gid, ArrayList<HashMap<String, Object>> resources) {
GroupTable parentGroupTable = getParentGroupTable(gid);
if (parentGroupTable == null) {
}
}
- private <T> void verifyExistanceInParentGroup(String gid, String property,
+ private <T> void verifyExistenceInParentGroup(String gid, String property,
ArrayList<T> values) {
GroupTable parentGroupTable = getParentGroupTable(gid);
if (parentGroupTable == null) {
.getPropertyValue(property);
if (groupValues == null) {
throw new BadRequestException(
- "verifying parent group existance failed");
+ "verifying parent group Existence failed");
}
if (!groupValues.containsAll(values)) {
throw new BadRequestException(
- "verifying parent group existance failed");
+ "verifying parent group Existence failed");
}
}
property + " is not supported property in the group");
}
}
-}
\ No newline at end of file
+}
HashMap<String, Object> parsedPayload = mCbor
.parsePayloadFromCbor(payload, HashMap.class);
- checkPayloadException(Arrays.asList(Constants.REQ_UUID_ID),
+ checkQueryException(Arrays.asList(Constants.KEYFIELD_UID),
+ request.getUriQueryMap());
+
+ checkPayloadException(Arrays.asList(Constants.KEYFIELD_GROUP_MEMBERS),
parsedPayload);
- String uid = parsedPayload.get(Constants.REQ_UUID_ID).toString();
+ // get user id
+ String uid = request.getUriQueryMap().get(Constants.KEYFIELD_UID)
+ .get(0);
if (uid == null || uid.isEmpty()) {
throw new BadRequestException(
Constants.KEYFIELD_GROUP_PARENT);
if (parent != null) {
- ArrayList<String> properties = new ArrayList<>();
- properties.add(Constants.KEYFIELD_GROUP);
+ ArrayList<String> properties = new ArrayList<>(
+ Arrays.asList(Constants.KEYFIELD_GROUP));
GroupBrokerManager.getInstance().verifyAuthorization(uid, parent,
properties, UserOperation.ADD);
}
IRequest request) {
HashMap<String, List<String>> queryMap = request.getUriQueryMap();
- checkQueryException(Arrays.asList(Constants.REQ_UUID_ID), queryMap);
-
- List<String> deviceList = queryMap.get(Constants.REQ_UUID_ID);
- String uid = deviceList.get(0);
+ checkQueryException(Arrays.asList(Constants.REQ_UUID_ID,
+ Constants.KEYFIELD_GROUP_MEMBERS), queryMap);
+ String uid = queryMap.get(Constants.REQ_UUID_ID).get(0);
+ if (!uid.equals(
+ queryMap.get(Constants.KEYFIELD_GROUP_MEMBERS).get(0))) {
+ throw new BadRequestException(
+ Constants.REQ_UUID_ID + "query value should be equal to "
+ + Constants.KEYFIELD_GROUP_MEMBERS + "query value");
+ }
switch (request.getObserve()) {
case SUBSCRIBE:
GroupBrokerManager.getInstance().addObserver(uid, srcDevice,
HashMap<String, Object> payloadData = mCbor
.parsePayloadFromCbor(request.getPayload(), HashMap.class);
- // check if the payload has the key "uid"
- checkPayloadException(Constants.REQ_UUID_ID, payloadData);
+ // TODO to be deleted
+ if (payloadData.containsKey(Constants.KEYFIELD_UID)) {
+ throw new BadRequestException(
+ " uid key is not supported in the payload");
+ }
+
+ checkQueryException(Arrays.asList(Constants.KEYFIELD_UID),
+ request.getUriQueryMap());
- // get "uid" value
- String mid = (String) payloadData.get(Constants.REQ_UUID_ID);
+ // get user id
+ String uid = request.getUriQueryMap().get(Constants.KEYFIELD_UID)
+ .get(0);
- if (mid == null || mid.isEmpty()) {
+ if (uid == null || uid.isEmpty()) {
throw new BadRequestException(
Constants.REQ_UUID_ID + " is null or empty");
}
String gid = request.getUriPathSegments()
.get(getUriPathSegments().size());
- payloadData.remove(Constants.REQ_UUID_ID);
-
// process POST oic/acl/group/<gid> to update group info
- if (request.getUriQuery() == null) {
- handlePostUpdateRequest(gid, mid, payloadData);
+ if (!request.getUriQueryMap()
+ .containsKey(Constants.REQ_GROUP_QUERY_OPERATION)) {
+ handlePostUpdateRequest(gid, uid, payloadData);
} else {
checkQueryException(Constants.REQ_GROUP_QUERY_OPERATION,
request.getUriQueryMap());
switch (postOption) {
case Constants.REQ_GROUP_QUERY_ADD:
- handlePostAddRequest(gid, mid, payloadData);
+ handlePostAddRequest(gid, uid, payloadData);
break;
case Constants.REQ_GROUP_QUERY_DELETE:
- handlePostDeleteRequest(gid, mid, payloadData);
+ handlePostDeleteRequest(gid, uid, payloadData);
break;
default:
throw new PreconditionFailedException(
private IResponse handleGroupGetRequest(IRequest request)
throws ServerException {
- checkQueryException(Constants.REQ_UUID_ID, request.getUriQueryMap());
+ HashMap<String, List<String>> queryMap = request.getUriQueryMap();
- HashMap<String, Object> responsePayload = null;
+ checkQueryException(Arrays.asList(Constants.REQ_UUID_ID,
+ Constants.KEYFIELD_GROUP_MEMBERS), queryMap);
- String mid = request.getUriQueryMap().get(Constants.REQ_UUID_ID).get(0);
+ String uid = queryMap.get(Constants.REQ_UUID_ID).get(0);
+ if (!uid.equals(
+ queryMap.get(Constants.KEYFIELD_GROUP_MEMBERS).get(0))) {
+ throw new BadRequestException(
+ Constants.REQ_UUID_ID + "query value should be equal to "
+ + Constants.KEYFIELD_GROUP_MEMBERS + "query value");
+ }
- if (mid == null || mid.isEmpty()) {
+ if (uid == null || uid.isEmpty()) {
throw new BadRequestException(
Constants.REQ_UUID_ID + " is null or empty");
}
String gid = request.getUriPathSegments()
.get(getUriPathSegments().size());
- GroupManager.getInstance().verifyGetRequestAuthz(gid, mid);
+ GroupManager.getInstance().verifyGetRequestAuthz(gid, uid);
+
+ HashMap<String, Object> responsePayload = null;
switch (request.getObserve()) {
case NOTHING:
private IResponse handleGroupDeleteRequest(IRequest request)
throws ServerException {
- checkQueryException(Arrays.asList(Constants.REQ_UUID_ID),
- request.getUriQueryMap());
+ HashMap<String, List<String>> queryMap = request.getUriQueryMap();
+
+ checkQueryException(Arrays.asList(Constants.REQ_UUID_ID,
+ Constants.KEYFIELD_GROUP_OWNER), queryMap);
- String mid = request.getUriQueryMap().get(Constants.REQ_UUID_ID).get(0);
+ String uid = queryMap.get(Constants.REQ_UUID_ID).get(0);
+ if (!uid.equals(queryMap.get(Constants.KEYFIELD_GROUP_OWNER).get(0))) {
+ throw new BadRequestException(
+ Constants.REQ_UUID_ID + "query value should be equal to "
+ + Constants.KEYFIELD_GROUP_OWNER
+ + "query value to delete group");
+ }
- if (mid == null || mid.isEmpty()) {
+ if (uid == null || uid.isEmpty()) {
throw new BadRequestException(
Constants.REQ_UUID_ID + " is null or empty");
}
String gid = request.getUriPathSegments()
.get(getUriPathSegments().size());
- GroupManager.getInstance().verifyDeleteRequestAuthz(gid, mid);
+ GroupManager.getInstance().verifyDeleteRequestAuthz(gid, uid);
String parent = GroupManager.getInstance().getGroupTable(gid)
.getParent();
import static org.mockito.Mockito.mock;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.concurrent.CountDownLatch;
public class GroupBrokerTest {
private String GROUP_URI = Constants.GROUP_FULL_URI;
- private String UID_QUERY = "uid=";
+ private String UID_QUERY = Constants.KEYFIELD_UID
+ + "=";
private String mGid1 = "g1";
private String mGid2 = "g2";
private String mGname1 = "myHome";
assertTrue(responseCodeCheck(mResponse, ResponseStatus.CHANGED));
assertTrue(checkProperty(mResponse, Constants.KEYFIELD_GID));
assertTrue(checkProperty(mResponse, Constants.KEYFIELD_GROUP_NAME));
+ assertTrue(checkProperty(mResponse, Constants.KEYFIELD_GROUP_OWNER));
+ assertTrue(checkProperty(mResponse, Constants.KEYFIELD_GROUP_MEMBERS));
assertTrue(mLatch.await(2L, SECONDS));
}
assertTrue(responseCodeCheck(mResponse, ResponseStatus.CHANGED));
assertTrue(checkProperty(mResponse, Constants.KEYFIELD_GID));
assertTrue(checkProperty(mResponse, Constants.KEYFIELD_GROUP_NAME));
+ assertTrue(checkProperty(mResponse, Constants.KEYFIELD_GROUP_OWNER));
+ assertTrue(checkProperty(mResponse, Constants.KEYFIELD_GROUP_MEMBERS));
+ assertTrue(checkProperty(mResponse, Constants.KEYFIELD_GROUP_PARENT));
assertTrue(mLatch.await(2L, SECONDS));
}
@Test
public void testGetGroupList() throws Exception {
getTestMethodName();
- GroupBrokerManager.getInstance().createGroup(mUid1, mGid1, null, null);
+ sendCreateGroupRequest(mMockDevice, mUid1, mGname1, null);
+ String gid = getProperty(mResponse, Constants.KEYFIELD_GID).toString();
+ sendCreateGroupRequest(mMockDevice, mUid1, null, gid);
sendGetGroupResquest(mMockDevice, mUid1);
assertTrue(responseCodeCheck(mResponse, ResponseStatus.CONTENT));
}
String gname, String parent) {
IRequest request = null;
HashMap<String, Object> payloadData = new HashMap<String, Object>();
- payloadData.put(Constants.REQ_UUID_ID, uid);
payloadData.put(Constants.KEYFIELD_GROUP_NAME, gname);
payloadData.put(Constants.KEYFIELD_GROUP_PARENT, parent);
+ payloadData.put(Constants.KEYFIELD_GROUP_MEMBERS,
+ new ArrayList<String>(Arrays.asList(uid)));
+ payloadData.put(Constants.KEYFIELD_OID, uid);
request = MessageBuilder.createRequest(RequestMethod.POST, GROUP_URI,
- null, ContentFormat.APPLICATION_CBOR,
+ Constants.KEYFIELD_UID + "=" + uid,
+ ContentFormat.APPLICATION_CBOR,
mCbor.encodingPayloadToCbor(payloadData));
mGroupResource.onDefaultRequestReceived(device, request);
}
private void sendGetGroupResquest(CoapDevice device, String uid) {
IRequest request = null;
request = MessageBuilder.createRequest(RequestMethod.GET, GROUP_URI,
- UID_QUERY + uid);
+ UID_QUERY + uid + ";" + Constants.KEYFIELD_GROUP_MEMBERS + "="
+ + uid);
mGroupResource.onDefaultRequestReceived(device, request);
}
Observe obs) {
IRequest request = null;
request = MessageBuilder.createRequest(RequestMethod.GET, GROUP_URI,
- UID_QUERY + uid);
+ UID_QUERY + uid + ";" + Constants.KEYFIELD_GROUP_MEMBERS + "="
+ + uid);
((CoapRequest) request).setObserve(obs);
mGroupResource.onDefaultRequestReceived(device, request);
}
}
@Test(expected = ServerException.BadRequestException.class)
+ public void testGetNonExistongGroup() throws Exception {
+ getTestMethodName();
+ HashMap<String, Object> properties = new HashMap<>();
+ ArrayList<String> members = new ArrayList<>();
+ members.add(mUid2);
+ members.add(mUid3);
+ properties.put(Constants.KEYFIELD_GROUP_MEMBERS, members);
+ // add members to the parent group
+ GroupManager.getInstance().addMembersToGroup(mGid1, members);
+ getGroupInfo(mMockDevice, mGid1 + "notExist", mUid1);
+ assertTrue(methodCheck(mResponse, ResponseStatus.CONTENT));
+ assertTrue(mLatch.await(2L, SECONDS));
+ }
+
+ @Test(expected = ServerException.BadRequestException.class)
public void testGetGroupByNonExistingUser() throws Exception {
getTestMethodName();
HashMap<String, Object> properties = new HashMap<>();
}
@Test(expected = ServerException.BadRequestException.class)
+ public void testDeleteNonExistingGroup() throws Exception {
+ getTestMethodName();
+ setExampleGroup();
+ deleteGroup(mMockDevice, mGid1 + "notExist", mUid1);
+ assertTrue(methodCheck(mResponse, ResponseStatus.DELETED));
+ assertTrue(mLatch.await(2L, SECONDS));
+ }
+
+ @Test(expected = ServerException.BadRequestException.class)
public void testDeleteGroupByMaster() throws Exception {
getTestMethodName();
setExampleGroup();
assertTrue(mLatch.await(2L, SECONDS));
}
+ @Test(expected = ServerException.BadRequestException.class)
+ public void testUpdatePropertiesToNonExistingGroup() throws Exception {
+ getTestMethodName();
+ setExampleGroup();
+ HashMap<String, Object> properties = new HashMap<>();
+ ArrayList<HashMap<String, Object>> resources = new ArrayList<>();
+ // add resource 1
+ resources.add(makeResources("/di/" + mDi1 + "/a/switch/1",
+ Arrays.asList("core.switch"),
+ Arrays.asList("oic.if.baseline")));
+ properties.put(Constants.KEYFIELD_GROUP_RESOURCES, resources);
+
+ ArrayList<String> members = new ArrayList<>();
+ members.add(mUid1);
+ members.add(mUid2);
+
+ properties.put(Constants.KEYFIELD_GROUP_MEMBERS, members);
+
+ ArrayList<String> masters = new ArrayList<>();
+ masters.add(mUid3);
+ properties.put(Constants.KEYFIELD_GROUP_MASTERS, masters);
+
+ updateProperties(mMockDevice, mGid1 + "nonExists", mUid1, properties);
+ assertTrue(methodCheck(mResponse, ResponseStatus.CHANGED));
+ assertTrue(mLatch.await(2L, SECONDS));
+ }
+
private HashMap<String, Object> setExampleGroup() throws Exception {
HashMap<String, Object> properties = new HashMap<>();
ArrayList<HashMap<String, Object>> resources = new ArrayList<>();
subgroupProperties.put(Constants.KEYFIELD_GROUP_RESOURCES,
subgroupResources);
addProperties(mMockDevice, mGid2, mUid1, subgroupProperties);
+ System.out.println("---------- set Example Group END");
return properties;
}
throws Exception {
System.out.println("-----Get group, gid : " + gid);
IRequest request = MessageBuilder.createRequest(RequestMethod.DELETE,
- GROUP_URI + "/" + gid, Constants.REQ_UUID_ID + "=" + uid);
+ GROUP_URI + "/" + gid, Constants.REQ_UUID_ID + "=" + uid + ";"
+ + Constants.KEYFIELD_GROUP_OWNER + "=" + uid);
mGroupResource.onDefaultRequestReceived(device, request);
}
throws Exception {
System.out.println("-----Get group, gid : " + gid);
IRequest request = MessageBuilder.createRequest(RequestMethod.GET,
- GROUP_URI + "/" + gid, Constants.REQ_UUID_ID + "=" + uid);
+ GROUP_URI + "/" + gid, Constants.REQ_UUID_ID + "=" + uid + ";"
+ + Constants.KEYFIELD_GROUP_MEMBERS + "=" + uid);
mGroupResource.onDefaultRequestReceived(device, request);
}
private void addProperties(CoapDevice device, String gid, String uid,
HashMap<String, Object> properties) throws Exception {
System.out.println("-----Add properties");
- properties.put(Constants.REQ_UUID_ID, uid);
IRequest request = null;
request = MessageBuilder.createRequest(RequestMethod.POST,
- GROUP_URI + "/" + gid, "op=" + Constants.REQ_GROUP_QUERY_ADD,
+ GROUP_URI + "/" + gid,
+ Constants.KEYFIELD_UID + "=" + uid + ";"
+ + Constants.REQ_GROUP_QUERY_OPERATION + "="
+ + Constants.REQ_GROUP_QUERY_ADD,
ContentFormat.APPLICATION_CBOR,
mCbor.encodingPayloadToCbor(properties));
mGroupResource.onDefaultRequestReceived(device, request);
private void updateProperties(CoapDevice device, String gid, String uid,
HashMap<String, Object> properties) throws Exception {
System.out.println("-----Update properties");
- properties.put(Constants.REQ_UUID_ID, uid);
IRequest request = null;
request = MessageBuilder.createRequest(RequestMethod.POST,
- GROUP_URI + "/" + gid, null, ContentFormat.APPLICATION_CBOR,
+ GROUP_URI + "/" + gid, Constants.KEYFIELD_UID + "=" + uid,
+ ContentFormat.APPLICATION_CBOR,
mCbor.encodingPayloadToCbor(properties));
mGroupResource.onDefaultRequestReceived(device, request);
}
private void deleteProperties(CoapDevice device, String gid, String uid,
HashMap<String, Object> properties) throws Exception {
System.out.println("-----Delete properties");
- properties.put(Constants.REQ_UUID_ID, uid);
IRequest request = null;
request = MessageBuilder.createRequest(RequestMethod.POST,
- GROUP_URI + "/" + gid, "op=" + Constants.REQ_GROUP_QUERY_DELETE,
+ GROUP_URI + "/" + gid,
+ Constants.KEYFIELD_UID + "=" + uid + ";"
+ + Constants.REQ_GROUP_QUERY_OPERATION + "="
+ + Constants.REQ_GROUP_QUERY_DELETE,
ContentFormat.APPLICATION_CBOR,
mCbor.encodingPayloadToCbor(properties));
mGroupResource.onDefaultRequestReceived(device, request);
String parent) throws Exception {
System.out.println("-----Create Group");
IRequest request = null;
- request = createGroupRequest(uid, gname, parent);
- mGroupResource.onDefaultRequestReceived(device, request);
- }
-
- private IRequest createGroupRequest(String uid, String gname,
- String parent) {
- IRequest request = null;
HashMap<String, Object> payloadData = new HashMap<String, Object>();
- payloadData.put(Constants.REQ_UUID_ID, uid);
payloadData.put(Constants.KEYFIELD_GROUP_NAME, gname);
payloadData.put(Constants.KEYFIELD_GROUP_PARENT, parent);
+ payloadData.put(Constants.KEYFIELD_GROUP_MEMBERS,
+ new ArrayList<String>(Arrays.asList(uid)));
+ payloadData.put(Constants.KEYFIELD_OID, uid);
request = MessageBuilder.createRequest(RequestMethod.POST, GROUP_URI,
- null, ContentFormat.APPLICATION_CBOR,
+ Constants.KEYFIELD_UID + "=" + uid,
+ ContentFormat.APPLICATION_CBOR,
mCbor.encodingPayloadToCbor(payloadData));
- return request;
+ mGroupResource.onDefaultRequestReceived(device, request);
}
private boolean hashmapCheck(IResponse response, String propertyName) {
String parent) throws Exception {
System.out.println("-----Create Group");
IRequest request = null;
- request = createGroupRequest(uid, gname, parent);
- mGroupResource.onDefaultRequestReceived(device, request);
- }
-
- private IRequest createGroupRequest(String uid, String gname,
- String parent) {
- IRequest request = null;
HashMap<String, Object> payloadData = new HashMap<String, Object>();
- payloadData.put(Constants.REQ_UUID_ID, uid);
payloadData.put(Constants.KEYFIELD_GROUP_NAME, gname);
payloadData.put(Constants.KEYFIELD_GROUP_PARENT, parent);
+ payloadData.put(Constants.KEYFIELD_GROUP_MEMBERS,
+ new ArrayList<String>(Arrays.asList(uid)));
+ payloadData.put(Constants.KEYFIELD_OID, uid);
request = MessageBuilder.createRequest(RequestMethod.POST, GROUP_URI,
- null, ContentFormat.APPLICATION_CBOR,
+ Constants.KEYFIELD_UID + "=" + uid,
+ ContentFormat.APPLICATION_CBOR,
mCbor.encodingPayloadToCbor(payloadData));
- return request;
+ mGroupResource.onDefaultRequestReceived(device, request);
}
}
\ No newline at end of file
for (String property : propertyList) {
if (!queryData.containsKey(property))
throw new PreconditionFailedException(
- property + " property is not include");
+ "query does not contatin " + property + " property");
if (queryData.get(property) == null)
throw new PreconditionFailedException(
property + " param is null");
for (String property : propertyList) {
if (!payloadData.containsKey(property))
throw new PreconditionFailedException(
- property + " property is not include");
+ "payload does not contain" + property + " property");
if (payloadData.get(property) == null)
throw new PreconditionFailedException(
- property + " param is null");
+ property + " param is null in the payload");
}
return true;
}