Java SDK and Eclipse plugin for simulator.
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ClientControllerPlugin / src / oic / simulator / clientcontroller / remoteresource / RemoteResource.java
1 /*
2  * Copyright 2015 Samsung Electronics All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package oic.simulator.clientcontroller.remoteresource;
18
19 import java.util.ArrayList;
20 import java.util.Iterator;
21 import java.util.LinkedList;
22 import java.util.List;
23 import java.util.Map;
24
25 import oic.simulator.clientcontroller.utils.Constants;
26
27 import org.oic.simulator.SimulatorResourceModel;
28 import org.oic.simulator.clientcontroller.SimulatorConnectivityType;
29 import org.oic.simulator.clientcontroller.SimulatorRemoteResource;
30
31 /**
32  * This class represents a remote resource. It maintains all the necessary
33  * information about the resource.
34  */
35 public class RemoteResource {
36     private String                               uId;
37     private String                               resourceURI;
38     private String                               host;
39     private LinkedList<String>                   resourceTypes;
40     private LinkedList<String>                   resourceInterfaces;
41     private SimulatorConnectivityType            connectivityType;
42     private boolean                              isObservable;
43
44     private boolean                              observed;
45
46     // Native object references
47     private SimulatorRemoteResource              resourceN;
48     private SimulatorResourceModel               resourceModel;
49     private Map<String, RemoteResourceAttribute> resourceAttributesMap;
50
51     private boolean                              configUploaded;
52
53     private boolean                              getAutomtnInProgress;
54     private boolean                              putAutomtnInProgress;
55     private boolean                              postAutomtnInProgress;
56
57     private int                                  getAutomtnId;
58     private int                                  putAutomtnId;
59     private int                                  postAutomtnId;
60
61     private boolean                              isFavorite;
62
63     public SimulatorResourceModel getResourceModel() {
64         return resourceModel;
65     }
66
67     public void setResourceModel(SimulatorResourceModel resourceModel) {
68         this.resourceModel = resourceModel;
69     }
70
71     public Map<String, RemoteResourceAttribute> getResourceAttributesMap() {
72         return resourceAttributesMap;
73     }
74
75     public void setResourceAttributesMap(
76             Map<String, RemoteResourceAttribute> resourceAttributesMap) {
77         this.resourceAttributesMap = resourceAttributesMap;
78     }
79
80     public int getGetAutomtnId() {
81         return getAutomtnId;
82     }
83
84     public void setGetAutomtnId(int getAutomtnId) {
85         this.getAutomtnId = getAutomtnId;
86     }
87
88     public int getPutAutomtnId() {
89         return putAutomtnId;
90     }
91
92     public void setPutAutomtnId(int putAutomtnId) {
93         this.putAutomtnId = putAutomtnId;
94     }
95
96     public int getPostAutomtnId() {
97         return postAutomtnId;
98     }
99
100     public void setPostAutomtnId(int postAutomtnId) {
101         this.postAutomtnId = postAutomtnId;
102     }
103
104     public String getResourceURI() {
105         return resourceURI;
106     }
107
108     public void setResourceURI(String resourceURI) {
109         this.resourceURI = resourceURI;
110     }
111
112     public String getHost() {
113         return host;
114     }
115
116     public void setHost(String host) {
117         this.host = host;
118     }
119
120     public LinkedList<String> getResourceTypes() {
121         return resourceTypes;
122     }
123
124     public void setResourceTypes(LinkedList<String> resourceTypes) {
125         this.resourceTypes = resourceTypes;
126     }
127
128     public LinkedList<String> getResourceInterfaces() {
129         return resourceInterfaces;
130     }
131
132     public void setResourceInterfaces(LinkedList<String> resourceInterfaces) {
133         this.resourceInterfaces = resourceInterfaces;
134     }
135
136     public SimulatorConnectivityType getConnectivityType() {
137         return connectivityType;
138     }
139
140     public void setConnectivityType(SimulatorConnectivityType connectivityType) {
141         this.connectivityType = connectivityType;
142     }
143
144     public boolean isObservable() {
145         return isObservable;
146     }
147
148     public void setObservable(boolean isObservable) {
149         this.isObservable = isObservable;
150     }
151
152     public boolean isGetAutomtnInProgress() {
153         return getAutomtnInProgress;
154     }
155
156     public void setGetAutomtnInProgress(boolean getAutomtnInProgress) {
157         this.getAutomtnInProgress = getAutomtnInProgress;
158     }
159
160     public boolean isPutAutomtnInProgress() {
161         return putAutomtnInProgress;
162     }
163
164     public void setPutAutomtnInProgress(boolean putAutomtnInProgress) {
165         this.putAutomtnInProgress = putAutomtnInProgress;
166     }
167
168     public boolean isPostAutomtnInProgress() {
169         return postAutomtnInProgress;
170     }
171
172     public void setPostAutomtnInProgress(boolean postAutomtnInProgress) {
173         this.postAutomtnInProgress = postAutomtnInProgress;
174     }
175
176     public boolean isConfigUploaded() {
177         return configUploaded;
178     }
179
180     public void setConfigUploaded(boolean configUploaded) {
181         this.configUploaded = configUploaded;
182     }
183
184     public SimulatorRemoteResource getResource() {
185         return resourceN;
186     }
187
188     public void setResource(SimulatorRemoteResource resource) {
189         this.resourceN = resource;
190     }
191
192     public boolean isObserved() {
193         return observed;
194     }
195
196     public void setObserved(boolean observed) {
197         this.observed = observed;
198     }
199
200     public List<PutPostAttributeModel> getPutPostModel() {
201         Map<String, RemoteResourceAttribute> attMap = getResourceAttributesMap();
202         if (null == attMap || attMap.size() < 1) {
203             return null;
204         }
205         List<PutPostAttributeModel> putPostModelList = new ArrayList<PutPostAttributeModel>();
206         String attName;
207         RemoteResourceAttribute attribute;
208         PutPostAttributeModel putPostModel;
209         Iterator<String> attItr = attMap.keySet().iterator();
210         while (attItr.hasNext()) {
211             attName = attItr.next();
212             attribute = attMap.get(attName);
213             putPostModel = PutPostAttributeModel.getModel(attribute);
214             if (null != putPostModel) {
215                 putPostModelList.add(putPostModel);
216             }
217         }
218         return putPostModelList;
219     }
220
221     public String getAttributeValue(String attName) {
222         RemoteResourceAttribute attribute = resourceAttributesMap.get(attName);
223         if (null == attribute) {
224             return null;
225         }
226         return String.valueOf(attribute.getAttributeValue());
227     }
228
229     public String getuId() {
230         return uId;
231     }
232
233     public void setuId(String uId) {
234         this.uId = uId;
235     }
236
237     public int getAutomationtype(int autoId) {
238         if (getAutomtnId == autoId) {
239             return Constants.GET_AUTOMATION_INDEX;
240         } else if (putAutomtnId == autoId) {
241             return Constants.PUT_AUTOMATION_INDEX;
242         } else {// if(postAutomtnId == autoId) {
243             return Constants.POST_AUTOMATION_INDEX;
244         }
245     }
246
247     public void updateAutomationStatus(int autoId, boolean status) {
248         if (getAutomtnId == autoId) {
249             getAutomtnInProgress = status;
250         } else if (putAutomtnId == autoId) {
251             putAutomtnInProgress = status;
252         } else {// if(postAutomtnId == autoId) {
253             postAutomtnInProgress = status;
254         }
255     }
256
257     public boolean isFavorite() {
258         return isFavorite;
259     }
260
261     public void setFavorite(boolean isFavorite) {
262         this.isFavorite = isFavorite;
263     }
264 }