008828c02af6067129543b50fa31301bbf44200e
[platform/upstream/iotivity.git] / service / easy-setup / mediator / richsdk / android / EasySetupCore / src / main / java / org / iotivity / service / easysetup / mediator / CloudProp.java
1 /**
2  * ***************************************************************
3  *
4  * Copyright 2016 Samsung Electronics All Rights Reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * ****************************************************************
19  */
20
21 package org.iotivity.service.easysetup.mediator;
22
23 import android.util.Log;
24
25 import org.iotivity.base.OcException;
26 import org.iotivity.base.OcRepresentation;
27
28 /**
29  * This class contains cloud server properties to be delivered to Enrollee
30  */
31 public class CloudProp {
32     private static final String TAG = CloudProp.class.getName();
33     protected OcRepresentation mRep = null;
34     protected String mCloudID = null;
35     protected int mCredID ;
36
37     /**
38      * Constructor
39      */
40     public CloudProp() {
41         mRep = new OcRepresentation();
42         mCloudID = "";
43     }
44
45     public void setCloudProp(String authCode, String authProvider, String ciServer)
46     {
47         if(authCode == null)
48         {
49             authCode = "";
50         }
51         if(authProvider == null)
52         {
53             authProvider = "";
54         }
55         if(ciServer == null)
56         {
57             ciServer = "";
58         }
59         try {
60             mRep.setValue(ESConstants.OC_RSRVD_ES_AUTHCODE, authCode);
61             mRep.setValue(ESConstants.OC_RSRVD_ES_AUTHPROVIDER, authProvider);
62             mRep.setValue(ESConstants.OC_RSRVD_ES_CISERVER, ciServer);
63         } catch (OcException e) {
64             Log.e(TAG, "setCloudProp is failed.");
65         }
66     }
67
68     public void setCloudID(String cloudID)
69     {
70         mCloudID = cloudID;
71     }
72
73     public void setCredID(int credID)
74     {
75         mCredID = credID;
76     }
77     /**
78      * This method returns the authCode used for the first registration to IoTivity cloud
79      * @return AuthCode for sign-up to IoTivity cloud
80      */
81     public String getAuthCode()
82     {
83         if(mRep == null)
84         {
85             return null;
86         }
87
88         try
89         {
90             if (mRep.hasAttribute(ESConstants.OC_RSRVD_ES_AUTHCODE))
91                 return mRep.getValue(ESConstants.OC_RSRVD_ES_AUTHCODE);
92         }
93         catch (OcException e)
94         {
95             Log.e(TAG, "getAuthCode is failed.");
96         }
97         return null;
98     }
99
100     /**
101      * This method returns the auth provider which issued the given AuthCode
102      * @return Auth provider which issued the given AuthCode
103      */
104     public String getAuthProvider()
105     {
106         if(mRep == null)
107         {
108             return null;
109         }
110
111         try
112         {
113             if (mRep.hasAttribute(ESConstants.OC_RSRVD_ES_AUTHPROVIDER))
114                 return mRep.getValue(ESConstants.OC_RSRVD_ES_AUTHPROVIDER);
115         }
116         catch (OcException e)
117         {
118             Log.e(TAG, "getAuthProvider is failed.");
119         }
120         return null;
121     }
122
123         /**
124      * This method returns the Cloud Interface server's URL to be registered
125      * @return CI server's URL to be registered
126      */
127     public String getCiServer()
128     {
129         if(mRep == null)
130         {
131             return null;
132         }
133
134         try
135         {
136             if (mRep.hasAttribute(ESConstants.OC_RSRVD_ES_CISERVER))
137                 return mRep.getValue(ESConstants.OC_RSRVD_ES_CISERVER);
138         }
139         catch (OcException e)
140         {
141             Log.e(TAG, "getCiServer is failed.");
142         }
143         return null;
144     }
145
146     /**
147      * This method returns the Cloud Interface server's UUID
148      * @return CI server's UUID
149      */
150     public String getCloudID()
151     {
152         return mCloudID;
153     }
154
155     /**
156      * This method returns the Cloud Certificate's Cred ID
157      * @return CI server's Credential ID of Certificate
158      */
159     public int getCredID()
160     {
161         return mCredID;
162     }
163
164     public OcRepresentation toOCRepresentation()
165     {
166         return mRep;
167     }
168 }