示例#1
0
  /**
   * Creates a new area. Does NOT save the area to repository.
   *
   * @param name name of the area
   * @param person owner of the area
   * @param visibility is area visible for unauthenticated visitors
   * @return created Area
   */
  public Area createArea(String name, Person person, Boolean visibility) {
    Area area = new Area();
    area.setName(name);
    area.setOwner(person);
    area.setVisibility(visibility);
    area.setElements(new ArrayList<>());

    return area;
  }
示例#2
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;
  }
示例#3
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;
  }
示例#4
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;
 }
示例#5
0
 public boolean isPublic(Area area) {
   return area.getVisibility();
 }
示例#6
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);
 }
示例#7
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);
   }
 }
示例#8
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);
   }
 }