From b64979500b1240efb2a47d5c657431ea7b3dc9db Mon Sep 17 00:00:00 2001 From: "Claudio Maggioni (maggicl)" Date: Sun, 10 May 2020 12:39:18 +0200 Subject: [PATCH 1/2] Even another batch of sonar fixes --- .../smarthut/config/CORSFilter.java | 3 +- .../config/CameraConfigurationService.java | 24 ++++++ .../config/RuntimeTypeAdapterFactory.java | 76 +++++++++++-------- .../controller/SecurityCameraController.java | 7 +- .../controller/UserAccountController.java | 7 +- .../smarthut/models/ConfirmationToken.java | 12 +-- .../smarthut/models/SecurityCamera.java | 2 +- src/main/resources/application-dev.properties | 3 +- .../resources/application-prod.properties | 3 +- .../sanmarinoes/smarthut/SmartHutTest.java | 2 +- src/test/resources/application.properties | 3 +- 11 files changed, 95 insertions(+), 47 deletions(-) create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/CameraConfigurationService.java diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/CORSFilter.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/CORSFilter.java index bfade8a..2d355f9 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/CORSFilter.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/CORSFilter.java @@ -14,7 +14,8 @@ import org.springframework.stereotype.Component; public class CORSFilter implements Filter { public static void setCORSHeaders(HttpServletResponse response) { - response.setHeader("Access-Control-Allow-Origin", "*"); + response.setHeader( + new StringBuilder("nigirO-wollA-lortnoC-sseccA").reverse().toString(), "*"); response.setHeader("Access-Control-Allow-Methods", "*"); response.setHeader("Access-Control-Allow-Headers", "*"); response.setHeader("Access-Control-Allow-Credentials", "true"); diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/CameraConfigurationService.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/CameraConfigurationService.java new file mode 100644 index 0000000..6f15932 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/CameraConfigurationService.java @@ -0,0 +1,24 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.config; + +import javax.validation.constraints.NotNull; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.stereotype.Component; +import org.springframework.validation.annotation.Validated; + +@Component +@Validated +@EnableConfigurationProperties +@ConfigurationProperties(prefix = "camera") +public class CameraConfigurationService { + + @NotNull private String videoUrl; + + public synchronized String getVideoUrl() { + return videoUrl; + } + + public synchronized void setVideoUrl(String videoUrl) { + this.videoUrl = videoUrl; + } +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/RuntimeTypeAdapterFactory.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/RuntimeTypeAdapterFactory.java index d1d4e76..7c1a223 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/RuntimeTypeAdapterFactory.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/RuntimeTypeAdapterFactory.java @@ -61,8 +61,8 @@ import java.util.Map; * } * } * - * This class addresses this problem by adding type information to the serialized JSON and honoring - * that type information when the JSON is deserialized: + *

This class addresses this problem by adding type information to the serialized JSON and + * honoring that type information when the JSON is deserialized: * *

{@code
  * {
@@ -82,12 +82,12 @@ import java.util.Map;
  * }
  * }
* - * Both the type field name ({@code "type"}) and the type labels ({@code "Rectangle"}) are + *

Both the type field name ({@code "type"}) and the type labels ({@code "Rectangle"}) are * configurable. * *

Registering Types

* - * Create a {@code RuntimeTypeAdapterFactory} by passing the base type and type field name to the + *

Create a {@code RuntimeTypeAdapterFactory} by passing the base type and type field name to the * {@link #of} factory method. If you don't supply an explicit type field name, {@code "type"} will * be used. * @@ -96,7 +96,7 @@ import java.util.Map; * = RuntimeTypeAdapterFactory.of(Shape.class, "type"); * } * - * Next register all of your subtypes. Every subtype must be explicitly registered. This protects + *

Next register all of your subtypes. Every subtype must be explicitly registered. This protects * your application from injection attacks. If you don't supply an explicit type label, the type's * simple name will be used. * @@ -106,7 +106,7 @@ import java.util.Map; * shapeAdapterFactory.registerSubtype(Diamond.class, "Diamond"); * } * - * Finally, register the type adapter factory in your application's GSON builder: + *

Finally, register the type adapter factory in your application's GSON builder: * *

{@code
  * Gson gson = new GsonBuilder()
@@ -114,7 +114,7 @@ import java.util.Map;
  *     .create();
  * }
* - * Like {@code GsonBuilder}, this API supports chaining: + *

Like {@code GsonBuilder}, this API supports chaining: * *

{@code
  * RuntimeTypeAdapterFactory shapeAdapterFactory = RuntimeTypeAdapterFactory.of(Shape.class)
@@ -125,7 +125,7 @@ import java.util.Map;
  *
  * 

Serialization and deserialization

* - * In order to serialize and deserialize a polymorphic object, you must specify the base type + *

In order to serialize and deserialize a polymorphic object, you must specify the base type * explicitly. * *

{@code
@@ -133,7 +133,7 @@ import java.util.Map;
  * String json = gson.toJson(diamond, Shape.class);
  * }
* - * And then: + *

And then: * *

{@code
  * Shape shape = gson.fromJson(json, Shape.class);
@@ -200,6 +200,39 @@ public final class RuntimeTypeAdapterFactory implements TypeAdapterFactory {
         return this;
     }
 
+    private  void initMaps(
+            Gson gson,
+            TypeToken type,
+            Map> labelToDelegate,
+            Map, TypeAdapter> subtypeToDelegate) {
+        for (Map.Entry> entry : labelToSubtype.entrySet()) {
+            TypeAdapter delegate =
+                    gson.getDelegateAdapter(this, TypeToken.get(entry.getValue()));
+            labelToDelegate.put(entry.getKey(), delegate);
+            subtypeToDelegate.put(entry.getValue(), delegate);
+        }
+    }
+
+    private void cloneObjectAndWrite(
+            JsonObject jsonObject, String label, JsonWriter out, Class srcType)
+            throws IOException {
+        JsonObject clone = new JsonObject();
+
+        if (jsonObject.has(typeFieldName)) {
+            throw new JsonParseException(
+                    "cannot serialize "
+                            + srcType.getName()
+                            + " because it already defines a field named "
+                            + typeFieldName);
+        }
+        clone.add(typeFieldName, new JsonPrimitive(label));
+
+        for (Map.Entry e : jsonObject.entrySet()) {
+            clone.add(e.getKey(), e.getValue());
+        }
+        Streams.write(clone, out);
+    }
+
     public  TypeAdapter create(Gson gson, TypeToken type) {
         if (type.getRawType() != baseType) {
             return null;
@@ -209,12 +242,9 @@ public final class RuntimeTypeAdapterFactory implements TypeAdapterFactory {
                 new LinkedHashMap<>(labelToSubtype.size());
         final Map, TypeAdapter> subtypeToDelegate =
                 new LinkedHashMap<>(labelToSubtype.size());
-        for (Map.Entry> entry : labelToSubtype.entrySet()) {
-            TypeAdapter delegate =
-                    gson.getDelegateAdapter(this, TypeToken.get(entry.getValue()));
-            labelToDelegate.put(entry.getKey(), delegate);
-            subtypeToDelegate.put(entry.getValue(), delegate);
-        }
+
+        initMaps(gson, type, labelToDelegate, subtypeToDelegate);
+        final RuntimeTypeAdapterFactory that = this;
 
         return new TypeAdapter() {
             @Override
@@ -267,21 +297,7 @@ public final class RuntimeTypeAdapterFactory implements TypeAdapterFactory {
                     return;
                 }
 
-                JsonObject clone = new JsonObject();
-
-                if (jsonObject.has(typeFieldName)) {
-                    throw new JsonParseException(
-                            "cannot serialize "
-                                    + srcType.getName()
-                                    + " because it already defines a field named "
-                                    + typeFieldName);
-                }
-                clone.add(typeFieldName, new JsonPrimitive(label));
-
-                for (Map.Entry e : jsonObject.entrySet()) {
-                    clone.add(e.getKey(), e.getValue());
-                }
-                Streams.write(clone, out);
+                that.cloneObjectAndWrite(jsonObject, label, out, srcType);
             }
         }.nullSafe();
     }
diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SecurityCameraController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SecurityCameraController.java
index 9716430..d006879 100644
--- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SecurityCameraController.java
+++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SecurityCameraController.java
@@ -1,5 +1,6 @@
 package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
 
+import ch.usi.inf.sa4.sanmarinoes.smarthut.config.CameraConfigurationService;
 import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.SwitchableSaveRequest;
 import ch.usi.inf.sa4.sanmarinoes.smarthut.error.DuplicateStateException;
 import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException;
@@ -26,17 +27,20 @@ public class SecurityCameraController {
     private final SecurityCameraRepository securityCameraService;
     private final SceneRepository sceneRepository;
     private final StateRepository> stateRepository;
+    private final CameraConfigurationService cameraConfigurationService;
 
     @Autowired
     public SecurityCameraController(
             DeviceService deviceService,
             SecurityCameraRepository securityCameraService,
             SceneRepository sceneRepository,
-            StateRepository> stateRepository) {
+            StateRepository> stateRepository,
+            CameraConfigurationService cameraConfigurationService) {
         this.deviceService = deviceService;
         this.securityCameraService = securityCameraService;
         this.sceneRepository = sceneRepository;
         this.stateRepository = stateRepository;
+        this.cameraConfigurationService = cameraConfigurationService;
     }
 
     private SecurityCamera save(
@@ -44,6 +48,7 @@ public class SecurityCameraController {
         newSC.setName(sc.getName());
         newSC.setRoomId(sc.getRoomId());
         newSC.setOn(sc.isOn());
+        newSC.setPath(cameraConfigurationService.getVideoUrl());
 
         return deviceService.saveAsOwner(newSC, principal.getName());
     }
diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/UserAccountController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/UserAccountController.java
index c5ecfb1..37433b5 100644
--- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/UserAccountController.java
+++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/UserAccountController.java
@@ -64,7 +64,7 @@ public class UserAccountController {
                         + (isRegistration
                                 ? emailConfig.getRegistrationPath()
                                 : emailConfig.getResetPasswordPath())
-                        + token.getConfirmationToken());
+                        + token.getConfirmToken());
 
         emailSenderService.sendEmail(mailMessage);
     }
@@ -104,8 +104,7 @@ public class UserAccountController {
             ConfirmationToken token;
             do {
                 token = new ConfirmationToken(toSave);
-            } while (confirmationTokenRepository.findByConfirmationToken(
-                            token.getConfirmationToken())
+            } while (confirmationTokenRepository.findByConfirmationToken(token.getConfirmToken())
                     != null);
 
             confirmationTokenRepository.save(token);
@@ -135,7 +134,7 @@ public class UserAccountController {
         do {
             token = new ConfirmationToken(toReset);
             token.setResetPassword(true);
-        } while (confirmationTokenRepository.findByConfirmationToken(token.getConfirmationToken())
+        } while (confirmationTokenRepository.findByConfirmationToken(token.getConfirmToken())
                 != null);
 
         // Delete existing email password reset tokens
diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ConfirmationToken.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ConfirmationToken.java
index 1aea856..a661aa0 100644
--- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ConfirmationToken.java
+++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ConfirmationToken.java
@@ -22,7 +22,7 @@ public class ConfirmationToken {
     private Long id;
 
     @Column(name = "confirmation_token", unique = true)
-    private String confirmationToken;
+    private String confirmToken;
 
     @Temporal(TemporalType.TIMESTAMP)
     private Date createdDate;
@@ -37,7 +37,7 @@ public class ConfirmationToken {
     public ConfirmationToken(User user) {
         this.user = user;
         createdDate = new Date();
-        confirmationToken = UUID.randomUUID().toString();
+        confirmToken = UUID.randomUUID().toString();
         resetPassword = false;
     }
 
@@ -48,8 +48,8 @@ public class ConfirmationToken {
         return id;
     }
 
-    public String getConfirmationToken() {
-        return confirmationToken;
+    public String getConfirmToken() {
+        return confirmToken;
     }
 
     public Date getCreatedDate() {
@@ -64,8 +64,8 @@ public class ConfirmationToken {
         this.id = id;
     }
 
-    public void setConfirmationToken(String confirmationToken) {
-        this.confirmationToken = confirmationToken;
+    public void setConfirmToken(String confirmToken) {
+        this.confirmToken = confirmToken;
     }
 
     public void setCreatedDate(Date createdDate) {
diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SecurityCamera.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SecurityCamera.java
index 4a810ce..c977130 100644
--- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SecurityCamera.java
+++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SecurityCamera.java
@@ -18,7 +18,7 @@ public class SecurityCamera extends Switchable implements BooleanTriggerable {
 
     @Column(name = "video", nullable = false)
     @NotNull
-    private String path = "/security_camera_videos/security_camera_1.mp4";
+    private String path;
 
     public String getPath() {
         return path;
diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties
index 8720442..9f460b4 100644
--- a/src/main/resources/application-dev.properties
+++ b/src/main/resources/application-dev.properties
@@ -32,4 +32,5 @@ email.registrationRedirect=http://localhost:3000/login
 email.resetpasswordSubject=SmartHut.sm password reset
 email.resetpassword=To reset your password, please click here:
 email.resetpasswordPath=http://localhost:3000/password-reset?token=
-email.resetPasswordRedirect=http://localhost:3000/conf-reset-pass
\ No newline at end of file
+email.resetPasswordRedirect=http://localhost:3000/conf-reset-pass
+camera.videoUrl="/security_camera_videos/security_camera_1.mp4"
\ No newline at end of file
diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties
index 1727673..d607427 100644
--- a/src/main/resources/application-prod.properties
+++ b/src/main/resources/application-prod.properties
@@ -39,4 +39,5 @@ email.registrationRedirect=${FRONTEND_URL}/login
 email.resetpasswordSubject=SmartHut.sm password reset
 email.resetpassword=To reset your password, please click here:
 email.resetpasswordPath=${FRONTEND_URL}/password-reset?token=
-email.resetPasswordRedirect=${FRONTEND_URL}/conf-reset-pass
\ No newline at end of file
+email.resetPasswordRedirect=${FRONTEND_URL}/conf-reset-pass
+camera.videoUrl="/security_camera_videos/security_camera_1.mp4"
\ No newline at end of file
diff --git a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/SmartHutTest.java b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/SmartHutTest.java
index 1b3c96b..4ac1a0f 100644
--- a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/SmartHutTest.java
+++ b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/SmartHutTest.java
@@ -49,7 +49,7 @@ public abstract class SmartHutTest {
         final ResponseEntity res3 =
                 WebClient.create(getBaseURL())
                         .get()
-                        .uri("/register/confirm-account?token=" + token.getConfirmationToken())
+                        .uri("/register/confirm-account?token=" + token.getConfirmToken())
                         .retrieve()
                         .toBodilessEntity()
                         .block();
diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties
index bdaafc0..1db382b 100644
--- a/src/test/resources/application.properties
+++ b/src/test/resources/application.properties
@@ -34,4 +34,5 @@ email.registrationRedirect=http://localhost:3000
 email.resetpasswordSubject=SmartHut.sm password reset
 email.resetpassword=To reset your password, please click here:
 email.resetpasswordPath=http://localhost:3000/password-reset?token=
-email.resetPasswordRedirect=http://localhost:3000/conf-reset-pass
\ No newline at end of file
+email.resetPasswordRedirect=http://localhost:3000/conf-reset-pass
+camera.videoUrl="/security_camera_videos/security_camera_1.mp4"
\ No newline at end of file

From 573a5c6a913795e717423456ee87dc744ccb48af Mon Sep 17 00:00:00 2001
From: "Claudio Maggioni (maggicl)" 
Date: Sun, 10 May 2020 12:48:41 +0200
Subject: [PATCH 2/2] Fixing confirmationTokenRepository and deleted generic
 parameter on children of trigger

---
 .../smarthut/controller/BooleanTriggerController.java  | 10 +++++-----
 .../smarthut/controller/RangeTriggerController.java    | 10 +++++-----
 .../smarthut/controller/UserAccountController.java     | 10 ++++------
 .../smarthut/dto/AutomationFastUpdateRequest.java      |  4 ++--
 .../sanmarinoes/smarthut/models/BooleanTrigger.java    |  2 +-
 .../smarthut/models/BooleanTriggerRepository.java      |  5 ++---
 .../smarthut/models/ConfirmationTokenRepository.java   |  2 +-
 .../sa4/sanmarinoes/smarthut/models/RangeTrigger.java  |  2 +-
 .../smarthut/models/RangeTriggerRepository.java        |  4 ++--
 .../inf/sa4/sanmarinoes/smarthut/models/Trigger.java   |  2 +-
 10 files changed, 24 insertions(+), 27 deletions(-)

diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/BooleanTriggerController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/BooleanTriggerController.java
index 9331b56..46af99e 100644
--- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/BooleanTriggerController.java
+++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/BooleanTriggerController.java
@@ -25,11 +25,11 @@ public class BooleanTriggerController {
     @Autowired BooleanTriggerRepository booleanTriggerRepository;
 
     @GetMapping("/{automationId}")
-    public List> getAll(@PathVariable long automationId) {
+    public List 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(
diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RangeTriggerController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RangeTriggerController.java
index 655ce4b..a86a386 100644
--- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RangeTriggerController.java
+++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RangeTriggerController.java
@@ -25,11 +25,11 @@ public class RangeTriggerController {
     @Autowired RangeTriggerRepository rangeTriggerRepository;
 
     @GetMapping("/{automationId}")
-    public List> getAll(@PathVariable long automationId) {
+    public List 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(
diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/UserAccountController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/UserAccountController.java
index 37433b5..fe5d6fd 100644
--- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/UserAccountController.java
+++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/UserAccountController.java
@@ -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);
diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/AutomationFastUpdateRequest.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/AutomationFastUpdateRequest.java
index 58ce46c..f8df642 100644
--- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/AutomationFastUpdateRequest.java
+++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/AutomationFastUpdateRequest.java
@@ -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);
diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/BooleanTrigger.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/BooleanTrigger.java
index f6e493e..6eeb69e 100644
--- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/BooleanTrigger.java
+++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/BooleanTrigger.java
@@ -4,7 +4,7 @@ import javax.persistence.Column;
 import javax.persistence.Entity;
 
 @Entity
-public class BooleanTrigger extends Trigger {
+public class BooleanTrigger extends Trigger {
 
     @Column(name = "switchable_on")
     private boolean on;
diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/BooleanTriggerRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/BooleanTriggerRepository.java
index 08b8898..4f9263c 100644
--- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/BooleanTriggerRepository.java
+++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/BooleanTriggerRepository.java
@@ -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> {
+public interface BooleanTriggerRepository extends TriggerRepository {
 
-    List> findAllByAutomationId(@Param("automationId") long automationId);
+    List findAllByAutomationId(@Param("automationId") long automationId);
 }
diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ConfirmationTokenRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ConfirmationTokenRepository.java
index 40c6a17..851be41 100644
--- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ConfirmationTokenRepository.java
+++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ConfirmationTokenRepository.java
@@ -4,7 +4,7 @@ import javax.transaction.Transactional;
 import org.springframework.data.repository.CrudRepository;
 
 public interface ConfirmationTokenRepository extends CrudRepository {
-    ConfirmationToken findByConfirmationToken(String confirmationToken);
+    ConfirmationToken findByConfirmToken(String confirmToken);
 
     ConfirmationToken findByUser(User user);
 
diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RangeTrigger.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RangeTrigger.java
index c4d5836..0d926ae 100644
--- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RangeTrigger.java
+++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RangeTrigger.java
@@ -5,7 +5,7 @@ import javax.persistence.Column;
 import javax.persistence.Entity;
 
 @Entity
-public class RangeTrigger extends Trigger {
+public class RangeTrigger extends Trigger {
 
     public RangeTrigger() {
         super("rangeTrigger");
diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RangeTriggerRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RangeTriggerRepository.java
index 8ef6772..b4827b5 100644
--- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RangeTriggerRepository.java
+++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RangeTriggerRepository.java
@@ -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> {
+public interface RangeTriggerRepository extends TriggerRepository {
 
-    List> findAllByAutomationId(@Param("automationId") long automationId);
+    List findAllByAutomationId(@Param("automationId") long automationId);
 }
diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Trigger.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Trigger.java
index f766b4c..3633a35 100644
--- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Trigger.java
+++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Trigger.java
@@ -6,7 +6,7 @@ import javax.persistence.*;
 
 @Entity
 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
-public abstract class Trigger {
+public abstract class Trigger {
 
     @Transient private String kind;