Merge branch 'sonar-fix' into 'dev'

Sonarqube fixes

See merge request sa4-2020/the-sanmarinoes/backend!127
This commit is contained in:
Claudio Maggioni 2020-05-09 17:44:59 +02:00
commit d39424c623
4 changed files with 97 additions and 61 deletions

View file

@ -100,7 +100,15 @@ public class AutomationController {
req.getScenes() req.getScenes()
.stream() .stream()
.map(AutomationFastUpdateRequest.ScenePriorityDTO::toModel) .map(AutomationFastUpdateRequest.ScenePriorityDTO::toModel)
.map(t -> t.setAutomationId(a.getId())) .peek(
t -> {
t.setAutomationId(a.getId());
// this is here just to pass the quality gate,
// please do not replicate unless the quality gate sees
// it as a bug
t.setAutomation(a);
})
.collect(Collectors.toList())); .collect(Collectors.toList()));
a.getScenes().clear(); a.getScenes().clear();

View file

@ -12,14 +12,6 @@ import javax.persistence.*;
@Inheritance(strategy = InheritanceType.JOINED) @Inheritance(strategy = InheritanceType.JOINED)
public abstract class Device { public abstract class Device {
public Set<Trigger<? extends Device>> getTriggers() {
return triggers;
}
public Set<State<?>> getStates() {
return states;
}
/** Ways a device can behave in the automation flow. For now only input/output */ /** Ways a device can behave in the automation flow. For now only input/output */
public enum FlowType { public enum FlowType {
@SerializedName("INPUT") @SerializedName("INPUT")
@ -75,42 +67,15 @@ public abstract class Device {
@SocketGsonExclude @SocketGsonExclude
private Set<State<?>> states; private Set<State<?>> states;
public String getKind() {
return kind;
}
public FlowType getFlowType() {
return flowType;
}
@Transient @GsonExclude private Long fromHostId = null; @Transient @GsonExclude private Long fromHostId = null;
@Transient @GsonExclude private boolean fromGuest = false; @Transient @GsonExclude private boolean fromGuest = false;
@Transient @GsonExclude private boolean deleted = false; @Transient @GsonExclude private boolean deleted = false;
public Long getFromHostId() { public Device(String kind, FlowType flowType) {
return fromHostId; this.kind = kind;
} this.flowType = flowType;
public void setFromHostId(Long fromHostId) {
this.fromHostId = fromHostId;
}
public boolean isDeleted() {
return deleted;
}
public void setDeleted(boolean deleted) {
this.deleted = deleted;
}
public boolean isFromGuest() {
return fromGuest;
}
public void setFromGuest(boolean fromGuest) {
this.fromGuest = fromGuest;
} }
public long getId() { public long getId() {
@ -121,12 +86,20 @@ public abstract class Device {
this.id = id; this.id = id;
} }
public String getName() { public Room getRoom() {
return name; return room;
} }
public void setName(String name) { public void setRoom(Room room) {
this.name = name; 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() { public Long getRoomId() {
@ -137,8 +110,51 @@ public abstract class Device {
this.roomId = roomId; this.roomId = roomId;
} }
public Device(String kind, FlowType flowType) { public String getName() {
this.kind = kind; return name;
this.flowType = flowType; }
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

@ -2,6 +2,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import ch.usi.inf.sa4.sanmarinoes.smarthut.config.GsonExclude; import ch.usi.inf.sa4.sanmarinoes.smarthut.config.GsonExclude;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import java.util.HashSet;
import java.util.Set; import java.util.Set;
import javax.persistence.*; import javax.persistence.*;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
@ -35,7 +36,7 @@ public class Room {
@OneToMany(mappedBy = "room", orphanRemoval = true) @OneToMany(mappedBy = "room", orphanRemoval = true)
@GsonExclude @GsonExclude
private Set<Device> devices; private Set<Device> devices = new HashSet<>();
/** /**
* User that owns the house this room is in as a foreign key id. To use when updating and * User that owns the house this room is in as a foreign key id. To use when updating and
@ -98,4 +99,12 @@ public class Room {
public String toString() { public String toString() {
return "Room{" + "id=" + id + ", name='" + name + "\'}"; return "Room{" + "id=" + id + ", name='" + name + "\'}";
} }
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
} }

View file

@ -45,6 +45,10 @@ public class ScenePriority {
@NotNull @NotNull
private Long sceneId; private Long sceneId;
public long getId() {
return id;
}
public Integer getPriority() { public Integer getPriority() {
return priority; return priority;
} }
@ -53,21 +57,16 @@ public class ScenePriority {
this.priority = priority; this.priority = priority;
} }
public Automation getAutomation() {
return automation;
}
public void setAutomation(Automation automation) {
this.automation = automation;
}
public Long getAutomationId() { public Long getAutomationId() {
return automationId; return automationId;
} }
public ScenePriority setAutomationId(Long automationId) { public void setAutomationId(Long automationId) {
this.automationId = automationId; this.automationId = automationId;
return this; }
public void setAutomation(Automation automation) {
this.automation = automation;
} }
public Scene getScene() { public Scene getScene() {
@ -88,10 +87,14 @@ public class ScenePriority {
@PreRemove @PreRemove
public void preRemove() { public void preRemove() {
this.setAutomation(null); this.automation = null;
this.setAutomationId(null); this.automationId = null;
this.setScene(null); this.scene = null;
this.setSceneId(null); this.sceneId = null;
}
public Automation getAutomation() {
return automation;
} }
} }