Beispiel #1
0
  /**
   * Goes through all the Areas a user has subscribed to and creates a list of contents published in
   * those areas, ordered by their modification times.
   *
   * @param person the person whose subscriptions will be used
   * @return list of the content in chronological order
   */
  public List<Content> createListOfSubscribedContents(Person person) {
    List<Content> newList = new ArrayList<>();

    // Builds new list without duplicates
    person
        .getSubscriptions()
        .stream()
        .forEach(
            (area) -> {
              area.getElements()
                  .stream()
                  .filter((content) -> (!newList.contains(content)))
                  .forEach(
                      (content) -> {
                        newList.add((Content) content);
                      });
            });

    // sorts new list to chronological order. Newest first.
    newList.sort(
        (Content x, Content y) -> {
          return y.getModifyTime().compareTo(x.getModifyTime());
        });

    return newList;
  }
Beispiel #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;
  }
Beispiel #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;
  }