Code smells fix

This commit is contained in:
Claudio Maggioni (maggicl) 2020-05-24 12:31:39 +02:00
parent 2f9585bd20
commit 838aaf93ee
3 changed files with 23 additions and 23 deletions

View file

@ -18,23 +18,23 @@ public class Automation {
@ApiModelProperty(hidden = true) @ApiModelProperty(hidden = true)
private long id; 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) @OneToMany(mappedBy = "automation", orphanRemoval = true, cascade = CascadeType.REMOVE)
private Set<Trigger<?>> triggers = new HashSet<>(); private Set<Trigger<?>> triggers = new HashSet<>();
@OneToMany(mappedBy = "automation", cascade = CascadeType.REMOVE) @OneToMany(mappedBy = "automation", cascade = CascadeType.REMOVE)
private Set<ScenePriority> scenes = new HashSet<>(); private Set<ScenePriority> scenes = new HashSet<>();
@ManyToOne
@JoinColumn(name = "user_id", updatable = false, insertable = false)
@GsonExclude
private User user;
@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<>();
@Column(name = "user_id", nullable = false)
@GsonExclude
private Long userId;
@NotEmpty private String name; @NotEmpty private String name;
} }

View file

@ -21,16 +21,25 @@ public abstract class Condition<D> {
return kind; 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 @Id
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", updatable = false, nullable = false, unique = true) @Column(name = "id", updatable = false, nullable = false, unique = true)
@ApiModelProperty(hidden = true) @ApiModelProperty(hidden = true)
private long id; private long id;
@ManyToOne(targetEntity = Device.class) @ManyToOne
@JoinColumn(name = "device_id", updatable = false, insertable = false) @JoinColumn(name = "automation_id", updatable = false, insertable = false)
@GsonExclude @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 * 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<D> {
@Column(name = "device_id", nullable = false) @Column(name = "device_id", nullable = false)
private Long deviceId; 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 abstract boolean triggered();
public Condition<D> setAutomationId(Long automationId) { public Condition<D> setAutomationId(Long automationId) {

View file

@ -17,12 +17,12 @@ public class RangeCondition extends Condition<RangeTriggerable> {
@Getter @Getter
@Setter @Setter
@Column(nullable = false) @Column(nullable = false)
private Operator operator; private double range;
@Getter @Getter
@Setter @Setter
@Column(nullable = false) @Column(nullable = false)
private double range; private Operator operator;
@Override @Override
public boolean triggered() { public boolean triggered() {