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