Skip to content

Commit

Permalink
added RGBLight and Thermometer devices
Browse files Browse the repository at this point in the history
  • Loading branch information
Gituser010 committed Aug 7, 2023
1 parent 1b64cca commit bdae078
Show file tree
Hide file tree
Showing 45 changed files with 2,948 additions and 389 deletions.
10 changes: 5 additions & 5 deletions checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@
<!-- See https://checkstyle.sourceforge.io/config_javadoc.html -->
<module name="JavadocMethod">
<property name="accessModifiers" value="public"/>
<property name="severity" value="warning" />
<property name="severity" value="warning"/>
</module>
<module name="JavadocType">
<property name="scope" value="public"/>
<property name="severity" value="warning" />
<property name="severity" value="warning"/>
</module>
<module name="JavadocStyle">
<property name="scope" value="public"/>
<property name="checkFirstSentence" value="false"/>
<property name="severity" value="warning" />
<property name="severity" value="warning"/>
</module>

<!-- Checks for import related problems. -->
Expand Down Expand Up @@ -116,13 +116,13 @@
<module name="ArrayTypeStyle"/>
<module name="CommentsIndentation"/>
<module name="Indentation">
<property name="basicOffset" value="8"/>
<property name="basicOffset" value="4"/>
</module>
</module>

<!-- Checks whether files end with a new line. -->
<!-- See http://checkstyle.sf.net/config_misc.html#NewlineAtEndOfFile -->
<module name="NewlineAtEndOfFile" />
<module name="NewlineAtEndOfFile"/>

<!-- Checks for Size Violations. -->
<!-- See http://checkstyle.sf.net/config_sizes.html -->
Expand Down
179 changes: 92 additions & 87 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,92 +1,97 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>io.patriot-framework</groupId>
<artifactId>virtual-smart-home-plus</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>virtual-smart-home-plus</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.26</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>io.patriot-framework</groupId>
<artifactId>virtual-smart-home-plus</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>virtual-smart-home-plus</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.26</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.patriot-framework</groupId>
<artifactId>generator</artifactId>
<version>2.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>

</dependencies>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.2.0</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>10.5.0</version>
</dependency>
</dependencies>
<configuration>
<configLocation>checkstyle.xml</configLocation>
</configuration>
<executions>
<execution>
<id>checkstyle</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
<configuration>
<consoleOutput>true</consoleOutput>
<failOnViolation>false</failOnViolation>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.2.0</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>10.5.0</version>
</dependency>
</dependencies>
<configuration>
<configLocation>checkstyle.xml</configLocation>
</configuration>
<executions>
<execution>
<id>checkstyle</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
<configuration>
<consoleOutput>true</consoleOutput>
<failOnViolation>false</failOnViolation>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import org.springframework.http.HttpStatus;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -14,15 +15,16 @@
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class APIError {
private HttpStatus status;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy hh:mm:ss")
private LocalDateTime timestamp;
private final String message;
private final HttpStatus status;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy hh:mm:ss")
private final LocalDateTime timestamp;
private List<APISubError> subErrors;

/**
* Constructs instance of APIError with current time, error message and
* @param status status for the recipient
*
* @param status status for the recipient
* @param message message for the recipient
*/
public APIError(HttpStatus status, String message) {
Expand All @@ -33,10 +35,11 @@ public APIError(HttpStatus status, String message) {

/**
* Adds instance of APISubError to the list of errors which caused this error
*
* @param error another sub-error which caused error
*/
public void addSubError(APISubError error) {
if(subErrors == null) {
if (subErrors == null) {
subErrors = new ArrayList<>();
}
subErrors.add(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,23 @@ public class NotValidSubError extends APISubError {
/**
* object name
*/
private String object;
private final String object;
/**
* field where the error occurs
*/
private String field;
private final String field;
/**
* rejected value
*/
private Object rejectedValue;
private final Object rejectedValue;
/**
* default message what causes the error
*/
private String message;
private final String message;

/**
* Creates instance of NotValidSubError with initialized attributes. Values are parsed from FieldError
*
* @param fieldError instance of FieldError
*/
public NotValidSubError(FieldError fieldError) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

import javax.management.openmbean.KeyAlreadyExistsException;
import java.util.NoSuchElementException;

/**
* Handles custom exceptions
*/
Expand All @@ -19,24 +23,69 @@ public class APIExceptionHandler extends ResponseEntityExceptionHandler {

/**
* Returns proper response entity on MethodArgumentNotValidException.
* @param ex exception which caused this method call
*
* @param ex exception which caused this method call
* @param headers http headers
* @param status http status
* @param status http status
* @param request web request
* @return {@link io.patriotframework.virtualsmarthomeplus.APIErrors.APIError APIError} instance whith list of
* {@link io.patriotframework.virtualsmarthomeplus.APIErrors.NotValidSubError NotValidSubError} instances, which
* informs about specific validity violations
* {@link io.patriotframework.virtualsmarthomeplus.APIErrors.NotValidSubError NotValidSubError} instances, which
* informs about specific validity violations
*/
@Override
protected ResponseEntity<Object> handleMethodArgumentNotValid(
MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {

String message = "Malformed JSON body";
APIError apiError = new APIError(status, message);
final String message = "Malformed JSON body";
final APIError apiError = new APIError(status, message);

ex.getBindingResult().getAllErrors().forEach((error) ->
apiError.addSubError(new NotValidSubError((FieldError)error)));
apiError.addSubError(new NotValidSubError((FieldError) error)));

return new ResponseEntity<>(apiError, status);
}
/**
* Returns proper response entity on NoSuchElementException.
*
* @param ex exception which caused this method call
* @return {@link io.patriotframework.virtualsmarthomeplus.APIErrors.APIError APIError} instance whith list of
* {@link io.patriotframework.virtualsmarthomeplus.APIErrors.NotValidSubError NotValidSubError} instances, which
* informs about specific validity violations
*/
@ExceptionHandler(value = NoSuchElementException.class)
protected ResponseEntity<Object> handleNotFound(NoSuchElementException ex) {
final String message = "Device not found";
final APIError apiError = new APIError(HttpStatus.NOT_FOUND,message);
return new ResponseEntity<>(apiError,HttpStatus.NOT_FOUND);
}
/**
* Returns proper response entity on IllegalArgumentException.
*
* @param ex exception which caused this method call
* @return {@link io.patriotframework.virtualsmarthomeplus.APIErrors.APIError APIError} instance whith list of
* {@link io.patriotframework.virtualsmarthomeplus.APIErrors.NotValidSubError NotValidSubError} instances, which
* informs about specific validity violations
*/
@ExceptionHandler(value = IllegalArgumentException.class)
protected ResponseEntity<Object> handleWrongArgument(IllegalArgumentException ex) {
final String message = "Wrong label";
final APIError apiError = new APIError(HttpStatus.BAD_REQUEST,message);
return new ResponseEntity<>(apiError,HttpStatus.BAD_REQUEST);
}
/**
* Returns proper response entity on KeyAlreadyExistException.
*
* @param ex exception which caused this method call
* @return {@link io.patriotframework.virtualsmarthomeplus.APIErrors.APIError APIError} instance whith list of
* {@link io.patriotframework.virtualsmarthomeplus.APIErrors.NotValidSubError NotValidSubError} instances, which
* informs about specific validity violations
*/
@ExceptionHandler(value = KeyAlreadyExistsException.class)
protected ResponseEntity<Object> handleExistingDevice(IllegalArgumentException ex) {
final String message = "Device already exists";
final APIError apiError = new APIError(HttpStatus.CONFLICT,message);
return new ResponseEntity<>(apiError,HttpStatus.CONFLICT);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,15 @@ public class APIRoutes {
/**
* Route of the final device door.
*/
public static final String DOOR_ROUTE = DEVICE_ROUTE + "door/";;
public static final String DOOR_ROUTE = DEVICE_ROUTE + "door/";
/**
* Route of the final device thermometer.
*/
public static final String THERMOMETER_ROUTE = DEVICE_ROUTE + "thermometer/";
/**
* Route of the final device RGBLight.
*/
public static final String RGB_LIGHT_ROUTE = DEVICE_ROUTE + "RGBLight/";


}
Loading

0 comments on commit bdae078

Please sign in to comment.