wip
This commit is contained in:
parent
a4213198ba
commit
5c0df55de9
2 changed files with 123 additions and 0 deletions
|
@ -0,0 +1,23 @@
|
|||
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
@Entity
|
||||
public class BooleanTrigger<D extends Device> extends Trigger<D> {
|
||||
|
||||
@Column(name = "switchable_on")
|
||||
private boolean on;
|
||||
|
||||
public boolean isOn() {
|
||||
return on;
|
||||
}
|
||||
|
||||
public void setOn(boolean on) {
|
||||
this.on = on;
|
||||
}
|
||||
|
||||
public boolean check(boolean on) {
|
||||
return this.on == on;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
||||
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.config.GsonExclude;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.PreRemove;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Entity
|
||||
@Table(uniqueConstraints = {@UniqueConstraint(columnNames = {"device_id", "scene_id"})})
|
||||
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
|
||||
public abstract class Trigger<D extends Device> {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
@Column(name = "id", updatable = false, nullable = false, unique = true)
|
||||
@ApiModelProperty(hidden = true)
|
||||
private long id;
|
||||
|
||||
@ManyToOne(targetEntity = OutputDevice.class)
|
||||
@JoinColumn(name = "device_id", updatable = false, insertable = false)
|
||||
@GsonExclude
|
||||
private D device;
|
||||
|
||||
/**
|
||||
* The device this trigger belongs to, as a foreign key id. To use when updating and inserting
|
||||
* from a REST call.
|
||||
*/
|
||||
@Column(name = "device_id", nullable = false)
|
||||
@NotNull
|
||||
private Long deviceId;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "scene_id", updatable = false, insertable = false)
|
||||
@GsonExclude
|
||||
private Scene scene;
|
||||
|
||||
@Column(name = "scene_id", nullable = false)
|
||||
@NotNull
|
||||
private Long sceneId;
|
||||
|
||||
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 Scene getScene() {
|
||||
return scene;
|
||||
}
|
||||
|
||||
public void setScene(Scene scene) {
|
||||
this.scene = scene;
|
||||
}
|
||||
|
||||
public Long getSceneId() {
|
||||
return sceneId;
|
||||
}
|
||||
|
||||
public void setSceneId(Long sceneId) {
|
||||
this.sceneId = sceneId;
|
||||
}
|
||||
|
||||
@PreRemove
|
||||
public void removeDeviceAndScene() {
|
||||
this.setScene(null);
|
||||
this.setSceneId(null);
|
||||
|
||||
this.setDevice(null);
|
||||
this.setDeviceId(null);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue