Search in sources :

Example 6 with DeviceConfig

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

the class DeviceResourceServlet method doPostConfigs.

private synchronized boolean doPostConfigs(String deviceId, HttpServletResponse response, FromJson json) throws JsonSyntaxException, ConfigWriteException, RestConfigIsNotCorrectException, Error, MissingJsonObjectException, IllegalStateException {
    boolean ok = false;
    DriverConfig driverConfig;
    DeviceConfig deviceConfig = rootConfig.getDevice(deviceId);
    JsonObject jso = json.getJsonObject();
    String driverId = jso.get(Const.DRIVER).getAsString();
    if (driverId != null) {
        driverConfig = rootConfig.getDriver(driverId);
    } else {
        throw new Error("No driver ID in JSON");
    }
    if (driverConfig == null) {
        ServletLib.sendHTTPErrorAndLogErr(response, HttpServletResponse.SC_CONFLICT, logger, "Driver does not exists: ", driverId);
    } else if (deviceConfig != null) {
        ServletLib.sendHTTPErrorAndLogErr(response, HttpServletResponse.SC_CONFLICT, logger, "Device already exists: ", deviceId);
    } else {
        try {
            deviceConfig = driverConfig.addDevice(deviceId);
            json.setDeviceConfig(deviceConfig, deviceId);
        } catch (IdCollisionException e) {
        }
        configService.setConfig(rootConfig);
        configService.writeConfigToFile();
        response.setStatus(HttpServletResponse.SC_OK);
        ok = true;
    }
    return ok;
}
Also used : IdCollisionException(org.openmuc.framework.config.IdCollisionException) DriverConfig(org.openmuc.framework.config.DriverConfig) JsonObject(com.google.gson.JsonObject) DeviceConfig(org.openmuc.framework.config.DeviceConfig)

Example 7 with DeviceConfig

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

the class DriverResourceServlet method getDeviceIdList.

private List<String> getDeviceIdList(String driverId) {
    List<String> deviceList = new ArrayList<>();
    DriverConfig driverConfig = rootConfig.getDriver(driverId);
    Collection<DeviceConfig> deviceConfigs = driverConfig.getDevices();
    for (DeviceConfig deviceConfig : deviceConfigs) {
        deviceList.add(deviceConfig.getId());
    }
    return deviceList;
}
Also used : ArrayList(java.util.ArrayList) DriverConfig(org.openmuc.framework.config.DriverConfig) DeviceConfig(org.openmuc.framework.config.DeviceConfig)

Example 8 with DeviceConfig

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

the class RestDriverWrapper method getDriver.

public static RestDriverWrapper getDriver(DriverConfig config, ConfigService configService, DataAccessService data) {
    boolean running;
    DriverInfo driver;
    try {
        driver = configService.getDriverInfo(config.getId());
        running = true;
    } catch (DriverNotAvailableException e) {
        driver = new DriverInfo(config.getId(), null, null, null, null, null);
        running = false;
    }
    List<RestDevice> devices = new LinkedList<RestDevice>();
    for (DeviceConfig device : config.getDevices()) {
        List<RestChannel> channels = new LinkedList<RestChannel>();
        for (ChannelConfig channel : device.getChannels()) {
            channels.add(RestChannelMapper.getRestChannel(data.getChannel(channel.getId())));
        }
        devices.add(RestDeviceMapper.getRestDevice(device, configService.getDeviceState(device.getId()), channels));
    }
    return new RestDriverWrapper(config, driver, devices, running);
}
Also used : ChannelConfig(org.openmuc.framework.config.ChannelConfig) DriverNotAvailableException(org.openmuc.framework.config.DriverNotAvailableException) DeviceConfig(org.openmuc.framework.config.DeviceConfig) DriverInfo(org.openmuc.framework.config.DriverInfo) LinkedList(java.util.LinkedList)

Example 9 with DeviceConfig

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

the class DeviceResourceServlet method doGetDeviceList.

private void doGetDeviceList(ToJson json) throws IOException {
    List<RestDeviceWrapper> deviceList = new LinkedList<RestDeviceWrapper>();
    Collection<DeviceConfig> deviceConfigs = getConfigsList();
    for (DeviceConfig config : deviceConfigs) {
        deviceList.add(RestDeviceWrapper.getDevice(config, configService, dataAccess));
    }
    json.addDeviceList(deviceList);
}
Also used : RestDeviceWrapper(org.openmuc.framework.lib.rest.objects.RestDeviceWrapper) DeviceConfig(org.openmuc.framework.config.DeviceConfig) LinkedList(java.util.LinkedList)

Example 10 with DeviceConfig

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

the class DeviceResourceServlet method getConfigsList.

private List<DeviceConfig> getConfigsList() {
    List<DeviceConfig> deviceConfigs = new ArrayList<DeviceConfig>();
    Collection<DriverConfig> driverConfigs;
    driverConfigs = rootConfig.getDrivers();
    for (DriverConfig driverConfig : driverConfigs) {
        String driverId = driverConfig.getId();
        deviceConfigs.addAll(rootConfig.getDriver(driverId).getDevices());
    }
    return deviceConfigs;
}
Also used : 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