2 * //******************************************************************
4 * // Copyright 2016 Samsung Electronics All Rights Reserved.
6 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
8 * // Licensed under the Apache License, Version 2.0 (the "License");
9 * // you may not use this file except in compliance with the License.
10 * // You may obtain a copy of the License at
12 * // http://www.apache.org/licenses/LICENSE-2.0
14 * // Unless required by applicable law or agreed to in writing, software
15 * // distributed under the License is distributed on an "AS IS" BASIS,
16 * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * // See the License for the specific language governing permissions and
18 * // limitations under the License.
20 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
22 package org.iotivity.cloud.accountserver.db;
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.HashMap;
28 import org.iotivity.cloud.accountserver.Constants;
29 import org.iotivity.cloud.base.exception.ServerException.BadRequestException;
31 public class GroupTable {
33 private String gid = null;
34 private String gname = null;
35 private String owner = null;
36 private ArrayList<String> members = null;
37 private ArrayList<String> masters = null;
38 private ArrayList<String> devices = null;
39 private ArrayList<Object> resources = null;
40 private ArrayList<String> subgroups = null;
41 private String parent = null;
42 private ArrayList<Object> gacl = null;
48 private ArrayList<Object> makeGAcl() {
49 HashMap<String, Object> publicGAcl = new HashMap<>();
50 publicGAcl.put(Constants.KEYFIELD_ACE_PERMISSION, (int) 31);
51 ArrayList<HashMap<String, Object>> resources = new ArrayList<>();
52 HashMap<String, Object> resource = new HashMap<>();
53 resource.put(Constants.KEYFIELD_ACE_RESOURCE_HREF, "*");
54 resource.put(Constants.KEYFIELD_ACE_RESOURCE_RT,
55 new ArrayList<String>());
56 resource.put(Constants.KEYFIELD_ACE_RESOURCE_IF,
57 Arrays.asList(Constants.DEFAULT_INTERFACE));
58 resources.add(resource);
59 publicGAcl.put(Constants.KEYFIELD_GROUP_RESOURCES, resources);
61 ArrayList<Object> gaclList = new ArrayList<>();
62 gaclList.add(publicGAcl);
67 public GroupTable(String gid, String gname, String owner,
68 ArrayList<String> masters, ArrayList<String> members,
69 ArrayList<String> devices, ArrayList<Object> resources,
70 ArrayList<String> subgroups, String parent,
71 ArrayList<Object> gacl) {
75 this.members = members;
76 this.masters = masters;
77 this.devices = devices;
78 this.resources = resources;
79 this.subgroups = subgroups;
89 public String getGid() {
99 public void setGid(String gid) {
100 this.gid = gid.toString();
103 public String getGname() {
107 public void setGname(String gname) {
108 this.gname = gname.toString();
111 public String getOwner() {
115 public void setOwner(String owner) {
116 this.owner = owner.toString();
119 public ArrayList<String> getMasters() {
123 public void setMasters(ArrayList<String> masters) {
124 this.masters = masters;
127 public ArrayList<String> getMembers() {
131 public void setMembers(ArrayList<String> members) {
132 this.members = members;
135 public ArrayList<String> getDevices() {
139 public void setDevices(ArrayList<String> devices) {
140 this.devices = devices;
143 public ArrayList<Object> getResources() {
147 public void setResources(ArrayList<Object> resources) {
148 this.resources = resources;
151 public ArrayList<String> getSubgroups() {
155 public void setSubgroups(ArrayList<String> subgroups) {
156 this.subgroups = subgroups;
159 public String getParent() {
163 public void setParent(String parentGid) {
164 this.parent = parentGid;
168 * API to get group ACL
172 public ArrayList<Object> getGacl() {
177 * API to set group ACL of the group
180 * group ACL to be set
182 public void setGacl(ArrayList<Object> gacl) {
186 public <T> T getPropertyValue(String property) {
188 case Constants.REQ_GROUP_ID:
190 case Constants.KEYFIELD_GROUP_NAME:
192 case Constants.KEYFIELD_GROUP_OWNER:
194 case Constants.KEYFIELD_GROUP_MEMBERS:
196 case Constants.KEYFIELD_GROUP_MASTERS:
198 case Constants.KEYFIELD_GROUP_DEVICES:
200 case Constants.KEYFIELD_GROUP_RESOURCES:
201 return (T) resources;
202 case Constants.KEYFIELD_GROUP_SUBGROUPS:
203 return (T) subgroups;
204 case Constants.KEYFIELD_GROUP_GACL:
207 throw new BadRequestException(
208 property + " is not supported in the group");
212 public void setPropertyValue(String property, Object value) {
214 case Constants.REQ_GROUP_ID:
215 this.gid = (String) value;
217 case Constants.KEYFIELD_GROUP_NAME:
218 this.gname = (String) value;
220 case Constants.KEYFIELD_GROUP_OWNER:
221 this.owner = (String) value;
223 case Constants.KEYFIELD_GROUP_MEMBERS:
224 this.members = (ArrayList<String>) value;
226 case Constants.KEYFIELD_GROUP_MASTERS:
227 this.masters = (ArrayList<String>) value;
229 case Constants.KEYFIELD_GROUP_DEVICES:
230 this.devices = (ArrayList<String>) value;
232 case Constants.KEYFIELD_GROUP_RESOURCES:
233 this.resources = (ArrayList<Object>) value;
235 case Constants.KEYFIELD_GROUP_SUBGROUPS:
236 this.subgroups = (ArrayList<String>) value;
238 case Constants.KEYFIELD_GROUP_GACL:
239 this.gacl = (ArrayList<Object>) value;
242 throw new BadRequestException(
243 property + " is not supported in the group");