Skip to content

Commit

Permalink
code reformated
Browse files Browse the repository at this point in the history
  • Loading branch information
Gituser010 committed Jun 26, 2024
1 parent 99fc503 commit 807e84e
Show file tree
Hide file tree
Showing 31 changed files with 272 additions and 301 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,47 +44,50 @@ protected ResponseEntity<Object> handleMethodArgumentNotValid(

return new ResponseEntity<>(apiError, status);
}

/**
* Returns proper response entity on NoSuchElementException.
*
* @param ex exception which caused this method call
* @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);
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
* @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);
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
* @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);
final APIError apiError = new APIError(HttpStatus.CONFLICT, message);
return new ResponseEntity<>(apiError, HttpStatus.CONFLICT);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.Setter;

import java.util.Objects;

/**
* Base class for actuator devices
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package io.patriotframework.virtualsmarthomeplus.DTOs;

/**
* Base class for sensor devices DTOs
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package io.patriotframework.virtualsmarthomeplus.Mapper;

import io.patriotframework.virtualsmarthomeplus.DTOs.ThermometerDTO;
import io.patriotframework.virtualsmarthomeplus.DTOs.HouseDTO;
import io.patriotframework.virtualsmarthomeplus.DTOs.RGBLightDTO;
import io.patriotframework.virtualsmarthomeplus.DTOs.DeviceDTO;
import io.patriotframework.virtualsmarthomeplus.DTOs.DoorDTO;
import io.patriotframework.virtualsmarthomeplus.DTOs.FireplaceDTO;
import io.patriotframework.virtualsmarthomeplus.DTOs.*;
import io.patriotframework.virtualsmarthomeplus.house.House;
import io.patriotframework.virtualsmarthomeplus.house.devices.Device;
import io.patriotframework.virtualsmarthomeplus.house.devices.finalDevices.Door;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class DeviceController {
private static final String DEVICE_ID_ROUTE = APIRoutes.DEVICE_ROUTE + "/{label}";
private final House house;
private final DTOMapper dtoMapper;

@Autowired
public DeviceController(House house) {
this.house = house;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@
import io.patriotframework.virtualsmarthomeplus.house.devices.finalDevices.Door;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;

import javax.validation.Valid;
Expand Down Expand Up @@ -78,7 +70,7 @@ public ResponseEntity<DeviceDTO> postDoor(
*
* @param device updated door
* @param apiVersion api version specified in route
* @param label label of the new device
* @param label label of the new device
* @return door updated or added to the house
*/
@PutMapping(DOOR_ID_ROUTE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public DeviceDTO handlePut(String label, DeviceDTO device)
deviceToUpdate.update(device);



return dtoMapper.map(deviceToUpdate);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@
import io.patriotframework.virtualsmarthomeplus.house.devices.finalDevices.Fireplace;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;

import javax.validation.Valid;
Expand Down Expand Up @@ -72,7 +66,7 @@ public DeviceDTO postFireplace(@Valid @RequestBody FireplaceDTO device, @PathVar
*
* @param device updated fireplace DTO
* @param apiVersion api version specified in route
* @param label label of the device to be created
* @param label label of the device to be created
* @return fireplace updated or added to the house
*/
@PutMapping(FIREPLACE_ID_ROUTE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@
import io.patriotframework.virtualsmarthomeplus.house.devices.finalDevices.RGBLight;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;

import javax.validation.Valid;
Expand Down Expand Up @@ -68,7 +62,7 @@ public ResponseEntity<DeviceDTO> getLed(@PathVariable @NotNull String label, @Pa
*
* @param device updated RGBLight DTO
* @param apiVersion api version specified in route
* @param label label of the RGBLight to be created
* @param label label of the RGBLight to be created
* @return RGBLight updated or added to the house
*/
@PutMapping(RGB_LIGHT_ID_ROUTE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;

import javax.validation.constraints.NotNull;
Expand Down Expand Up @@ -76,7 +70,7 @@ public DeviceDTO postThermometer(
*
* @param thermometer updated thermometer DTO
* @param apiVersion api version specified in route
* @param label label of the thermometer to be updated
* @param label label of the thermometer to be updated
* @return thermometer updated or added to the house
*/
@PutMapping(THERMOMETER_ID_ROUTE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public DeviceFactory() {
* @param device DTO of device to be created
* @return devices of certain type
*/
public Device createDevice( DeviceDTO device) throws IllegalArgumentException {
public Device createDevice(DeviceDTO device) throws IllegalArgumentException {
final String deviceType = device.getClass().getSimpleName();
return switch (deviceType) {
case "RGBLightDTO" -> new RGBLight(device.getLabel());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void removeDevice(String label) throws IllegalArgumentException, NoSuchEl
* Provide device of certain type which is stored in house.
*
* @param deviceType type of requested device
* @param label label of requested device
* @param label label of requested device
* @return device of requested type
*/
public Device getDeviceOfType(Class<? extends Device> deviceType, String label) throws IllegalArgumentException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public Actuator(String label) {
* Creates new Actuator with the same values of the attributes as given Actuator except label.
* Label of the new Actuator is given by parameter.
*
* @param newLabel label creates identity of the thermometer and is compared in the equals method
* @param newLabel label creates identity of the thermometer and is compared in the equals method
* @param origDevice template for the new Actuator
* @throws IllegalArgumentException if given label is null or blank
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ public void setEnabled(Boolean enabled) {
* Method responsible for check whether two Devices has the same values of attributes
*
* @param device device to which this object will be compared
* @throws IllegalArgumentException if parameter device is null
* @return return true if objects have same attributes and false otherwise
* @throws IllegalArgumentException if parameter device is null
*/
public abstract boolean hasSameAttributes(Device device) throws IllegalArgumentException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public boolean hasSameAttributes(Device door) throws IllegalArgumentException {
}
return typedDoor.opened == opened;
}

/**
* Updates the door object with the values from provided DTO.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public boolean hasSameAttributes(Device fireplace) throws IllegalArgumentExcepti
}
return typedFireplace.onFire == onFire;
}

/**
* Updates the fireplace object with the values from provided DTO.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.awt.Color;
import java.awt.*;


@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Thermometer(String label) {
/**
* Creates new thermometer with given label and given unit.
*
* @param unit measuring unit
* @param unit measuring unit
* @param label label of the new thermometer
* @throws IllegalArgumentException if given label is null or blank
*/
Expand Down Expand Up @@ -85,22 +85,22 @@ public Float getTemperature() {
}

/**
* Method sets new measuring unit
* Method gets type of measuring unit
*
* @param unit change measuring unit to unit
* @return measuring unit
*/
public void setUnit(String unit) {
Thermometer.this.unit = unit;
LOGGER.debug(String.format("Measuring unit changed to %s", unit));
public String getUnit() {
return unit;
}

/**
* Method gets type of measuring unit
* Method sets new measuring unit
*
* @return measuring unit
* @param unit change measuring unit to unit
*/
public String getUnit() {
return unit;
public void setUnit(String unit) {
Thermometer.this.unit = unit;
LOGGER.debug(String.format("Measuring unit changed to %s", unit));
}

/**
Expand Down Expand Up @@ -130,6 +130,7 @@ public boolean hasSameAttributes(Device thermometer) throws IllegalArgumentExcep
}
return typedThermometer.unit.equals(unit);
}

/**
* Updates the thermometer object with the values from provided DTO.
*
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@

server.error.whitelabel.enabled=false
server.error.include-message=always
2 changes: 1 addition & 1 deletion src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
server:
port : 8081
port: 8081
Loading

0 comments on commit 807e84e

Please sign in to comment.