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.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.StreamSupport;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@ -68,6 +70,7 @@ public class DeviceService {
|
||||||
throws NotFoundException {
|
throws NotFoundException {
|
||||||
try {
|
try {
|
||||||
Iterable<Device> devices;
|
Iterable<Device> devices;
|
||||||
|
User host = null;
|
||||||
if (hostId == null) {
|
if (hostId == null) {
|
||||||
if (roomId != null) {
|
if (roomId != null) {
|
||||||
roomRepository
|
roomRepository
|
||||||
|
@ -79,8 +82,7 @@ public class DeviceService {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final User guest = userRepository.findByUsername(username);
|
final User guest = userRepository.findByUsername(username);
|
||||||
final User host =
|
host = userRepository.findById(hostId).orElseThrow(NotFoundException::new);
|
||||||
userRepository.findById(hostId).orElseThrow(NotFoundException::new);
|
|
||||||
|
|
||||||
if (!guest.getHosts().contains(host)) {
|
if (!guest.getHosts().contains(host)) {
|
||||||
throw new NotFoundException();
|
throw new NotFoundException();
|
||||||
|
@ -99,7 +101,13 @@ public class DeviceService {
|
||||||
|
|
||||||
populateComputedFields(devices);
|
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);
|
return toList(devices);
|
||||||
|
}
|
||||||
} catch (NotFoundException e) {
|
} catch (NotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
throw e;
|
throw e;
|
||||||
|
|
Loading…
Reference in a new issue