From 6fc17052c6fe89494e058f29fd575b635f61a5ab Mon Sep 17 00:00:00 2001 From: Claudio Maggioni Date: Thu, 20 Feb 2020 21:58:23 +0100 Subject: [PATCH 1/9] Added a sketch of the data model Added a rough hint of the class structure needed to store the application state --- .../executionHistory/executionHistory.bin | Bin 0 -> 18720 bytes .../executionHistory/executionHistory.lock | Bin 0 -> 17 bytes build.gradle | 5 +- gradle/wrapper/gradle-wrapper.properties | 3 +- .../sa4/sanmarinoes/smarthut/HelloWorld.java | 15 ------ .../smarthut/SmarthutApplication.java | 2 - .../smarthut/WelcomeController.java | 19 +++++++ .../sanmarinoes/smarthut/models/Device.java | 51 ++++++++++++++++++ .../sanmarinoes/smarthut/models/Dimmer.java | 7 +++ .../sanmarinoes/smarthut/models/Light.java | 24 +++++++++ .../smarthut/models/MotionSensor.java | 7 +++ .../sanmarinoes/smarthut/models/Sensor.java | 7 +++ .../smarthut/models/SmartPlug.java | 7 +++ .../sanmarinoes/smarthut/models/Switch.java | 7 +++ src/main/resources/application.properties | 2 +- 15 files changed, 136 insertions(+), 20 deletions(-) create mode 100644 .gradle/6.0.1/executionHistory/executionHistory.bin create mode 100644 .gradle/6.0.1/executionHistory/executionHistory.lock delete mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/HelloWorld.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/WelcomeController.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Dimmer.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Light.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensor.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Sensor.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SmartPlug.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Switch.java diff --git a/.gradle/6.0.1/executionHistory/executionHistory.bin b/.gradle/6.0.1/executionHistory/executionHistory.bin new file mode 100644 index 0000000000000000000000000000000000000000..6ccb7e3ea257ccc3175fb6d977b8a52bffd1c6b9 GIT binary patch literal 18720 zcmeI%F-ikL6oBE`fQ<;IkwkAGgh9yW0Lm6(DW;am?#pH{?yS2TB^U4j7B(p@ZEUTy zwy=zaNALo6I$;etfgth^yqU+$FueD*6Diehe*Fx!8e6NB3;_fXKmY**5I_I{1Q0*~ z0R#|0009ILKmY**{)<50H?m$g)9y4D$>x<(dmBCp4&-6`=ws)zK0e%E{vRw?zrS0b zF(ZHg0tg_000IagfB*srAbks%+AtiBZ1-Gx*(9uMZQQ8mz!j-Z3zLjR zo80QklxL+*tVuIhRyHnmB)MdXWbyP^a#vI*{>Et}u`5g^N%OkZzw6BIA6uiBr`xqR N7yQDTzTCja`!^-rZdd>S literal 0 HcmV?d00001 diff --git a/.gradle/6.0.1/executionHistory/executionHistory.lock b/.gradle/6.0.1/executionHistory/executionHistory.lock new file mode 100644 index 0000000000000000000000000000000000000000..7de975e1f72ae1bec0d228a5b248208c615ec6bc GIT binary patch literal 17 UcmZQBWZ1;(YB=pQ0|ama03;X#6aWAK literal 0 HcmV?d00001 diff --git a/build.gradle b/build.gradle index da2744c..a293ca9 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,10 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter' - implementation 'org.springframework.boot:spring-boot-starter-web' + implementation('org.springframework.boot:spring-boot-starter-web') { + exclude group: 'org.springframework.boot', module: 'spring-boot-starter-json' + } + implementation 'com.google.code.gson:gson:2.8.4' testImplementation('org.springframework.boot:spring-boot-starter-test') { exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9492014..52d63d1 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Thu Feb 20 21:04:58 CET 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/HelloWorld.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/HelloWorld.java deleted file mode 100644 index 2abbbf2..0000000 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/HelloWorld.java +++ /dev/null @@ -1,15 +0,0 @@ -package ch.usi.inf.sa4.sanmarinoes.smarthut; - -import org.springframework.boot.*; -import org.springframework.boot.autoconfigure.*; -import org.springframework.web.bind.annotation.*; - -@RestController -@EnableAutoConfiguration -public class HelloWorld { - - @RequestMapping("/") - String home() { - return "Hello World!"; - } -} \ No newline at end of file diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/SmarthutApplication.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/SmarthutApplication.java index 4c956eb..98979fd 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/SmarthutApplication.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/SmarthutApplication.java @@ -5,9 +5,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class SmarthutApplication { - public static void main(String[] args) { SpringApplication.run(SmarthutApplication.class, args); } - } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/WelcomeController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/WelcomeController.java new file mode 100644 index 0000000..ccc605e --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/WelcomeController.java @@ -0,0 +1,19 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut; + +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*; +import org.springframework.boot.autoconfigure.*; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +import java.util.*; + +@RestController +@EnableAutoConfiguration +@Controller +public class WelcomeController { + + @GetMapping("/") + List testDevices() { + return Arrays.asList(new Dimmer(), new Light(), new MotionSensor(), new Sensor(), new SmartPlug(), new Switch()); + } +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java new file mode 100644 index 0000000..f06bfa6 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java @@ -0,0 +1,51 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +import com.google.gson.annotations.Expose; + +/** + * Generic abstraction for a smart home device + */ +public abstract class Device { + + /** + * Ways a device can behave in the automation flow. For now only input/output + */ + public enum FlowType { + INPUT, + OUTPUT + } + + private static long nextId = 1; + + /** + * Device identifier + */ + @Expose + private long id; + + /** + * The name for the category of this particular device (e.g 'dimmer'). + */ + @Expose + private final String kind; + + /** + * The way this device behaves in the automation flow. + */ + @Expose + private final FlowType flowType; + + + public long getId() { + return id; + } + + public Device(String kind, FlowType flowType) { + synchronized (Device.class) { + id = nextId; + nextId++; + } + this.kind = kind; + this.flowType = flowType; + } +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Dimmer.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Dimmer.java new file mode 100644 index 0000000..caf2330 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Dimmer.java @@ -0,0 +1,7 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +public class Dimmer extends Device { + public Dimmer() { + super("dimmer", FlowType.INPUT); + } +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Light.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Light.java new file mode 100644 index 0000000..48ac61e --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Light.java @@ -0,0 +1,24 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +public class Light extends Device { + + /** + * If the light bulb is dimmable. If set to true, the only valid intensity values are 0 (off) or 100 (on) + */ + private final boolean dimmable; + + /** + * The light intensity value. Goes from 0 (off) to 100 (on) + */ + private int intensity = 0; + + public Light(int intensity, boolean dimmable) { + super("light", FlowType.OUTPUT); + this.intensity = intensity; + this.dimmable = dimmable; + } + + public Light() { + this(0, false); + } +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensor.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensor.java new file mode 100644 index 0000000..c76cb76 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensor.java @@ -0,0 +1,7 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +public class MotionSensor extends Device { + public MotionSensor() { + super("motion-sensor", FlowType.INPUT); + } +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Sensor.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Sensor.java new file mode 100644 index 0000000..e4dafe8 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Sensor.java @@ -0,0 +1,7 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +public class Sensor extends Device { + public Sensor() { + super("sensor", FlowType.INPUT); + } +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SmartPlug.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SmartPlug.java new file mode 100644 index 0000000..0b3a2e7 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SmartPlug.java @@ -0,0 +1,7 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +public class SmartPlug extends Device { + public SmartPlug() { + super("smart-plug", FlowType.OUTPUT); + } +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Switch.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Switch.java new file mode 100644 index 0000000..cc56c3f --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Switch.java @@ -0,0 +1,7 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +public class Switch extends Device { + public Switch() { + super("switch", FlowType.INPUT); + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 8b13789..0c73d97 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1 @@ - +spring.http.converters.preferred-json-mapper=gson \ No newline at end of file From 0489d0221c32a9f59e5b8800daed50cd790c9aaa Mon Sep 17 00:00:00 2001 From: Claudio Maggioni Date: Fri, 21 Feb 2020 14:23:07 +0100 Subject: [PATCH 2/9] Updated to the skeleton data model Added the concept of rules and a few interfaces --- .../{ => controller}/WelcomeController.java | 9 +++++- .../sanmarinoes/smarthut/models/Device.java | 11 ++++++- .../smarthut/models/DimmableLight.java | 19 ++++++++++++ .../smarthut/models/DimmableOutput.java | 20 ++++++++++++ .../smarthut/models/InputDevice.java | 7 +++++ .../sanmarinoes/smarthut/models/Light.java | 31 +++++++++---------- .../smarthut/models/OutputDevice.java | 8 +++++ .../sa4/sanmarinoes/smarthut/models/Rule.java | 28 +++++++++++++++++ .../smarthut/models/SwitchRule.java | 12 +++++++ .../smarthut/models/SwitchableOutput.java | 10 ++++++ .../smarthut/models/TimerRule.java | 12 +++++++ 11 files changed, 148 insertions(+), 19 deletions(-) rename src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/{ => controller}/WelcomeController.java (60%) create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLight.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableOutput.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/InputDevice.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/OutputDevice.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Rule.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchRule.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchableOutput.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/TimerRule.java diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/WelcomeController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/WelcomeController.java similarity index 60% rename from src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/WelcomeController.java rename to src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/WelcomeController.java index ccc605e..ac59190 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/WelcomeController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/WelcomeController.java @@ -1,8 +1,9 @@ -package ch.usi.inf.sa4.sanmarinoes.smarthut; +package ch.usi.inf.sa4.sanmarinoes.smarthut.controller; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*; import org.springframework.boot.autoconfigure.*; import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; import java.util.*; @@ -16,4 +17,10 @@ public class WelcomeController { List testDevices() { return Arrays.asList(new Dimmer(), new Light(), new MotionSensor(), new Sensor(), new SmartPlug(), new Switch()); } + + @GetMapping("/giovanni") + public String index(@RequestParam(name = "name", required = false, defaultValue = "World") String name, Model model) { + model.addAttribute("name", name); + return "index"; + } } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java index f06bfa6..12575d0 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java @@ -2,6 +2,8 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import com.google.gson.annotations.Expose; +//Rules + /** * Generic abstraction for a smart home device */ @@ -23,6 +25,12 @@ public abstract class Device { @Expose private long id; + /** + * The name for the category of this particular device (e.g 'dimmer'). + */ + @Expose + private String name; + /** * The name for the category of this particular device (e.g 'dimmer'). */ @@ -42,10 +50,11 @@ public abstract class Device { public Device(String kind, FlowType flowType) { synchronized (Device.class) { - id = nextId; + this.id = nextId; nextId++; } this.kind = kind; this.flowType = flowType; + this.name = kind + " " + this.id; } } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLight.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLight.java new file mode 100644 index 0000000..988d4b5 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLight.java @@ -0,0 +1,19 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +public class DimmableLight extends Light implements DimmableOutput { + + /** + * The light intensity value. Goes from 0 (off) to 100 (on) + */ + private int intensity = 0; + + @Override + public int getDimLevel() { + return intensity; + } + + @Override + public void dimTo(int level) { + intensity = level; + } +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableOutput.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableOutput.java new file mode 100644 index 0000000..ccdc80a --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableOutput.java @@ -0,0 +1,20 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +public interface DimmableOutput extends SwitchableOutput { + + int getDimLevel(); + + void dimTo(int level); + + default void dimUp() { + int newLevel = getDimLevel() + 10; + dimTo(newLevel > 100 ? 100 : newLevel); + setStatus(getDimLevel() != 0); + } + + default void dimDown() { + int newLevel = getDimLevel() - 10; + dimTo(newLevel < 0 ? 0 : newLevel); + setStatus(getDimLevel() != 0); + } +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/InputDevice.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/InputDevice.java new file mode 100644 index 0000000..7af532e --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/InputDevice.java @@ -0,0 +1,7 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +public abstract class InputDevice extends Device { + public InputDevice(String kind) { + super(kind, FlowType.INPUT); + } +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Light.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Light.java index 48ac61e..ad6ad55 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Light.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Light.java @@ -1,24 +1,21 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; -public class Light extends Device { +public class Light extends Device implements SwitchableOutput { - /** - * If the light bulb is dimmable. If set to true, the only valid intensity values are 0 (off) or 100 (on) - */ - private final boolean dimmable; - - /** - * The light intensity value. Goes from 0 (off) to 100 (on) - */ - private int intensity = 0; - - public Light(int intensity, boolean dimmable) { - super("light", FlowType.OUTPUT); - this.intensity = intensity; - this.dimmable = dimmable; - } + boolean isOn; public Light() { - this(0, false); + super("light", FlowType.OUTPUT); + this.isOn = false; + } + + @Override + public boolean isOn() { + return isOn; + } + + @Override + public void setStatus(boolean isOn) { + this.isOn = isOn; } } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/OutputDevice.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/OutputDevice.java new file mode 100644 index 0000000..634c35e --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/OutputDevice.java @@ -0,0 +1,8 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +public abstract class OutputDevice extends Device { + public OutputDevice(String kind) { + super(kind, FlowType.OUTPUT); + } +} + diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Rule.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Rule.java new file mode 100644 index 0000000..a4862dd --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Rule.java @@ -0,0 +1,28 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +import javax.validation.constraints.NotNull; +import java.util.*; +import java.util.ArrayList; + +public abstract class Rule { + + private static List> rules = new ArrayList<>(); + + protected T input; + protected U output; + + public Rule(T input, U output) { + this.input = input; + this.output = output; + } + + abstract void apply(); + + public static void addRule(Rule rule) { + rules.add(rule); + } + + public static void applyOnInput(@NotNull InputDevice input) { + rules.stream().filter(input::equals).forEach(Rule::apply); + } +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchRule.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchRule.java new file mode 100644 index 0000000..0430176 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchRule.java @@ -0,0 +1,12 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +public class SwitchRule extends Rule { + public SwitchRule(T input, U output) { + super(input, output); + } + + @Override + void apply() { + output.toggle(); + } +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchableOutput.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchableOutput.java new file mode 100644 index 0000000..aaa5b23 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchableOutput.java @@ -0,0 +1,10 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +public interface SwitchableOutput { + boolean isOn(); + void setStatus(boolean isOn); + + default void toggle() { + setStatus(!isOn()); + } +} \ No newline at end of file diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/TimerRule.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/TimerRule.java new file mode 100644 index 0000000..ad78358 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/TimerRule.java @@ -0,0 +1,12 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +public class TimerRule extends Rule { + public TimerRule(T input, U output) { + super(input, output); + } + + @Override + void apply() { + + } +} From 346d305950f167e47289f8954dabdbc56ad9d5ea Mon Sep 17 00:00:00 2001 From: Claudio Maggioni Date: Fri, 21 Feb 2020 14:26:14 +0100 Subject: [PATCH 3/9] removed giovanni --- .../sanmarinoes/smarthut/controller/WelcomeController.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/WelcomeController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/WelcomeController.java index ac59190..a875104 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/WelcomeController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/WelcomeController.java @@ -17,10 +17,4 @@ public class WelcomeController { List testDevices() { return Arrays.asList(new Dimmer(), new Light(), new MotionSensor(), new Sensor(), new SmartPlug(), new Switch()); } - - @GetMapping("/giovanni") - public String index(@RequestParam(name = "name", required = false, defaultValue = "World") String name, Model model) { - model.addAttribute("name", name); - return "index"; - } } From 7d582dbb4795de903dd0ab5c4d631fd043cb8102 Mon Sep 17 00:00:00 2001 From: Jacob Salvi Date: Fri, 21 Feb 2020 15:36:04 +0100 Subject: [PATCH 4/9] small changes --- .../buildOutputCleanup.lock | Bin 17 -> 17 bytes .gradle/buildOutputCleanup/cache.properties | 4 +-- .idea/misc.xml | 2 +- backend.iml | 12 ++++++++ .../sanmarinoes/smarthut/models/Device.java | 9 +++--- .../smarthut/models/DimmableLight.java | 3 ++ .../sa4/sanmarinoes/smarthut/models/Room.java | 27 ++++++++++++++++ .../sanmarinoes/smarthut/models/house.java | 29 ++++++++++++++++++ 8 files changed, 78 insertions(+), 8 deletions(-) create mode 100644 backend.iml create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Room.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/house.java diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 847deb8b8d77746d6487459e2a66a99d177a9c13..a64b376b09b584415f1b8924ab3f624dc015fae9 100644 GIT binary patch literal 17 TcmZSf>8w2@k-Vdo0Rlt;FAf9c literal 17 TcmZSf>8w2@k-Vdo0Rk8SF8Tw} diff --git a/.gradle/buildOutputCleanup/cache.properties b/.gradle/buildOutputCleanup/cache.properties index 79b47e9..9fc555b 100644 --- a/.gradle/buildOutputCleanup/cache.properties +++ b/.gradle/buildOutputCleanup/cache.properties @@ -1,2 +1,2 @@ -#Wed Feb 19 20:29:41 CET 2020 -gradle.version=6.0.1 +#Thu Feb 20 16:16:13 CET 2020 +gradle.version=6.2 diff --git a/.idea/misc.xml b/.idea/misc.xml index cf95fe9..8f27022 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,7 +1,7 @@ - + \ No newline at end of file diff --git a/backend.iml b/backend.iml new file mode 100644 index 0000000..1eae0df --- /dev/null +++ b/backend.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java index 12575d0..667b587 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java @@ -2,6 +2,8 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import com.google.gson.annotations.Expose; +import java.util.concurrent.atomic.AtomicLong; + //Rules /** @@ -17,7 +19,7 @@ public abstract class Device { OUTPUT } - private static long nextId = 1; + private static AtomicLong nextId = new AtomicLong(1); /** * Device identifier @@ -49,10 +51,7 @@ public abstract class Device { } public Device(String kind, FlowType flowType) { - synchronized (Device.class) { - this.id = nextId; - nextId++; - } + this.id = nextId.getAndIncrement(); this.kind = kind; this.flowType = flowType; this.name = kind + " " + this.id; diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLight.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLight.java index 988d4b5..1fb140c 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLight.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLight.java @@ -14,6 +14,9 @@ public class DimmableLight extends Light implements DimmableOutput { @Override public void dimTo(int level) { + if(level<0 || level>100){ + throw new java.lang.Error("The intensity level can't go below 0 or above 100"); + } intensity = level; } } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Room.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Room.java new file mode 100644 index 0000000..f073e43 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Room.java @@ -0,0 +1,27 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; +import java.util.*; + +public class Room { + private ArrayList devices; + + //Constructor + public Room(){ + this.devices=new ArrayList(); + } + + //add a device to the list + public void addDevice(Device device){ + if(!this.devices.contains(device)){ + this.devices.add(device); + } + } + + //remove a certain device from the Room + public void removeDevice(Device device){ + int a=this.devices.indexOf(device); + if(a!=-1) { + this.devices.remove(a); + } + } + +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/house.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/house.java new file mode 100644 index 0000000..49c17fa --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/house.java @@ -0,0 +1,29 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +import java.util.ArrayList; + +public class house { + //a list of the rooms present in the house + private ArrayList rooms; + + //Constructor + public house(){ + this.rooms=new ArrayList(); + } + + //this method add a Room to the house + public void addRoom(Room room){ + if(!this.rooms.contains(room)) { + this.rooms.add(room); + } + } + + //this method removes the given room if it is present in the house + public void remove(Room room){ + int a=this.rooms.indexOf(room); + if(a!=-1) { + this.rooms.remove(a); + } + } + +} From 9f5821e9936164e4f53d6ccee2502ffeaed984d2 Mon Sep 17 00:00:00 2001 From: Jacob Salvi Date: Fri, 21 Feb 2020 16:10:58 +0100 Subject: [PATCH 5/9] small changes to Romm --- .../sa4/sanmarinoes/smarthut/models/Room.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Room.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Room.java index f073e43..f755fbc 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Room.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Room.java @@ -1,11 +1,20 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; +import java.awt.image.BufferedImage; import java.util.*; +import java.io.File; + public class Room { private ArrayList devices; + private String name; + private File icon; + private File image; //Constructor - public Room(){ + public Room(String name, String icon, String image){ + this.name=name; + this.icon= new File(icon); + this.image= new File(image); this.devices=new ArrayList(); } @@ -24,4 +33,18 @@ public class Room { } } + //changes the room's name with the given name + public void changeName(String name){ + this.name=name; + } + + //changes the room's icon with the given icon + public void changeIcon(String icon){ + this.icon= new File(icon); + } + + //changes the room's image with the given image + public void changeImage(String image){ + this.image= new File(image); + } } From 0cc59e608c4027a5627ffb7f74e7c8f263099c3a Mon Sep 17 00:00:00 2001 From: Claudio Maggioni Date: Sat, 22 Feb 2020 11:31:10 +0100 Subject: [PATCH 6/9] Updated models to implement JPA and agreed ER diagram --- build.gradle | 1 + .../controller/WelcomeController.java | 1 - .../sanmarinoes/smarthut/models/Device.java | 22 +++--- .../smarthut/models/DimmableLight.java | 13 ++-- .../smarthut/models/DimmableOutput.java | 20 ------ .../sanmarinoes/smarthut/models/Dimmer.java | 7 +- .../smarthut/models/InputDevice.java | 3 + .../sanmarinoes/smarthut/models/Light.java | 21 +++--- .../smarthut/models/MotionSensor.java | 7 +- .../smarthut/models/OutputDevice.java | 6 ++ .../sa4/sanmarinoes/smarthut/models/Room.java | 52 ++++++++++++++ .../sa4/sanmarinoes/smarthut/models/Rule.java | 28 -------- .../sanmarinoes/smarthut/models/Sensor.java | 7 +- .../smarthut/models/SmartPlug.java | 7 +- .../sanmarinoes/smarthut/models/Switch.java | 7 +- .../smarthut/models/SwitchRule.java | 12 ---- .../smarthut/models/SwitchableOutput.java | 10 --- .../smarthut/models/TimerRule.java | 12 ---- .../sa4/sanmarinoes/smarthut/models/User.java | 72 +++++++++++++++++++ 19 files changed, 186 insertions(+), 122 deletions(-) delete mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableOutput.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Room.java delete mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Rule.java delete mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchRule.java delete mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchableOutput.java delete mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/TimerRule.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/User.java diff --git a/build.gradle b/build.gradle index a293ca9..48ad88a 100644 --- a/build.gradle +++ b/build.gradle @@ -14,6 +14,7 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter' + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation('org.springframework.boot:spring-boot-starter-web') { exclude group: 'org.springframework.boot', module: 'spring-boot-starter-json' } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/WelcomeController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/WelcomeController.java index a875104..4069d44 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/WelcomeController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/WelcomeController.java @@ -3,7 +3,6 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.controller; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*; import org.springframework.boot.autoconfigure.*; import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; import java.util.*; diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java index 12575d0..3f373d6 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java @@ -1,12 +1,12 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; -import com.google.gson.annotations.Expose; - -//Rules +import javax.persistence.*; /** * Generic abstraction for a smart home device */ +@Entity +@Inheritance(strategy = InheritanceType.JOINED) public abstract class Device { /** @@ -17,30 +17,28 @@ public abstract class Device { OUTPUT } - private static long nextId = 1; - /** * Device identifier */ - @Expose + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id", updatable = false, nullable = false) private long id; /** - * The name for the category of this particular device (e.g 'dimmer'). + * The name of the device as assigned by the user (e.g. 'Master bedroom light') */ - @Expose private String name; /** * The name for the category of this particular device (e.g 'dimmer'). */ - @Expose + @Column private final String kind; /** * The way this device behaves in the automation flow. */ - @Expose private final FlowType flowType; @@ -49,10 +47,6 @@ public abstract class Device { } public Device(String kind, FlowType flowType) { - synchronized (Device.class) { - this.id = nextId; - nextId++; - } this.kind = kind; this.flowType = flowType; this.name = kind + " " + this.id; diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLight.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLight.java index 988d4b5..c79f785 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLight.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLight.java @@ -1,19 +1,20 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; -public class DimmableLight extends Light implements DimmableOutput { +import javax.persistence.Entity; + +@Entity +public class DimmableLight extends Light { /** * The light intensity value. Goes from 0 (off) to 100 (on) */ private int intensity = 0; - @Override - public int getDimLevel() { + public int getIntensity() { return intensity; } - @Override - public void dimTo(int level) { - intensity = level; + public void setIntensity(int intensity) { + this.intensity = intensity; } } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableOutput.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableOutput.java deleted file mode 100644 index ccdc80a..0000000 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableOutput.java +++ /dev/null @@ -1,20 +0,0 @@ -package ch.usi.inf.sa4.sanmarinoes.smarthut.models; - -public interface DimmableOutput extends SwitchableOutput { - - int getDimLevel(); - - void dimTo(int level); - - default void dimUp() { - int newLevel = getDimLevel() + 10; - dimTo(newLevel > 100 ? 100 : newLevel); - setStatus(getDimLevel() != 0); - } - - default void dimDown() { - int newLevel = getDimLevel() - 10; - dimTo(newLevel < 0 ? 0 : newLevel); - setStatus(getDimLevel() != 0); - } -} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Dimmer.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Dimmer.java index caf2330..691a7b7 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Dimmer.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Dimmer.java @@ -1,7 +1,10 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; -public class Dimmer extends Device { +import javax.persistence.Entity; + +@Entity +public class Dimmer extends InputDevice { public Dimmer() { - super("dimmer", FlowType.INPUT); + super("dimmer"); } } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/InputDevice.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/InputDevice.java index 7af532e..cd36ea4 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/InputDevice.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/InputDevice.java @@ -1,5 +1,8 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; +import javax.persistence.Entity; + +@Entity public abstract class InputDevice extends Device { public InputDevice(String kind) { super(kind, FlowType.INPUT); diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Light.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Light.java index ad6ad55..989a7fa 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Light.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Light.java @@ -1,21 +1,24 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; -public class Light extends Device implements SwitchableOutput { +import javax.persistence.Entity; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; - boolean isOn; +@Entity +@Inheritance(strategy = InheritanceType.JOINED) +public class Light extends OutputDevice { + boolean on; public Light() { - super("light", FlowType.OUTPUT); - this.isOn = false; + super("light"); + this.on = false; } - @Override public boolean isOn() { - return isOn; + return on; } - @Override - public void setStatus(boolean isOn) { - this.isOn = isOn; + public void setOn(boolean on) { + this.on = on; } } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensor.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensor.java index c76cb76..4526e97 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensor.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensor.java @@ -1,7 +1,10 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; -public class MotionSensor extends Device { +import javax.persistence.Entity; + +@Entity +public class MotionSensor extends InputDevice { public MotionSensor() { - super("motion-sensor", FlowType.INPUT); + super("motion-sensor"); } } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/OutputDevice.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/OutputDevice.java index 634c35e..8c94814 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/OutputDevice.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/OutputDevice.java @@ -1,5 +1,11 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; +import javax.persistence.Entity; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; + +@Entity +@Inheritance(strategy = InheritanceType.JOINED) public abstract class OutputDevice extends Device { public OutputDevice(String kind) { super(kind, FlowType.OUTPUT); diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Room.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Room.java new file mode 100644 index 0000000..6e4afa3 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Room.java @@ -0,0 +1,52 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +import javax.persistence.*; + +@Entity +public class Room { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id", updatable = false, nullable = false) + private Long id; + + @ManyToOne + @JoinColumn(name="user_id") + private User user; + + @Column + private String name; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + return "Room{" + + "id=" + id + + ", user=" + user + + ", name='" + name + '\'' + + '}'; + } +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Rule.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Rule.java deleted file mode 100644 index a4862dd..0000000 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Rule.java +++ /dev/null @@ -1,28 +0,0 @@ -package ch.usi.inf.sa4.sanmarinoes.smarthut.models; - -import javax.validation.constraints.NotNull; -import java.util.*; -import java.util.ArrayList; - -public abstract class Rule { - - private static List> rules = new ArrayList<>(); - - protected T input; - protected U output; - - public Rule(T input, U output) { - this.input = input; - this.output = output; - } - - abstract void apply(); - - public static void addRule(Rule rule) { - rules.add(rule); - } - - public static void applyOnInput(@NotNull InputDevice input) { - rules.stream().filter(input::equals).forEach(Rule::apply); - } -} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Sensor.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Sensor.java index e4dafe8..e92c6db 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Sensor.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Sensor.java @@ -1,7 +1,10 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; -public class Sensor extends Device { +import javax.persistence.Entity; + +@Entity +public class Sensor extends InputDevice { public Sensor() { - super("sensor", FlowType.INPUT); + super("sensor"); } } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SmartPlug.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SmartPlug.java index 0b3a2e7..6d7db70 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SmartPlug.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SmartPlug.java @@ -1,7 +1,10 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; -public class SmartPlug extends Device { +import javax.persistence.Entity; + +@Entity +public class SmartPlug extends OutputDevice { public SmartPlug() { - super("smart-plug", FlowType.OUTPUT); + super("smart-plug"); } } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Switch.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Switch.java index cc56c3f..142665c 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Switch.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Switch.java @@ -1,7 +1,10 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; -public class Switch extends Device { +import javax.persistence.Entity; + +@Entity +public class Switch extends InputDevice { public Switch() { - super("switch", FlowType.INPUT); + super("switch"); } } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchRule.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchRule.java deleted file mode 100644 index 0430176..0000000 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchRule.java +++ /dev/null @@ -1,12 +0,0 @@ -package ch.usi.inf.sa4.sanmarinoes.smarthut.models; - -public class SwitchRule extends Rule { - public SwitchRule(T input, U output) { - super(input, output); - } - - @Override - void apply() { - output.toggle(); - } -} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchableOutput.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchableOutput.java deleted file mode 100644 index aaa5b23..0000000 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchableOutput.java +++ /dev/null @@ -1,10 +0,0 @@ -package ch.usi.inf.sa4.sanmarinoes.smarthut.models; - -public interface SwitchableOutput { - boolean isOn(); - void setStatus(boolean isOn); - - default void toggle() { - setStatus(!isOn()); - } -} \ No newline at end of file diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/TimerRule.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/TimerRule.java deleted file mode 100644 index ad78358..0000000 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/TimerRule.java +++ /dev/null @@ -1,12 +0,0 @@ -package ch.usi.inf.sa4.sanmarinoes.smarthut.models; - -public class TimerRule extends Rule { - public TimerRule(T input, U output) { - super(input, output); - } - - @Override - void apply() { - - } -} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/User.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/User.java new file mode 100644 index 0000000..294dcf3 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/User.java @@ -0,0 +1,72 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +import javax.persistence.*; +import java.util.Set; + +@Entity +public class User { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id", updatable = false, nullable = false) + private Long id; + + @Column + private String name; + + @Column + private String hashedPassword; + + @Column + private String email; + + @OneToMany(mappedBy = "user") + private Set rooms; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getHashedPassword() { + return hashedPassword; + } + + public void setHashedPassword(String hashedPassword) { + this.hashedPassword = hashedPassword; + } + + public Set getRooms() { + return rooms; + } + + @Override + public String toString() { + return "User{" + + "id=" + id + + ", name='" + name + '\'' + + ", hashedPassword='" + hashedPassword + '\'' + + ", email='" + email + '\'' + + ", rooms=" + rooms + + '}'; + } +} From 32f1412564a3479e5f5f7c25681d215a2b855e96 Mon Sep 17 00:00:00 2001 From: "Claudio Maggioni (maggicl)" Date: Sat, 22 Feb 2020 23:19:34 +0100 Subject: [PATCH 7/9] Improvements to data model Set up connection parameters for local postgres db. Updated schema in order not to cause clashes with reserved SQL tokens. --- .idea/jarRepositories.xml | 20 +++++++++++++++++++ .idea/misc.xml | 2 +- build.gradle | 6 ++++-- .../sanmarinoes/smarthut/models/Light.java | 2 ++ .../sa4/sanmarinoes/smarthut/models/User.java | 2 +- src/main/resources/application.properties | 13 +++++++++++- 6 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 .idea/jarRepositories.xml diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..fdc392f --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 241f098..e513ffa 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,7 +1,7 @@ - + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 48ad88a..c65502c 100644 --- a/build.gradle +++ b/build.gradle @@ -13,12 +13,14 @@ repositories { } dependencies { + compile 'org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final' implementation 'org.springframework.boot:spring-boot-starter' - implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'org.postgresql:postgresql' implementation('org.springframework.boot:spring-boot-starter-web') { exclude group: 'org.springframework.boot', module: 'spring-boot-starter-json' } - implementation 'com.google.code.gson:gson:2.8.4' + implementation 'com.google.code.gson:gson' testImplementation('org.springframework.boot:spring-boot-starter-test') { exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Light.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Light.java index 989a7fa..dd17db9 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Light.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Light.java @@ -1,5 +1,6 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; +import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; @@ -7,6 +8,7 @@ import javax.persistence.InheritanceType; @Entity @Inheritance(strategy = InheritanceType.JOINED) public class Light extends OutputDevice { + @Column(name="light_on") boolean on; public Light() { diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/User.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/User.java index 294dcf3..a68c6cd 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/User.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/User.java @@ -3,7 +3,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import javax.persistence.*; import java.util.Set; -@Entity +@Entity(name = "smarthutuser") public class User { @Id diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 0c73d97..7cadd1e 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1,12 @@ -spring.http.converters.preferred-json-mapper=gson \ No newline at end of file +spring.http.converters.preferred-json-mapper=gson +spring.datasource.url=jdbc:postgresql://localhost:5432/smarthut +spring.datasource.username=postgres +spring.datasource.password= + +# Hibernate properties +spring.jpa.database=POSTGRESQL +spring.jpa.show-sql=true +spring.jpa.hibernate.ddl-auto=create-drop +spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl +spring.jpa.properties.hibernate.format_sql=true +, \ No newline at end of file From a353007651ad54ea32a8070fcff4668dba5c6ba5 Mon Sep 17 00:00:00 2001 From: "Claudio Maggioni (maggicl)" Date: Sun, 23 Feb 2020 00:11:09 +0100 Subject: [PATCH 8/9] Upd. models and added repository for each entity --- .../controller/WelcomeController.java | 3 +- .../smarthut/models/ButtonDimmer.java | 14 +++++++ .../models/ButtonDimmerRepository.java | 6 +++ .../sanmarinoes/smarthut/models/Device.java | 38 ++++++++++++++++--- .../smarthut/models/DimmableLight.java | 9 +++++ .../models/DimmableLightRepository.java | 6 +++ .../sanmarinoes/smarthut/models/Dimmer.java | 12 ++++-- .../smarthut/models/InputDevice.java | 4 ++ .../smarthut/models/KnobDimmer.java | 13 +++++++ .../smarthut/models/KnobDimmerRepository.java | 6 +++ .../sanmarinoes/smarthut/models/Light.java | 15 ++++++-- .../smarthut/models/MotionSensor.java | 3 ++ .../models/MotionSensorRepository.java | 6 +++ .../smarthut/models/OutputDevice.java | 5 ++- .../smarthut/models/RegularLight.java | 13 +++++++ .../models/RegularLightRepository.java | 6 +++ .../sa4/sanmarinoes/smarthut/models/Room.java | 21 ++++++++++ .../smarthut/models/RoomRepository.java | 6 +++ .../sanmarinoes/smarthut/models/Sensor.java | 34 +++++++++++++++++ .../smarthut/models/SensorRepository.java | 6 +++ .../smarthut/models/SmartPlug.java | 19 ++++++++++ .../smarthut/models/SmartPlugRepository.java | 6 +++ .../sanmarinoes/smarthut/models/Switch.java | 4 ++ .../smarthut/models/SwitchRepository.java | 6 +++ .../sa4/sanmarinoes/smarthut/models/User.java | 17 +++++++++ .../smarthut/models/UserRepository.java | 6 +++ .../sanmarinoes/smarthut/models/house.java | 29 -------------- 27 files changed, 270 insertions(+), 43 deletions(-) create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ButtonDimmer.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ButtonDimmerRepository.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLightRepository.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/KnobDimmer.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/KnobDimmerRepository.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensorRepository.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RegularLight.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RegularLightRepository.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RoomRepository.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SensorRepository.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SmartPlugRepository.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchRepository.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/UserRepository.java delete mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/house.java diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/WelcomeController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/WelcomeController.java index 4069d44..fa38d1b 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/WelcomeController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/WelcomeController.java @@ -14,6 +14,7 @@ public class WelcomeController { @GetMapping("/") List testDevices() { - return Arrays.asList(new Dimmer(), new Light(), new MotionSensor(), new Sensor(), new SmartPlug(), new Switch()); + return Arrays.asList(new KnobDimmer(), new RegularLight(), new MotionSensor(), + new Sensor(), new SmartPlug(), new Switch()); } } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ButtonDimmer.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ButtonDimmer.java new file mode 100644 index 0000000..bb1f70a --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ButtonDimmer.java @@ -0,0 +1,14 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +import javax.persistence.Entity; + +/** + * Represents a dimmer that can only instruct an increase or decrease of intensity + * (i.e. like a dimmer with a '+' and a '-' button) + */ +@Entity +public class ButtonDimmer extends Dimmer { + public ButtonDimmer() { + super("button-dimmer"); + } +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ButtonDimmerRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ButtonDimmerRepository.java new file mode 100644 index 0000000..af1a566 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ButtonDimmerRepository.java @@ -0,0 +1,6 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +import org.springframework.data.repository.CrudRepository; + +public interface ButtonDimmerRepository extends CrudRepository { +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java index 3f373d6..54eba35 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java @@ -6,7 +6,7 @@ import javax.persistence.*; * Generic abstraction for a smart home device */ @Entity -@Inheritance(strategy = InheritanceType.JOINED) +@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) public abstract class Device { /** @@ -25,27 +25,55 @@ public abstract class Device { @Column(name = "id", updatable = false, nullable = false) private long id; + /** + * The room this device belongs in + */ + @ManyToOne + @JoinColumn(name="room_id") + private Room room; + /** * The name of the device as assigned by the user (e.g. 'Master bedroom light') */ + @Column private String name; /** * The name for the category of this particular device (e.g 'dimmer'). + * Not stored in the database (thanks to 'transient') but set thanks to constructors */ - @Column - private final String kind; + private transient final String kind; /** * The way this device behaves in the automation flow. + * Not stored in the database (thanks to 'transient') but set thanks to constructors */ - private final FlowType flowType; - + private transient final FlowType flowType; public long getId() { return id; } + public void setId(long id) { + this.id = id; + } + + public Room getRoom() { + return room; + } + + public void setRoom(Room room) { + this.room = room; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + public Device(String kind, FlowType flowType) { this.kind = kind; this.flowType = flowType; diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLight.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLight.java index 87c1fe7..24d1672 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLight.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLight.java @@ -1,13 +1,22 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; +import javax.persistence.Column; import javax.persistence.Entity; +/** + * Represent a dimmable light + */ @Entity public class DimmableLight extends Light { + public DimmableLight() { + super("light"); + } + /** * The light intensity value. Goes from 0 (off) to 100 (on) */ + @Column private int intensity = 0; public int getIntensity() { diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLightRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLightRepository.java new file mode 100644 index 0000000..741aecf --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLightRepository.java @@ -0,0 +1,6 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +import org.springframework.data.repository.CrudRepository; + +public interface DimmableLightRepository extends CrudRepository { +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Dimmer.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Dimmer.java index 691a7b7..b88a6a2 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Dimmer.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Dimmer.java @@ -1,10 +1,16 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import javax.persistence.Entity; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +/** + * Represents a generic dimmer input device + */ @Entity -public class Dimmer extends InputDevice { - public Dimmer() { - super("dimmer"); +@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) +public abstract class Dimmer extends InputDevice { + public Dimmer(String kind) { + super(kind); } } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/InputDevice.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/InputDevice.java index cd36ea4..4b5d562 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/InputDevice.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/InputDevice.java @@ -2,6 +2,10 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import javax.persistence.Entity; +/** + * A generic abstraction for an input device, i.e. something that captures input either from the environment (sensor) + * or the user (switch / dimmer). + */ @Entity public abstract class InputDevice extends Device { public InputDevice(String kind) { diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/KnobDimmer.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/KnobDimmer.java new file mode 100644 index 0000000..cc5f6b5 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/KnobDimmer.java @@ -0,0 +1,13 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +import javax.persistence.Entity; + +/** + * Represents a dimmer able to set absolute intensity values (i.e. knowing the absolute intensity value, like a knob) + */ +@Entity +public class KnobDimmer extends Dimmer { + public KnobDimmer() { + super("knob-dimmer"); + } +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/KnobDimmerRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/KnobDimmerRepository.java new file mode 100644 index 0000000..2dbe912 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/KnobDimmerRepository.java @@ -0,0 +1,6 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +import org.springframework.data.repository.CrudRepository; + +public interface KnobDimmerRepository extends CrudRepository { +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Light.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Light.java index dd17db9..2624cc0 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Light.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Light.java @@ -5,14 +5,21 @@ import javax.persistence.Entity; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; +/** + * Represents a generic light + */ @Entity -@Inheritance(strategy = InheritanceType.JOINED) -public class Light extends OutputDevice { +@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) +public abstract class Light extends OutputDevice { + + /** + * Whether the light is on or not + */ @Column(name="light_on") boolean on; - public Light() { - super("light"); + protected Light(String kind) { + super(kind); this.on = false; } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensor.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensor.java index 4526e97..a3491e0 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensor.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensor.java @@ -2,6 +2,9 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import javax.persistence.Entity; +/** + * Represents a motion sensor device + */ @Entity public class MotionSensor extends InputDevice { public MotionSensor() { diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensorRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensorRepository.java new file mode 100644 index 0000000..801da31 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensorRepository.java @@ -0,0 +1,6 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +import org.springframework.data.repository.CrudRepository; + +public interface MotionSensorRepository extends CrudRepository { +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/OutputDevice.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/OutputDevice.java index 8c94814..aecad0d 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/OutputDevice.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/OutputDevice.java @@ -4,8 +4,11 @@ import javax.persistence.Entity; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; +/** + * Represents a generic output device, i.e. something that causes some behaviour (light, smartPlugs, ...). + */ @Entity -@Inheritance(strategy = InheritanceType.JOINED) +@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) public abstract class OutputDevice extends Device { public OutputDevice(String kind) { super(kind, FlowType.OUTPUT); diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RegularLight.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RegularLight.java new file mode 100644 index 0000000..402f677 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RegularLight.java @@ -0,0 +1,13 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +import javax.persistence.Entity; + +/** + * Represents a standard non-dimmable light + */ +@Entity +public class RegularLight extends Light { + public RegularLight() { + super("regular-light"); + } +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RegularLightRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RegularLightRepository.java new file mode 100644 index 0000000..1031db9 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RegularLightRepository.java @@ -0,0 +1,6 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +import org.springframework.data.repository.CrudRepository; + +public interface RegularLightRepository extends CrudRepository { +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Room.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Room.java index 6e4afa3..9e0a211 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Room.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Room.java @@ -1,7 +1,11 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import javax.persistence.*; +import java.util.Set; +/** + * Represents a room in the house owned by the user + */ @Entity public class Room { @@ -10,13 +14,25 @@ public class Room { @Column(name = "id", updatable = false, nullable = false) private Long id; + /** + * User that owns the house this room is in + */ @ManyToOne @JoinColumn(name="user_id") private User user; + /** + * The user given name of this room (e.g. 'Master bedroom') + */ @Column private String name; + /** + * Collectiion of devices present in this room + */ + @OneToMany(mappedBy = "room") + private Set devices; + public Long getId() { return id; } @@ -41,12 +57,17 @@ public class Room { this.name = name; } + public Set getDevices() { + return devices; + } + @Override public String toString() { return "Room{" + "id=" + id + ", user=" + user + ", name='" + name + '\'' + + ", devices=" + devices + '}'; } } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RoomRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RoomRepository.java new file mode 100644 index 0000000..35371b1 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RoomRepository.java @@ -0,0 +1,6 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +import org.springframework.data.repository.CrudRepository; + +public interface RoomRepository extends CrudRepository { +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Sensor.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Sensor.java index e92c6db..ec22464 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Sensor.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Sensor.java @@ -1,9 +1,43 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; +import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +/** + * A sensor input device that measures a quantity in a continuous scale (e.g. temperature) + */ @Entity public class Sensor extends InputDevice { + + /** + * Type of sensor, i.e. of the thing the sensor measures. + */ + enum SensorType { + /** + * A sensor that measures temperature in degrees celsius + */ + TEMPERATURE, + + /** + * A sensor that measures relative humidity in percentage points + */ + HUMIDITY, + + /** + * A sensor that measures light in degrees + */ + LIGHT + } + + /** + * The type of this sensor + */ + @Column + @Enumerated(value=EnumType.STRING) + private SensorType sensor; + public Sensor() { super("sensor"); } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SensorRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SensorRepository.java new file mode 100644 index 0000000..1cc8e62 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SensorRepository.java @@ -0,0 +1,6 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +import org.springframework.data.repository.CrudRepository; + +public interface SensorRepository extends CrudRepository { +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SmartPlug.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SmartPlug.java index 6d7db70..4a54912 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SmartPlug.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SmartPlug.java @@ -1,9 +1,28 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; +import javax.persistence.Column; import javax.persistence.Entity; +/** + * A smart plug that can be turned either on or off + */ @Entity public class SmartPlug extends OutputDevice { + + /** + * Whether the smart plug is on + */ + @Column(name="smart_plug_on") + private boolean on; + + public boolean isOn() { + return on; + } + + public void setOn(boolean on) { + this.on = on; + } + public SmartPlug() { super("smart-plug"); } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SmartPlugRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SmartPlugRepository.java new file mode 100644 index 0000000..9099b85 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SmartPlugRepository.java @@ -0,0 +1,6 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +import org.springframework.data.repository.CrudRepository; + +public interface SmartPlugRepository extends CrudRepository { +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Switch.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Switch.java index 142665c..5e915f2 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Switch.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Switch.java @@ -2,6 +2,10 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import javax.persistence.Entity; +/** + * A switch input device + * TODO: define switch behaviour (push button vs on/off state) + */ @Entity public class Switch extends InputDevice { public Switch() { diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchRepository.java new file mode 100644 index 0000000..d59bbe3 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchRepository.java @@ -0,0 +1,6 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +import org.springframework.data.repository.CrudRepository; + +public interface SwitchRepository extends CrudRepository { +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/User.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/User.java index a68c6cd..1190652 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/User.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/User.java @@ -3,6 +3,9 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import javax.persistence.*; import java.util.Set; +/** + * A user of the Smarthut application + */ @Entity(name = "smarthutuser") public class User { @@ -11,15 +14,29 @@ public class User { @Column(name = "id", updatable = false, nullable = false) private Long id; + /** + * The full name of the user + */ @Column private String name; + /** + * A properly salted way to store the password + * TODO: define the implementation of salt + */ @Column private String hashedPassword; + /** + * The user's email + * TODO: validate email in setters + */ @Column private String email; + /** + * All rooms in the user's house + */ @OneToMany(mappedBy = "user") private Set rooms; diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/UserRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/UserRepository.java new file mode 100644 index 0000000..f33a9b7 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/UserRepository.java @@ -0,0 +1,6 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +import org.springframework.data.repository.CrudRepository; + +public interface UserRepository extends CrudRepository { +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/house.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/house.java deleted file mode 100644 index 49c17fa..0000000 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/house.java +++ /dev/null @@ -1,29 +0,0 @@ -package ch.usi.inf.sa4.sanmarinoes.smarthut.models; - -import java.util.ArrayList; - -public class house { - //a list of the rooms present in the house - private ArrayList rooms; - - //Constructor - public house(){ - this.rooms=new ArrayList(); - } - - //this method add a Room to the house - public void addRoom(Room room){ - if(!this.rooms.contains(room)) { - this.rooms.add(room); - } - } - - //this method removes the given room if it is present in the house - public void remove(Room room){ - int a=this.rooms.indexOf(room); - if(a!=-1) { - this.rooms.remove(a); - } - } - -} From e3df659e82454d6d9ca3d4dbd528f9e47dbb189a Mon Sep 17 00:00:00 2001 From: Claudio Maggioni Date: Mon, 24 Feb 2020 14:28:13 +0100 Subject: [PATCH 9/9] Formatted code according to google java (aosp) format --- .../controller/WelcomeController.java | 12 ++-- .../smarthut/models/ButtonDimmer.java | 4 +- .../models/ButtonDimmerRepository.java | 3 +- .../sanmarinoes/smarthut/models/Device.java | 37 +++++-------- .../smarthut/models/DimmableLight.java | 11 +--- .../models/DimmableLightRepository.java | 3 +- .../sanmarinoes/smarthut/models/Dimmer.java | 4 +- .../smarthut/models/InputDevice.java | 4 +- .../smarthut/models/KnobDimmer.java | 3 +- .../smarthut/models/KnobDimmerRepository.java | 3 +- .../sanmarinoes/smarthut/models/Light.java | 10 +--- .../smarthut/models/MotionSensor.java | 4 +- .../models/MotionSensorRepository.java | 3 +- .../smarthut/models/OutputDevice.java | 4 +- .../smarthut/models/RegularLight.java | 4 +- .../models/RegularLightRepository.java | 3 +- .../sa4/sanmarinoes/smarthut/models/Room.java | 40 ++++++-------- .../smarthut/models/RoomRepository.java | 3 +- .../sanmarinoes/smarthut/models/Sensor.java | 26 +++------ .../smarthut/models/SensorRepository.java | 3 +- .../smarthut/models/SmartPlug.java | 10 +--- .../smarthut/models/SmartPlugRepository.java | 3 +- .../sanmarinoes/smarthut/models/Switch.java | 5 +- .../smarthut/models/SwitchRepository.java | 3 +- .../sa4/sanmarinoes/smarthut/models/User.java | 55 ++++++++----------- .../smarthut/models/UserRepository.java | 3 +- 26 files changed, 101 insertions(+), 162 deletions(-) diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/WelcomeController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/WelcomeController.java index fa38d1b..e462306 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/WelcomeController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/WelcomeController.java @@ -1,12 +1,11 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.controller; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*; +import java.util.*; import org.springframework.boot.autoconfigure.*; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; -import java.util.*; - @RestController @EnableAutoConfiguration @Controller @@ -14,7 +13,12 @@ public class WelcomeController { @GetMapping("/") List testDevices() { - return Arrays.asList(new KnobDimmer(), new RegularLight(), new MotionSensor(), - new Sensor(), new SmartPlug(), new Switch()); + return Arrays.asList( + new KnobDimmer(), + new RegularLight(), + new MotionSensor(), + new Sensor(), + new SmartPlug(), + new Switch()); } } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ButtonDimmer.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ButtonDimmer.java index bb1f70a..e666c3e 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ButtonDimmer.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ButtonDimmer.java @@ -3,8 +3,8 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import javax.persistence.Entity; /** - * Represents a dimmer that can only instruct an increase or decrease of intensity - * (i.e. like a dimmer with a '+' and a '-' button) + * Represents a dimmer that can only instruct an increase or decrease of intensity (i.e. like a + * dimmer with a '+' and a '-' button) */ @Entity public class ButtonDimmer extends Dimmer { diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ButtonDimmerRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ButtonDimmerRepository.java index af1a566..a74e68f 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ButtonDimmerRepository.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ButtonDimmerRepository.java @@ -2,5 +2,4 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import org.springframework.data.repository.CrudRepository; -public interface ButtonDimmerRepository extends CrudRepository { -} +public interface ButtonDimmerRepository extends CrudRepository {} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java index 54eba35..078a7ad 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java @@ -2,53 +2,42 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import javax.persistence.*; -/** - * Generic abstraction for a smart home device - */ +/** Generic abstraction for a smart home device */ @Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) public abstract class Device { - /** - * 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 { INPUT, OUTPUT } - /** - * Device identifier - */ + /** Device identifier */ @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id", updatable = false, nullable = false) private long id; - /** - * The room this device belongs in - */ + /** The room this device belongs in */ @ManyToOne - @JoinColumn(name="room_id") + @JoinColumn(name = "room_id") private Room room; - /** - * The name of the device as assigned by the user (e.g. 'Master bedroom light') - */ - @Column - private String name; + /** The name of the device as assigned by the user (e.g. 'Master bedroom light') */ + @Column private String name; /** - * The name for the category of this particular device (e.g 'dimmer'). - * Not stored in the database (thanks to 'transient') but set thanks to constructors + * The name for the category of this particular device (e.g 'dimmer'). Not stored in the + * database (thanks to 'transient') but set thanks to constructors */ - private transient final String kind; + private final transient String kind; /** - * The way this device behaves in the automation flow. - * Not stored in the database (thanks to 'transient') but set thanks to constructors + * The way this device behaves in the automation flow. Not stored in the database (thanks to + * 'transient') but set thanks to constructors */ - private transient final FlowType flowType; + private final transient FlowType flowType; public long getId() { return id; diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLight.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLight.java index 24d1672..666fbee 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLight.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLight.java @@ -3,9 +3,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import javax.persistence.Column; import javax.persistence.Entity; -/** - * Represent a dimmable light - */ +/** Represent a dimmable light */ @Entity public class DimmableLight extends Light { @@ -13,11 +11,8 @@ public class DimmableLight extends Light { super("light"); } - /** - * The light intensity value. Goes from 0 (off) to 100 (on) - */ - @Column - private int intensity = 0; + /** The light intensity value. Goes from 0 (off) to 100 (on) */ + @Column private int intensity = 0; public int getIntensity() { return intensity; diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLightRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLightRepository.java index 741aecf..fd3fe43 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLightRepository.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLightRepository.java @@ -2,5 +2,4 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import org.springframework.data.repository.CrudRepository; -public interface DimmableLightRepository extends CrudRepository { -} +public interface DimmableLightRepository extends CrudRepository {} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Dimmer.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Dimmer.java index b88a6a2..2658b35 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Dimmer.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Dimmer.java @@ -4,9 +4,7 @@ import javax.persistence.Entity; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; -/** - * Represents a generic dimmer input device - */ +/** Represents a generic dimmer input device */ @Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) public abstract class Dimmer extends InputDevice { diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/InputDevice.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/InputDevice.java index 4b5d562..e632178 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/InputDevice.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/InputDevice.java @@ -3,8 +3,8 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import javax.persistence.Entity; /** - * A generic abstraction for an input device, i.e. something that captures input either from the environment (sensor) - * or the user (switch / dimmer). + * A generic abstraction for an input device, i.e. something that captures input either from the + * environment (sensor) or the user (switch / dimmer). */ @Entity public abstract class InputDevice extends Device { diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/KnobDimmer.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/KnobDimmer.java index cc5f6b5..80d59ab 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/KnobDimmer.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/KnobDimmer.java @@ -3,7 +3,8 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import javax.persistence.Entity; /** - * Represents a dimmer able to set absolute intensity values (i.e. knowing the absolute intensity value, like a knob) + * Represents a dimmer able to set absolute intensity values (i.e. knowing the absolute intensity + * value, like a knob) */ @Entity public class KnobDimmer extends Dimmer { diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/KnobDimmerRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/KnobDimmerRepository.java index 2dbe912..803ed90 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/KnobDimmerRepository.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/KnobDimmerRepository.java @@ -2,5 +2,4 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import org.springframework.data.repository.CrudRepository; -public interface KnobDimmerRepository extends CrudRepository { -} +public interface KnobDimmerRepository extends CrudRepository {} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Light.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Light.java index 2624cc0..bf1ed39 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Light.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Light.java @@ -5,17 +5,13 @@ import javax.persistence.Entity; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; -/** - * Represents a generic light - */ +/** Represents a generic light */ @Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) public abstract class Light extends OutputDevice { - /** - * Whether the light is on or not - */ - @Column(name="light_on") + /** Whether the light is on or not */ + @Column(name = "light_on") boolean on; protected Light(String kind) { diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensor.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensor.java index a3491e0..d1c47b3 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensor.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensor.java @@ -2,9 +2,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import javax.persistence.Entity; -/** - * Represents a motion sensor device - */ +/** Represents a motion sensor device */ @Entity public class MotionSensor extends InputDevice { public MotionSensor() { diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensorRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensorRepository.java index 801da31..e354262 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensorRepository.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensorRepository.java @@ -2,5 +2,4 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import org.springframework.data.repository.CrudRepository; -public interface MotionSensorRepository extends CrudRepository { -} +public interface MotionSensorRepository extends CrudRepository {} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/OutputDevice.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/OutputDevice.java index aecad0d..39e5dd0 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/OutputDevice.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/OutputDevice.java @@ -5,7 +5,8 @@ import javax.persistence.Inheritance; import javax.persistence.InheritanceType; /** - * Represents a generic output device, i.e. something that causes some behaviour (light, smartPlugs, ...). + * Represents a generic output device, i.e. something that causes some behaviour (light, smartPlugs, + * ...). */ @Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @@ -14,4 +15,3 @@ public abstract class OutputDevice extends Device { super(kind, FlowType.OUTPUT); } } - diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RegularLight.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RegularLight.java index 402f677..8f07377 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RegularLight.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RegularLight.java @@ -2,9 +2,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import javax.persistence.Entity; -/** - * Represents a standard non-dimmable light - */ +/** Represents a standard non-dimmable light */ @Entity public class RegularLight extends Light { public RegularLight() { diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RegularLightRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RegularLightRepository.java index 1031db9..7f3f4a6 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RegularLightRepository.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RegularLightRepository.java @@ -2,5 +2,4 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import org.springframework.data.repository.CrudRepository; -public interface RegularLightRepository extends CrudRepository { -} +public interface RegularLightRepository extends CrudRepository {} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Room.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Room.java index 9e0a211..ec732b1 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Room.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Room.java @@ -1,11 +1,9 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; -import javax.persistence.*; import java.util.Set; +import javax.persistence.*; -/** - * Represents a room in the house owned by the user - */ +/** Represents a room in the house owned by the user */ @Entity public class Room { @@ -14,22 +12,15 @@ public class Room { @Column(name = "id", updatable = false, nullable = false) private Long id; - /** - * User that owns the house this room is in - */ + /** User that owns the house this room is in */ @ManyToOne - @JoinColumn(name="user_id") + @JoinColumn(name = "user_id") private User user; - /** - * The user given name of this room (e.g. 'Master bedroom') - */ - @Column - private String name; + /** The user given name of this room (e.g. 'Master bedroom') */ + @Column private String name; - /** - * Collectiion of devices present in this room - */ + /** Collectiion of devices present in this room */ @OneToMany(mappedBy = "room") private Set devices; @@ -63,11 +54,16 @@ public class Room { @Override public String toString() { - return "Room{" + - "id=" + id + - ", user=" + user + - ", name='" + name + '\'' + - ", devices=" + devices + - '}'; + return "Room{" + + "id=" + + id + + ", user=" + + user + + ", name='" + + name + + '\'' + + ", devices=" + + devices + + '}'; } } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RoomRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RoomRepository.java index 35371b1..d9efb14 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RoomRepository.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RoomRepository.java @@ -2,5 +2,4 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import org.springframework.data.repository.CrudRepository; -public interface RoomRepository extends CrudRepository { -} +public interface RoomRepository extends CrudRepository {} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Sensor.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Sensor.java index ec22464..e5d7938 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Sensor.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Sensor.java @@ -5,37 +5,25 @@ import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; -/** - * A sensor input device that measures a quantity in a continuous scale (e.g. temperature) - */ +/** A sensor input device that measures a quantity in a continuous scale (e.g. temperature) */ @Entity public class Sensor extends InputDevice { - /** - * Type of sensor, i.e. of the thing the sensor measures. - */ + /** Type of sensor, i.e. of the thing the sensor measures. */ enum SensorType { - /** - * A sensor that measures temperature in degrees celsius - */ + /** A sensor that measures temperature in degrees celsius */ TEMPERATURE, - /** - * A sensor that measures relative humidity in percentage points - */ + /** A sensor that measures relative humidity in percentage points */ HUMIDITY, - /** - * A sensor that measures light in degrees - */ + /** A sensor that measures light in degrees */ LIGHT } - /** - * The type of this sensor - */ + /** The type of this sensor */ @Column - @Enumerated(value=EnumType.STRING) + @Enumerated(value = EnumType.STRING) private SensorType sensor; public Sensor() { diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SensorRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SensorRepository.java index 1cc8e62..cc4eefa 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SensorRepository.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SensorRepository.java @@ -2,5 +2,4 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import org.springframework.data.repository.CrudRepository; -public interface SensorRepository extends CrudRepository { -} +public interface SensorRepository extends CrudRepository {} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SmartPlug.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SmartPlug.java index 4a54912..e7fd36a 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SmartPlug.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SmartPlug.java @@ -3,16 +3,12 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import javax.persistence.Column; import javax.persistence.Entity; -/** - * A smart plug that can be turned either on or off - */ +/** A smart plug that can be turned either on or off */ @Entity public class SmartPlug extends OutputDevice { - /** - * Whether the smart plug is on - */ - @Column(name="smart_plug_on") + /** Whether the smart plug is on */ + @Column(name = "smart_plug_on") private boolean on; public boolean isOn() { diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SmartPlugRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SmartPlugRepository.java index 9099b85..24897a0 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SmartPlugRepository.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SmartPlugRepository.java @@ -2,5 +2,4 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import org.springframework.data.repository.CrudRepository; -public interface SmartPlugRepository extends CrudRepository { -} +public interface SmartPlugRepository extends CrudRepository {} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Switch.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Switch.java index 5e915f2..fbf1eed 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Switch.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Switch.java @@ -2,10 +2,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import javax.persistence.Entity; -/** - * A switch input device - * TODO: define switch behaviour (push button vs on/off state) - */ +/** A switch input device TODO: define switch behaviour (push button vs on/off state) */ @Entity public class Switch extends InputDevice { public Switch() { diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchRepository.java index d59bbe3..c2e0be9 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchRepository.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchRepository.java @@ -2,5 +2,4 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import org.springframework.data.repository.CrudRepository; -public interface SwitchRepository extends CrudRepository { -} +public interface SwitchRepository extends CrudRepository {} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/User.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/User.java index 1190652..92202e2 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/User.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/User.java @@ -1,11 +1,9 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; -import javax.persistence.*; import java.util.Set; +import javax.persistence.*; -/** - * A user of the Smarthut application - */ +/** A user of the Smarthut application */ @Entity(name = "smarthutuser") public class User { @@ -14,29 +12,16 @@ public class User { @Column(name = "id", updatable = false, nullable = false) private Long id; - /** - * The full name of the user - */ - @Column - private String name; + /** The full name of the user */ + @Column private String name; - /** - * A properly salted way to store the password - * TODO: define the implementation of salt - */ - @Column - private String hashedPassword; + /** A properly salted way to store the password TODO: define the implementation of salt */ + @Column private String hashedPassword; - /** - * The user's email - * TODO: validate email in setters - */ - @Column - private String email; + /** The user's email TODO: validate email in setters */ + @Column private String email; - /** - * All rooms in the user's house - */ + /** All rooms in the user's house */ @OneToMany(mappedBy = "user") private Set rooms; @@ -78,12 +63,20 @@ public class User { @Override public String toString() { - return "User{" + - "id=" + id + - ", name='" + name + '\'' + - ", hashedPassword='" + hashedPassword + '\'' + - ", email='" + email + '\'' + - ", rooms=" + rooms + - '}'; + return "User{" + + "id=" + + id + + ", name='" + + name + + '\'' + + ", hashedPassword='" + + hashedPassword + + '\'' + + ", email='" + + email + + '\'' + + ", rooms=" + + rooms + + '}'; } } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/UserRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/UserRepository.java index f33a9b7..a0a0f1f 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/UserRepository.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/UserRepository.java @@ -2,5 +2,4 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import org.springframework.data.repository.CrudRepository; -public interface UserRepository extends CrudRepository { -} +public interface UserRepository extends CrudRepository {}