diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/DeviceService.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/DeviceService.java index b0a8d7a..789b53a 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/DeviceService.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/DeviceService.java @@ -9,6 +9,8 @@ import java.util.Collection; import java.util.Comparator; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -68,6 +70,7 @@ public class DeviceService { throws NotFoundException { try { Iterable devices; + User host = null; if (hostId == null) { if (roomId != null) { roomRepository @@ -79,8 +82,7 @@ public class DeviceService { } } else { final User guest = userRepository.findByUsername(username); - final User host = - userRepository.findById(hostId).orElseThrow(NotFoundException::new); + host = userRepository.findById(hostId).orElseThrow(NotFoundException::new); if (!guest.getHosts().contains(host)) { throw new NotFoundException(); @@ -99,7 +101,13 @@ public class DeviceService { populateComputedFields(devices); - return toList(devices); + if (host != null && !host.isCameraEnabled()) { + return StreamSupport.stream(devices.spliterator(), true) + .filter(d -> !(d instanceof SecurityCamera)) + .collect(Collectors.toList()); + } else { + return toList(devices); + } } catch (NotFoundException e) { e.printStackTrace(); throw e;