Merge branch 'sonar-fix' into 'dev'

Removed @NotNull from models

See merge request sa4-2020/the-sanmarinoes/backend!138
This commit is contained in:
Claudio Maggioni 2020-05-12 17:23:07 +02:00
commit c9fbffea7a
18 changed files with 20 additions and 105 deletions

View file

@ -1,6 +1,6 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller; package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.BooleanConditionSaveRequest; import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.BooleanConditionOrTriggerSaveRequest;
import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException; import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanCondition; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanCondition;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanConditionRepository; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanConditionRepository;
@ -29,7 +29,7 @@ public class BooleanConditionController {
return booleanConditionRepository.findAllByAutomationId(automationId); return booleanConditionRepository.findAllByAutomationId(automationId);
} }
private BooleanCondition save(BooleanCondition newRL, BooleanConditionSaveRequest s) { private BooleanCondition save(BooleanCondition newRL, BooleanConditionOrTriggerSaveRequest s) {
newRL.setDeviceId(s.getDeviceId()); newRL.setDeviceId(s.getDeviceId());
newRL.setAutomationId(s.getAutomationId()); newRL.setAutomationId(s.getAutomationId());
newRL.setOn(s.isOn()); newRL.setOn(s.isOn());
@ -39,13 +39,13 @@ public class BooleanConditionController {
@PostMapping @PostMapping
public BooleanCondition create( public BooleanCondition create(
@Valid @RequestBody BooleanConditionSaveRequest booleanTriggerSaveRequest) { @Valid @RequestBody BooleanConditionOrTriggerSaveRequest booleanTriggerSaveRequest) {
return save(new BooleanCondition(), booleanTriggerSaveRequest); return save(new BooleanCondition(), booleanTriggerSaveRequest);
} }
@PutMapping @PutMapping
public BooleanCondition update( public BooleanCondition update(
@Valid @RequestBody BooleanConditionSaveRequest booleanTriggerSaveRequest) @Valid @RequestBody BooleanConditionOrTriggerSaveRequest booleanTriggerSaveRequest)
throws NotFoundException { throws NotFoundException {
return save( return save(
booleanConditionRepository booleanConditionRepository

View file

@ -1,6 +1,6 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller; package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.BooleanTriggerSaveRequest; import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.BooleanConditionOrTriggerSaveRequest;
import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException; import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanTrigger; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanTrigger;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanTriggerRepository; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanTriggerRepository;
@ -29,7 +29,7 @@ public class BooleanTriggerController {
return booleanTriggerRepository.findAllByAutomationId(automationId); return booleanTriggerRepository.findAllByAutomationId(automationId);
} }
private BooleanTrigger save(BooleanTrigger newRL, BooleanTriggerSaveRequest s) { private BooleanTrigger save(BooleanTrigger newRL, BooleanConditionOrTriggerSaveRequest s) {
newRL.setDeviceId(s.getDeviceId()); newRL.setDeviceId(s.getDeviceId());
newRL.setAutomationId(s.getAutomationId()); newRL.setAutomationId(s.getAutomationId());
newRL.setOn(s.isOn()); newRL.setOn(s.isOn());
@ -39,13 +39,13 @@ public class BooleanTriggerController {
@PostMapping @PostMapping
public BooleanTrigger create( public BooleanTrigger create(
@Valid @RequestBody BooleanTriggerSaveRequest booleanTriggerSaveRequest) { @Valid @RequestBody BooleanConditionOrTriggerSaveRequest booleanTriggerSaveRequest) {
return save(new BooleanTrigger(), booleanTriggerSaveRequest); return save(new BooleanTrigger(), booleanTriggerSaveRequest);
} }
@PutMapping @PutMapping
public BooleanTrigger update( public BooleanTrigger update(
@Valid @RequestBody BooleanTriggerSaveRequest booleanTriggerSaveRequest) @Valid @RequestBody BooleanConditionOrTriggerSaveRequest booleanTriggerSaveRequest)
throws NotFoundException { throws NotFoundException {
return save( return save(
booleanTriggerRepository booleanTriggerRepository

View file

@ -1,6 +1,6 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller; package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.RangeConditionSaveRequest; import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.RangeConditionOrTriggerSaveRequest;
import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException; import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeCondition; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeCondition;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeConditionRepository; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeConditionRepository;
@ -29,7 +29,7 @@ public class RangeConditionController {
return rangeConditionRepository.findAllByAutomationId(automationId); return rangeConditionRepository.findAllByAutomationId(automationId);
} }
private RangeCondition save(RangeCondition newRL, RangeConditionSaveRequest s) { private RangeCondition save(RangeCondition newRL, RangeConditionOrTriggerSaveRequest s) {
newRL.setDeviceId(s.getDeviceId()); newRL.setDeviceId(s.getDeviceId());
newRL.setAutomationId(s.getAutomationId()); newRL.setAutomationId(s.getAutomationId());
newRL.setOperator(s.getOperator()); newRL.setOperator(s.getOperator());
@ -40,13 +40,13 @@ public class RangeConditionController {
@PostMapping @PostMapping
public RangeCondition create( public RangeCondition create(
@Valid @RequestBody RangeConditionSaveRequest booleanTriggerSaveRequest) { @Valid @RequestBody RangeConditionOrTriggerSaveRequest booleanTriggerSaveRequest) {
return save(new RangeCondition(), booleanTriggerSaveRequest); return save(new RangeCondition(), booleanTriggerSaveRequest);
} }
@PutMapping @PutMapping
public RangeCondition update( public RangeCondition update(
@Valid @RequestBody RangeConditionSaveRequest booleanTriggerSaveRequest) @Valid @RequestBody RangeConditionOrTriggerSaveRequest booleanTriggerSaveRequest)
throws NotFoundException { throws NotFoundException {
return save( return save(
rangeConditionRepository rangeConditionRepository

View file

@ -1,6 +1,6 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller; package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.RangeTriggerSaveRequest; import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.RangeConditionOrTriggerSaveRequest;
import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException; import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeTrigger; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeTrigger;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeTriggerRepository; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeTriggerRepository;
@ -29,7 +29,7 @@ public class RangeTriggerController {
return rangeTriggerRepository.findAllByAutomationId(automationId); return rangeTriggerRepository.findAllByAutomationId(automationId);
} }
private RangeTrigger save(RangeTrigger newRL, RangeTriggerSaveRequest s) { private RangeTrigger save(RangeTrigger newRL, RangeConditionOrTriggerSaveRequest s) {
newRL.setDeviceId(s.getDeviceId()); newRL.setDeviceId(s.getDeviceId());
newRL.setAutomationId(s.getAutomationId()); newRL.setAutomationId(s.getAutomationId());
newRL.setOperator(s.getOperator()); newRL.setOperator(s.getOperator());
@ -40,13 +40,13 @@ public class RangeTriggerController {
@PostMapping @PostMapping
public RangeTrigger create( public RangeTrigger create(
@Valid @RequestBody RangeTriggerSaveRequest booleanTriggerSaveRequest) { @Valid @RequestBody RangeConditionOrTriggerSaveRequest booleanTriggerSaveRequest) {
return save(new RangeTrigger(), booleanTriggerSaveRequest); return save(new RangeTrigger(), booleanTriggerSaveRequest);
} }
@PutMapping @PutMapping
public RangeTrigger update( public RangeTrigger update(
@Valid @RequestBody RangeTriggerSaveRequest booleanTriggerSaveRequest) @Valid @RequestBody RangeConditionOrTriggerSaveRequest booleanTriggerSaveRequest)
throws NotFoundException { throws NotFoundException {
return save( return save(
rangeTriggerRepository rangeTriggerRepository

View file

@ -4,7 +4,7 @@ import javax.validation.constraints.NotNull;
import lombok.Data; import lombok.Data;
@Data @Data
public class BooleanTriggerSaveRequest { public class BooleanConditionOrTriggerSaveRequest {
private long id; private long id;

View file

@ -1,42 +0,0 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import javax.validation.constraints.NotNull;
public class BooleanConditionSaveRequest {
@NotNull private long id;
@NotNull private Long deviceId;
@NotNull private Long automationId;
@NotNull 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

@ -5,7 +5,7 @@ import javax.validation.constraints.NotNull;
import lombok.Data; import lombok.Data;
@Data @Data
public class RangeTriggerSaveRequest { public class RangeConditionOrTriggerSaveRequest {
private long id; private long id;

View file

@ -1,19 +0,0 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Operator;
import javax.validation.constraints.NotNull;
import lombok.Data;
@Data
public class RangeConditionSaveRequest {
@NotNull private long id;
@NotNull private Long deviceId;
@NotNull private Long automationId;
@NotNull private Operator operator;
@NotNull private double range;
}

View file

@ -6,7 +6,6 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import javax.persistence.*; import javax.persistence.*;
import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import lombok.Data; import lombok.Data;
@Data @Data
@ -24,7 +23,6 @@ public class Automation {
@GsonExclude @GsonExclude
private User user; private User user;
@NotNull
@Column(name = "user_id", nullable = false) @Column(name = "user_id", nullable = false)
@GsonExclude @GsonExclude
private Long userId; private Long userId;
@ -38,5 +36,5 @@ public class Automation {
@OneToMany(mappedBy = "automation", orphanRemoval = true, cascade = CascadeType.REMOVE) @OneToMany(mappedBy = "automation", orphanRemoval = true, cascade = CascadeType.REMOVE)
private Set<Condition<?>> conditions = new HashSet<>(); private Set<Condition<?>> conditions = new HashSet<>();
@NotNull @NotEmpty private String name; @NotEmpty private String name;
} }

View file

@ -6,7 +6,6 @@ import java.util.Set;
import javax.persistence.*; import javax.persistence.*;
import javax.validation.constraints.Max; import javax.validation.constraints.Max;
import javax.validation.constraints.Min; import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@ -26,14 +25,12 @@ public class Dimmable extends Switchable implements RangeTriggerable {
private Set<Dimmer> dimmers; private Set<Dimmer> dimmers;
/** The light intensity value. Goes from 0 (off) to 100 (on) */ /** The light intensity value. Goes from 0 (off) to 100 (on) */
@NotNull
@Column(nullable = false) @Column(nullable = false)
@Min(0) @Min(0)
@Max(100) @Max(100)
@Getter @Getter
private Integer intensity = 0; private Integer intensity = 0;
@NotNull
@Column(nullable = false) @Column(nullable = false)
@Getter @Getter
@Setter @Setter

View file

@ -2,7 +2,6 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.validation.constraints.NotNull;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@ -12,7 +11,6 @@ public class RegularLight extends Switchable implements BooleanTriggerable {
/** Whether the light is on or not */ /** Whether the light is on or not */
@Column(name = "light_on", nullable = false) @Column(name = "light_on", nullable = false)
@NotNull
@Getter @Getter
@Setter @Setter
boolean on; boolean on;

View file

@ -5,7 +5,6 @@ import io.swagger.annotations.ApiModelProperty;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import javax.persistence.*; import javax.persistence.*;
import javax.validation.constraints.NotNull;
/** Represents a room in the house owned by the user */ /** Represents a room in the house owned by the user */
@Entity @Entity
@ -42,12 +41,10 @@ public class Room {
* User that owns the house this room is in as a foreign key id. To use when updating and * User that owns the house this room is in as a foreign key id. To use when updating and
* inserting from a REST call. * inserting from a REST call.
*/ */
@NotNull
@Column(name = "user_id", nullable = false) @Column(name = "user_id", nullable = false)
private Long userId; private Long userId;
/** The user given name of this room (e.g. 'Master bedroom') */ /** The user given name of this room (e.g. 'Master bedroom') */
@NotNull
@Column(nullable = false) @Column(nullable = false)
private String name; private String name;

View file

@ -5,7 +5,6 @@ import io.swagger.annotations.ApiModelProperty;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import javax.persistence.*; import javax.persistence.*;
import javax.validation.constraints.NotNull;
/** /**
* Represent a collection of state changes to devices even in different rooms but belonging to the * Represent a collection of state changes to devices even in different rooms but belonging to the
@ -25,7 +24,6 @@ public class Scene {
@GsonExclude @GsonExclude
private User user; private User user;
@NotNull
@Column(name = "user_id", nullable = false) @Column(name = "user_id", nullable = false)
@GsonExclude @GsonExclude
private Long userId; private Long userId;
@ -35,12 +33,10 @@ public class Scene {
private Set<State<?>> states = new HashSet<>(); private Set<State<?>> states = new HashSet<>();
/** The user given name of this room (e.g. 'Master bedroom') */ /** The user given name of this room (e.g. 'Master bedroom') */
@NotNull
@Column(nullable = false) @Column(nullable = false)
private String name; private String name;
@Column(nullable = false) @Column(nullable = false)
@NotNull
private Icon icon; private Icon icon;
/** Determines whether a guest can access this scene */ /** Determines whether a guest can access this scene */

View file

@ -11,7 +11,6 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.PreRemove; import javax.persistence.PreRemove;
import javax.validation.constraints.Min; import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
@Entity @Entity
public class ScenePriority { public class ScenePriority {
@ -30,7 +29,6 @@ public class ScenePriority {
@Column(name = "automation_id", nullable = false) @Column(name = "automation_id", nullable = false)
private Long automationId; private Long automationId;
@NotNull
@Min(0) @Min(0)
@Column(nullable = false) @Column(nullable = false)
private Integer priority; private Integer priority;

View file

@ -2,7 +2,6 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.validation.constraints.NotNull;
@Entity @Entity
public class SecurityCamera extends Switchable implements BooleanTriggerable { public class SecurityCamera extends Switchable implements BooleanTriggerable {
@ -13,7 +12,6 @@ public class SecurityCamera extends Switchable implements BooleanTriggerable {
} }
@Column(name = "camera_on", nullable = false) @Column(name = "camera_on", nullable = false)
@NotNull
private boolean on; private boolean on;
@Column(name = "video", nullable = false) @Column(name = "video", nullable = false)

View file

@ -3,7 +3,6 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import java.math.BigDecimal; import java.math.BigDecimal;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.validation.constraints.NotNull;
/** A smart plug that can be turned either on or off */ /** A smart plug that can be turned either on or off */
@Entity @Entity
@ -14,7 +13,6 @@ public class SmartPlug extends Switchable implements BooleanTriggerable {
/** The total amount of power that the smart plug has consumed represented in W/h */ /** The total amount of power that the smart plug has consumed represented in W/h */
@Column(precision = 13, scale = 3) @Column(precision = 13, scale = 3)
@NotNull
private BigDecimal totalConsumption = BigDecimal.ZERO; private BigDecimal totalConsumption = BigDecimal.ZERO;
/** Whether the smart plug is on */ /** Whether the smart plug is on */

View file

@ -3,7 +3,6 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import ch.usi.inf.sa4.sanmarinoes.smarthut.config.GsonExclude; import ch.usi.inf.sa4.sanmarinoes.smarthut.config.GsonExclude;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import javax.persistence.*; import javax.persistence.*;
import javax.validation.constraints.NotNull;
/** /**
* Represents instructions on how to change the state of a particular device. Many states (plus * Represents instructions on how to change the state of a particular device. Many states (plus
@ -30,7 +29,6 @@ public abstract class State<D extends OutputDevice> {
* from a REST call. * from a REST call.
*/ */
@Column(name = "device_id", nullable = false) @Column(name = "device_id", nullable = false)
@NotNull
private Long deviceId; private Long deviceId;
@ManyToOne @ManyToOne
@ -39,7 +37,6 @@ public abstract class State<D extends OutputDevice> {
private Scene scene; private Scene scene;
@Column(name = "scene_id", nullable = false) @Column(name = "scene_id", nullable = false)
@NotNull
private Long sceneId; private Long sceneId;
/** Sets the state of the connected device to the state represented by this object. */ /** Sets the state of the connected device to the state represented by this object. */

View file

@ -5,7 +5,6 @@ import java.math.BigDecimal;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Transient; import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
/** A thermostat capable of controlling cooling and heating. */ /** A thermostat capable of controlling cooling and heating. */
@Entity @Entity
@ -72,7 +71,7 @@ public class Thermostat extends Switchable implements BooleanTriggerable {
Sensor.TYPICAL_VALUES.get(Sensor.SensorType.TEMPERATURE); Sensor.TYPICAL_VALUES.get(Sensor.SensorType.TEMPERATURE);
/** State of this thermostat */ /** State of this thermostat */
@Column @NotNull private Thermostat.Mode mode; @Column private Thermostat.Mode mode;
@Transient private BigDecimal measuredTemperature; @Transient private BigDecimal measuredTemperature;