]> git.basschouten.com Git - openhab-addons.git/blob
7d57f93a394a442bdbc501579a39017b357ced03
[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.rest;
14
15 import javax.ws.rs.core.UriBuilder;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.freeboxos.internal.api.FreeboxException;
20 import org.openhab.binding.freeboxos.internal.api.Response;
21
22 /**
23  * The {@link ConfigurableRest} is the Java class used to handle portions of the Api that accept to get and set
24  * configuration based on a given DTO
25  *
26  * @author GaĆ«l L'hopital - Initial contribution
27  */
28 @NonNullByDefault
29 public class ConfigurableRest<T, Y extends Response<T>> extends RestManager {
30     protected static final String CONFIG_PATH = "config";
31
32     private final Class<Y> responseClazz;
33     private final @Nullable String configPath;
34
35     protected ConfigurableRest(FreeboxOsSession session, LoginManager.Permission required, Class<Y> responseClazz,
36             UriBuilder uri, @Nullable String configPath) throws FreeboxException {
37         super(session, required, uri);
38         this.responseClazz = responseClazz;
39         this.configPath = configPath;
40     }
41
42     public T getConfig() throws FreeboxException {
43         return configPath != null ? getSingle(responseClazz, configPath) : getSingle(responseClazz);
44     }
45
46     protected T setConfig(T config) throws FreeboxException {
47         return configPath != null ? put(responseClazz, config, configPath) : put(responseClazz, config);
48     }
49 }