Removed duplication

This commit is contained in:
Claudio Maggioni 2020-05-12 17:20:19 +02:00
parent 0d10d759a6
commit 6223434979
8 changed files with 18 additions and 79 deletions

View file

@ -1,6 +1,6 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller; package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.BooleanConditionSaveRequest; import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.BooleanConditionOrTriggerSaveRequest;
import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException; import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanCondition; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanCondition;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanConditionRepository; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanConditionRepository;
@ -29,7 +29,7 @@ public class BooleanConditionController {
return booleanConditionRepository.findAllByAutomationId(automationId); return booleanConditionRepository.findAllByAutomationId(automationId);
} }
private BooleanCondition save(BooleanCondition newRL, BooleanConditionSaveRequest s) { private BooleanCondition save(BooleanCondition newRL, BooleanConditionOrTriggerSaveRequest s) {
newRL.setDeviceId(s.getDeviceId()); newRL.setDeviceId(s.getDeviceId());
newRL.setAutomationId(s.getAutomationId()); newRL.setAutomationId(s.getAutomationId());
newRL.setOn(s.isOn()); newRL.setOn(s.isOn());
@ -39,13 +39,13 @@ public class BooleanConditionController {
@PostMapping @PostMapping
public BooleanCondition create( public BooleanCondition create(
@Valid @RequestBody BooleanConditionSaveRequest booleanTriggerSaveRequest) { @Valid @RequestBody BooleanConditionOrTriggerSaveRequest booleanTriggerSaveRequest) {
return save(new BooleanCondition(), booleanTriggerSaveRequest); return save(new BooleanCondition(), booleanTriggerSaveRequest);
} }
@PutMapping @PutMapping
public BooleanCondition update( public BooleanCondition update(
@Valid @RequestBody BooleanConditionSaveRequest booleanTriggerSaveRequest) @Valid @RequestBody BooleanConditionOrTriggerSaveRequest booleanTriggerSaveRequest)
throws NotFoundException { throws NotFoundException {
return save( return save(
booleanConditionRepository booleanConditionRepository

View file

@ -1,6 +1,6 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller; package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.BooleanTriggerSaveRequest; import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.BooleanConditionOrTriggerSaveRequest;
import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException; import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanTrigger; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanTrigger;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanTriggerRepository; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanTriggerRepository;
@ -29,7 +29,7 @@ public class BooleanTriggerController {
return booleanTriggerRepository.findAllByAutomationId(automationId); return booleanTriggerRepository.findAllByAutomationId(automationId);
} }
private BooleanTrigger save(BooleanTrigger newRL, BooleanTriggerSaveRequest s) { private BooleanTrigger save(BooleanTrigger newRL, BooleanConditionOrTriggerSaveRequest s) {
newRL.setDeviceId(s.getDeviceId()); newRL.setDeviceId(s.getDeviceId());
newRL.setAutomationId(s.getAutomationId()); newRL.setAutomationId(s.getAutomationId());
newRL.setOn(s.isOn()); newRL.setOn(s.isOn());
@ -39,13 +39,13 @@ public class BooleanTriggerController {
@PostMapping @PostMapping
public BooleanTrigger create( public BooleanTrigger create(
@Valid @RequestBody BooleanTriggerSaveRequest booleanTriggerSaveRequest) { @Valid @RequestBody BooleanConditionOrTriggerSaveRequest booleanTriggerSaveRequest) {
return save(new BooleanTrigger(), booleanTriggerSaveRequest); return save(new BooleanTrigger(), booleanTriggerSaveRequest);
} }
@PutMapping @PutMapping
public BooleanTrigger update( public BooleanTrigger update(
@Valid @RequestBody BooleanTriggerSaveRequest booleanTriggerSaveRequest) @Valid @RequestBody BooleanConditionOrTriggerSaveRequest booleanTriggerSaveRequest)
throws NotFoundException { throws NotFoundException {
return save( return save(
booleanTriggerRepository booleanTriggerRepository

View file

@ -1,6 +1,6 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller; package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.RangeConditionSaveRequest; import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.RangeConditionOrTriggerSaveRequest;
import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException; import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeCondition; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeCondition;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeConditionRepository; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeConditionRepository;
@ -29,7 +29,7 @@ public class RangeConditionController {
return rangeConditionRepository.findAllByAutomationId(automationId); return rangeConditionRepository.findAllByAutomationId(automationId);
} }
private RangeCondition save(RangeCondition newRL, RangeConditionSaveRequest s) { private RangeCondition save(RangeCondition newRL, RangeConditionOrTriggerSaveRequest s) {
newRL.setDeviceId(s.getDeviceId()); newRL.setDeviceId(s.getDeviceId());
newRL.setAutomationId(s.getAutomationId()); newRL.setAutomationId(s.getAutomationId());
newRL.setOperator(s.getOperator()); newRL.setOperator(s.getOperator());
@ -40,13 +40,13 @@ public class RangeConditionController {
@PostMapping @PostMapping
public RangeCondition create( public RangeCondition create(
@Valid @RequestBody RangeConditionSaveRequest booleanTriggerSaveRequest) { @Valid @RequestBody RangeConditionOrTriggerSaveRequest booleanTriggerSaveRequest) {
return save(new RangeCondition(), booleanTriggerSaveRequest); return save(new RangeCondition(), booleanTriggerSaveRequest);
} }
@PutMapping @PutMapping
public RangeCondition update( public RangeCondition update(
@Valid @RequestBody RangeConditionSaveRequest booleanTriggerSaveRequest) @Valid @RequestBody RangeConditionOrTriggerSaveRequest booleanTriggerSaveRequest)
throws NotFoundException { throws NotFoundException {
return save( return save(
rangeConditionRepository rangeConditionRepository

View file

@ -1,6 +1,6 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller; package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.RangeTriggerSaveRequest; import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.RangeConditionOrTriggerSaveRequest;
import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException; import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeTrigger; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeTrigger;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeTriggerRepository; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeTriggerRepository;
@ -29,7 +29,7 @@ public class RangeTriggerController {
return rangeTriggerRepository.findAllByAutomationId(automationId); return rangeTriggerRepository.findAllByAutomationId(automationId);
} }
private RangeTrigger save(RangeTrigger newRL, RangeTriggerSaveRequest s) { private RangeTrigger save(RangeTrigger newRL, RangeConditionOrTriggerSaveRequest s) {
newRL.setDeviceId(s.getDeviceId()); newRL.setDeviceId(s.getDeviceId());
newRL.setAutomationId(s.getAutomationId()); newRL.setAutomationId(s.getAutomationId());
newRL.setOperator(s.getOperator()); newRL.setOperator(s.getOperator());
@ -40,13 +40,13 @@ public class RangeTriggerController {
@PostMapping @PostMapping
public RangeTrigger create( public RangeTrigger create(
@Valid @RequestBody RangeTriggerSaveRequest booleanTriggerSaveRequest) { @Valid @RequestBody RangeConditionOrTriggerSaveRequest booleanTriggerSaveRequest) {
return save(new RangeTrigger(), booleanTriggerSaveRequest); return save(new RangeTrigger(), booleanTriggerSaveRequest);
} }
@PutMapping @PutMapping
public RangeTrigger update( public RangeTrigger update(
@Valid @RequestBody RangeTriggerSaveRequest booleanTriggerSaveRequest) @Valid @RequestBody RangeConditionOrTriggerSaveRequest booleanTriggerSaveRequest)
throws NotFoundException { throws NotFoundException {
return save( return save(
rangeTriggerRepository rangeTriggerRepository

View file

@ -4,7 +4,7 @@ import javax.validation.constraints.NotNull;
import lombok.Data; import lombok.Data;
@Data @Data
public class BooleanTriggerSaveRequest { public class BooleanConditionOrTriggerSaveRequest {
private long id; private long id;

View file

@ -1,42 +0,0 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import javax.validation.constraints.NotNull;
public class BooleanConditionSaveRequest {
@NotNull private long id;
@NotNull private Long deviceId;
@NotNull private Long automationId;
@NotNull private boolean on;
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 boolean isOn() {
return on;
}
public void setOn(boolean on) {
this.on = on;
}
}

View file

@ -5,7 +5,7 @@ import javax.validation.constraints.NotNull;
import lombok.Data; import lombok.Data;
@Data @Data
public class RangeTriggerSaveRequest { public class RangeConditionOrTriggerSaveRequest {
private long id; private long id;

View file

@ -1,19 +0,0 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Operator;
import javax.validation.constraints.NotNull;
import lombok.Data;
@Data
public class RangeConditionSaveRequest {
@NotNull private long id;
@NotNull private Long deviceId;
@NotNull private Long automationId;
@NotNull private Operator operator;
@NotNull private double range;
}