04c39d1c39f6092fa59a97572bc29e936542f018
[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.List;
22 import java.util.Map;
23
24 import oic.simulator.clientcontroller.utils.Constants;
25
26 import org.oic.simulator.SimulatorResourceModel;
27 import org.oic.simulator.client.SimulatorRemoteResource;
28
29 /**
30  * This class represents a remote resource. It maintains all the necessary
31  * information about the resource.
32  */
33 public class RemoteResource {
34
35     private boolean                              observed;
36
37     // Native object references
38     private SimulatorRemoteResource              remoteResourceRef;
39     private SimulatorResourceModel               resourceModelRef;
40     private Map<String, RemoteResourceAttribute> resourceAttributesMap;
41
42     private boolean                              configUploaded;
43
44     private boolean                              getAutomtnInProgress;
45     private boolean                              putAutomtnInProgress;
46     private boolean                              postAutomtnInProgress;
47
48     private int                                  getAutomtnId;
49     private int                                  putAutomtnId;
50     private int                                  postAutomtnId;
51
52     private boolean                              isFavorite;
53
54     public SimulatorResourceModel getResourceModelRef() {
55         return resourceModelRef;
56     }
57
58     public void setResourceModelRef(SimulatorResourceModel resourceModel) {
59         this.resourceModelRef = resourceModel;
60     }
61
62     public Map<String, RemoteResourceAttribute> getResourceAttributesMap() {
63         return resourceAttributesMap;
64     }
65
66     public void setResourceAttributesMap(
67             Map<String, RemoteResourceAttribute> resourceAttributesMap) {
68         this.resourceAttributesMap = resourceAttributesMap;
69     }
70
71     public int getGetAutomtnId() {
72         return getAutomtnId;
73     }
74
75     public void setGetAutomtnId(int getAutomtnId) {
76         this.getAutomtnId = getAutomtnId;
77     }
78
79     public int getPutAutomtnId() {
80         return putAutomtnId;
81     }
82
83     public void setPutAutomtnId(int putAutomtnId) {
84         this.putAutomtnId = putAutomtnId;
85     }
86
87     public int getPostAutomtnId() {
88         return postAutomtnId;
89     }
90
91     public void setPostAutomtnId(int postAutomtnId) {
92         this.postAutomtnId = postAutomtnId;
93     }
94
95     public boolean isGetAutomtnInProgress() {
96         return getAutomtnInProgress;
97     }
98
99     public void setGetAutomtnInProgress(boolean getAutomtnInProgress) {
100         this.getAutomtnInProgress = getAutomtnInProgress;
101     }
102
103     public boolean isPutAutomtnInProgress() {
104         return putAutomtnInProgress;
105     }
106
107     public void setPutAutomtnInProgress(boolean putAutomtnInProgress) {
108         this.putAutomtnInProgress = putAutomtnInProgress;
109     }
110
111     public boolean isPostAutomtnInProgress() {
112         return postAutomtnInProgress;
113     }
114
115     public void setPostAutomtnInProgress(boolean postAutomtnInProgress) {
116         this.postAutomtnInProgress = postAutomtnInProgress;
117     }
118
119     public boolean isConfigUploaded() {
120         return configUploaded;
121     }
122
123     public void setConfigUploaded(boolean configUploaded) {
124         this.configUploaded = configUploaded;
125     }
126
127     public SimulatorRemoteResource getRemoteResourceRef() {
128         return remoteResourceRef;
129     }
130
131     public void setRemoteResourceRef(SimulatorRemoteResource resource) {
132         this.remoteResourceRef = resource;
133     }
134
135     public boolean isObserved() {
136         return observed;
137     }
138
139     public void setObserved(boolean observed) {
140         this.observed = observed;
141     }
142
143     public List<PutPostAttributeModel> getPutPostModel() {
144         Map<String, RemoteResourceAttribute> attMap = getResourceAttributesMap();
145         if (null == attMap || attMap.size() < 1) {
146             return null;
147         }
148         List<PutPostAttributeModel> putPostModelList = new ArrayList<PutPostAttributeModel>();
149         String attName;
150         RemoteResourceAttribute attribute;
151         PutPostAttributeModel putPostModel;
152         Iterator<String> attItr = attMap.keySet().iterator();
153         while (attItr.hasNext()) {
154             attName = attItr.next();
155             attribute = attMap.get(attName);
156             putPostModel = PutPostAttributeModel.getModel(attribute);
157             if (null != putPostModel) {
158                 putPostModelList.add(putPostModel);
159             }
160         }
161         return putPostModelList;
162     }
163
164     public String getAttributeValue(String attName) {
165         RemoteResourceAttribute attribute = resourceAttributesMap.get(attName);
166         if (null == attribute) {
167             return null;
168         }
169         return String.valueOf(attribute.getAttributeValue());
170     }
171
172     public int getAutomationtype(int autoId) {
173         if (getAutomtnId == autoId) {
174             return Constants.GET_AUTOMATION_INDEX;
175         } else if (putAutomtnId == autoId) {
176             return Constants.PUT_AUTOMATION_INDEX;
177         } else {// if(postAutomtnId == autoId) {
178             return Constants.POST_AUTOMATION_INDEX;
179         }
180     }
181
182     public void updateAutomationStatus(int autoId, boolean status) {
183         if (getAutomtnId == autoId) {
184             getAutomtnInProgress = status;
185         } else if (putAutomtnId == autoId) {
186             putAutomtnInProgress = status;
187         } else {// if(postAutomtnId == autoId) {
188             postAutomtnInProgress = status;
189         }
190     }
191
192     public boolean isFavorite() {
193         return isFavorite;
194     }
195
196     public void setFavorite(boolean isFavorite) {
197         this.isFavorite = isFavorite;
198     }
199 }