Fixing confirmationTokenRepository and deleted generic parameter on children of trigger
This commit is contained in:
parent
b64979500b
commit
573a5c6a91
10 changed files with 24 additions and 27 deletions
|
@ -25,11 +25,11 @@ public class BooleanTriggerController {
|
||||||
@Autowired BooleanTriggerRepository booleanTriggerRepository;
|
@Autowired BooleanTriggerRepository booleanTriggerRepository;
|
||||||
|
|
||||||
@GetMapping("/{automationId}")
|
@GetMapping("/{automationId}")
|
||||||
public List<BooleanTrigger<?>> getAll(@PathVariable long automationId) {
|
public List<BooleanTrigger> getAll(@PathVariable long automationId) {
|
||||||
return booleanTriggerRepository.findAllByAutomationId(automationId);
|
return booleanTriggerRepository.findAllByAutomationId(automationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private BooleanTrigger<?> save(BooleanTrigger<?> newRL, BooleanTriggerSaveRequest s) {
|
private BooleanTrigger save(BooleanTrigger newRL, BooleanTriggerSaveRequest 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());
|
||||||
|
@ -38,13 +38,13 @@ public class BooleanTriggerController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public BooleanTrigger<?> create(
|
public BooleanTrigger create(
|
||||||
@Valid @RequestBody BooleanTriggerSaveRequest booleanTriggerSaveRequest) {
|
@Valid @RequestBody BooleanTriggerSaveRequest 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 BooleanTriggerSaveRequest booleanTriggerSaveRequest)
|
||||||
throws NotFoundException {
|
throws NotFoundException {
|
||||||
return save(
|
return save(
|
||||||
|
|
|
@ -25,11 +25,11 @@ public class RangeTriggerController {
|
||||||
@Autowired RangeTriggerRepository rangeTriggerRepository;
|
@Autowired RangeTriggerRepository rangeTriggerRepository;
|
||||||
|
|
||||||
@GetMapping("/{automationId}")
|
@GetMapping("/{automationId}")
|
||||||
public List<RangeTrigger<?>> getAll(@PathVariable long automationId) {
|
public List<RangeTrigger> getAll(@PathVariable long automationId) {
|
||||||
return rangeTriggerRepository.findAllByAutomationId(automationId);
|
return rangeTriggerRepository.findAllByAutomationId(automationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private RangeTrigger<?> save(RangeTrigger<?> newRL, RangeTriggerSaveRequest s) {
|
private RangeTrigger save(RangeTrigger newRL, RangeTriggerSaveRequest 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());
|
||||||
|
@ -39,13 +39,13 @@ public class RangeTriggerController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public RangeTrigger<?> create(
|
public RangeTrigger create(
|
||||||
@Valid @RequestBody RangeTriggerSaveRequest booleanTriggerSaveRequest) {
|
@Valid @RequestBody RangeTriggerSaveRequest 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 RangeTriggerSaveRequest booleanTriggerSaveRequest)
|
||||||
throws NotFoundException {
|
throws NotFoundException {
|
||||||
return save(
|
return save(
|
||||||
|
|
|
@ -104,7 +104,7 @@ public class UserAccountController {
|
||||||
ConfirmationToken token;
|
ConfirmationToken token;
|
||||||
do {
|
do {
|
||||||
token = new ConfirmationToken(toSave);
|
token = new ConfirmationToken(toSave);
|
||||||
} while (confirmationTokenRepository.findByConfirmationToken(token.getConfirmToken())
|
} while (confirmationTokenRepository.findByConfirmToken(token.getConfirmToken())
|
||||||
!= null);
|
!= null);
|
||||||
|
|
||||||
confirmationTokenRepository.save(token);
|
confirmationTokenRepository.save(token);
|
||||||
|
@ -134,8 +134,7 @@ public class UserAccountController {
|
||||||
do {
|
do {
|
||||||
token = new ConfirmationToken(toReset);
|
token = new ConfirmationToken(toReset);
|
||||||
token.setResetPassword(true);
|
token.setResetPassword(true);
|
||||||
} while (confirmationTokenRepository.findByConfirmationToken(token.getConfirmToken())
|
} while (confirmationTokenRepository.findByConfirmToken(token.getConfirmToken()) != null);
|
||||||
!= null);
|
|
||||||
|
|
||||||
// Delete existing email password reset tokens
|
// Delete existing email password reset tokens
|
||||||
confirmationTokenRepository.deleteByUserAndResetPassword(toReset, true);
|
confirmationTokenRepository.deleteByUserAndResetPassword(toReset, true);
|
||||||
|
@ -157,8 +156,7 @@ public class UserAccountController {
|
||||||
public void resetPassword(@Valid @RequestBody PasswordResetRequest resetRequest)
|
public void resetPassword(@Valid @RequestBody PasswordResetRequest resetRequest)
|
||||||
throws EmailTokenNotFoundException {
|
throws EmailTokenNotFoundException {
|
||||||
final ConfirmationToken token =
|
final ConfirmationToken token =
|
||||||
confirmationTokenRepository.findByConfirmationToken(
|
confirmationTokenRepository.findByConfirmToken(resetRequest.getConfirmationToken());
|
||||||
resetRequest.getConfirmationToken());
|
|
||||||
|
|
||||||
if (token == null || !token.getResetPassword()) {
|
if (token == null || !token.getResetPassword()) {
|
||||||
throw new EmailTokenNotFoundException();
|
throw new EmailTokenNotFoundException();
|
||||||
|
@ -186,7 +184,7 @@ public class UserAccountController {
|
||||||
final HttpServletResponse response)
|
final HttpServletResponse response)
|
||||||
throws EmailTokenNotFoundException, IOException {
|
throws EmailTokenNotFoundException, IOException {
|
||||||
final ConfirmationToken token =
|
final ConfirmationToken token =
|
||||||
confirmationTokenRepository.findByConfirmationToken(confirmationToken);
|
confirmationTokenRepository.findByConfirmToken(confirmationToken);
|
||||||
|
|
||||||
if (token != null && !token.getResetPassword()) {
|
if (token != null && !token.getResetPassword()) {
|
||||||
token.getUser().setEnabled(true);
|
token.getUser().setEnabled(true);
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class AutomationFastUpdateRequest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Trigger<?> toModel() {
|
public Trigger<?> toModel() {
|
||||||
BooleanTrigger<?> t = new BooleanTrigger<>();
|
BooleanTrigger t = new BooleanTrigger();
|
||||||
t.setDeviceId(this.deviceId);
|
t.setDeviceId(this.deviceId);
|
||||||
t.setOn(this.on);
|
t.setOn(this.on);
|
||||||
return t;
|
return t;
|
||||||
|
@ -34,7 +34,7 @@ public class AutomationFastUpdateRequest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Trigger<?> toModel() {
|
public Trigger<?> toModel() {
|
||||||
RangeTrigger<?> t = new RangeTrigger<>();
|
RangeTrigger t = new RangeTrigger();
|
||||||
t.setDeviceId(this.deviceId);
|
t.setDeviceId(this.deviceId);
|
||||||
t.setOperator(this.operator);
|
t.setOperator(this.operator);
|
||||||
t.setRange(this.range);
|
t.setRange(this.range);
|
||||||
|
|
|
@ -4,7 +4,7 @@ import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class BooleanTrigger<D extends Device & BooleanTriggerable> extends Trigger<D> {
|
public class BooleanTrigger extends Trigger<BooleanTriggerable> {
|
||||||
|
|
||||||
@Column(name = "switchable_on")
|
@Column(name = "switchable_on")
|
||||||
private boolean on;
|
private boolean on;
|
||||||
|
|
|
@ -3,8 +3,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
|
|
||||||
public interface BooleanTriggerRepository
|
public interface BooleanTriggerRepository extends TriggerRepository<BooleanTrigger> {
|
||||||
extends TriggerRepository<BooleanTrigger<? extends Device>> {
|
|
||||||
|
|
||||||
List<BooleanTrigger<?>> findAllByAutomationId(@Param("automationId") long automationId);
|
List<BooleanTrigger> findAllByAutomationId(@Param("automationId") long automationId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import javax.transaction.Transactional;
|
||||||
import org.springframework.data.repository.CrudRepository;
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
|
||||||
public interface ConfirmationTokenRepository extends CrudRepository<ConfirmationToken, String> {
|
public interface ConfirmationTokenRepository extends CrudRepository<ConfirmationToken, String> {
|
||||||
ConfirmationToken findByConfirmationToken(String confirmationToken);
|
ConfirmationToken findByConfirmToken(String confirmToken);
|
||||||
|
|
||||||
ConfirmationToken findByUser(User user);
|
ConfirmationToken findByUser(User user);
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class RangeTrigger<D extends Device & RangeTriggerable> extends Trigger<D> {
|
public class RangeTrigger extends Trigger<RangeTriggerable> {
|
||||||
|
|
||||||
public RangeTrigger() {
|
public RangeTrigger() {
|
||||||
super("rangeTrigger");
|
super("rangeTrigger");
|
||||||
|
|
|
@ -3,7 +3,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
|
|
||||||
public interface RangeTriggerRepository extends TriggerRepository<RangeTrigger<? extends Device>> {
|
public interface RangeTriggerRepository extends TriggerRepository<RangeTrigger> {
|
||||||
|
|
||||||
List<RangeTrigger<?>> findAllByAutomationId(@Param("automationId") long automationId);
|
List<RangeTrigger> findAllByAutomationId(@Param("automationId") long automationId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import javax.persistence.*;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
|
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
|
||||||
public abstract class Trigger<D extends Device> {
|
public abstract class Trigger<D> {
|
||||||
|
|
||||||
@Transient private String kind;
|
@Transient private String kind;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue