More lombok-ification

This commit is contained in:
Claudio Maggioni 2020-05-12 16:57:49 +02:00
parent 3bb008517a
commit 582f44581b
19 changed files with 99 additions and 408 deletions

View file

@ -158,7 +158,7 @@ public class UserAccountController {
final ConfirmationToken token =
confirmationTokenRepository.findByConfirmToken(resetRequest.getConfirmationToken());
if (token == null || !token.getResetPassword()) {
if (token == null || !token.isResetPassword()) {
throw new EmailTokenNotFoundException();
}
@ -186,7 +186,7 @@ public class UserAccountController {
final ConfirmationToken token =
confirmationTokenRepository.findByConfirmToken(confirmationToken);
if (token != null && !token.getResetPassword()) {
if (token != null && !token.isResetPassword()) {
token.getUser().setEnabled(true);
userRepository.save(token.getUser());
response.sendRedirect(emailConfig.getRegistrationRedirect());

View file

@ -1,14 +1,6 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanCondition;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanTrigger;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Condition;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeCondition;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeTrigger;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ScenePriority;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Thermostat;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ThermostatCondition;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Trigger;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*;
import java.util.List;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
@ -36,7 +28,7 @@ public class AutomationFastUpdateRequest {
}
public static class RangeTriggerDTO extends TriggerDTO {
@NotNull RangeTrigger.Operator operator;
@NotNull Operator operator;
@NotNull double range;
@Override
@ -85,7 +77,7 @@ public class AutomationFastUpdateRequest {
public static class RangeConditionDTO extends ConditionDTO {
@NotNull RangeCondition.Operator operator;
@NotNull Operator operator;
@NotNull double range;
@Override

View file

@ -1,9 +1,10 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeCondition;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeCondition.Operator;
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;
@ -12,43 +13,7 @@ public class RangeConditionSaveRequest {
@NotNull private Long automationId;
@NotNull private RangeCondition.Operator operator;
@NotNull private Operator operator;
@NotNull private double range;
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 Operator getOperator() {
return operator;
}
public void setOperator(Operator operator) {
this.operator = operator;
}
public double getRange() {
return range;
}
public void setRange(double range) {
this.range = range;
}
}

View file

@ -1,6 +1,6 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeTrigger;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Operator;
import javax.validation.constraints.NotNull;
import lombok.Data;
@ -13,7 +13,7 @@ public class RangeTriggerSaveRequest {
@NotNull private Long automationId;
@NotNull private RangeTrigger.Operator operator;
@NotNull private Operator operator;
@NotNull private double range;
}

View file

@ -7,7 +7,9 @@ import java.util.Set;
import javax.persistence.*;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import lombok.Data;
@Data
@Entity
public class Automation {
@ -37,48 +39,4 @@ public class Automation {
private Set<Condition<?>> conditions = new HashSet<>();
@NotNull @NotEmpty private String name;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public Set<ScenePriority> getScenes() {
return scenes;
}
public Set<Trigger<?>> getTriggers() {
return triggers;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public Set<Condition<?>> getConditions() {
return conditions;
}
}

View file

@ -2,10 +2,14 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import javax.persistence.Column;
import javax.persistence.Entity;
import lombok.Getter;
import lombok.Setter;
@Entity
public class BooleanCondition extends Condition<BooleanTriggerable> {
@Getter
@Setter
@Column(name = "switchable_on")
private boolean on;
@ -13,14 +17,6 @@ public class BooleanCondition extends Condition<BooleanTriggerable> {
super("booleanCondition");
}
public boolean isOn() {
return on;
}
public void setOn(boolean on) {
this.on = on;
}
@Override
public boolean triggered() {
return this.getDevice().readTriggerState() == isOn();

View file

@ -2,29 +2,21 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import javax.persistence.Column;
import javax.persistence.Entity;
import lombok.Getter;
import lombok.Setter;
@Entity
public class BooleanTrigger extends Trigger<BooleanTriggerable> {
@Column(name = "switchable_on")
@Getter
@Setter
private boolean on;
public BooleanTrigger() {
super("booleanTrigger");
}
public boolean isOn() {
return on;
}
public void setOn(boolean on) {
this.on = on;
}
public boolean check(boolean on) {
return this.on == on;
}
@Override
public boolean triggered() {
return getDevice().readTriggerState() == isOn();

View file

@ -1,5 +1,6 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import javax.persistence.Entity;
/**

View file

@ -10,7 +10,9 @@ import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;
import lombok.Data;
@Data
@Entity
public abstract class Condition<D> {
@ -52,42 +54,6 @@ public abstract class Condition<D> {
public abstract boolean triggered();
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public D getDevice() {
return device;
}
public void setDevice(D device) {
this.device = device;
}
public Long getDeviceId() {
return deviceId;
}
public void setDeviceId(Long deviceId) {
this.deviceId = deviceId;
}
public Automation getAutomation() {
return automation;
}
public void setAutomation(Automation automation) {
this.automation = automation;
}
public Long getAutomationId() {
return automationId;
}
public Condition<D> setAutomationId(Long automationId) {
this.automationId = automationId;
return this;

View file

@ -12,7 +12,9 @@ import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import lombok.Data;
@Data
@Entity
public class ConfirmationToken {
@ -40,47 +42,4 @@ public class ConfirmationToken {
confirmToken = UUID.randomUUID().toString();
resetPassword = false;
}
/** Constructor for hibernate reflective stuff things whatever */
public ConfirmationToken() {}
public Long getId() {
return id;
}
public String getConfirmToken() {
return confirmToken;
}
public Date getCreatedDate() {
return (Date) createdDate.clone();
}
public User getUser() {
return user;
}
public void setId(Long id) {
this.id = id;
}
public void setConfirmToken(String confirmToken) {
this.confirmToken = confirmToken;
}
public void setCreatedDate(Date createdDate) {
this.createdDate = (Date) createdDate.clone();
}
public void setUser(User user) {
this.user = user;
}
public boolean getResetPassword() {
return resetPassword;
}
public void setResetPassword(boolean resetPassword) {
this.resetPassword = resetPassword;
}
}

View file

@ -6,9 +6,11 @@ import com.google.gson.annotations.SerializedName;
import io.swagger.annotations.ApiModelProperty;
import java.util.Set;
import javax.persistence.*;
import lombok.Data;
/** Generic abstraction for a smart home device */
@Entity
@Data
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Device {
@ -73,88 +75,8 @@ public abstract class Device {
@Transient @GsonExclude private boolean deleted = false;
public Device(String kind, FlowType flowType) {
protected Device(String kind, FlowType flowType) {
this.kind = kind;
this.flowType = flowType;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public Room getRoom() {
return room;
}
public void setRoom(Room room) {
this.room = room;
}
public Set<Trigger<? extends Device>> getTriggers() {
return triggers;
}
public void setTriggers(Set<Trigger<? extends Device>> triggers) {
this.triggers = triggers;
}
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;
}
public String getKind() {
return kind;
}
public FlowType getFlowType() {
return flowType;
}
public Set<State<?>> getStates() {
return states;
}
public void setStates(Set<State<?>> states) {
this.states = states;
}
public Long getFromHostId() {
return fromHostId;
}
public void setFromHostId(Long fromHostId) {
this.fromHostId = fromHostId;
}
public boolean isFromGuest() {
return fromGuest;
}
public void setFromGuest(boolean fromGuest) {
this.fromGuest = fromGuest;
}
public boolean isDeleted() {
return deleted;
}
public void setDeleted(boolean deleted) {
this.deleted = deleted;
}
}

View file

@ -7,6 +7,8 @@ import javax.persistence.*;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@ -19,6 +21,8 @@ public class Dimmable extends Switchable implements RangeTriggerable {
@ManyToMany(mappedBy = "dimmables", cascade = CascadeType.DETACH)
@GsonExclude
@SocketGsonExclude
@Getter
@Setter
private Set<Dimmer> dimmers;
/** The light intensity value. Goes from 0 (off) to 100 (on) */
@ -26,16 +30,15 @@ public class Dimmable extends Switchable implements RangeTriggerable {
@Column(nullable = false)
@Min(0)
@Max(100)
@Getter
private Integer intensity = 0;
@NotNull
@Column(nullable = false)
@Getter
@Setter
private Integer oldIntensity = 100;
public Integer getIntensity() {
return intensity;
}
/**
* Sets the intensity to a certain level. Out of bound values are corrected to the respective
* extremums. An intensity level of 0 turns the light off, but keeps the old intensity level
@ -65,10 +68,6 @@ public class Dimmable extends Switchable implements RangeTriggerable {
intensity = on ? oldIntensity : 0;
}
public Set<Dimmer> getDimmers() {
return this.dimmers;
}
public void readStateAndSet(DimmableState<? extends Dimmable> state) {
setIntensity(state.getIntensity());
}

View file

@ -3,6 +3,8 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import javax.persistence.Entity;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import lombok.Getter;
import lombok.Setter;
/** Represent a state for an IDimmable device */
@Entity
@ -11,16 +13,10 @@ public class DimmableState<T extends Dimmable> extends State<T> {
/** The light intensity value. Goes from 0 (off) to 100 (on) */
@Min(0)
@Max(100)
@Getter
@Setter
private int intensity = 0;
public int getIntensity() {
return intensity;
}
public void setIntensity(int dimAmount) {
this.intensity = dimAmount;
}
@Override
public void apply() {
getDevice().readStateAndSet(this);

View file

@ -10,7 +10,7 @@ import javax.persistence.*;
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Dimmer extends InputDevice implements Connectable<Dimmable> {
public Dimmer(String kind) {
protected Dimmer(String kind) {
super(kind);
}

View file

@ -2,22 +2,18 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import javax.persistence.Column;
import javax.persistence.Entity;
import lombok.Getter;
import lombok.Setter;
/** Represents a motion sensor device */
@Entity
public class MotionSensor extends InputDevice implements BooleanTriggerable {
@Getter
@Setter
@Column(nullable = false)
private boolean detected;
public boolean isDetected() {
return detected;
}
public void setDetected(boolean detected) {
this.detected = detected;
}
public MotionSensor() {
super("motionSensor");
}

View file

@ -0,0 +1,33 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import com.google.gson.annotations.SerializedName;
public enum Operator {
@SerializedName("EQUAL")
EQUAL,
@SerializedName("LESS")
LESS,
@SerializedName("GREATER")
GREATER,
@SerializedName("LESS_EQUAL")
LESS_EQUAL,
@SerializedName("GREATER_EQUAL")
GREATER_EQUAL;
boolean checkAgainst(double value, double range) {
switch (this) {
case EQUAL:
return value == range;
case LESS:
return value < range;
case GREATER:
return value > range;
case GREATER_EQUAL:
return value >= range;
case LESS_EQUAL:
return value <= range;
default:
throw new IllegalStateException();
}
}
}

View file

@ -1,10 +1,9 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeTrigger.Operator;
import com.google.gson.annotations.SerializedName;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
@Entity
public class RangeCondition extends Condition<RangeTriggerable> {
@ -13,57 +12,18 @@ public class RangeCondition extends Condition<RangeTriggerable> {
super("rangeCondition");
}
public enum Operator {
@SerializedName("EQUAL")
EQUAL,
@SerializedName("LESS")
LESS,
@SerializedName("GREATER")
GREATER,
@SerializedName("LESS_EQUAL")
LESS_EQUAL,
@SerializedName("GREATER_EQUAL")
GREATER_EQUAL
}
@Getter
@Setter
@Column(nullable = false)
private RangeCondition.Operator operator;
private Operator operator;
@NotNull
@Getter
@Setter
@Column(nullable = false)
private double range;
public RangeCondition.Operator getOperator() {
return operator;
}
public void setOperator(RangeCondition.Operator operator) {
this.operator = operator;
}
public double getRange() {
return range;
}
public void setRange(Double range) {
this.range = range;
}
@Override
public boolean triggered() {
double value = getDevice().readTriggerState();
switch (operator) {
case EQUAL:
return value == range;
case LESS:
return value < range;
case GREATER:
return value > range;
case GREATER_EQUAL:
return value >= range;
case LESS_EQUAL:
return value <= range;
}
throw new IllegalStateException();
return operator.checkAgainst(getDevice().readTriggerState(), range);
}
}

View file

@ -1,8 +1,9 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import com.google.gson.annotations.SerializedName;
import javax.persistence.Column;
import javax.persistence.Entity;
import lombok.Getter;
import lombok.Setter;
@Entity
public class RangeTrigger extends Trigger<RangeTriggerable> {
@ -11,56 +12,18 @@ public class RangeTrigger extends Trigger<RangeTriggerable> {
super("rangeTrigger");
}
@Override
public boolean triggered() {
double value = getDevice().readTriggerState();
switch (operator) {
case EQUAL:
return value == range;
case LESS:
return value < range;
case GREATER:
return value > range;
case GREATER_EQUAL:
return value >= range;
case LESS_EQUAL:
return value <= range;
}
throw new IllegalStateException();
}
public enum Operator {
@SerializedName("EQUAL")
EQUAL,
@SerializedName("LESS")
LESS,
@SerializedName("GREATER")
GREATER,
@SerializedName("LESS_EQUAL")
LESS_EQUAL,
@SerializedName("GREATER_EQUAL")
GREATER_EQUAL
}
@Getter
@Setter
@Column(nullable = false)
private Operator operator;
@Getter
@Setter
@Column(nullable = false)
private double range;
public Operator getOperator() {
return operator;
}
public void setOperator(Operator operator) {
this.operator = operator;
}
public double getRange() {
return range;
}
public void setRange(Double range) {
this.range = range;
@Override
public boolean triggered() {
return operator.checkAgainst(getDevice().readTriggerState(), range);
}
}

View file

@ -3,6 +3,8 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
/** Represents a standard non-dimmable light */
@Entity
@ -11,21 +13,12 @@ public class RegularLight extends Switchable implements BooleanTriggerable {
/** Whether the light is on or not */
@Column(name = "light_on", nullable = false)
@NotNull
@Getter
@Setter
boolean on;
public RegularLight() {
super("regularLight");
this.on = false;
}
@Override
public boolean isOn() {
return on;
}
@Override
public void setOn(boolean on) {
this.on = on;
}
@Override