Exemple #1
0
  /**
   * Updates an Area's attributes if the currently logged in user is the owner of the Area.
   *
   * @param areaId which area will be updated
   * @param name areas new name
   * @param visibility areas new visibility
   * @param whoIsLogged to check who is logged in
   * @return true if update was successful, false if not
   */
  public boolean updateArea(Long areaId, String name, boolean visibility, Person whoIsLogged) {
    Area area = findAreaById(areaId);
    if (whoIsLogged.getId() == area.getOwner().getId()) {
      area.setName(name);
      area.setVisibility(visibility);

      areaRepository.save(area);
      return true;
    }
    return false;
  }
Exemple #2
0
  /**
   * Deletes an Area if the currently logged in user is the owner of the Area.
   *
   * @param areaid which area will be deleted
   * @param whoIsLoggedIn to check who is logged in
   * @return true if deletion was successful, false if not
   */
  public boolean deleteArea(Long areaid, Person whoIsLoggedIn) {

    if (areaRepository.exists(areaid)) {

      Area area = areaRepository.findOne(areaid);
      if (area.getOwner().getId() == whoIsLoggedIn.getId()) {
        if (findAreaById(areaid).getElements().isEmpty()) {
          areaRepository.delete(areaid);
          return true;
        }
      }
      return false;
    }
    return false;
  }