From 5bfce7e99b7555f102094e18ab3065d95a11d1e5 Mon Sep 17 00:00:00 2001 From: "Claudio Maggioni (maggicl)" Date: Mon, 4 May 2020 15:09:11 +0200 Subject: [PATCH] Added icons to scenes --- .../smarthut/controller/RoomController.java | 4 +- .../smarthut/controller/SceneController.java | 3 + .../smarthut/dto/RoomSaveRequest.java | 8 +- .../smarthut/dto/SceneSaveRequest.java | 11 ++ .../sa4/sanmarinoes/smarthut/models/Icon.java | 103 ++++++++++++++++++ .../sa4/sanmarinoes/smarthut/models/Room.java | 101 ----------------- .../sanmarinoes/smarthut/models/Scene.java | 12 ++ 7 files changed, 135 insertions(+), 107 deletions(-) create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Icon.java diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RoomController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RoomController.java index e6ab648..8b7f648 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RoomController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RoomController.java @@ -75,7 +75,7 @@ public class RoomController { final String username = principal.getName(); final Long userId = userRepository.findByUsername(username).getId(); final String img = r.getImage(); - final Room.Icon icon = r.getIcon(); + final Icon icon = r.getIcon(); final Room newRoom = new Room(); newRoom.setUserId(userId); @@ -95,7 +95,7 @@ public class RoomController { .findByIdAndUsername(id, principal.getName()) .orElseThrow(NotFoundException::new); final String img = r.getImage(); - final Room.Icon icon = r.getIcon(); + final Icon icon = r.getIcon(); if (r.getName() != null) { newRoom.setName(r.getName()); diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SceneController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SceneController.java index 66dc5aa..c795049 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SceneController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SceneController.java @@ -56,6 +56,7 @@ public class SceneController { newScene.setUserId(userId); newScene.setName(s.getName()); newScene.setGuestAccessEnabled(s.isGuestAccessEnabled()); + newScene.setIcon(s.getIcon()); return sceneRepository.save(newScene); } @@ -84,6 +85,8 @@ public class SceneController { newScene.setName(s.getName()); } + newScene.setIcon(s.getIcon()); + newScene.setGuestAccessEnabled(s.isGuestAccessEnabled()); return sceneRepository.save(newScene); diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/RoomSaveRequest.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/RoomSaveRequest.java index 02a0e35..cf362ac 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/RoomSaveRequest.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/RoomSaveRequest.java @@ -1,6 +1,6 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto; -import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Room; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Icon; import javax.persistence.Lob; import javax.validation.constraints.NotNull; @@ -9,7 +9,7 @@ public class RoomSaveRequest { /** Room identifier */ private long id; - @NotNull private Room.Icon icon; + @NotNull private Icon icon; /** * Image is to be given as byte[]. In order to get an encoded string from it, the @@ -38,11 +38,11 @@ public class RoomSaveRequest { this.name = name; } - public Room.Icon getIcon() { + public Icon getIcon() { return icon; } - public void setIcon(Room.Icon icon) { + public void setIcon(Icon icon) { this.icon = icon; } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SceneSaveRequest.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SceneSaveRequest.java index 080ea2b..e7ce3ad 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SceneSaveRequest.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SceneSaveRequest.java @@ -1,5 +1,6 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.dto; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Icon; import com.sun.istack.NotNull; import javax.persistence.Column; @@ -11,6 +12,8 @@ public class SceneSaveRequest { /** The user given name of this room (e.g. 'Master bedroom') */ @NotNull private String name; + @NotNull private Icon icon; + /** Determines whether a guest can access this scene */ @Column @NotNull private boolean guestAccessEnabled; @@ -33,4 +36,12 @@ public class SceneSaveRequest { public void setName(String name) { this.name = name; } + + public Icon getIcon() { + return icon; + } + + public void setIcon(Icon icon) { + this.icon = icon; + } } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Icon.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Icon.java new file mode 100644 index 0000000..0ad9e4d --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Icon.java @@ -0,0 +1,103 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +import com.google.gson.annotations.SerializedName; + +/** A collection of Semantic UI icons */ +@SuppressWarnings("unused") +public enum Icon { + @SerializedName("home") + HOME("home"), + @SerializedName("coffee") + COFFEE("coffee"), + @SerializedName("beer") + BEER("beer"), + @SerializedName("glass martini") + GLASS_MARTINI("glass martini"), + @SerializedName("film") + FILM("film"), + @SerializedName("video") + VIDEO("video"), + @SerializedName("music") + MUSIC("music"), + @SerializedName("headphones") + HEADPHONES("headphones"), + @SerializedName("fax") + FAX("fax"), + @SerializedName("phone") + PHONE("phone"), + @SerializedName("laptop") + LAPTOP("laptop"), + @SerializedName("bath") + BATH("bath"), + @SerializedName("shower") + SHOWER("shower"), + @SerializedName("bed") + BED("bed"), + @SerializedName("child") + CHILD("child"), + @SerializedName("warehouse") + WAREHOUSE("warehouse"), + @SerializedName("car") + CAR("car"), + @SerializedName("bicycle") + BICYCLE("bicycle"), + @SerializedName("motorcycle") + MOTORCYCLE("motorcycle"), + @SerializedName("archive") + ARCHIVE("archive"), + @SerializedName("boxes") + BOXES("boxes"), + @SerializedName("cubes") + CUBES("cubes"), + @SerializedName("chess") + CHESS("chess"), + @SerializedName("gamepad") + GAMEPAD("gamepad"), + @SerializedName("futbol") + FUTBOL("futbol"), + @SerializedName("table tennis") + TABLE_TENNIS("table tennis"), + @SerializedName("server") + SERVER("server"), + @SerializedName("tv") + TV("tv"), + @SerializedName("heart") + HEART("heart"), + @SerializedName("camera") + CAMERA("camera"), + @SerializedName("trophy") + TROPHY("trophy"), + @SerializedName("wrench") + WRENCH("wrench"), + @SerializedName("image") + IMAGE("image"), + @SerializedName("book") + BOOK("book"), + @SerializedName("university") + UNIVERSITY("university"), + @SerializedName("medkit") + MEDKIT("medkit"), + @SerializedName("paw") + PAW("paw"), + @SerializedName("tree") + TREE("tree"), + @SerializedName("utensils") + UTENSILS("utensils"), + @SerializedName("male") + MALE("male"), + @SerializedName("female") + FEMALE("female"), + @SerializedName("life ring outline") + LIFE_RING_OUTLINE("life ring outline"); + + private String iconName; + + Icon(String s) { + this.iconName = s; + } + + @Override + public String toString() { + return iconName; + } +} 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 34f3824..73d7794 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,6 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import ch.usi.inf.sa4.sanmarinoes.smarthut.config.GsonExclude; -import com.google.gson.annotations.SerializedName; import io.swagger.annotations.ApiModelProperty; import java.util.HashSet; import java.util.Set; @@ -12,106 +11,6 @@ import javax.validation.constraints.NotNull; @Entity public class Room { - /** A collection of Semantic UI icons */ - @SuppressWarnings("unused") - public enum Icon { - @SerializedName("home") - HOME("home"), - @SerializedName("coffee") - COFFEE("coffee"), - @SerializedName("beer") - BEER("beer"), - @SerializedName("glass martini") - GLASS_MARTINI("glass martini"), - @SerializedName("film") - FILM("film"), - @SerializedName("video") - VIDEO("video"), - @SerializedName("music") - MUSIC("music"), - @SerializedName("headphones") - HEADPHONES("headphones"), - @SerializedName("fax") - FAX("fax"), - @SerializedName("phone") - PHONE("phone"), - @SerializedName("laptop") - LAPTOP("laptop"), - @SerializedName("bath") - BATH("bath"), - @SerializedName("shower") - SHOWER("shower"), - @SerializedName("bed") - BED("bed"), - @SerializedName("child") - CHILD("child"), - @SerializedName("warehouse") - WAREHOUSE("warehouse"), - @SerializedName("car") - CAR("car"), - @SerializedName("bicycle") - BICYCLE("bicycle"), - @SerializedName("motorcycle") - MOTORCYCLE("motorcycle"), - @SerializedName("archive") - ARCHIVE("archive"), - @SerializedName("boxes") - BOXES("boxes"), - @SerializedName("cubes") - CUBES("cubes"), - @SerializedName("chess") - CHESS("chess"), - @SerializedName("gamepad") - GAMEPAD("gamepad"), - @SerializedName("futbol") - FUTBOL("futbol"), - @SerializedName("table tennis") - TABLE_TENNIS("table tennis"), - @SerializedName("server") - SERVER("server"), - @SerializedName("tv") - TV("tv"), - @SerializedName("heart") - HEART("heart"), - @SerializedName("camera") - CAMERA("camera"), - @SerializedName("trophy") - TROPHY("trophy"), - @SerializedName("wrench") - WRENCH("wrench"), - @SerializedName("image") - IMAGE("image"), - @SerializedName("book") - BOOK("book"), - @SerializedName("university") - UNIVERSITY("university"), - @SerializedName("medkit") - MEDKIT("medkit"), - @SerializedName("paw") - PAW("paw"), - @SerializedName("tree") - TREE("tree"), - @SerializedName("utensils") - UTENSILS("utensils"), - @SerializedName("male") - MALE("male"), - @SerializedName("female") - FEMALE("female"), - @SerializedName("life ring outline") - LIFE_RING_OUTLINE("life ring outline"); - - private String iconName; - - Icon(String s) { - this.iconName = s; - } - - @Override - public String toString() { - return iconName; - } - } - @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id", updatable = false, nullable = false, unique = true) diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Scene.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Scene.java index f35d54d..83a9367 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Scene.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Scene.java @@ -39,9 +39,21 @@ public class Scene { @Column(nullable = false) private String name; + @Column(nullable = false) + @NotNull + private Icon icon; + /** Determines whether a guest can access this scene */ @Column private boolean guestAccessEnabled; + public Icon getIcon() { + return icon; + } + + public void setIcon(Icon icon) { + this.icon = icon; + } + public boolean isGuestAccessEnabled() { return guestAccessEnabled; }