]> git.basschouten.com Git - openhab-addons.git/blob
94645ce409e910fa3b7716d9e8c34bf1a6bd9aaa
[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.freeboxos.internal.api;
14
15 import java.util.List;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.freeboxos.internal.api.rest.LoginManager;
19
20 /**
21  * Defines an API result that returns a single object
22  *
23  * @author GaĆ«l L'hopital - Initial contribution
24  */
25 @NonNullByDefault
26 public class Response<ResultType> {
27     public enum ErrorCode {
28         AUTH_REQUIRED,
29         BAD_LOGIN,
30         TOO_SHORT,
31         IN_DICTIONNARY,
32         BAD_XKCD,
33         NOT_ENOUGH_DIFFERENT_CHARS,
34         INVALID_TOKEN,
35         PENDING_TOKEN,
36         INSUFFICIENT_RIGHTS,
37         DENIED_FROM_EXTERNAL_IP,
38         INVALID_REQUEST,
39         RATELIMITED,
40         NEW_APPS_DENIED,
41         APPS_AUTHORIZATION_DENIED,
42         APPS_AUTHORIZATION_TIMEOUT,
43         PASSWORD_RESET_DENIED,
44         APPS_DENIED,
45         INTERNAL_ERROR,
46         SERVICE_DOWN,
47         DISK_FULL,
48         OP_FAILED,
49         DISK_BUSY,
50         ARRAY_START_FAILED,
51         ARRAY_STOP_FAILED,
52         ARRAY_NOT_FOUND,
53         INVAL,
54         NODEV,
55         NOENT,
56         NETDOWN,
57         BUSY,
58         INVALID_PORT,
59         INSECURE_PASSWORD,
60         INVALID_PROVIDER,
61         INVALID_NEXT_HOP,
62         INVALID_API_VERSION,
63         INVAL_WPS_MACFILTER,
64         INVAL_WPS_NEEDS_CCMP,
65         INVALID_ID,
66         PATH_NOT_FOUND,
67         ACCESS_DENIED,
68         DESTINATION_CONFLICT,
69         CANCELLED,
70         TASK_NOT_FOUND,
71         HTTP,
72         INVALID_URL,
73         INVALID_OPERATION,
74         INVALID_FILE,
75         CTX_FILE_ERROR,
76         HIBERNATING,
77         TOO_MANY_TASKS,
78         EXISTS,
79         EXIST,
80         CONNECTION_REFUSED,
81         NO_FREEBOX,
82         ALREADY_AUTHORIZED,
83         ECRC,
84         ERR_001,
85         ERR_002,
86         ERR_003,
87         ERR_004,
88         ERR_005,
89         ERR_009,
90         ERR_010,
91         ERR_030,
92         ERR_031,
93         NONE,
94         UNKNOWN
95     }
96
97     private ErrorCode errorCode = ErrorCode.NONE;
98     private LoginManager.Permission missingRight = LoginManager.Permission.NONE;
99     private String msg = "";
100     private List<ResultType> result = List.of();
101     private boolean success;
102
103     // In some cases I did not understand deserialization can still produce null result
104     @SuppressWarnings("null")
105     public List<ResultType> getResult() {
106         List<ResultType> localResult = result;
107         return localResult != null ? localResult : List.of();
108     }
109
110     public boolean isSuccess() {
111         return success;
112     }
113
114     public LoginManager.Permission getMissingRight() {
115         return missingRight;
116     }
117
118     public ErrorCode getErrorCode() {
119         return errorCode;
120     }
121
122     public String getMsg() {
123         return msg;
124     }
125 }