Merge branch 'sonar-fix' into 'dev'

Added lombok and converted DTOs

See merge request sa4-2020/the-sanmarinoes/backend!136
This commit is contained in:
Claudio Maggioni 2020-05-12 15:49:54 +02:00
commit 328ad4e882
30 changed files with 62 additions and 643 deletions

View file

@ -4,6 +4,7 @@ plugins {
id 'java'
id 'jacoco'
id "org.sonarqube" version "2.8"
id 'io.freefair.lombok' version '5.0.1'
}
group = 'ch.usi.inf.sa4.sanmarinoes'
version = '0.0.1-SNAPSHOT'

3
lombok.config Normal file
View file

@ -0,0 +1,3 @@
# This file is generated by the 'io.freefair.lombok' Gradle plugin
config.stopBubbling = true
lombok.addLombokGeneratedAnnotation = true

View file

@ -46,7 +46,7 @@ public class GuestController {
@PutMapping("/guests")
public List<User> setGuests(
@RequestBody @Valid GuestsUpdateRequest g, final Principal principal) {
Iterable<User> guests = userRepository.findAllById(g.ids);
Iterable<User> guests = userRepository.findAllById(g.getIds());
User host = userRepository.findByUsername(principal.getName());
for (final User oldGuest : host.getGuests()) {

View file

@ -13,7 +13,9 @@ import java.util.List;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import lombok.Data;
@Data
public class AutomationFastUpdateRequest {
public abstract static class TriggerDTO {
@NotNull public long deviceId;
@ -117,44 +119,4 @@ public class AutomationFastUpdateRequest {
@NotNull private long id;
@NotNull @NotEmpty private String name;
public long getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<ScenePriorityDTO> getScenes() {
return scenes;
}
public void setScenes(List<ScenePriorityDTO> scenes) {
this.scenes = scenes;
}
public List<TriggerDTO> getTriggers() {
return triggers;
}
public void setTriggers(List<TriggerDTO> triggers) {
this.triggers = triggers;
}
public void setId(long id) {
this.id = id;
}
public List<ConditionDTO> getConditions() {
return conditions;
}
public void setConditions(List<ConditionDTO> conditions) {
this.conditions = conditions;
}
}

View file

@ -2,22 +2,10 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import lombok.Data;
@Data
public class AutomationSaveRequest {
private long id;
@NotNull @NotEmpty private String name;
public long getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View file

@ -1,7 +1,9 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import javax.validation.constraints.NotNull;
import lombok.Data;
@Data
public class BooleanTriggerSaveRequest {
private long id;
@ -11,32 +13,4 @@ public class BooleanTriggerSaveRequest {
@NotNull private Long automationId;
private boolean on;
public long getId() {
return id;
}
public Long getDeviceId() {
return deviceId;
}
public void setDeviceId(Long deviceId) {
this.deviceId = deviceId;
}
public Long getAutomationId() {
return automationId;
}
public void setAutomationId(Long automationId) {
this.automationId = automationId;
}
public boolean isOn() {
return on;
}
public void setOn(boolean on) {
this.on = on;
}
}

View file

@ -1,8 +1,10 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import javax.validation.constraints.NotNull;
import lombok.Data;
/** A 'dim' event from a button dimmer. */
@Data
public class ButtonDimmerDimRequest {
/** The device id */
@ -15,20 +17,4 @@ public class ButtonDimmerDimRequest {
/** Whether the dim is up or down */
@NotNull private DimType dimType;
public DimType getDimType() {
return dimType;
}
public void setDimType(DimType dimType) {
this.dimType = dimType;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}

View file

@ -2,7 +2,9 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import lombok.Data;
@Data
public class DeviceSaveRequest {
/** Device identifier */
private long id;
@ -15,28 +17,4 @@ public class DeviceSaveRequest {
/** The name of the device as assigned by the user (e.g. 'Master bedroom light') */
@NotNull @NotEmpty private String name;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public Long getRoomId() {
return roomId;
}
public void setRoomId(Long roomId) {
this.roomId = roomId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View file

@ -3,7 +3,9 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import lombok.Data;
@Data
public class DimmableSaveRequest {
/** Device id (used only for update requests) */
@ -23,36 +25,4 @@ public class DimmableSaveRequest {
/** The name of the device as assigned by the user (e.g. 'Master bedroom light') */
@NotNull private String name;
public void setRoomId(Long roomId) {
this.roomId = roomId;
}
public void setName(String name) {
this.name = name;
}
public Long getRoomId() {
return roomId;
}
public String getName() {
return name;
}
public Integer getIntensity() {
return intensity;
}
public void setIntensity(Integer intensity) {
this.intensity = intensity;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
}

View file

@ -3,7 +3,9 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import lombok.Data;
@Data
public class DimmableStateSaveRequest {
/** Device id (used only for update requests) */
@ -13,16 +15,4 @@ public class DimmableStateSaveRequest {
@Min(0)
@Max(100)
private Integer intensity = 0;
public Integer getIntensity() {
return intensity;
}
public void setIntensity(Integer intensity) {
this.intensity = intensity;
}
public Long getId() {
return id;
}
}

View file

@ -1,7 +1,9 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import javax.validation.constraints.NotNull;
import lombok.Data;
@Data
public class GenericDeviceSaveReguest {
/**
* The room this device belongs in, as a foreign key id. To use when updating and inserting from
@ -11,20 +13,4 @@ public class GenericDeviceSaveReguest {
/** The name of the device as assigned by the user (e.g. 'Master bedroom light') */
@NotNull private String name;
public void setRoomId(Long roomId) {
this.roomId = roomId;
}
public void setName(String name) {
this.name = name;
}
public Long getRoomId() {
return roomId;
}
public String getName() {
return name;
}
}

View file

@ -1,13 +1,8 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import lombok.Data;
@Data
public class GuestPermissionsRequest {
private boolean cameraEnabled;
public boolean isCameraEnabled() {
return cameraEnabled;
}
public void setCameraEnabled(boolean cameraEnabled) {
this.cameraEnabled = cameraEnabled;
}
}

View file

@ -2,7 +2,9 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import java.util.List;
import javax.validation.constraints.NotNull;
import lombok.Data;
@Data
public class GuestsUpdateRequest {
@NotNull public List<Long> ids;
@NotNull private List<Long> ids;
}

View file

@ -3,8 +3,10 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Pattern;
import lombok.Data;
/** DTO for password reset request */
@Data
public class InitPasswordResetRequest {
/**
* The user's email (validated according to criteria used in <code>&gt;input type="email"&lt;>
@ -14,12 +16,4 @@ public class InitPasswordResetRequest {
@Email(message = "Please provide a valid email address")
@Pattern(regexp = ".+@.+\\..+", message = "Please provide a valid email address")
private String email;
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}

View file

@ -1,36 +1,10 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import javax.validation.constraints.NotNull;
import lombok.Data;
@Data
public class JWTRequest {
@NotNull private String usernameOrEmail;
@NotNull private String password;
public String getUsernameOrEmail() {
return this.usernameOrEmail;
}
public void setUsernameOrEmail(String usernameOrEmail) {
this.usernameOrEmail = usernameOrEmail;
}
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public String toString() {
return "JWTRequest{"
+ "usernameOrEmail='"
+ usernameOrEmail
+ '\''
+ ", password='"
+ password
+ '\''
+ '}';
}
}

View file

@ -1,13 +1,10 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class JWTResponse {
private final String jwttoken;
public JWTResponse(String jwttoken) {
this.jwttoken = jwttoken;
}
public String getToken() {
return this.jwttoken;
}
}

View file

@ -3,7 +3,9 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import lombok.Data;
@Data
public class KnobDimmerDimRequest {
/** The device id */
@ -14,20 +16,4 @@ public class KnobDimmerDimRequest {
@Min(0)
@Max(100)
private Integer intensity;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Integer getIntensity() {
return intensity;
}
public void setIntensity(Integer intensity) {
this.intensity = intensity;
}
}

View file

@ -1,8 +1,10 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import javax.validation.constraints.*;
import lombok.Data;
/** DTO for password reset request */
@Data
public class PasswordResetRequest {
@NotNull private String confirmationToken;
@ -15,20 +17,4 @@ public class PasswordResetRequest {
max = 255,
message = "Your password should be at least 6 characters long and up to 255 chars long")
private String password;
public String getConfirmationToken() {
return confirmationToken;
}
public void setConfirmationToken(String confirmationToken) {
this.confirmationToken = confirmationToken;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}

View file

@ -2,7 +2,9 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeTrigger;
import javax.validation.constraints.NotNull;
import lombok.Data;
@Data
public class RangeTriggerSaveRequest {
private long id;
@ -14,44 +16,4 @@ public class RangeTriggerSaveRequest {
@NotNull private RangeTrigger.Operator operator;
@NotNull private double range;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public Long getDeviceId() {
return deviceId;
}
public void setDeviceId(Long deviceId) {
this.deviceId = deviceId;
}
public Long getAutomationId() {
return automationId;
}
public void setAutomationId(Long automationId) {
this.automationId = automationId;
}
public RangeTrigger.Operator getOperator() {
return operator;
}
public void setOperator(RangeTrigger.Operator operator) {
this.operator = operator;
}
public double getRange() {
return range;
}
public void setRange(Double range) {
this.range = range;
}
}

View file

@ -3,7 +3,9 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Icon;
import javax.persistence.Lob;
import javax.validation.constraints.NotNull;
import lombok.Data;
@Data
public class RoomSaveRequest {
/** Room identifier */
@ -21,36 +23,4 @@ public class RoomSaveRequest {
/** The user given name of this room (e.g. 'Master bedroom') */
@NotNull private String name;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Icon getIcon() {
return icon;
}
public void setIcon(Icon icon) {
this.icon = icon;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
}

View file

@ -2,7 +2,9 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import lombok.Data;
@Data
public class ScenePrioritySaveRequest {
@NotNull private Long automationId;
@ -11,28 +13,4 @@ public class ScenePrioritySaveRequest {
private Integer priority;
@NotNull private Long sceneId;
public Long getAutomationId() {
return automationId;
}
public void setAutomationId(Long automationId) {
this.automationId = automationId;
}
public Integer getPriority() {
return priority;
}
public void setPriority(Integer priority) {
this.priority = priority;
}
public Long getSceneId() {
return sceneId;
}
public void setSceneId(Long sceneId) {
this.sceneId = sceneId;
}
}

View file

@ -3,7 +3,9 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Icon;
import javax.persistence.Column;
import javax.validation.constraints.NotNull;
import lombok.Data;
@Data
public class SceneSaveRequest {
/** Room identifier */
@ -16,32 +18,4 @@ public class SceneSaveRequest {
/** Determines whether a guest can access this scene */
@Column @NotNull private boolean guestAccessEnabled;
public boolean isGuestAccessEnabled() {
return guestAccessEnabled;
}
public void setGuestAccessEnabled(boolean guestAccessEnabled) {
this.guestAccessEnabled = guestAccessEnabled;
}
public long getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Icon getIcon() {
return icon;
}
public void setIcon(Icon icon) {
this.icon = icon;
}
}

View file

@ -1,29 +1,14 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Sensor;
import com.google.gson.annotations.SerializedName;
import java.math.BigDecimal;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.validation.constraints.NotNull;
import lombok.Data;
@Data
public class SensorSaveRequest {
/** Type of sensor, i.e. of the thing the sensor measures. */
public enum SensorType {
/** A sensor that measures temperature in degrees celsius */
@SerializedName("TEMPERATURE")
TEMPERATURE,
/** A sensor that measures relative humidity in percentage points */
@SerializedName("HUMIDITY")
HUMIDITY,
/** A sensor that measures light in degrees */
@SerializedName("LIGHT")
LIGHT
}
/** The type of this sensor */
@NotNull
@Enumerated(value = EnumType.STRING)
@ -39,36 +24,4 @@ public class SensorSaveRequest {
/** The name of the device as assigned by the user (e.g. 'Master bedroom light') */
@NotNull private String name;
public void setRoomId(Long roomId) {
this.roomId = roomId;
}
public void setName(String name) {
this.name = name;
}
public Long getRoomId() {
return roomId;
}
public String getName() {
return name;
}
public Sensor.SensorType getSensor() {
return sensor;
}
public void setSensor(Sensor.SensorType sensor) {
this.sensor = sensor;
}
public BigDecimal getValue() {
return value;
}
public void setValue(BigDecimal value) {
this.value = value;
}
}

View file

@ -1,8 +1,10 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import javax.validation.constraints.NotNull;
import lombok.Data;
/** An on/off/toggle operation on a switch */
@Data
public class SwitchOperationRequest {
/** The device id */
@ -16,20 +18,4 @@ public class SwitchOperationRequest {
/** The type of switch operation */
@NotNull private SwitchOperationRequest.OperationType type;
public OperationType getType() {
return type;
}
public void setType(OperationType type) {
this.type = type;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}

View file

@ -1,7 +1,9 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import javax.validation.constraints.NotNull;
import lombok.Data;
@Data
public class SwitchableSaveRequest {
/** The state of this switch */
private boolean on;
@ -17,36 +19,4 @@ public class SwitchableSaveRequest {
/** The name of the device as assigned by the user (e.g. 'Master bedroom light') */
@NotNull private String name;
public void setRoomId(Long roomId) {
this.roomId = roomId;
}
public void setName(String name) {
this.name = name;
}
public long getId() {
return id;
}
public Long getRoomId() {
return roomId;
}
public String getName() {
return name;
}
public boolean isOn() {
return on;
}
public void setOn(boolean on) {
this.on = on;
}
public void setId(long id) {
this.id = id;
}
}

View file

@ -1,23 +1,13 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import javax.validation.constraints.NotNull;
import lombok.Data;
@Data
public class SwitchableStateSaveRequest {
/** Device id (used only for update requests) */
@NotNull private Long id;
@NotNull private boolean on;
public boolean isOn() {
return on;
}
public void setOn(boolean on) {
this.on = on;
}
public Long getId() {
return id;
}
}

View file

@ -2,7 +2,9 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import java.math.BigDecimal;
import javax.validation.constraints.NotNull;
import lombok.Data;
@Data
public class ThermostatSaveRequest {
/** Device identifier */
@ -24,52 +26,4 @@ public class ThermostatSaveRequest {
/** State of this thermostat */
@NotNull private boolean turnOn;
public boolean isTurnOn() {
return turnOn;
}
public void setTurnOn(boolean turnOn) {
this.turnOn = turnOn;
}
public boolean isUseExternalSensors() {
return useExternalSensors;
}
public void setUseExternalSensors(boolean useExternalSensors) {
this.useExternalSensors = useExternalSensors;
}
public BigDecimal getTargetTemperature() {
return this.targetTemperature;
}
public void setTargetTemperature(BigDecimal targetTemperature) {
this.targetTemperature = targetTemperature;
}
public void setRoomId(Long roomId) {
this.roomId = roomId;
}
public void setName(String name) {
this.name = name;
}
public long getId() {
return id;
}
public Long getRoomId() {
return roomId;
}
public String getName() {
return name;
}
public void setId(long id) {
this.id = id;
}
}

View file

@ -1,7 +1,9 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import javax.validation.constraints.*;
import lombok.Data;
@Data
public class UserRegistrationRequest {
/** The full name of the user */
@ -35,36 +37,4 @@ public class UserRegistrationRequest {
@Email(message = "Please provide a valid email address")
@Pattern(regexp = ".+@.+\\..+", message = "Please provide a valid email address")
private String email;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}

View file

@ -1,14 +1,14 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.User;
import lombok.Data;
@Data
public class UserResponse {
private Long id;
private String username;
private String name;
private UserResponse() {}
public static UserResponse fromUser(User u) {
final UserResponse us = new UserResponse();
us.name = u.getName();
@ -16,16 +16,4 @@ public class UserResponse {
us.username = u.getUsername();
return us;
}
public Long getId() {
return id;
}
public String getUsername() {
return username;
}
public String getName() {
return name;
}
}

View file

@ -1,48 +0,0 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Pattern;
public class UserUpdateRequest {
/** The full name of the user */
@NotEmpty(message = "Please provide a full name")
private String name;
/** A non-salted password */
@NotEmpty(message = "Please provide a password")
private String password;
/**
* The user's email (validated according to criteria used in <code>&gt;input type="email"&lt;>
* </code>, technically not RFC 5322 compliant
*/
@NotEmpty(message = "Please provide an email")
@Email(message = "Please provide a valid email address")
@Pattern(regexp = ".+@.+\\..+", message = "Please provide a valid email address")
private String email;
public String getName() {
return name;
}
public String getPassword() {
return password;
}
public String getEmail() {
return email;
}
public void setName(String name) {
this.name = name;
}
public void setPassword(String password) {
this.password = password;
}
public void setEmail(String email) {
this.email = email;
}
}