Done security camera filtering if required by host
This commit is contained in:
parent
1ddc8f5ba6
commit
c24598cc6a
1 changed files with 11 additions and 3 deletions
|
@ -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);
|
||||
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue