Fixing confirmationTokenRepository and deleted generic parameter on children of trigger

This commit is contained in:
Claudio Maggioni (maggicl) 2020-05-10 12:48:41 +02:00
parent b64979500b
commit 573a5c6a91
10 changed files with 24 additions and 27 deletions

View file

@ -25,11 +25,11 @@ public class BooleanTriggerController {
@Autowired BooleanTriggerRepository booleanTriggerRepository;
@GetMapping("/{automationId}")
public List<BooleanTrigger<?>> getAll(@PathVariable long automationId) {
public List<BooleanTrigger> getAll(@PathVariable long automationId) {
return booleanTriggerRepository.findAllByAutomationId(automationId);
}
private BooleanTrigger<?> save(BooleanTrigger<?> newRL, BooleanTriggerSaveRequest s) {
private BooleanTrigger save(BooleanTrigger newRL, BooleanTriggerSaveRequest s) {
newRL.setDeviceId(s.getDeviceId());
newRL.setAutomationId(s.getAutomationId());
newRL.setOn(s.isOn());
@ -38,13 +38,13 @@ public class BooleanTriggerController {
}
@PostMapping
public BooleanTrigger<?> create(
public BooleanTrigger create(
@Valid @RequestBody BooleanTriggerSaveRequest booleanTriggerSaveRequest) {
return save(new BooleanTrigger<>(), booleanTriggerSaveRequest);
return save(new BooleanTrigger(), booleanTriggerSaveRequest);
}
@PutMapping
public BooleanTrigger<?> update(
public BooleanTrigger update(
@Valid @RequestBody BooleanTriggerSaveRequest booleanTriggerSaveRequest)
throws NotFoundException {
return save(

View file

@ -25,11 +25,11 @@ public class RangeTriggerController {
@Autowired RangeTriggerRepository rangeTriggerRepository;
@GetMapping("/{automationId}")
public List<RangeTrigger<?>> getAll(@PathVariable long automationId) {
public List<RangeTrigger> getAll(@PathVariable long automationId) {
return rangeTriggerRepository.findAllByAutomationId(automationId);
}
private RangeTrigger<?> save(RangeTrigger<?> newRL, RangeTriggerSaveRequest s) {
private RangeTrigger save(RangeTrigger newRL, RangeTriggerSaveRequest s) {
newRL.setDeviceId(s.getDeviceId());
newRL.setAutomationId(s.getAutomationId());
newRL.setOperator(s.getOperator());
@ -39,13 +39,13 @@ public class RangeTriggerController {
}
@PostMapping
public RangeTrigger<?> create(
public RangeTrigger create(
@Valid @RequestBody RangeTriggerSaveRequest booleanTriggerSaveRequest) {
return save(new RangeTrigger<>(), booleanTriggerSaveRequest);
return save(new RangeTrigger(), booleanTriggerSaveRequest);
}
@PutMapping
public RangeTrigger<?> update(
public RangeTrigger update(
@Valid @RequestBody RangeTriggerSaveRequest booleanTriggerSaveRequest)
throws NotFoundException {
return save(

View file

@ -104,7 +104,7 @@ public class UserAccountController {
ConfirmationToken token;
do {
token = new ConfirmationToken(toSave);
} while (confirmationTokenRepository.findByConfirmationToken(token.getConfirmToken())
} while (confirmationTokenRepository.findByConfirmToken(token.getConfirmToken())
!= null);
confirmationTokenRepository.save(token);
@ -134,8 +134,7 @@ public class UserAccountController {
do {
token = new ConfirmationToken(toReset);
token.setResetPassword(true);
} while (confirmationTokenRepository.findByConfirmationToken(token.getConfirmToken())
!= null);
} while (confirmationTokenRepository.findByConfirmToken(token.getConfirmToken()) != null);
// Delete existing email password reset tokens
confirmationTokenRepository.deleteByUserAndResetPassword(toReset, true);
@ -157,8 +156,7 @@ public class UserAccountController {
public void resetPassword(@Valid @RequestBody PasswordResetRequest resetRequest)
throws EmailTokenNotFoundException {
final ConfirmationToken token =
confirmationTokenRepository.findByConfirmationToken(
resetRequest.getConfirmationToken());
confirmationTokenRepository.findByConfirmToken(resetRequest.getConfirmationToken());
if (token == null || !token.getResetPassword()) {
throw new EmailTokenNotFoundException();
@ -186,7 +184,7 @@ public class UserAccountController {
final HttpServletResponse response)
throws EmailTokenNotFoundException, IOException {
final ConfirmationToken token =
confirmationTokenRepository.findByConfirmationToken(confirmationToken);
confirmationTokenRepository.findByConfirmToken(confirmationToken);
if (token != null && !token.getResetPassword()) {
token.getUser().setEnabled(true);

View file

@ -21,7 +21,7 @@ public class AutomationFastUpdateRequest {
@Override
public Trigger<?> toModel() {
BooleanTrigger<?> t = new BooleanTrigger<>();
BooleanTrigger t = new BooleanTrigger();
t.setDeviceId(this.deviceId);
t.setOn(this.on);
return t;
@ -34,7 +34,7 @@ public class AutomationFastUpdateRequest {
@Override
public Trigger<?> toModel() {
RangeTrigger<?> t = new RangeTrigger<>();
RangeTrigger t = new RangeTrigger();
t.setDeviceId(this.deviceId);
t.setOperator(this.operator);
t.setRange(this.range);

View file

@ -4,7 +4,7 @@ import javax.persistence.Column;
import javax.persistence.Entity;
@Entity
public class BooleanTrigger<D extends Device & BooleanTriggerable> extends Trigger<D> {
public class BooleanTrigger extends Trigger<BooleanTriggerable> {
@Column(name = "switchable_on")
private boolean on;

View file

@ -3,8 +3,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import java.util.List;
import org.springframework.data.repository.query.Param;
public interface BooleanTriggerRepository
extends TriggerRepository<BooleanTrigger<? extends Device>> {
public interface BooleanTriggerRepository extends TriggerRepository<BooleanTrigger> {
List<BooleanTrigger<?>> findAllByAutomationId(@Param("automationId") long automationId);
List<BooleanTrigger> findAllByAutomationId(@Param("automationId") long automationId);
}

View file

@ -4,7 +4,7 @@ import javax.transaction.Transactional;
import org.springframework.data.repository.CrudRepository;
public interface ConfirmationTokenRepository extends CrudRepository<ConfirmationToken, String> {
ConfirmationToken findByConfirmationToken(String confirmationToken);
ConfirmationToken findByConfirmToken(String confirmToken);
ConfirmationToken findByUser(User user);

View file

@ -5,7 +5,7 @@ import javax.persistence.Column;
import javax.persistence.Entity;
@Entity
public class RangeTrigger<D extends Device & RangeTriggerable> extends Trigger<D> {
public class RangeTrigger extends Trigger<RangeTriggerable> {
public RangeTrigger() {
super("rangeTrigger");

View file

@ -3,7 +3,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import java.util.List;
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);
}

View file

@ -6,7 +6,7 @@ import javax.persistence.*;
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Trigger<D extends Device> {
public abstract class Trigger<D> {
@Transient private String kind;