/** * 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; }
/** * 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; }
/** * 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); } }
/** * 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); }
/** * 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); } }