public void removeOwner(Long id, String username) {
   User user = userService.findOne(username);
   Device device = findOneForCurrentUser(id);
   Set<User> owners = device.getOwners();
   owners.remove(user);
   deviceRepository.save(device);
 }
 public Device addOwner(Long id, String username) {
   User user = userService.findOne(username);
   Device device = findOneForCurrentUser(id);
   Set<User> owners = device.getOwners();
   owners.add(user);
   deviceRepository.save(device);
   return device;
 }
 public Alert addAlert(Long id, AlertDTO alertDTO) {
   Device device = findOneForCurrentUser(id);
   Alert alert =
       new Alert(
           device,
           alertDTO.getDescription(),
           alertDTO.getAfter(),
           alertDTO.getBefore(),
           alertDTO.getFields());
   List<Alert> alerts = device.getAlerts();
   alerts.add(alert);
   deviceRepository.save(device);
   return alert;
 }
  public Track addTrack(TrackDTO trackDTO) {
    Device device = findOne(trackDTO.getDeviceId());

    Track track =
        new Track(
            device,
            trackDTO.getFields(),
            trackDTO.getLocation(),
            trackDTO.getReceivedAt(),
            trackDTO.getRecordedAt());

    device.getTracks().add(track);

    deviceRepository.save(device);

    return track;
  }