Code review for SecurityCamera

This commit is contained in:
Claudio Maggioni 2020-04-15 17:00:16 +02:00
parent 2b93ffa07b
commit cddf718767
5 changed files with 3 additions and 14 deletions

View file

@ -71,6 +71,7 @@ public class SpringFoxConfig {
.or(PathSelectors.regex("/dimmableLight.*")::apply) .or(PathSelectors.regex("/dimmableLight.*")::apply)
.or(PathSelectors.regex("/knobDimmer.*")::apply) .or(PathSelectors.regex("/knobDimmer.*")::apply)
.or(PathSelectors.regex("/regularLight.*")::apply) .or(PathSelectors.regex("/regularLight.*")::apply)
.or(PathSelectors.regex("/securityCamera.*")::apply)
.or(PathSelectors.regex("/sensor.*")::apply) .or(PathSelectors.regex("/sensor.*")::apply)
.or(PathSelectors.regex("/smartPlug.*")::apply) .or(PathSelectors.regex("/smartPlug.*")::apply)
.or(PathSelectors.regex("/switch.*")::apply) .or(PathSelectors.regex("/switch.*")::apply)

View file

@ -51,6 +51,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
// dont authenticate this particular request // dont authenticate this particular request
.authorizeRequests() .authorizeRequests()
.antMatchers( .antMatchers(
"/security_camera_videos/**",
"/sensor-socket", "/sensor-socket",
"/auth/login", "/auth/login",
"/swagger-ui.html", "/swagger-ui.html",

View file

@ -11,7 +11,6 @@ import java.util.List;
import javax.validation.Valid; import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 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.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
@ -38,12 +37,6 @@ public class SecurityCameraController {
return securityCameraService.findById(id).orElseThrow(NotFoundException::new); 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) { private SecurityCamera save(SecurityCamera newSC, SecurityCameraSaveRequest sc) {
newSC.setName(sc.getName()); newSC.setName(sc.getName());
newSC.setRoomId(sc.getRoomId()); newSC.setRoomId(sc.getRoomId());

View file

@ -1,10 +1,8 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models; package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import java.io.File;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import org.springframework.core.io.FileSystemResource;
@Entity @Entity
public class SecurityCamera extends Switchable { public class SecurityCamera extends Switchable {
@ -20,16 +18,12 @@ public class SecurityCamera extends Switchable {
@Column(name = "video", nullable = false) @Column(name = "video", nullable = false)
@NotNull @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() { public String getPath() {
return path; return path;
} }
public FileSystemResource getSurveillanceVideo() {
return new FileSystemResource(new File(path));
}
@Override @Override
public boolean isOn() { public boolean isOn() {
return on; return on;