From 838aaf93eeb9b4b110ab379c5c50a1e6de3c50f8 Mon Sep 17 00:00:00 2001 From: "Claudio Maggioni (maggicl)" Date: Sun, 24 May 2020 12:31:39 +0200 Subject: [PATCH] Code smells fix --- .../smarthut/models/Automation.java | 18 +++++++------- .../smarthut/models/Condition.java | 24 +++++++++---------- .../smarthut/models/RangeCondition.java | 4 ++-- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Automation.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Automation.java index cb04e9d..2a27ee9 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Automation.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Automation.java @@ -18,23 +18,23 @@ public class Automation { @ApiModelProperty(hidden = true) private long id; - @ManyToOne - @JoinColumn(name = "user_id", updatable = false, insertable = false) - @GsonExclude - private User user; - - @Column(name = "user_id", nullable = false) - @GsonExclude - private Long userId; - @OneToMany(mappedBy = "automation", orphanRemoval = true, cascade = CascadeType.REMOVE) private Set> triggers = new HashSet<>(); @OneToMany(mappedBy = "automation", cascade = CascadeType.REMOVE) private Set scenes = new HashSet<>(); + @ManyToOne + @JoinColumn(name = "user_id", updatable = false, insertable = false) + @GsonExclude + private User user; + @OneToMany(mappedBy = "automation", orphanRemoval = true, cascade = CascadeType.REMOVE) private Set> conditions = new HashSet<>(); + @Column(name = "user_id", nullable = false) + @GsonExclude + private Long userId; + @NotEmpty private String name; } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Condition.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Condition.java index 70bad76..62fa6df 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Condition.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Condition.java @@ -21,16 +21,25 @@ public abstract class Condition { return kind; } + @ManyToOne(targetEntity = Device.class) + @JoinColumn(name = "device_id", updatable = false, insertable = false) + @GsonExclude + private D device; + + @Column(name = "automation_id", nullable = false) + private Long automationId; + @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id", updatable = false, nullable = false, unique = true) @ApiModelProperty(hidden = true) private long id; - @ManyToOne(targetEntity = Device.class) - @JoinColumn(name = "device_id", updatable = false, insertable = false) + @ManyToOne + @JoinColumn(name = "automation_id", updatable = false, insertable = false) @GsonExclude - private D device; + @EqualsAndHashCode.Exclude + private Automation automation; /** * The device this condition belongs to, as a foreign key id. To use when updating and inserting @@ -39,15 +48,6 @@ public abstract class Condition { @Column(name = "device_id", nullable = false) private Long deviceId; - @ManyToOne - @JoinColumn(name = "automation_id", updatable = false, insertable = false) - @GsonExclude - @EqualsAndHashCode.Exclude - private Automation automation; - - @Column(name = "automation_id", nullable = false) - private Long automationId; - public abstract boolean triggered(); public Condition setAutomationId(Long automationId) { diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RangeCondition.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RangeCondition.java index b5a7a5d..1a92fa9 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RangeCondition.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RangeCondition.java @@ -17,12 +17,12 @@ public class RangeCondition extends Condition { @Getter @Setter @Column(nullable = false) - private Operator operator; + private double range; @Getter @Setter @Column(nullable = false) - private double range; + private Operator operator; @Override public boolean triggered() {