Search in sources :

Example 16 with DeviceConfig

use of org.openmuc.framework.config.DeviceConfig in project OpenMUC by isc-konstanz.

the class DeviceResourceServlet method doPut.

@Override
public void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType(APPLICATION_JSON);
    String[] pathAndQueryString = checkIfItIsACorrectRest(request, response, logger);
    if (pathAndQueryString != null) {
        setConfigAccess();
        String pathInfo = pathAndQueryString[ServletLib.PATH_ARRAY_NR];
        String[] pathInfoArray = ServletLib.getPathInfoArray(pathInfo);
        FromJson json = ServletLib.getFromJson(request, logger, response);
        if (json == null) {
            return;
        }
        if (pathInfoArray.length < 1) {
            ServletLib.sendHTTPErrorAndLogDebug(response, HttpServletResponse.SC_NOT_FOUND, logger, REQUESTED_REST_PATH_IS_NOT_AVAILABLE, REST_PATH, request.getPathInfo());
        } else {
            String deviceId = pathInfoArray[0];
            DeviceConfig deviceConfig = rootConfig.getDevice(deviceId);
            if (deviceConfig != null && pathInfoArray.length == 2 && pathInfoArray[1].equalsIgnoreCase(Const.CONFIGS)) {
                doSetConfigs(deviceId, response, json, true);
            } else {
                ServletLib.sendHTTPErrorAndLogDebug(response, HttpServletResponse.SC_NOT_FOUND, logger, REQUESTED_REST_PATH_IS_NOT_AVAILABLE, REST_PATH, request.getPathInfo());
            }
        }
    }
}
Also used : FromJson(org.openmuc.framework.lib.rest.FromJson) DeviceConfig(org.openmuc.framework.config.DeviceConfig)

Example 17 with DeviceConfig

use of org.openmuc.framework.config.DeviceConfig in project OpenMUC by isc-konstanz.

the class DriverResourceServlet method getChannelList.

private List<Channel> getChannelList(String driverId) {
    List<Channel> driverChannels = new ArrayList<>();
    DriverConfig driverConfig = rootConfig.getDriver(driverId);
    Collection<DeviceConfig> deviceConfigs = driverConfig.getDevices();
    for (DeviceConfig deviceConfig : deviceConfigs) {
        Collection<ChannelConfig> channelConfigs = deviceConfig.getChannels();
        for (ChannelConfig channelConfig : channelConfigs) {
            driverChannels.add(dataAccess.getChannel(channelConfig.getId()));
        }
    }
    return driverChannels;
}
Also used : ChannelConfig(org.openmuc.framework.config.ChannelConfig) Channel(org.openmuc.framework.dataaccess.Channel) ArrayList(java.util.ArrayList) DriverConfig(org.openmuc.framework.config.DriverConfig) DeviceConfig(org.openmuc.framework.config.DeviceConfig)

Aggregations

DeviceConfig (org.openmuc.framework.config.DeviceConfig)17 DriverConfig (org.openmuc.framework.config.DriverConfig)6 ArrayList (java.util.ArrayList)5 ChannelConfig (org.openmuc.framework.config.ChannelConfig)4 JsonObject (com.google.gson.JsonObject)3 LinkedList (java.util.LinkedList)3 IdCollisionException (org.openmuc.framework.config.IdCollisionException)3 JsonElement (com.google.gson.JsonElement)2 HashMap (java.util.HashMap)2 DriverInfo (org.openmuc.framework.config.DriverInfo)2 DriverNotAvailableException (org.openmuc.framework.config.DriverNotAvailableException)2 DeviceState (org.openmuc.framework.dataaccess.DeviceState)2 LogicalDevice (org.openmuc.framework.dataaccess.LogicalDevice)2 JsonArray (com.google.gson.JsonArray)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 Deque (java.util.Deque)1 LinkedHashMap (java.util.LinkedHashMap)1