31 changed files with 491 additions and 21 deletions
@ -1,16 +0,0 @@ |
|||||
package org.elitclass.mobidigimproject.service; |
|
||||
|
|
||||
import com.fasterxml.jackson.databind.ObjectMapper; |
|
||||
import org.springframework.stereotype.Service; |
|
||||
|
|
||||
import java.io.IOException; |
|
||||
import java.util.Map; |
|
||||
|
|
||||
@Service |
|
||||
public class service { |
|
||||
private void saveFileToData(Map<String, Object> data) throws IOException { |
|
||||
ObjectMapper mapper = new ObjectMapper(); |
|
||||
String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(data); |
|
||||
|
|
||||
} |
|
||||
} |
|
||||
@ -1,4 +1,4 @@ |
|||||
package org.elitclass.mobidigimproject; |
package org.mobidgim.mobidigimproject; |
||||
|
|
||||
import org.springframework.boot.SpringApplication; |
import org.springframework.boot.SpringApplication; |
||||
import org.springframework.boot.autoconfigure.SpringBootApplication; |
import org.springframework.boot.autoconfigure.SpringBootApplication; |
||||
@ -0,0 +1,46 @@ |
|||||
|
package org.mobidgim.mobidigimproject.common.api; |
||||
|
|
||||
|
import jakarta.validation.Valid; |
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.Data; |
||||
|
import lombok.NoArgsConstructor; |
||||
|
import org.mobidgim.mobidigimproject.common.error.ErrorCodeIfs; |
||||
|
|
||||
|
@AllArgsConstructor |
||||
|
@NoArgsConstructor |
||||
|
@Data |
||||
|
public class Api<T> { |
||||
|
|
||||
|
private Result result; |
||||
|
@Valid |
||||
|
private T body; |
||||
|
|
||||
|
public static <T> Api<T> OK(T Data){ |
||||
|
var api = new Api<T>(); |
||||
|
api.result = Result.OK(); |
||||
|
api.body = Data; |
||||
|
return api; |
||||
|
} |
||||
|
public static Api<Object> ERROR(Result result){ |
||||
|
var api = new Api<Object>(); |
||||
|
api.result = result; |
||||
|
return api; |
||||
|
} |
||||
|
public static Api<Object> ERROR(ErrorCodeIfs errorCodeIfs){ |
||||
|
var api = new Api<Object>(); |
||||
|
api.result = Result.ERROR(errorCodeIfs); |
||||
|
return api; |
||||
|
} |
||||
|
public static Api<Object> ERROR(ErrorCodeIfs errorCodeIfs, Throwable tx){ |
||||
|
var api = new Api<Object>(); |
||||
|
api.result = Result.ERROR(errorCodeIfs,tx); |
||||
|
return api; |
||||
|
} |
||||
|
public static Api<Object> ERROR(ErrorCodeIfs errorCodeIfs, String description){ |
||||
|
var api = new Api<Object>(); |
||||
|
api.result = Result.ERROR(errorCodeIfs,description); |
||||
|
return api; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,48 @@ |
|||||
|
package org.mobidgim.mobidigimproject.common.api; |
||||
|
|
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.Builder; |
||||
|
import lombok.Data; |
||||
|
import lombok.NoArgsConstructor; |
||||
|
import org.mobidgim.mobidigimproject.common.error.ErrorCode; |
||||
|
import org.mobidgim.mobidigimproject.common.error.ErrorCodeIfs; |
||||
|
|
||||
|
@AllArgsConstructor |
||||
|
@NoArgsConstructor |
||||
|
@Data |
||||
|
@Builder |
||||
|
public class Result { |
||||
|
private Integer resultCode; |
||||
|
private String resultMessage; |
||||
|
private String resultDescription; |
||||
|
|
||||
|
public static Result OK(){ |
||||
|
return Result.builder() |
||||
|
.resultCode(ErrorCode.OK.getErrorCode()) |
||||
|
.resultMessage(ErrorCode.OK.getErrorDescription()) |
||||
|
.resultDescription("성공") |
||||
|
.build(); |
||||
|
} |
||||
|
public static Result ERROR(ErrorCodeIfs errorCodeIfs){ |
||||
|
return Result.builder() |
||||
|
.resultCode(errorCodeIfs.getErrorCode()) |
||||
|
.resultMessage(errorCodeIfs.getErrorDescription()) |
||||
|
.resultDescription("에러") |
||||
|
.build(); |
||||
|
} |
||||
|
public static Result ERROR(ErrorCodeIfs errorCodeIfs,Throwable tx){ |
||||
|
return Result.builder() |
||||
|
.resultCode(errorCodeIfs.getErrorCode()) |
||||
|
.resultMessage(errorCodeIfs.getErrorDescription()) |
||||
|
.resultDescription(tx.getLocalizedMessage()) |
||||
|
.build(); |
||||
|
} |
||||
|
public static Result ERROR(ErrorCodeIfs errorCodeIfs,String Description){ |
||||
|
return Result.builder() |
||||
|
.resultCode(errorCodeIfs.getErrorCode()) |
||||
|
.resultMessage(errorCodeIfs.getErrorDescription()) |
||||
|
.resultDescription(Description) |
||||
|
.build(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,20 @@ |
|||||
|
package org.mobidgim.mobidigimproject.common.error; |
||||
|
|
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.Getter; |
||||
|
import org.springframework.http.HttpStatus; |
||||
|
|
||||
|
@AllArgsConstructor |
||||
|
@Getter |
||||
|
public enum ErrorCode implements ErrorCodeIfs { |
||||
|
|
||||
|
OK(200, 200, "성공"), |
||||
|
BAD_REQUEST(HttpStatus.BAD_REQUEST.value(), 400, "잘못된 요청"), |
||||
|
NULL_POINT(HttpStatus.INTERNAL_SERVER_ERROR.value(), 512, "NULL POINT"), |
||||
|
SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR.value(), 500, "서버 에러"); |
||||
|
|
||||
|
private final Integer httpStatusCode; |
||||
|
private final Integer errorCode; |
||||
|
private final String errorDescription; |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
package org.mobidgim.mobidigimproject.common.error; |
||||
|
|
||||
|
public interface ErrorCodeIfs { |
||||
|
|
||||
|
Integer getHttpStatusCode(); |
||||
|
|
||||
|
Integer getErrorCode(); |
||||
|
|
||||
|
String getErrorDescription(); |
||||
|
} |
||||
@ -0,0 +1,28 @@ |
|||||
|
package org.mobidgim.mobidigimproject.config.objectmapper; |
||||
|
|
||||
|
import com.fasterxml.jackson.databind.DeserializationFeature; |
||||
|
import com.fasterxml.jackson.databind.ObjectMapper; |
||||
|
import com.fasterxml.jackson.databind.PropertyNamingStrategies; |
||||
|
import com.fasterxml.jackson.databind.SerializationFeature; |
||||
|
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; |
||||
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; |
||||
|
import org.springframework.context.annotation.Bean; |
||||
|
import org.springframework.context.annotation.Configuration; |
||||
|
|
||||
|
@Configuration |
||||
|
public class ObjectMapperConfig { |
||||
|
|
||||
|
@Bean |
||||
|
public ObjectMapper objectMapper() { |
||||
|
var objectMapper = new ObjectMapper(); |
||||
|
|
||||
|
objectMapper.registerModule(new Jdk8Module()); |
||||
|
objectMapper.registerModule(new JavaTimeModule()); |
||||
|
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false); |
||||
|
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); |
||||
|
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); |
||||
|
objectMapper.setPropertyNamingStrategy(new PropertyNamingStrategies.SnakeCaseStrategy()); |
||||
|
|
||||
|
return objectMapper; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
package org.mobidgim.mobidigimproject.config.swagger; |
||||
|
|
||||
|
import com.fasterxml.jackson.databind.ObjectMapper; |
||||
|
import io.swagger.v3.core.jackson.ModelResolver; |
||||
|
import org.springframework.context.annotation.Bean; |
||||
|
import org.springframework.context.annotation.Configuration; |
||||
|
|
||||
|
@Configuration |
||||
|
public class SwaggerConfig { |
||||
|
@Bean |
||||
|
public ModelResolver modelResolver(ObjectMapper objectMapper) { |
||||
|
return new ModelResolver(objectMapper); |
||||
|
} |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,34 @@ |
|||||
|
package org.mobidgim.mobidigimproject.controller; |
||||
|
|
||||
|
import jakarta.servlet.ServletResponse; |
||||
|
import lombok.AllArgsConstructor; |
||||
|
import org.mobidgim.mobidigimproject.common.api.Api; |
||||
|
import org.mobidgim.mobidigimproject.model.device.DeviceDTO; |
||||
|
import org.mobidgim.mobidigimproject.model.register.RegisterDTO; |
||||
|
import org.mobidgim.mobidigimproject.service.SettingService; |
||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
import java.io.IOException; |
||||
|
|
||||
|
@RestController |
||||
|
@RequestMapping("/setting") |
||||
|
@AllArgsConstructor |
||||
|
public class Controller { |
||||
|
|
||||
|
private SettingService settingService; |
||||
|
|
||||
|
@PostMapping("/device") |
||||
|
public Api<DeviceDTO> settingDevice(@RequestBody DeviceDTO request) throws IOException { |
||||
|
settingService.saveFileWithDevice(request); |
||||
|
|
||||
|
return Api.OK(request); |
||||
|
} |
||||
|
@PostMapping("/register") |
||||
|
public Api<RegisterDTO> settingRegister(@RequestBody RegisterDTO request)throws IOException{ |
||||
|
settingService.saveFileWithRegister(request); |
||||
|
return Api.OK(request); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,36 @@ |
|||||
|
package org.mobidgim.mobidigimproject.model.device; |
||||
|
|
||||
|
import com.fasterxml.jackson.annotation.JsonInclude; |
||||
|
import com.fasterxml.jackson.annotation.JsonUnwrapped; |
||||
|
import lombok.Getter; |
||||
|
import lombok.Setter; |
||||
|
import org.mobidgim.mobidigimproject.model.device.subDTO.Imu; |
||||
|
import org.mobidgim.mobidigimproject.model.device.subDTO.*; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
@Getter |
||||
|
@Setter |
||||
|
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
|
public class DeviceDTO { |
||||
|
|
||||
|
@JsonUnwrapped |
||||
|
private Wifi wifiConfig; |
||||
|
|
||||
|
@JsonUnwrapped |
||||
|
private Ethernet ethernetConfig; |
||||
|
|
||||
|
@JsonUnwrapped |
||||
|
private Server serverConfig; |
||||
|
|
||||
|
@JsonUnwrapped |
||||
|
private CanBus canBusConfig; |
||||
|
|
||||
|
@JsonUnwrapped |
||||
|
private Rs485 rs485Config; |
||||
|
|
||||
|
@JsonUnwrapped |
||||
|
private Imu imuConfig; |
||||
|
|
||||
|
private List<WifiSSIDS> wifiSSID; |
||||
|
} |
||||
@ -0,0 +1,13 @@ |
|||||
|
package org.mobidgim.mobidigimproject.model.device; |
||||
|
|
||||
|
|
||||
|
import lombok.Data; |
||||
|
import org.mobidgim.mobidigimproject.model.device.enums.WiFiSecurity; |
||||
|
|
||||
|
|
||||
|
@Data |
||||
|
public class WifiSSIDS { |
||||
|
private String wifiSSID; |
||||
|
private String wifiPassword; |
||||
|
private WiFiSecurity wifiSecurity; |
||||
|
} |
||||
@ -0,0 +1,17 @@ |
|||||
|
package org.mobidgim.mobidigimproject.model.device.enums; |
||||
|
|
||||
|
import com.fasterxml.jackson.annotation.JsonValue; |
||||
|
import lombok.AllArgsConstructor; |
||||
|
|
||||
|
@AllArgsConstructor |
||||
|
public enum CanBusType { |
||||
|
EXTENDED("extended"), |
||||
|
STANDARD("standard"); |
||||
|
private final String Type; |
||||
|
|
||||
|
@JsonValue |
||||
|
public String getType() { |
||||
|
return Type; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,17 @@ |
|||||
|
package org.mobidgim.mobidigimproject.model.device.enums; |
||||
|
|
||||
|
import com.fasterxml.jackson.annotation.JsonValue; |
||||
|
import lombok.AllArgsConstructor; |
||||
|
|
||||
|
|
||||
|
@AllArgsConstructor |
||||
|
public enum ImuRemap { |
||||
|
X("x"), |
||||
|
Y("y"); |
||||
|
private final String remap; |
||||
|
|
||||
|
@JsonValue |
||||
|
public String getRemap() { |
||||
|
return remap; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
package org.mobidgim.mobidigimproject.model.device.enums; |
||||
|
|
||||
|
import com.fasterxml.jackson.annotation.JsonValue; |
||||
|
import lombok.AllArgsConstructor; |
||||
|
|
||||
|
@AllArgsConstructor |
||||
|
public enum ImuRemapSign { |
||||
|
MINUS("minus"), |
||||
|
PLUS("plus"); |
||||
|
private final String sign; |
||||
|
|
||||
|
@JsonValue |
||||
|
public String getSign() { |
||||
|
return sign; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
package org.mobidgim.mobidigimproject.model.device.enums; |
||||
|
|
||||
|
import com.fasterxml.jackson.annotation.JsonValue; |
||||
|
import lombok.AllArgsConstructor; |
||||
|
|
||||
|
@AllArgsConstructor |
||||
|
public enum Rs485Mode { |
||||
|
HALF_DUPLEX("half"), |
||||
|
FULL_DUPLEX("full"); |
||||
|
private final String value; |
||||
|
|
||||
|
@JsonValue |
||||
|
public String getValue() { |
||||
|
return value; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
package org.mobidgim.mobidigimproject.model.device.enums; |
||||
|
|
||||
|
import com.fasterxml.jackson.annotation.JsonValue; |
||||
|
import lombok.AllArgsConstructor; |
||||
|
|
||||
|
@AllArgsConstructor |
||||
|
public enum WiFiSecurity { |
||||
|
NONE("none"), |
||||
|
WPA_WPA2("wpa/wpa2"); |
||||
|
private final String value; |
||||
|
|
||||
|
@JsonValue |
||||
|
public String getValue() { |
||||
|
return value; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
package org.mobidgim.mobidigimproject.model.device.enums; |
||||
|
|
||||
|
import com.fasterxml.jackson.annotation.JsonValue; |
||||
|
import lombok.AllArgsConstructor; |
||||
|
|
||||
|
@AllArgsConstructor |
||||
|
public enum WifiStatic { |
||||
|
ON("on") , |
||||
|
OFF("off") ; |
||||
|
private final String Type; |
||||
|
|
||||
|
@JsonValue |
||||
|
public String getType() { |
||||
|
return Type; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,13 @@ |
|||||
|
package org.mobidgim.mobidigimproject.model.device.subDTO; |
||||
|
|
||||
|
|
||||
|
import lombok.Getter; |
||||
|
import lombok.Setter; |
||||
|
import org.mobidgim.mobidigimproject.model.device.enums.CanBusType; |
||||
|
|
||||
|
@Getter |
||||
|
@Setter |
||||
|
public class CanBus { |
||||
|
private CanBusType canBusType; |
||||
|
private int baudrate; |
||||
|
} |
||||
@ -0,0 +1,12 @@ |
|||||
|
package org.mobidgim.mobidigimproject.model.device.subDTO; |
||||
|
|
||||
|
import lombok.Getter; |
||||
|
import lombok.Setter; |
||||
|
|
||||
|
@Getter |
||||
|
@Setter |
||||
|
public class Ethernet { |
||||
|
private String ethIp; |
||||
|
private String ethNetmask; |
||||
|
private String ethGateway; |
||||
|
} |
||||
@ -0,0 +1,17 @@ |
|||||
|
package org.mobidgim.mobidigimproject.model.device.subDTO; |
||||
|
|
||||
|
import lombok.Getter; |
||||
|
import lombok.Setter; |
||||
|
import org.mobidgim.mobidigimproject.model.device.enums.ImuRemap; |
||||
|
import org.mobidgim.mobidigimproject.model.device.enums.ImuRemapSign; |
||||
|
|
||||
|
@Getter |
||||
|
@Setter |
||||
|
public class Imu { |
||||
|
private ImuRemap imuRempaX; |
||||
|
private ImuRemap imuRempaY; |
||||
|
private ImuRemap imuRempaZ; |
||||
|
private ImuRemapSign imuRemapXSign; |
||||
|
private ImuRemapSign imuRemapYSign; |
||||
|
private ImuRemapSign imuRemapZSign; |
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
package org.mobidgim.mobidigimproject.model.device.subDTO; |
||||
|
|
||||
|
import lombok.Getter; |
||||
|
import lombok.Setter; |
||||
|
import org.mobidgim.mobidigimproject.model.device.enums.Rs485Mode; |
||||
|
|
||||
|
@Getter |
||||
|
@Setter |
||||
|
public class Rs485 { |
||||
|
private Rs485Mode rs485Mode; |
||||
|
private int rs485baudrate; |
||||
|
private int rs485dataBits; |
||||
|
private String rs485parity; |
||||
|
private int rs485StopBits; |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
package org.mobidgim.mobidigimproject.model.device.subDTO; |
||||
|
|
||||
|
import lombok.*; |
||||
|
|
||||
|
@Getter |
||||
|
@Setter |
||||
|
public class Server { |
||||
|
private String protocolServerIp; |
||||
|
private int protocolServerPort; |
||||
|
private String updateServerIp; |
||||
|
private int updateServerPort; |
||||
|
private String rtcmServerIp; |
||||
|
private int rtcmServerPort; |
||||
|
private String opcUaServerIp; |
||||
|
private int opcUaServerPort; |
||||
|
private String modbusServerIp; |
||||
|
private int modbusServerPort; |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
package org.mobidgim.mobidigimproject.model.device.subDTO; |
||||
|
|
||||
|
import lombok.Getter; |
||||
|
import lombok.Setter; |
||||
|
import org.mobidgim.mobidigimproject.model.device.enums.WifiStatic; |
||||
|
|
||||
|
@Getter |
||||
|
@Setter |
||||
|
public class Wifi { |
||||
|
private WifiStatic wifiStatic; |
||||
|
private String wifiIp; |
||||
|
private String netmask; |
||||
|
private String gateway; |
||||
|
private String dns1; |
||||
|
private String dns2; |
||||
|
} |
||||
@ -0,0 +1,4 @@ |
|||||
|
package org.mobidgim.mobidigimproject.model.register; |
||||
|
|
||||
|
public class RegisterDTO { |
||||
|
} |
||||
@ -0,0 +1,36 @@ |
|||||
|
package org.mobidgim.mobidigimproject.service; |
||||
|
|
||||
|
import com.fasterxml.jackson.databind.ObjectMapper; |
||||
|
import com.fasterxml.jackson.databind.PropertyNamingStrategies; |
||||
|
import org.mobidgim.mobidigimproject.model.device.DeviceDTO; |
||||
|
import org.mobidgim.mobidigimproject.model.register.RegisterDTO; |
||||
|
import org.springframework.boot.context.config.ConfigData; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.io.IOException; |
||||
|
import java.nio.file.Files; |
||||
|
import java.nio.file.Paths; |
||||
|
|
||||
|
@Service |
||||
|
public class SettingService { |
||||
|
|
||||
|
public DeviceDTO saveFileWithDevice(DeviceDTO request) throws IOException { |
||||
|
ObjectMapper mapper = new ObjectMapper(); |
||||
|
mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE); |
||||
|
String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(request); |
||||
|
String filename = "./temp/deviceConfig.json"; |
||||
|
Files.writeString(Paths.get(filename), json); |
||||
|
|
||||
|
return request; |
||||
|
} |
||||
|
|
||||
|
public RegisterDTO saveFileWithRegister(RegisterDTO request) throws IOException { |
||||
|
ObjectMapper mapper = new ObjectMapper(); |
||||
|
mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE); |
||||
|
String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(request); |
||||
|
String filename = "./temp/registerConfig.json"; |
||||
|
|
||||
|
return request; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -1 +0,0 @@ |
|||||
spring.application.name=mobidigimProject |
|
||||
@ -1,4 +1,4 @@ |
|||||
package org.elitclass.mobidigimproject; |
package org.mobidgim.mobidigimproject; |
||||
|
|
||||
import org.junit.jupiter.api.Test; |
import org.junit.jupiter.api.Test; |
||||
import org.springframework.boot.test.context.SpringBootTest; |
import org.springframework.boot.test.context.SpringBootTest; |
||||
Loading…
Reference in new issue