use of org.openmuc.framework.config.IdCollisionException in project OpenMUC by isc-konstanz.
the class DriverConfigImpl method addDriverFromDomNode.
static void addDriverFromDomNode(Node driverConfigNode, RootConfigImpl parentConfig) throws ParseException {
String id = ChannelConfigImpl.getAttributeValue(driverConfigNode, "id");
if (id == null) {
throw new ParseException("driver has no id attribute");
}
DriverConfigImpl config;
try {
config = parentConfig.addDriver(id);
} catch (IdCollisionException e) {
throw new ParseException(e);
}
parseDiverNode(driverConfigNode, config);
}
use of org.openmuc.framework.config.IdCollisionException 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.IdCollisionException 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.IdCollisionException in project OpenMUC by isc-konstanz.
the class DriverResourceServlet method doSetConfigs.
private synchronized boolean doSetConfigs(String driverId, HttpServletResponse response, String json) {
boolean ok = false;
try {
DriverConfig driverConfig = rootConfig.getDriver(driverId);
if (driverConfig != null) {
try {
FromJson fromJson = new FromJson(json);
fromJson.setDriverConfig(driverConfig, driverId);
} catch (IdCollisionException e) {
}
configService.setConfig(rootConfig);
configService.writeConfigToFile();
response.setStatus(HttpServletResponse.SC_OK);
ok = true;
} else {
ServletLib.sendHTTPErrorAndLogErr(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, logger, "Not able to access to driver ", driverId);
}
} catch (JsonSyntaxException e) {
ServletLib.sendHTTPErrorAndLogDebug(response, HttpServletResponse.SC_CONFLICT, logger, "JSON syntax is wrong.");
} catch (MissingJsonObjectException e) {
ServletLib.sendHTTPErrorAndLogDebug(response, HttpServletResponse.SC_NOT_FOUND, logger, e.getMessage());
} catch (ConfigWriteException e) {
ServletLib.sendHTTPErrorAndLogErr(response, HttpServletResponse.SC_CONFLICT, logger, "Could not write driver \"", driverId, "\".");
logger.debug(e.getMessage());
} catch (RestConfigIsNotCorrectException e) {
ServletLib.sendHTTPErrorAndLogDebug(response, HttpServletResponse.SC_NOT_ACCEPTABLE, logger, "Not correct formed driver config json.", " JSON = ", json);
} catch (IllegalStateException e) {
ServletLib.sendHTTPErrorAndLogDebug(response, HttpServletResponse.SC_CONFLICT, logger, e.getMessage());
}
return ok;
}
use of org.openmuc.framework.config.IdCollisionException in project OpenMUC by isc-konstanz.
the class DeviceResourceServlet method doPutConfigs.
private synchronized boolean doPutConfigs(String deviceId, HttpServletResponse response, FromJson json) throws JsonSyntaxException, ConfigWriteException, RestConfigIsNotCorrectException, MissingJsonObjectException, IllegalStateException {
boolean ok = false;
DeviceConfig deviceConfig = rootConfig.getDevice(deviceId);
if (deviceConfig != null) {
try {
json.setDeviceConfig(deviceConfig, deviceId);
} catch (IdCollisionException e) {
}
configService.setConfig(rootConfig);
configService.writeConfigToFile();
response.setStatus(HttpServletResponse.SC_OK);
ok = true;
} else {
ServletLib.sendHTTPErrorAndLogErr(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, logger, "Not able to access to device ", deviceId);
}
return ok;
}
Aggregations