From cddf7187673b51a615abedfa37f8a55b053fbf00 Mon Sep 17 00:00:00 2001 From: Claudio Maggioni Date: Wed, 15 Apr 2020 17:00:16 +0200 Subject: [PATCH] Code review for SecurityCamera --- .../smarthut/config/SpringFoxConfig.java | 1 + .../smarthut/config/WebSecurityConfig.java | 1 + .../controller/SecurityCameraController.java | 7 ------- .../sanmarinoes/smarthut/models/SecurityCamera.java | 8 +------- .../security_camera_videos/security_camera_1.mp4 | Bin 5 files changed, 3 insertions(+), 14 deletions(-) rename {media => src/main/resources/static}/security_camera_videos/security_camera_1.mp4 (100%) diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/SpringFoxConfig.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/SpringFoxConfig.java index 971a7fb..e779abb 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/SpringFoxConfig.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/SpringFoxConfig.java @@ -71,6 +71,7 @@ public class SpringFoxConfig { .or(PathSelectors.regex("/dimmableLight.*")::apply) .or(PathSelectors.regex("/knobDimmer.*")::apply) .or(PathSelectors.regex("/regularLight.*")::apply) + .or(PathSelectors.regex("/securityCamera.*")::apply) .or(PathSelectors.regex("/sensor.*")::apply) .or(PathSelectors.regex("/smartPlug.*")::apply) .or(PathSelectors.regex("/switch.*")::apply) diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/WebSecurityConfig.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/WebSecurityConfig.java index ec116c3..2b2f118 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/WebSecurityConfig.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/WebSecurityConfig.java @@ -51,6 +51,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { // dont authenticate this particular request .authorizeRequests() .antMatchers( + "/security_camera_videos/**", "/sensor-socket", "/auth/login", "/swagger-ui.html", diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SecurityCameraController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SecurityCameraController.java index d31dbd1..9baf353 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SecurityCameraController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SecurityCameraController.java @@ -11,7 +11,6 @@ import java.util.List; import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.core.io.FileSystemResource; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -38,12 +37,6 @@ public class SecurityCameraController { return securityCameraService.findById(id).orElseThrow(NotFoundException::new); } - @GetMapping("/{id}/video") - public FileSystemResource getVideo(@PathVariable("id") long id) throws NotFoundException { - SecurityCamera s = findById(id); - return s.getSurveillanceVideo(); - } - private SecurityCamera save(SecurityCamera newSC, SecurityCameraSaveRequest sc) { newSC.setName(sc.getName()); newSC.setRoomId(sc.getRoomId()); diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SecurityCamera.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SecurityCamera.java index e751f60..7ddde5d 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SecurityCamera.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SecurityCamera.java @@ -1,10 +1,8 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; -import java.io.File; import javax.persistence.Column; import javax.persistence.Entity; import javax.validation.constraints.NotNull; -import org.springframework.core.io.FileSystemResource; @Entity public class SecurityCamera extends Switchable { @@ -20,16 +18,12 @@ public class SecurityCamera extends Switchable { @Column(name = "video", nullable = false) @NotNull - private String path = "backend/media/security_camera_videos/security_camera_1.mp4"; + private String path = "/security_camera_videos/security_camera_1.mp4"; public String getPath() { return path; } - public FileSystemResource getSurveillanceVideo() { - return new FileSystemResource(new File(path)); - } - @Override public boolean isOn() { return on; diff --git a/media/security_camera_videos/security_camera_1.mp4 b/src/main/resources/static/security_camera_videos/security_camera_1.mp4 similarity index 100% rename from media/security_camera_videos/security_camera_1.mp4 rename to src/main/resources/static/security_camera_videos/security_camera_1.mp4