From e806c188094381c7634d549999a1fc1d9450ffe8 Mon Sep 17 00:00:00 2001 From: tommi27 Date: Tue, 3 Mar 2020 11:04:58 +0100 Subject: [PATCH 1/4] added uniqueness constraints --- .../ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java | 2 +- .../usi/inf/sa4/sanmarinoes/smarthut/models/KnobDimmer.java | 6 +++++- .../ch/usi/inf/sa4/sanmarinoes/smarthut/models/Room.java | 4 ++-- .../ch/usi/inf/sa4/sanmarinoes/smarthut/models/User.java | 6 +++--- 4 files changed, 11 insertions(+), 7 deletions(-) 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 7aa65e8..e8a621b 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 @@ -30,7 +30,7 @@ public abstract class Device { * The room this device belongs in, as a foreign key id. To use when updating and inserting from * a REST call. */ - @Column(name = "room_id", nullable = false) + @Column(name = "room_id", nullable = false, unique = true) @NotNull private Long roomId; 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 0a90998..7f4056b 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 @@ -33,7 +33,11 @@ public class KnobDimmer extends Dimmer { dl.setIntensity((dl.getIntensity() + 5) % 105); } else { dl.setIntensity(dl.getIntensity() + (5 - remainder)); - dl.setIntensity((dl.getIntensity() - 5) % 105); + if (dl.getIntensity() == 0) { + dl.setIntensity(100); + } else { + dl.setIntensity(dl.getIntensity() - 5); + } } } } 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 e15805b..f6edfd3 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 @@ -10,7 +10,7 @@ public class Room { @Id @GeneratedValue(strategy = GenerationType.AUTO) - @Column(name = "id", updatable = false, nullable = false) + @Column(name = "id", updatable = false, nullable = false, unique = true) @ApiModelProperty(hidden = true) private Long id; @@ -33,7 +33,7 @@ public class Room { * inserting from a REST call. */ @NotNull - @Column(name = "user_id", nullable = false) + @Column(name = "user_id", nullable = false, unique = true) private Long userId; /** The user given name of this room (e.g. 'Master bedroom') */ 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 67f95d4..e33b130 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 @@ -14,7 +14,7 @@ public class User { @Id @GeneratedValue(strategy = GenerationType.AUTO) - @Column(name = "id", updatable = false, nullable = false) + @Column(name = "id", updatable = false, nullable = false, unique = true) @ApiModelProperty(hidden = true) private Long id; @@ -24,9 +24,9 @@ public class User { @NotEmpty(message = "Please provide a full name") private String name; - /** The full name of the user */ + /** The full username of the user */ @NotNull - @Column(nullable = false) + @Column(nullable = false, unique = true) @NotEmpty(message = "Please provide a username") private String username; From 7cd2b44a447dd4c13b7d8799040c34f04f53bb76 Mon Sep 17 00:00:00 2001 From: tommi27 Date: Wed, 4 Mar 2020 15:25:53 +0100 Subject: [PATCH 2/4] added gitignore for iml files --- .gitignore | 3 +++ backend.iml | 12 ------------ 2 files changed, 3 insertions(+), 12 deletions(-) delete mode 100644 backend.iml diff --git a/.gitignore b/.gitignore index 1b1a367..ee01dda 100644 --- a/.gitignore +++ b/.gitignore @@ -136,3 +136,6 @@ gradle-app.setting # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 # gradle/wrapper/gradle-wrapper.properties + +# IntelliJ +*.iml \ No newline at end of file diff --git a/backend.iml b/backend.iml deleted file mode 100644 index 1eae0df..0000000 --- a/backend.iml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file From 749d79d51e5149fd33fd293d79f2c09ae34d5666 Mon Sep 17 00:00:00 2001 From: tommi27 Date: Wed, 4 Mar 2020 16:07:23 +0100 Subject: [PATCH 3/4] added skeleton for websockets --- build.gradle | 1 + .../smarthut/websocket/HouseEndpoint.java | 24 +++++++++++++++++ .../smarthut/websocket/WebSocketConfig.java | 26 +++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/websocket/HouseEndpoint.java create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/websocket/WebSocketConfig.java diff --git a/build.gradle b/build.gradle index d511c0b..4f4082f 100644 --- a/build.gradle +++ b/build.gradle @@ -15,6 +15,7 @@ repositories { dependencies { compile 'org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final' + compile "org.springframework.boot:spring-boot-starter-websocket" implementation 'org.springframework.boot:spring-boot-starter' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-security' diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/websocket/HouseEndpoint.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/websocket/HouseEndpoint.java new file mode 100644 index 0000000..2e6de11 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/websocket/HouseEndpoint.java @@ -0,0 +1,24 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.websocket; + +import java.io.IOException; +import javax.websocket.*; +import javax.websocket.server.ServerEndpoint; + +@ServerEndpoint( + value = + "theEndpointMustHaveAShotNameBecauseAndreaBritesMartesMaronesIsAVeryNiceProgrammerThatMustTypeThisByHand.exe") // DONE: choose path +public class HouseEndpoint { + private Session session; + + @OnOpen + public void onOpen(Session session) throws IOException {} + + @OnMessage + public void onMessage() throws IOException {} + + @OnClose + public void onClose() {} + + @OnError + public void onError() {} +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/websocket/WebSocketConfig.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/websocket/WebSocketConfig.java new file mode 100644 index 0000000..d5ea39a --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/websocket/WebSocketConfig.java @@ -0,0 +1,26 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.websocket; + +import org.springframework.context.annotation.Configuration; +import org.springframework.messaging.simp.config.MessageBrokerRegistry; +import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; +import org.springframework.web.socket.config.annotation.StompEndpointRegistry; +import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; + +@Configuration +@EnableWebSocketMessageBroker +public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { + + @Override + public void registerStompEndpoints(StompEndpointRegistry registry) { + registry.addEndpoint("/house") + .setAllowedOrigins("domainURL") + .withSockJS(); // TODO: set domain URL + } + + /** Creates message brokers in-memory to send and receive messages for topic and queue route */ + @Override + public void configureMessageBroker(MessageBrokerRegistry config) { + config.enableSimpleBroker("/topic/", "/queue/"); + config.setApplicationDestinationPrefixes("/app"); + } +} From 73e1328d7046ff37400bbc48f4d9d66a3076358b Mon Sep 17 00:00:00 2001 From: Claudio Maggioni Date: Sat, 14 Mar 2020 20:07:58 +0100 Subject: [PATCH 4/4] Branch cleaning --- build.gradle | 3 +-- .../smarthut/models/KnobDimmer.java | 6 +---- .../smarthut/websocket/HouseEndpoint.java | 24 ----------------- .../smarthut/websocket/WebSocketConfig.java | 26 ------------------- 4 files changed, 2 insertions(+), 57 deletions(-) delete mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/websocket/HouseEndpoint.java delete mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/websocket/WebSocketConfig.java diff --git a/build.gradle b/build.gradle index 4f4082f..c7b20f6 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,6 @@ repositories { dependencies { compile 'org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final' - compile "org.springframework.boot:spring-boot-starter-websocket" implementation 'org.springframework.boot:spring-boot-starter' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-security' @@ -25,7 +24,7 @@ dependencies { implementation 'org.postgresql:postgresql' compile "io.springfox:springfox-swagger2:2.9.2" compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2' - + 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/models/KnobDimmer.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/KnobDimmer.java index 7f4056b..0a90998 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 @@ -33,11 +33,7 @@ public class KnobDimmer extends Dimmer { dl.setIntensity((dl.getIntensity() + 5) % 105); } else { dl.setIntensity(dl.getIntensity() + (5 - remainder)); - if (dl.getIntensity() == 0) { - dl.setIntensity(100); - } else { - dl.setIntensity(dl.getIntensity() - 5); - } + dl.setIntensity((dl.getIntensity() - 5) % 105); } } } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/websocket/HouseEndpoint.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/websocket/HouseEndpoint.java deleted file mode 100644 index 2e6de11..0000000 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/websocket/HouseEndpoint.java +++ /dev/null @@ -1,24 +0,0 @@ -package ch.usi.inf.sa4.sanmarinoes.smarthut.websocket; - -import java.io.IOException; -import javax.websocket.*; -import javax.websocket.server.ServerEndpoint; - -@ServerEndpoint( - value = - "theEndpointMustHaveAShotNameBecauseAndreaBritesMartesMaronesIsAVeryNiceProgrammerThatMustTypeThisByHand.exe") // DONE: choose path -public class HouseEndpoint { - private Session session; - - @OnOpen - public void onOpen(Session session) throws IOException {} - - @OnMessage - public void onMessage() throws IOException {} - - @OnClose - public void onClose() {} - - @OnError - public void onError() {} -} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/websocket/WebSocketConfig.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/websocket/WebSocketConfig.java deleted file mode 100644 index d5ea39a..0000000 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/websocket/WebSocketConfig.java +++ /dev/null @@ -1,26 +0,0 @@ -package ch.usi.inf.sa4.sanmarinoes.smarthut.websocket; - -import org.springframework.context.annotation.Configuration; -import org.springframework.messaging.simp.config.MessageBrokerRegistry; -import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; -import org.springframework.web.socket.config.annotation.StompEndpointRegistry; -import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; - -@Configuration -@EnableWebSocketMessageBroker -public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { - - @Override - public void registerStompEndpoints(StompEndpointRegistry registry) { - registry.addEndpoint("/house") - .setAllowedOrigins("domainURL") - .withSockJS(); // TODO: set domain URL - } - - /** Creates message brokers in-memory to send and receive messages for topic and queue route */ - @Override - public void configureMessageBroker(MessageBrokerRegistry config) { - config.enableSimpleBroker("/topic/", "/queue/"); - config.setApplicationDestinationPrefixes("/app"); - } -}