Merge remote-tracking branch 'origin/extended-easysetup'
[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;
34     protected String mCloudID;
35
36     /**
37      * Constructor
38      */
39     public CloudProp() {
40         mRep = new OcRepresentation();
41         mCloudID = "";
42     }
43
44     public void setCloudProp(String authCode, String authProvider, String ciServer)
45     {
46         try {
47             mRep.setValue(ESConstants.OC_RSRVD_ES_AUTHCODE, authCode);
48             mRep.setValue(ESConstants.OC_RSRVD_ES_AUTHPROVIDER, authProvider);
49             mRep.setValue(ESConstants.OC_RSRVD_ES_CISERVER, ciServer);
50         } catch (OcException e) {
51             Log.e(TAG, "setCloudProp is failed.");
52         }
53     }
54
55     public void setCloudID(String cloudID)
56     {
57         mCloudID = cloudID;
58     }
59
60     /**
61      * This method returns the authCode used for the first registration to IoTivity cloud
62      * @return AuthCode for sign-up to IoTivity cloud
63      */
64     public String getAuthCode()
65     {
66         try {
67             if (mRep.hasAttribute(ESConstants.OC_RSRVD_ES_AUTHCODE))
68                 return mRep.getValue(ESConstants.OC_RSRVD_ES_AUTHCODE);
69         } catch (OcException e) {
70             Log.e(TAG, "getAuthCode is failed.");
71         }
72         return new String("");
73     }
74
75     /**
76      * This method returns the auth provider which issued the given AuthCode
77      * @return Auth provider which issued the given AuthCode
78      */
79     public String getAuthProvider()
80     {
81         try {
82             if (mRep.hasAttribute(ESConstants.OC_RSRVD_ES_AUTHPROVIDER))
83                 return mRep.getValue(ESConstants.OC_RSRVD_ES_AUTHPROVIDER);
84         } catch (OcException e) {
85             Log.e(TAG, "getAuthProvider is failed.");
86         }
87         return new String("");
88     }
89
90         /**
91      * This method returns the Cloud Interface server's URL to be registered
92      * @return CI server's URL to be registered
93      */
94     public String getCiServer()
95     {
96         try {
97             if (mRep.hasAttribute(ESConstants.OC_RSRVD_ES_CISERVER))
98                 return mRep.getValue(ESConstants.OC_RSRVD_ES_CISERVER);
99         } catch (OcException e) {
100             Log.e(TAG, "getCiServer is failed.");
101         }
102         return new String("");
103     }
104
105     /**
106      * This method returns the Cloud Interface server's UUID
107      * @return CI server's UUID
108      */
109     public String getCloudID()
110     {
111         return mCloudID;
112     }
113
114     public OcRepresentation toOCRepresentation()
115     {
116         return mRep;
117     }
118 }