@RequestMapping(
      value = "/deleteAllHistoryRecords",
      method = {RequestMethod.POST})
  public ModelAndView execute(HttpServletRequest request) throws DBException, IOException {

    HttpSession session = request.getSession();
    User user = (User) session.getAttribute("user");
    Long userId = user.getId();

    historyRecordDAO.deleteAllHistoryRecordByUserId(userId);

    sessionService.updateSessionVariables(request);

    return new ModelAndView("redirect:/taskHistory");
  }
  @Test
  public void testCreate() throws DBException {
    User user = createUser("F", "L");

    userDAO.createNewUserInDatabase(user);

    User userFromDB = userDAO.getUserById(user.getUserId());
    assertNotNull(userFromDB);
    assertEquals(user.getUserId(), userFromDB.getUserId());
    assertEquals(user.getFirstName(), userFromDB.getFirstName());
    assertEquals(user.getLastName(), userFromDB.getLastName());
  }
  @RequestMapping(
      value = "deleteProperty/delete/{ID}",
      method = {RequestMethod.GET},
      headers = "Accept=*/*",
      produces = "application/json") // Ajax controller
  public @ResponseBody ModelAndView execute2(
      @PathVariable(value = "ID") Long ID, HttpServletRequest request) {
    HttpSession session = request.getSession();
    String userName = (String) session.getAttribute("userName");
    String userPassword = (String) session.getAttribute("userPassword");
    User user = new User();
    List<Property> clientProperties = new ArrayList<>();

    Property propertyToDelete = new Property();

    String message = "";

    try {
      propertyToDelete = propertyDao.findPropertyById(ID);
      List<PropertyOwner> owners = propertyToDelete.getPropertyOwners();
      List<Utility> utilities = propertyToDelete.getPropertyUtilities();
      List<Photo> photos = propertyToDelete.getPropertyPhotos();
      owners.clear();
      utilities.clear();
      photos.clear();
      propertyDao.delete(ID);
      message = "Property Nr." + ID + " deleted successfully!";
      user = userDao.findUserByCredentials(userName, userPassword);
      if (user != null) {
        clientProperties = propertyDao.findPropertyByClient(user);
        user.setListOfProperties(clientProperties);
      }
    } catch (DBException e) {
      System.out.println("Error!");
    }

    List<Property> propertiesOfThisUser = user.getListOfProperties();
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.addObject("model", propertiesOfThisUser);
    modelAndView.addObject("message", message);
    modelAndView.setViewName("/deleteSpecificProperty");

    return modelAndView;
  }
  @RequestMapping(
      value = "deleteProperty",
      method = {RequestMethod.GET}) // Ajax controller
  public ModelAndView execute(HttpServletRequest request) {

    HttpSession session = request.getSession();
    String userName = (String) session.getAttribute("userName");
    String userPassword = (String) session.getAttribute("userPassword");
    User user = new User();
    List<Property> clientProperties = new ArrayList<>();
    try {
      user = userDao.findUserByCredentials(userName, userPassword);
      if (user != null) {
        clientProperties = propertyDao.findPropertyByClient(user);
        user.setListOfProperties(clientProperties);
      }
    } catch (DBException e) {
      System.out.println("Error!");
    }

    List<Property> propertiesOfThisUser = user.getListOfProperties();
    return new ModelAndView("deleteSpecificProperty", "model", propertiesOfThisUser);
  }
 private User createUser(String firstName, String lastName) {
   User user = new User();
   user.setFirstName(firstName);
   user.setLastName(lastName);
   return user;
 }