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;
}
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);
}
}
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);
}
}
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);
}
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;
}
Aggregations