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;
castUserTableToMap(userInfo));
// make my private group
- GroupResource.getInstance().createGroup(userInfo.getUuid(),
+ GroupManager.getInstance().createGroup(userInfo.getUuid(),
Constants.REQ_GTYPE_PRIVATE);
}
tokenInfo.setUuid(userUuid);
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
}
*/
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
*
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);
String gid = (String) record.get(Constants.KEYFIELD_GID);
HashSet<String> diSet = new HashSet<>();
diSet.add(di);
- GroupResource.getInstance().removeGroupDevice(gid, diSet);
+ removeGroupDevice(gid, diSet);
}
}
}
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 {
}
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());
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)) {
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);
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()
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());
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)) {
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);