Deletion propagation implemented
This commit is contained in:
parent
69d1b38ff2
commit
21bc66d24b
16 changed files with 49 additions and 20 deletions
|
@ -75,6 +75,6 @@ public class ButtonDimmerController
|
|||
@DeleteMapping("/{id}")
|
||||
public void delete(@PathVariable("id") long id, final Principal principal)
|
||||
throws NotFoundException {
|
||||
deviceService.delete(id, principal.getName());
|
||||
deviceService.deleteByIdAsOwner(id, principal.getName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ public class CurtainsController {
|
|||
@DeleteMapping("/{id}")
|
||||
public void delete(@PathVariable("id") long id, final Principal principal)
|
||||
throws NotFoundException {
|
||||
deviceService.delete(id, principal.getName());
|
||||
deviceService.deleteByIdAsOwner(id, principal.getName());
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/state")
|
||||
|
|
|
@ -66,7 +66,9 @@ public class DimmableLightController extends GuestEnabledController<DimmableLigh
|
|||
*/
|
||||
@PutMapping
|
||||
public DimmableLight update(
|
||||
@Valid @RequestBody DimmableSaveRequest sp, final Principal principal, Long hostId)
|
||||
@Valid @RequestBody DimmableSaveRequest sp,
|
||||
final Principal principal,
|
||||
@RequestParam(value = "hostId", required = false) Long hostId)
|
||||
throws NotFoundException {
|
||||
|
||||
return save(
|
||||
|
@ -79,7 +81,7 @@ public class DimmableLightController extends GuestEnabledController<DimmableLigh
|
|||
@DeleteMapping("/{id}")
|
||||
public void delete(@PathVariable("id") long id, final Principal principal)
|
||||
throws NotFoundException {
|
||||
deviceService.delete(id, principal.getName());
|
||||
deviceService.deleteByIdAsOwner(id, principal.getName());
|
||||
}
|
||||
|
||||
// the full url should be: "/dimmableLight/{id}/state?sceneId={sceneId}
|
||||
|
|
|
@ -62,6 +62,6 @@ public class KnobDimmerController extends InputDeviceConnectionController<KnobDi
|
|||
@DeleteMapping("/{id}")
|
||||
public void delete(@PathVariable("id") long id, final Principal principal)
|
||||
throws NotFoundException {
|
||||
deviceService.delete(id, principal.getName());
|
||||
deviceService.deleteByIdAsOwner(id, principal.getName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,6 +53,6 @@ public class MotionSensorController {
|
|||
@DeleteMapping("/{id}")
|
||||
public void delete(@PathVariable("id") long id, final Principal principal)
|
||||
throws NotFoundException {
|
||||
deviceService.delete(id, principal.getName());
|
||||
deviceService.deleteByIdAsOwner(id, principal.getName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,7 +80,9 @@ public class RegularLightController extends GuestEnabledController<RegularLight>
|
|||
|
||||
@PutMapping
|
||||
public RegularLight update(
|
||||
@Valid @RequestBody SwitchableSaveRequest rl, final Principal principal, Long hostId)
|
||||
@Valid @RequestBody SwitchableSaveRequest rl,
|
||||
final Principal principal,
|
||||
@RequestParam(value = "hostId", required = false) Long hostId)
|
||||
throws NotFoundException {
|
||||
return save(
|
||||
fetchIfOwnerOrGuest(principal, rl.getId(), hostId),
|
||||
|
@ -92,7 +94,7 @@ public class RegularLightController extends GuestEnabledController<RegularLight>
|
|||
@DeleteMapping("/{id}")
|
||||
public void delete(@PathVariable("id") long id, final Principal principal)
|
||||
throws NotFoundException {
|
||||
deviceService.delete(id, principal.getName());
|
||||
deviceService.deleteByIdAsOwner(id, principal.getName());
|
||||
}
|
||||
|
||||
// the full url should be: "/regularLight/{id}/state?sceneId={sceneId}
|
||||
|
|
|
@ -124,6 +124,11 @@ public class RoomController {
|
|||
roomRepository
|
||||
.findByIdAndUsername(id, principal.getName())
|
||||
.orElseThrow(NotFoundException::new);
|
||||
List<Device> devices = deviceService.findAll(r.getId(), null, principal.getName());
|
||||
for (Device d : devices) {
|
||||
deviceService.deleteByIdAsOwner(d.getId(), principal.getName());
|
||||
}
|
||||
|
||||
roomRepository.delete(r);
|
||||
}
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ public class SecurityCameraController {
|
|||
@DeleteMapping("/{id}")
|
||||
public void delete(@PathVariable("id") long id, final Principal principal)
|
||||
throws NotFoundException {
|
||||
deviceService.delete(id, principal.getName());
|
||||
deviceService.deleteByIdAsOwner(id, principal.getName());
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/state")
|
||||
|
|
|
@ -57,6 +57,6 @@ public class SensorController {
|
|||
@DeleteMapping("/{id}")
|
||||
public void deleteById(@PathVariable("id") long id, final Principal principal)
|
||||
throws NotFoundException {
|
||||
deviceService.delete(id, principal.getName());
|
||||
deviceService.deleteByIdAsOwner(id, principal.getName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ public class SmartPlugController {
|
|||
@DeleteMapping("/{id}")
|
||||
public void deleteById(@PathVariable("id") long id, final Principal principal)
|
||||
throws NotFoundException {
|
||||
deviceService.delete(id, principal.getName());
|
||||
deviceService.deleteByIdAsOwner(id, principal.getName());
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/state")
|
||||
|
|
|
@ -81,6 +81,6 @@ public class SwitchController extends InputDeviceConnectionController<Switch, Sw
|
|||
@DeleteMapping("/{id}")
|
||||
public void deleteById(@PathVariable("id") long id, final Principal principal)
|
||||
throws NotFoundException {
|
||||
deviceService.delete(id, principal.getName());
|
||||
deviceService.deleteByIdAsOwner(id, principal.getName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ public class ThermostatController {
|
|||
@DeleteMapping("/{id}")
|
||||
public void deleteById(@PathVariable("id") long id, final Principal principal)
|
||||
throws NotFoundException {
|
||||
deviceService.delete(id, principal.getName());
|
||||
deviceService.deleteByIdAsOwner(id, principal.getName());
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/state")
|
||||
|
|
|
@ -27,7 +27,7 @@ public class Automation {
|
|||
@GsonExclude
|
||||
private Long userId;
|
||||
|
||||
@OneToMany(mappedBy = "automation", orphanRemoval = true)
|
||||
@OneToMany(mappedBy = "automation", orphanRemoval = true, cascade = CascadeType.REMOVE)
|
||||
private Set<Trigger<?>> triggers = new HashSet<>();
|
||||
|
||||
@OneToMany(mappedBy = "automation", cascade = CascadeType.REMOVE)
|
||||
|
|
|
@ -10,7 +10,13 @@ import javax.persistence.*;
|
|||
@Entity
|
||||
public class Switch extends InputDevice implements BooleanTriggerable {
|
||||
|
||||
@ManyToMany(cascade = CascadeType.DETACH)
|
||||
@ManyToMany(
|
||||
cascade = {
|
||||
CascadeType.DETACH,
|
||||
CascadeType.MERGE,
|
||||
CascadeType.REFRESH,
|
||||
CascadeType.PERSIST
|
||||
})
|
||||
@GsonExclude
|
||||
@SocketGsonExclude
|
||||
@JoinTable(
|
||||
|
|
|
@ -14,7 +14,14 @@ public abstract class Switchable extends OutputDevice {
|
|||
public static final Connector<Switch, Switchable> SWITCH_SWITCHABLE_CONNECTOR =
|
||||
Connector.basic(Switch::getOutputs, Switchable::getSwitches);
|
||||
|
||||
@ManyToMany(mappedBy = "switchables", cascade = CascadeType.DETACH)
|
||||
@ManyToMany(
|
||||
mappedBy = "switchables",
|
||||
cascade = {
|
||||
CascadeType.DETACH,
|
||||
CascadeType.MERGE,
|
||||
CascadeType.REFRESH,
|
||||
CascadeType.PERSIST
|
||||
})
|
||||
@GsonExclude
|
||||
@SocketGsonExclude
|
||||
private Set<Switch> inputs = new HashSet<>();
|
||||
|
|
|
@ -206,13 +206,20 @@ public class DeviceService {
|
|||
return device;
|
||||
}
|
||||
|
||||
public void delete(Long id, String username) throws NotFoundException {
|
||||
Device device =
|
||||
public void deleteByIdAsOwner(Long id, String username) throws NotFoundException {
|
||||
Device d =
|
||||
deviceRepository
|
||||
.findByIdAndUsername(id, username)
|
||||
.orElseThrow(NotFoundException::new);
|
||||
deviceRepository.delete(device);
|
||||
|
||||
propagateUpdateAsOwner(device, username, false);
|
||||
final User user = userRepository.findByUsername(username);
|
||||
final Set<User> guests = user.getGuests();
|
||||
// make sure we're broadcasting from host
|
||||
for (final User guest : guests) {
|
||||
// broadcast to endpoint the object device, with receiving user set to guest
|
||||
endpoint.queueDeviceUpdate(d, guest, false, user.getId(), true);
|
||||
}
|
||||
|
||||
deviceRepository.delete(d);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue