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

View file

@ -1,14 +1,6 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto; 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.*;
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 java.util.List; import java.util.List;
import javax.validation.constraints.Min; import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotEmpty;
@ -36,7 +28,7 @@ public class AutomationFastUpdateRequest {
} }
public static class RangeTriggerDTO extends TriggerDTO { public static class RangeTriggerDTO extends TriggerDTO {
@NotNull RangeTrigger.Operator operator; @NotNull Operator operator;
@NotNull double range; @NotNull double range;
@Override @Override
@ -85,7 +77,7 @@ public class AutomationFastUpdateRequest {
public static class RangeConditionDTO extends ConditionDTO { public static class RangeConditionDTO extends ConditionDTO {
@NotNull RangeCondition.Operator operator; @NotNull Operator operator;
@NotNull double range; @NotNull double range;
@Override @Override

View file

@ -1,9 +1,10 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto; 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.Operator;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeCondition.Operator;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import lombok.Data;
@Data
public class RangeConditionSaveRequest { public class RangeConditionSaveRequest {
@NotNull private long id; @NotNull private long id;
@ -12,43 +13,7 @@ public class RangeConditionSaveRequest {
@NotNull private Long automationId; @NotNull private Long automationId;
@NotNull private RangeCondition.Operator operator; @NotNull private Operator operator;
@NotNull private double range; @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; 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 javax.validation.constraints.NotNull;
import lombok.Data; import lombok.Data;
@ -13,7 +13,7 @@ public class RangeTriggerSaveRequest {
@NotNull private Long automationId; @NotNull private Long automationId;
@NotNull private RangeTrigger.Operator operator; @NotNull private Operator operator;
@NotNull private double range; @NotNull private double range;
} }

View file

@ -7,7 +7,9 @@ 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 javax.validation.constraints.NotNull;
import lombok.Data;
@Data
@Entity @Entity
public class Automation { public class Automation {
@ -37,48 +39,4 @@ public class Automation {
private Set<Condition<?>> conditions = new HashSet<>(); private Set<Condition<?>> conditions = new HashSet<>();
@NotNull @NotEmpty private String name; @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.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import lombok.Getter;
import lombok.Setter;
@Entity @Entity
public class BooleanCondition extends Condition<BooleanTriggerable> { public class BooleanCondition extends Condition<BooleanTriggerable> {
@Getter
@Setter
@Column(name = "switchable_on") @Column(name = "switchable_on")
private boolean on; private boolean on;
@ -13,14 +17,6 @@ public class BooleanCondition extends Condition<BooleanTriggerable> {
super("booleanCondition"); super("booleanCondition");
} }
public boolean isOn() {
return on;
}
public void setOn(boolean on) {
this.on = on;
}
@Override @Override
public boolean triggered() { public boolean triggered() {
return this.getDevice().readTriggerState() == isOn(); 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.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import lombok.Getter;
import lombok.Setter;
@Entity @Entity
public class BooleanTrigger extends Trigger<BooleanTriggerable> { public class BooleanTrigger extends Trigger<BooleanTriggerable> {
@Column(name = "switchable_on") @Column(name = "switchable_on")
@Getter
@Setter
private boolean on; private boolean on;
public BooleanTrigger() { public BooleanTrigger() {
super("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 @Override
public boolean triggered() { public boolean triggered() {
return getDevice().readTriggerState() == isOn(); return getDevice().readTriggerState() == isOn();

View file

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

View file

@ -10,7 +10,9 @@ import javax.persistence.Id;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.Transient; import javax.persistence.Transient;
import lombok.Data;
@Data
@Entity @Entity
public abstract class Condition<D> { public abstract class Condition<D> {
@ -52,42 +54,6 @@ public abstract class Condition<D> {
public abstract boolean triggered(); 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) { public Condition<D> setAutomationId(Long automationId) {
this.automationId = automationId; this.automationId = automationId;
return this; return this;

View file

@ -12,7 +12,9 @@ import javax.persistence.JoinColumn;
import javax.persistence.OneToOne; import javax.persistence.OneToOne;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import lombok.Data;
@Data
@Entity @Entity
public class ConfirmationToken { public class ConfirmationToken {
@ -40,47 +42,4 @@ public class ConfirmationToken {
confirmToken = UUID.randomUUID().toString(); confirmToken = UUID.randomUUID().toString();
resetPassword = false; 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 io.swagger.annotations.ApiModelProperty;
import java.util.Set; import java.util.Set;
import javax.persistence.*; import javax.persistence.*;
import lombok.Data;
/** Generic abstraction for a smart home device */ /** Generic abstraction for a smart home device */
@Entity @Entity
@Data
@Inheritance(strategy = InheritanceType.JOINED) @Inheritance(strategy = InheritanceType.JOINED)
public abstract class Device { public abstract class Device {
@ -73,88 +75,8 @@ public abstract class Device {
@Transient @GsonExclude private boolean deleted = false; @Transient @GsonExclude private boolean deleted = false;
public Device(String kind, FlowType flowType) { protected Device(String kind, FlowType flowType) {
this.kind = kind; this.kind = kind;
this.flowType = flowType; 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.Max;
import javax.validation.constraints.Min; import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
@Entity @Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE) @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@ -19,6 +21,8 @@ public class Dimmable extends Switchable implements RangeTriggerable {
@ManyToMany(mappedBy = "dimmables", cascade = CascadeType.DETACH) @ManyToMany(mappedBy = "dimmables", cascade = CascadeType.DETACH)
@GsonExclude @GsonExclude
@SocketGsonExclude @SocketGsonExclude
@Getter
@Setter
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) */
@ -26,16 +30,15 @@ public class Dimmable extends Switchable implements RangeTriggerable {
@Column(nullable = false) @Column(nullable = false)
@Min(0) @Min(0)
@Max(100) @Max(100)
@Getter
private Integer intensity = 0; private Integer intensity = 0;
@NotNull @NotNull
@Column(nullable = false) @Column(nullable = false)
@Getter
@Setter
private Integer oldIntensity = 100; 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 * 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 * 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; intensity = on ? oldIntensity : 0;
} }
public Set<Dimmer> getDimmers() {
return this.dimmers;
}
public void readStateAndSet(DimmableState<? extends Dimmable> state) { public void readStateAndSet(DimmableState<? extends Dimmable> state) {
setIntensity(state.getIntensity()); setIntensity(state.getIntensity());
} }

View file

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

View file

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

View file

@ -2,22 +2,18 @@ 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 lombok.Getter;
import lombok.Setter;
/** Represents a motion sensor device */ /** Represents a motion sensor device */
@Entity @Entity
public class MotionSensor extends InputDevice implements BooleanTriggerable { public class MotionSensor extends InputDevice implements BooleanTriggerable {
@Getter
@Setter
@Column(nullable = false) @Column(nullable = false)
private boolean detected; private boolean detected;
public boolean isDetected() {
return detected;
}
public void setDetected(boolean detected) {
this.detected = detected;
}
public MotionSensor() { public MotionSensor() {
super("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; 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.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.validation.constraints.NotNull; import lombok.Getter;
import lombok.Setter;
@Entity @Entity
public class RangeCondition extends Condition<RangeTriggerable> { public class RangeCondition extends Condition<RangeTriggerable> {
@ -13,57 +12,18 @@ public class RangeCondition extends Condition<RangeTriggerable> {
super("rangeCondition"); super("rangeCondition");
} }
public enum Operator { @Getter
@SerializedName("EQUAL") @Setter
EQUAL,
@SerializedName("LESS")
LESS,
@SerializedName("GREATER")
GREATER,
@SerializedName("LESS_EQUAL")
LESS_EQUAL,
@SerializedName("GREATER_EQUAL")
GREATER_EQUAL
}
@Column(nullable = false) @Column(nullable = false)
private RangeCondition.Operator operator; private Operator operator;
@NotNull @Getter
@Setter
@Column(nullable = false) @Column(nullable = false)
private double range; 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 @Override
public boolean triggered() { public boolean triggered() {
double value = getDevice().readTriggerState(); return operator.checkAgainst(getDevice().readTriggerState(), range);
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();
} }
} }

View file

@ -1,8 +1,9 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models; package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import com.google.gson.annotations.SerializedName;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import lombok.Getter;
import lombok.Setter;
@Entity @Entity
public class RangeTrigger extends Trigger<RangeTriggerable> { public class RangeTrigger extends Trigger<RangeTriggerable> {
@ -11,56 +12,18 @@ public class RangeTrigger extends Trigger<RangeTriggerable> {
super("rangeTrigger"); super("rangeTrigger");
} }
@Override @Getter
public boolean triggered() { @Setter
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
}
@Column(nullable = false) @Column(nullable = false)
private Operator operator; private Operator operator;
@Getter
@Setter
@Column(nullable = false) @Column(nullable = false)
private double range; private double range;
public Operator getOperator() { @Override
return operator; public boolean triggered() {
} return operator.checkAgainst(getDevice().readTriggerState(), range);
public void setOperator(Operator operator) {
this.operator = operator;
}
public double getRange() {
return range;
}
public void setRange(Double range) {
this.range = range;
} }
} }

View file

@ -3,6 +3,8 @@ 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 javax.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
/** Represents a standard non-dimmable light */ /** Represents a standard non-dimmable light */
@Entity @Entity
@ -11,21 +13,12 @@ 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 @NotNull
@Getter
@Setter
boolean on; boolean on;
public RegularLight() { public RegularLight() {
super("regularLight"); super("regularLight");
this.on = false;
}
@Override
public boolean isOn() {
return on;
}
@Override
public void setOn(boolean on) {
this.on = on;
} }
@Override @Override