use of org.openmuc.framework.lib.rest.exceptions.RestConfigIsNotCorrectException 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.lib.rest.exceptions.RestConfigIsNotCorrectException in project OpenMUC by isc-konstanz.
the class RestChannelMapper method setChannelConfig.
public static void setChannelConfig(ChannelConfig cc, RestChannelConfig rcc, String idFromUrl) throws IdCollisionException, RestConfigIsNotCorrectException {
if (cc == null) {
throw new RestConfigIsNotCorrectException("ChannelConfig is null!");
}
if (rcc == null) {
throw new RestConfigIsNotCorrectException();
}
if (rcc.getId() != null && !rcc.getId().isEmpty() && !idFromUrl.equals(rcc.getId())) {
cc.setId(rcc.getId());
}
cc.setDescription(rcc.getDescription());
cc.setAddress(rcc.getAddress());
cc.setSettings(rcc.getSettings());
List<ServerMapping> serverMappings = rcc.getServerMappings();
if (serverMappings != null) {
for (ServerMapping serverMapping : cc.getServerMappings()) {
cc.deleteServerMappings(serverMapping.getId());
}
for (ServerMapping restServerMapping : serverMappings) {
cc.addServerMapping(restServerMapping);
}
}
cc.setUnit(rcc.getUnit());
cc.setValueType(rcc.getValueType());
cc.setValueTypeLength(rcc.getValueTypeLength());
cc.setValueOffset(rcc.getValueOffset());
cc.setScalingFactor(rcc.getScalingFactor());
cc.setListening(rcc.isListening());
cc.setSamplingGroup(rcc.getSamplingGroup());
cc.setSamplingInterval(rcc.getSamplingInterval());
cc.setSamplingTimeOffset(rcc.getSamplingTimeOffset());
cc.setLoggingInterval(rcc.getLoggingInterval());
cc.setLoggingDelayMaximum(rcc.getLoggingTimeMax());
cc.setLoggingTimeOffset(rcc.getLoggingTimeOffset());
cc.setLoggingSettings(rcc.getLoggingSettings());
cc.setLoggingTolerance(rcc.getLoggingTolerance());
cc.setloggingAverage(rcc.isloggingAverage());
cc.setLoggingEvent(rcc.isLoggingEvent());
cc.setDisabled(rcc.isDisabled());
}
Aggregations