Done security camera filtering if required by host

This commit is contained in:
Claudio Maggioni (maggicl) 2020-05-04 16:35:46 +02:00
parent 1ddc8f5ba6
commit c24598cc6a

View file

@ -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<Device> 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;