]> git.basschouten.com Git - openhab-addons.git/blob
3e0a1e87f0d322cf5cef9a28bb127f1e64c9b496
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.ihc.internal.ws.datatypes;
14
15 import java.io.IOException;
16
17 import javax.xml.xpath.XPathExpressionException;
18
19 import org.openhab.binding.ihc.internal.ws.exeptions.IhcExecption;
20
21 /**
22  * Class for WSLoginResult complex type.
23  *
24  * @author Pauli Anttila - Initial contribution
25  */
26 public class WSLoginResult {
27
28     protected WSUser loggedInUser;
29     protected boolean loginWasSuccessful;
30     protected boolean loginFailedDueToConnectionRestrictions;
31     protected boolean loginFailedDueToInsufficientUserRights;
32     protected boolean loginFailedDueToAccountInvalid;
33
34     public WSLoginResult() {
35     }
36
37     public WSLoginResult(WSUser loggedInUser, boolean loginWasSuccessful,
38             boolean loginFailedDueToConnectionRestrictions, boolean loginFailedDueToInsufficientUserRights,
39             boolean loginFailedDueToAccountInvalid) {
40         this.loggedInUser = loggedInUser;
41         this.loginWasSuccessful = loginWasSuccessful;
42         this.loginFailedDueToConnectionRestrictions = loginFailedDueToConnectionRestrictions;
43         this.loginFailedDueToInsufficientUserRights = loginFailedDueToInsufficientUserRights;
44         this.loginFailedDueToAccountInvalid = loginFailedDueToAccountInvalid;
45     }
46
47     /**
48      * Gets the value of the loggedInUser property.
49      *
50      * @return possible object is {@link WSUser }
51      *
52      */
53     public WSUser getLoggedInUser() {
54         return loggedInUser;
55     }
56
57     /**
58      * Sets the value of the loggedInUser property.
59      *
60      * @param value allowed object is {@link WSUser }
61      *
62      */
63     public void setLoggedInUser(WSUser value) {
64         this.loggedInUser = value;
65     }
66
67     /**
68      * Gets the value of the loginWasSuccessful property.
69      *
70      */
71     public boolean isLoginWasSuccessful() {
72         return loginWasSuccessful;
73     }
74
75     /**
76      * Sets the value of the loginWasSuccessful property.
77      *
78      */
79     public void setLoginWasSuccessful(boolean value) {
80         this.loginWasSuccessful = value;
81     }
82
83     /**
84      * Gets the value of the loginFailedDueToConnectionRestrictions property.
85      *
86      */
87     public boolean isLoginFailedDueToConnectionRestrictions() {
88         return loginFailedDueToConnectionRestrictions;
89     }
90
91     /**
92      * Sets the value of the loginFailedDueToConnectionRestrictions property.
93      *
94      */
95     public void setLoginFailedDueToConnectionRestrictions(boolean value) {
96         this.loginFailedDueToConnectionRestrictions = value;
97     }
98
99     /**
100      * Gets the value of the loginFailedDueToInsufficientUserRights property.
101      *
102      */
103     public boolean isLoginFailedDueToInsufficientUserRights() {
104         return loginFailedDueToInsufficientUserRights;
105     }
106
107     /**
108      * Sets the value of the loginFailedDueToInsufficientUserRights property.
109      *
110      */
111     public void setLoginFailedDueToInsufficientUserRights(boolean value) {
112         this.loginFailedDueToInsufficientUserRights = value;
113     }
114
115     /**
116      * Gets the value of the loginFailedDueToAccountInvalid property.
117      *
118      */
119     public boolean isLoginFailedDueToAccountInvalid() {
120         return loginFailedDueToAccountInvalid;
121     }
122
123     /**
124      * Sets the value of the loginFailedDueToAccountInvalid property.
125      *
126      */
127     public void setLoginFailedDueToAccountInvalid(boolean value) {
128         this.loginFailedDueToAccountInvalid = value;
129     }
130
131     public WSLoginResult parseXMLData(String data) throws IhcExecption {
132         try {
133             loginWasSuccessful = XPathUtils.parseValueToBoolean(data,
134                     "/SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:authenticate2/ns1:loginWasSuccessful");
135
136             loginFailedDueToConnectionRestrictions = XPathUtils.parseValueToBoolean(data,
137                     "/SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:authenticate2/ns1:loginFailedDueToConnectionRestrictions");
138
139             loginFailedDueToInsufficientUserRights = XPathUtils.parseValueToBoolean(data,
140                     "/SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:authenticate2/ns1:loginFailedDueToInsufficientUserRights");
141
142             loginFailedDueToAccountInvalid = XPathUtils.parseValueToBoolean(data,
143                     "/SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:authenticate2/ns1:loginFailedDueToAccountInvalid");
144
145             return this;
146         } catch (IOException | XPathExpressionException e) {
147             throw new IhcExecption("Error occured during XML data parsing", e);
148         }
149     }
150 }