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 3, 2023
1 parent 1b64cca commit 2febe65
Show file tree
Hide file tree
Showing 37 changed files with 1,858 additions and 380 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 @@ -19,23 +19,24 @@ 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);
}
Expand Down
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/";


}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.patriotframework.virtualsmarthomeplus;

import org.modelmapper.ModelMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.modelmapper.ModelMapper;

@Configuration
public class AppConfig {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.patriotframework.virtualsmarthomeplus.DTOs;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.Objects;

@Getter
@Setter
@NoArgsConstructor
public class ActuatorDTO extends DeviceDTO {
/**
* True if actuator is switched on
*/
private Boolean switchedOn;

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof final ActuatorDTO that)) return false;
if (!super.equals(o)) return false;
return Objects.equals(getSwitchedOn(), that.getSwitchedOn());
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), getSwitchedOn());
}
}
Loading

0 comments on commit 2febe65

Please sign in to comment.