Search in sources :

Example 1 with ChannelConfig

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

the class ChannelResourceServlet method doPostConfigs.

private synchronized boolean doPostConfigs(String channelId, HttpServletResponse response, FromJson json) throws JsonSyntaxException, ConfigWriteException, RestConfigIsNotCorrectException, Error, MissingJsonObjectException, IllegalStateException {
    boolean ok = false;
    DeviceConfig deviceConfig;
    ChannelConfig channelConfig = rootConfig.getChannel(channelId);
    JsonObject jso = json.getJsonObject();
    JsonElement jsonElement = jso.get(Const.DEVICE);
    if (jsonElement == null) {
        ServletLib.sendHTTPErrorAndLogErr(response, HttpServletResponse.SC_BAD_REQUEST, logger, "Wrong json message syntax. Device statement is missing.");
    }
    String deviceID = jsonElement.getAsString();
    if (deviceID != null) {
        deviceConfig = rootConfig.getDevice(deviceID);
    } else {
        throw new Error("No device ID in JSON");
    }
    if (deviceConfig == null) {
        ServletLib.sendHTTPErrorAndLogErr(response, HttpServletResponse.SC_CONFLICT, logger, "Device does not exists: ", deviceID);
    } else if (channelConfig != null) {
        ServletLib.sendHTTPErrorAndLogErr(response, HttpServletResponse.SC_CONFLICT, logger, "Channel already exists: ", channelId);
    } else {
        try {
            channelConfig = deviceConfig.addChannel(channelId);
            json.setChannelConfig(channelConfig, channelId);
            if ((channelConfig.getValueType() == ValueType.STRING || channelConfig.getValueType() == ValueType.BYTE_ARRAY) && channelConfig.getValueTypeLength() == null) {
                ServletLib.sendHTTPErrorAndLogErr(response, HttpServletResponse.SC_NOT_ACCEPTABLE, logger, "Channel ", channelId, " with value type ", channelConfig.getValueType().toString(), ", missing valueTypeLength.");
                channelConfig.delete();
            } else {
                configService.setConfig(rootConfig);
                configService.writeConfigToFile();
            }
        } catch (IdCollisionException e) {
        }
        response.setStatus(HttpServletResponse.SC_OK);
        ok = true;
    }
    return ok;
}
Also used : ChannelConfig(org.openmuc.framework.config.ChannelConfig) JsonElement(com.google.gson.JsonElement) IdCollisionException(org.openmuc.framework.config.IdCollisionException) JsonObject(com.google.gson.JsonObject) DeviceConfig(org.openmuc.framework.config.DeviceConfig)

Example 2 with ChannelConfig

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

the class ChannelResourceServlet method doGetDriverId.

private void doGetDriverId(ToJson json, String channelId, HttpServletResponse response) {
    ChannelConfig channelConfig = getChannelConfig(channelId, response);
    if (channelConfig != null) {
        String driverId = channelConfig.getDevice().getDriver().getId();
        json.addString(Const.DRIVER_ID, driverId);
    }
}
Also used : ChannelConfig(org.openmuc.framework.config.ChannelConfig)

Example 3 with ChannelConfig

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

the class ChannelResourceServlet method doGetDeviceId.

private void doGetDeviceId(ToJson json, String channelId, HttpServletResponse response) {
    ChannelConfig channelConfig = getChannelConfig(channelId, response);
    if (channelConfig != null) {
        String deviceId = channelConfig.getDevice().getId();
        json.addString(Const.DEVICE_ID, deviceId);
    }
}
Also used : ChannelConfig(org.openmuc.framework.config.ChannelConfig)

Example 4 with ChannelConfig

use of org.openmuc.framework.config.ChannelConfig 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 5 with ChannelConfig

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

the class DeviceResourceServlet method getChannelList.

private List<Channel> getChannelList(String deviceId) {
    List<Channel> channels = new ArrayList<>();
    Collection<ChannelConfig> channelConfigs = rootConfig.getDevice(deviceId).getChannels();
    for (ChannelConfig channelConfig : channelConfigs) {
        channels.add(dataAccess.getChannel(channelConfig.getId()));
    }
    return channels;
}
Also used : ChannelConfig(org.openmuc.framework.config.ChannelConfig) Channel(org.openmuc.framework.dataaccess.Channel) ArrayList(java.util.ArrayList)

Aggregations

ChannelConfig (org.openmuc.framework.config.ChannelConfig)13 ArrayList (java.util.ArrayList)3 DeviceConfig (org.openmuc.framework.config.DeviceConfig)3 JsonElement (com.google.gson.JsonElement)2 JsonObject (com.google.gson.JsonObject)2 LinkedList (java.util.LinkedList)2 DriverInfo (org.openmuc.framework.config.DriverInfo)2 DriverNotAvailableException (org.openmuc.framework.config.DriverNotAvailableException)2 IdCollisionException (org.openmuc.framework.config.IdCollisionException)2 Channel (org.openmuc.framework.dataaccess.Channel)2 JsonArray (com.google.gson.JsonArray)1 ConfigWriteException (org.openmuc.framework.config.ConfigWriteException)1 DriverConfig (org.openmuc.framework.config.DriverConfig)1 ServerMapping (org.openmuc.framework.config.ServerMapping)1 FromJson (org.openmuc.framework.lib.rest.FromJson)1 RestChannelConfig (org.openmuc.framework.lib.rest.objects.RestChannelConfig)1 ServerMappingContainer (org.openmuc.framework.server.spi.ServerMappingContainer)1