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 {
32 private String gid = null;
33 private String gname = null;
34 private String owner = null;
35 private ArrayList<String> members = null;
36 private ArrayList<String> masters = null;
37 private ArrayList<String> devices = null;
38 private ArrayList<Object> resources = null;
39 private ArrayList<String> subgroups = null;
40 private String parent = null;
41 private ArrayList<Object> gacl = null;
47 private ArrayList<Object> makeGAcl() {
48 HashMap<String, Object> publicGAcl = new HashMap<>();
49 publicGAcl.put(Constants.KEYFIELD_ACE_PERMISSION, (int) 31);
50 ArrayList<HashMap<String, Object>> resources = new ArrayList<>();
51 HashMap<String, Object> resource = new HashMap<>();
52 resource.put(Constants.KEYFIELD_ACE_RESOURCE_HREF, "*");
53 resource.put(Constants.KEYFIELD_ACE_RESOURCE_RT,
54 new ArrayList<String>());
55 resource.put(Constants.KEYFIELD_ACE_RESOURCE_IF,
56 Arrays.asList(Constants.DEFAULT_INTERFACE));
57 resources.add(resource);
58 publicGAcl.put(Constants.KEYFIELD_GROUP_RESOURCES, resources);
60 ArrayList<Object> gaclList = new ArrayList<>();
61 gaclList.add(publicGAcl);
66 public GroupTable(String gid, String gname, String owner,
67 ArrayList<String> masters, ArrayList<String> members,
68 ArrayList<String> devices, ArrayList<Object> resources,
69 ArrayList<String> subgroups, String parent,
70 ArrayList<Object> gacl) {
74 this.members = members;
75 this.masters = masters;
76 this.devices = devices;
77 this.resources = resources;
78 this.subgroups = subgroups;
88 public String getGid() {
98 public void setGid(String gid) {
99 this.gid = gid.toString();
102 public String getGname() {
106 public void setGname(String gname) {
107 this.gname = gname.toString();
110 public String getOwner() {
114 public void setOwner(String owner) {
115 this.owner = owner.toString();
118 public ArrayList<String> getMasters() {
122 public void setMasters(ArrayList<String> masters) {
123 this.masters = masters;
126 public ArrayList<String> getMembers() {
130 public void setMembers(ArrayList<String> members) {
131 this.members = members;
134 public ArrayList<String> getDevices() {
138 public void setDevices(ArrayList<String> devices) {
139 this.devices = devices;
142 public ArrayList<Object> getResources() {
146 public void setResources(ArrayList<Object> resources) {
147 this.resources = resources;
150 public ArrayList<String> getSubgroups() {
154 public void setSubgroups(ArrayList<String> subgroups) {
155 this.subgroups = subgroups;
158 public String getParent() {
162 public void setParent(String parentGid) {
163 this.parent = parentGid;
167 * API to get group ACL
171 public ArrayList<Object> getGacl() {
176 * API to set group ACL of the group
179 * group ACL to be set
181 public void setGacl(ArrayList<Object> gacl) {
185 public <T> T getPropertyValue(String property) {
187 case Constants.REQ_GROUP_ID:
189 case Constants.KEYFIELD_GROUP_NAME:
191 case Constants.KEYFIELD_GROUP_OWNER:
193 case Constants.KEYFIELD_GROUP_MEMBERS:
195 case Constants.KEYFIELD_GROUP_MASTERS:
197 case Constants.KEYFIELD_GROUP_DEVICES:
199 case Constants.KEYFIELD_GROUP_RESOURCES:
200 return (T) resources;
201 case Constants.KEYFIELD_GROUP_SUBGROUPS:
202 return (T) subgroups;
203 case Constants.KEYFIELD_GROUP_GACL:
206 throw new BadRequestException(
207 property + " is not supported in the group");
211 public void setPropertyValue(String property, Object value) {
213 case Constants.REQ_GROUP_ID:
214 this.gid = (String) value;
216 case Constants.KEYFIELD_GROUP_NAME:
217 this.gname = (String) value;
219 case Constants.KEYFIELD_GROUP_OWNER:
220 this.owner = (String) value;
222 case Constants.KEYFIELD_GROUP_MEMBERS:
223 this.members = (ArrayList<String>) value;
225 case Constants.KEYFIELD_GROUP_MASTERS:
226 this.masters = (ArrayList<String>) value;
228 case Constants.KEYFIELD_GROUP_DEVICES:
229 this.devices = (ArrayList<String>) value;
231 case Constants.KEYFIELD_GROUP_RESOURCES:
232 this.resources = (ArrayList<Object>) value;
234 case Constants.KEYFIELD_GROUP_SUBGROUPS:
235 this.subgroups = (ArrayList<String>) value;
237 case Constants.KEYFIELD_GROUP_GACL:
238 this.gacl = (ArrayList<Object>) value;
241 throw new BadRequestException(
242 property + " is not supported in the group");