use of org.openmuc.framework.config.DeviceConfig in project OpenMUC by isc-konstanz.
the class DeviceResourceServlet method doDelete.
@Override
public synchronized void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(APPLICATION_JSON);
String[] pathAndQueryString = checkIfItIsACorrectRest(request, response, logger);
if (pathAndQueryString != null) {
setConfigAccess();
String pathInfo = pathAndQueryString[0];
String deviceId = null;
String[] pathInfoArray = ServletLib.getPathInfoArray(pathInfo);
deviceId = pathInfoArray[0];
DeviceConfig deviceConfig = rootConfig.getDevice(deviceId);
if (pathInfoArray.length != 1) {
ServletLib.sendHTTPErrorAndLogDebug(response, HttpServletResponse.SC_NOT_FOUND, logger, REQUESTED_REST_PATH_IS_NOT_AVAILABLE, REST_PATH, request.getPathInfo());
} else if (deviceConfig == null) {
ServletLib.sendHTTPErrorAndLogDebug(response, HttpServletResponse.SC_NOT_FOUND, logger, "Device \"" + deviceId + "\" does not exist.");
} else {
try {
deviceConfig.delete();
configService.setConfig(rootConfig);
configService.writeConfigToFile();
if (rootConfig.getDriver(deviceId) == null) {
response.setStatus(HttpServletResponse.SC_OK);
} else {
ServletLib.sendHTTPErrorAndLogErr(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, logger, "Not able to delete driver ", deviceId);
}
} catch (ConfigWriteException e) {
ServletLib.sendHTTPErrorAndLogErr(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, logger, "Not able to write into config.");
}
}
}
}
use of org.openmuc.framework.config.DeviceConfig in project OpenMUC by isc-konstanz.
the class DeviceResourceServlet method doGetDevice.
private void doGetDevice(ToJson json, String deviceId, HttpServletResponse response) {
DeviceConfig deviceConfig = rootConfig.getDevice(deviceId);
json.addDevice(RestDeviceWrapper.getDevice(deviceConfig, configService, dataAccess));
}
use of org.openmuc.framework.config.DeviceConfig 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;
}
use of org.openmuc.framework.config.DeviceConfig in project OpenMUC by isc-konstanz.
the class DeviceResourceServlet method getDeviceIdList.
private List<String> getDeviceIdList() {
List<String> deviceList = new ArrayList<>();
Collection<DeviceConfig> deviceConfigs = getConfigsList();
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 DeviceResourceServlet method doGetConfigField.
private void doGetConfigField(ToJson json, String deviceId, String configField, HttpServletResponse response) throws IOException {
DeviceConfig deviceConfig = rootConfig.getDevice(deviceId);
if (deviceConfig != null) {
JsonObject jsoConfigAll = ToJson.getDeviceConfigAsJsonObject(deviceConfig);
if (jsoConfigAll == null) {
ServletLib.sendHTTPErrorAndLogDebug(response, HttpServletResponse.SC_NOT_FOUND, logger, "Could not find JSON object \"configs\"");
} else {
JsonElement jseConfigField = jsoConfigAll.get(configField);
if (jseConfigField == null) {
ServletLib.sendHTTPErrorAndLogDebug(response, HttpServletResponse.SC_NOT_FOUND, logger, "Requested rest config field is not available.", " configField = ", configField);
} else {
JsonObject jso = new JsonObject();
jso.add(configField, jseConfigField);
json.addJsonObject(Const.CONFIGS, jso);
}
}
} else {
ServletLib.sendHTTPErrorAndLogDebug(response, HttpServletResponse.SC_NOT_FOUND, logger, REQUESTED_ID_IS_NOT_AVAILABLE, REST_ID, deviceId);
}
}
Aggregations