|
|
@ -18,42 +18,50 @@
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
package com.example.Public.Configuration.controller;
|
|
|
|
package com.example.Public.Configuration.controller;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.example.Public.Configuration.dto.DeviceConfigDto;
|
|
|
|
import com.example.Public.Configuration.model.DeviceConfig;
|
|
|
|
import com.example.Public.Configuration.model.DeviceConfig;
|
|
|
|
import com.example.Public.Configuration.response.Response;
|
|
|
|
import com.example.Public.Configuration.response.Response;
|
|
|
|
import com.example.Public.Configuration.service.impl.DeviceConfigServiceImpl;
|
|
|
|
import com.example.Public.Configuration.service.impl.DeviceConfigServiceImpl;
|
|
|
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
|
|
|
|
import jakarta.validation.Valid;
|
|
|
|
|
|
|
|
import jakarta.validation.Validation;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("/device-config")
|
|
|
|
@RequestMapping("/device-config")
|
|
|
|
|
|
|
|
@Validated
|
|
|
|
public class DeviceConfigController {
|
|
|
|
public class DeviceConfigController {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private DeviceConfigServiceImpl deviceConfigService;
|
|
|
|
private DeviceConfigServiceImpl deviceConfigService;
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/create")
|
|
|
|
@PostMapping("/")
|
|
|
|
public ResponseEntity<?> createDeviceConfigProfile(@RequestBody DeviceConfig deviceConfig) {
|
|
|
|
public ResponseEntity<?> createDeviceConfigProfile(@Valid @RequestBody DeviceConfigDto deviceConfig) {
|
|
|
|
DeviceConfig newDeviceConfig = deviceConfigService.getByConfigId(deviceConfig.getConfigId());
|
|
|
|
Gson ConfigProfile = new Gson();
|
|
|
|
if (newDeviceConfig == null) {
|
|
|
|
String profileJson = ConfigProfile.toJson(deviceConfig.getConfigProfile());
|
|
|
|
deviceConfigService.saveConfigProfile(deviceConfig);
|
|
|
|
DeviceConfig newConfig = new DeviceConfig();
|
|
|
|
|
|
|
|
newConfig.setConfigId(deviceConfig.getConfigId());
|
|
|
|
|
|
|
|
newConfig.setConfigProfile(profileJson);
|
|
|
|
|
|
|
|
newConfig.setConfigContent(deviceConfig.getConfigContent());
|
|
|
|
|
|
|
|
deviceConfigService.saveConfigProfile(newConfig);
|
|
|
|
return new ResponseEntity<>(new Response(HttpStatus.CREATED.value(),
|
|
|
|
return new ResponseEntity<>(new Response(HttpStatus.CREATED.value(),
|
|
|
|
"Device Config created successfully"), HttpStatus.CREATED);
|
|
|
|
"Device Config created successfully"), HttpStatus.CREATED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new ResponseEntity<>("Device already exists", HttpStatus.BAD_REQUEST);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/configs")
|
|
|
|
@GetMapping("/")
|
|
|
|
public List<DeviceConfig> getConfigsDevices() {
|
|
|
|
public List<DeviceConfig> getConfigsDevices() {
|
|
|
|
|
|
|
|
|
|
|
|
return deviceConfigService.getAllDeviceConfigs();
|
|
|
|
return deviceConfigService.getAllDeviceConfigs();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/{configId}/ones")
|
|
|
|
@GetMapping("/{configId}")
|
|
|
|
public ResponseEntity<?> fetchConfigByConfigId(@PathVariable int configId) {
|
|
|
|
public ResponseEntity<?> fetchConfigByConfigId(@PathVariable int configId) {
|
|
|
|
DeviceConfig deviceConfig1 = deviceConfigService.getByConfigId(configId);
|
|
|
|
DeviceConfig deviceConfig1 = deviceConfigService.getConfigProfileByConfigId(configId);
|
|
|
|
if (deviceConfig1 == null) {
|
|
|
|
if (deviceConfig1 == null) {
|
|
|
|
return new ResponseEntity<>(new Response(HttpStatus.NOT_FOUND.value(),
|
|
|
|
return new ResponseEntity<>(new Response(HttpStatus.NOT_FOUND.value(),
|
|
|
|
"No Device found for Config ID: +configId"), HttpStatus.NOT_FOUND);
|
|
|
|
"No Device found for Config ID: +configId"), HttpStatus.NOT_FOUND);
|
|
|
@ -63,7 +71,7 @@ public class DeviceConfigController {
|
|
|
|
|
|
|
|
|
|
|
|
@PutMapping("/{configId}")
|
|
|
|
@PutMapping("/{configId}")
|
|
|
|
public ResponseEntity<?> updateDeviceDetails(@PathVariable int configId, @RequestBody DeviceConfig deviceConfig) {
|
|
|
|
public ResponseEntity<?> updateDeviceDetails(@PathVariable int configId, @RequestBody DeviceConfig deviceConfig) {
|
|
|
|
DeviceConfig updateConfig = deviceConfigService.getByConfigId(configId);
|
|
|
|
DeviceConfig updateConfig = deviceConfigService.getConfigProfileByConfigId(configId);
|
|
|
|
if (updateConfig == null) {
|
|
|
|
if (updateConfig == null) {
|
|
|
|
deviceConfigService.UpdateConfigDetails(deviceConfig);
|
|
|
|
deviceConfigService.UpdateConfigDetails(deviceConfig);
|
|
|
|
return new ResponseEntity<>(new Response(HttpStatus.NOT_FOUND.value(),
|
|
|
|
return new ResponseEntity<>(new Response(HttpStatus.NOT_FOUND.value(),
|
|
|
@ -75,7 +83,7 @@ public class DeviceConfigController {
|
|
|
|
|
|
|
|
|
|
|
|
@DeleteMapping("/{configId}")
|
|
|
|
@DeleteMapping("/{configId}")
|
|
|
|
public ResponseEntity<?> deleteConfigConfigId(@PathVariable int configId) {
|
|
|
|
public ResponseEntity<?> deleteConfigConfigId(@PathVariable int configId) {
|
|
|
|
DeviceConfig deleteConfig = deviceConfigService.getByConfigId(configId);
|
|
|
|
DeviceConfig deleteConfig = deviceConfigService.getConfigProfileByConfigId(configId);
|
|
|
|
if (deleteConfig == null) {
|
|
|
|
if (deleteConfig == null) {
|
|
|
|
deviceConfigService.deleteConfigProfile(configId);
|
|
|
|
deviceConfigService.deleteConfigProfile(configId);
|
|
|
|
return new ResponseEntity<>(new Response(HttpStatus.NOT_FOUND.value(),
|
|
|
|
return new ResponseEntity<>(new Response(HttpStatus.NOT_FOUND.value(),
|
|
|
|