Example #1
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;
  }
Example #2
0
 /**
  * Saves an Area to the database.
  *
  * @param area the Area to be saved
  * @return true if Area was successfully saved, false otherwise
  */
 public boolean saveArea(Area area) {
   if ((area != null) && (findAreaByName(area.getName()) == null)) {
     areaRepository.save(area);
     return true;
   }
   return false;
 }
Example #3
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;
  }
Example #4
0
 public Area findAreaByName(String name) {
   return areaRepository.findByName(name);
 }
Example #5
0
 public Area findAreaById(Long id) {
   return areaRepository.findOne(id);
 }
Example #6
0
 public List<Area> findAllPublicAreas() {
   return areaRepository.findByVisibilityTrue();
 }
Example #7
0
 public List<Area> findAllAreas() {
   return areaRepository.findAll();
 }
Example #8
0
 /**
  * Deletes an Area subscription from a Person.
  *
  * @param person person whose subscription will be deleted
  * @param area which area will be un-subscribed
  */
 public void deleteSubcriptions(Person person, Area area) {
   List<Person> subscribers = area.getSubscribers();
   subscribers.remove(person);
   area.setSubscribers(subscribers);
   areaRepository.save(area);
 }
Example #9
0
 /**
  * Returns a list of the Areas that a Person owns.
  *
  * @param person whose areas will be found
  * @return list of Areas
  */
 public List<Area> findAreasByOwner(Person person) {
   return areaRepository.findByOwner(person);
 }
Example #10
0
 /**
  * Deletes all Areas from the repository.
  *
  * @return true if Area repository is now empty, false if not
  */
 public boolean deleteAllAreas() {
   areaRepository.deleteAll();
   return findAllAreas().isEmpty();
 }
Example #11
0
 /**
  * Goes through the list of areas that an element has a database connection to, and removes any
  * connections from the areas to the element -- but not from the element to the areas.
  *
  * @param element on which connections will be removed
  */
 public void deleteElementFromAreas(Element element) {
   for (Area area : element.getAreas()) {
     area.deleteElement(element);
     areaRepository.save(area);
   }
 }
Example #12
0
 /**
  * Goes through the list of areas that an element has a database connection to, and makes sure the
  * areas also have a connection to the element.
  *
  * @param element the element that connections will be checked on
  */
 public void saveContentToAreas(Element element) {
   for (Area area : element.getAreas()) {
     area.addElement(element);
     areaRepository.save(area);
   }
 }