user and relationship type now editable and removeable. Generic error page for admin site
| /trunk/src/ch/ffhs/webE/dao/UserDAO.java |
|---|
| 4,10 → 4,16 |
| import ch.ffhs.webE.domain.User; |
| public interface UserDAO { |
| public interface UserDAO |
| { |
| List<User> listUser(); |
| void saveUser(User user); |
| User searchUsername(String username); |
| void deleteUser(int userId); |
| List<User> listUser(); |
| User searchUsername(String username); |
| void deleteUser(int userId); |
| User listUserById(int userId); |
| void saveOrUpdateUser(User user); |
| } |
| /trunk/src/ch/ffhs/webE/dao/UserDAOImpl.java |
|---|
| 38,7 → 38,8 |
| e.printStackTrace(); |
| } |
| //If no user was checked, return an empty list to mitigate null pointer exceptions |
| // If no user was checked, return an empty list to mitigate null pointer |
| // exceptions |
| if (user == null) |
| { |
| user = new ArrayList<User>(); |
| 54,11 → 55,11 |
| * @return void |
| */ |
| @Override |
| public void saveUser(User user) |
| public void saveOrUpdateUser(User user) |
| { |
| try |
| { |
| session.save(user); |
| session.saveOrUpdate(user); |
| } |
| catch (Exception e) |
| { |
| 99,7 → 100,7 |
| { |
| User user = null; |
| //Exec query |
| // Exec query |
| try |
| { |
| user = (User) session |
| 112,4 → 113,22 |
| } |
| return user; |
| } |
| } |
| /** |
| * Used to list a single user by Id. |
| */ |
| @Override |
| public User listUserById(int userId) |
| { |
| User user = null; |
| try |
| { |
| user = (User) session.get(User.class, userId); |
| } |
| catch (Exception e) |
| { |
| e.printStackTrace(); |
| } |
| return user; |
| } |
| } |
| /trunk/src/ch/ffhs/webE/dao/RelationshipTypeDAO.java |
|---|
| 8,8 → 8,9 |
| List<RelationshipType> listRelationshipTypes(); |
| boolean saveRelationshipType(RelationshipType relType); |
| boolean deleteRelationshipType(int relTypeID); |
| RelationshipType listRelTypeById(int relTypeID); |
| boolean saveOrUpdateRelType(RelationshipType relType); |
| } |
| /trunk/src/ch/ffhs/webE/dao/RelationshipTypeDAOImpl.java |
|---|
| 57,11 → 57,11 |
| * relationshipType |
| */ |
| @Override |
| public boolean saveRelationshipType(RelationshipType relType) |
| public boolean saveOrUpdateRelType(RelationshipType relType) |
| { |
| try |
| { |
| session.save(relType); |
| session.saveOrUpdate(relType); |
| return true; |
| } |
| catch (Exception e) |
| 83,8 → 83,9 |
| { |
| try |
| { |
| User user = (User) session.get(RelationshipType.class, relTypeID); |
| session.delete(user); |
| RelationshipType relType = (RelationshipType) session.get( |
| RelationshipType.class, relTypeID); |
| session.delete(relType); |
| return true; |
| } |
| catch (Exception e) |
| 94,4 → 95,24 |
| return false; |
| } |
| } |
| /** |
| * Used to get a relationship type by ID |
| */ |
| @Override |
| public RelationshipType listRelTypeById(int relTypeID) |
| { |
| RelationshipType relType = null; |
| try |
| { |
| relType = (RelationshipType) session.get(RelationshipType.class, |
| relTypeID); |
| } |
| catch (Exception e) |
| { |
| e.printStackTrace(); |
| // TODO: Logging |
| } |
| return relType; |
| } |
| } |
| /trunk/src/ch/ffhs/webE/action/RelationshipTypeAction.java |
|---|
| 31,9 → 31,9 |
| return relType; |
| } |
| public String add() |
| public String addOrUpdate() |
| { |
| relTypeDAO.saveRelationshipType(relType); |
| relTypeDAO.saveOrUpdateRelType(relType); |
| return SUCCESS; |
| } |
| 42,21 → 42,33 |
| relTypeList = relTypeDAO.listRelationshipTypes(); |
| return SUCCESS; |
| } |
| public String edit() |
| { |
| int id = getIdParameter(); |
| if (id > 0) |
| { |
| relType = relTypeDAO.listRelTypeById(id); |
| return SUCCESS; |
| } |
| else |
| { |
| return ERROR; |
| } |
| } |
| /** |
| * deletes a relationshipType, gets the ID from the id parameter that was |
| * submitted |
| * Gets the ID Parameter for update / delete requests |
| * |
| * @return String - either success or error |
| * @return int from the ID request. If not set or wrong, it gives back -1 |
| */ |
| public String delete() |
| private int getIdParameter() |
| { |
| HttpServletRequest request = (HttpServletRequest) ActionContext |
| .getContext().get(ServletActionContext.HTTP_REQUEST); |
| //Make sure the ID from the request parameter is valid |
| int id = 0; |
| int id = -1; |
| try |
| { |
| id = Integer.parseInt(request.getParameter("id")); |
| 63,9 → 75,22 |
| } |
| catch (Exception e) |
| { |
| return ERROR; |
| // TODO: Logging - wrong parameter set |
| } |
| return id; |
| } |
| /** |
| * deletes a relationshipType, gets the ID from the id parameter that was |
| * submitted |
| * |
| * @return String - either success or error |
| */ |
| public String delete() |
| { |
| int id = getIdParameter(); |
| // Check for malicious ID values |
| if (id > 0) |
| { |
| /trunk/src/ch/ffhs/webE/action/UserAction.java |
|---|
| 35,9 → 35,9 |
| * |
| * @return |
| */ |
| public String add() |
| public String addOrUpdate() |
| { |
| userDAO.saveUser(user); |
| userDAO.saveOrUpdateUser(user); |
| return SUCCESS; |
| } |
| 52,19 → 52,32 |
| return SUCCESS; |
| } |
| public String edit() |
| { |
| int id = getIdParameter(); |
| if (id > 0) |
| { |
| user = userDAO.listUserById(id); |
| return SUCCESS; |
| } |
| else |
| { |
| return ERROR; |
| } |
| } |
| /** |
| * deletes a user, gets the ID from the "id" parameter that was submitted |
| * with the HTTP request |
| * Gets the ID Parameter for update / delete requests |
| * |
| * @return String - either SUCCESS or ERROR constant |
| * @return int from the ID request. If not set or wrong, it gives back -1 |
| */ |
| public String delete() |
| private int getIdParameter() |
| { |
| HttpServletRequest request = (HttpServletRequest) ActionContext |
| .getContext().get(ServletActionContext.HTTP_REQUEST); |
| int id = 0; |
| int id = -1; |
| try |
| { |
| id = Integer.parseInt(request.getParameter("id")); |
| 71,9 → 84,23 |
| } |
| catch (Exception e) |
| { |
| return ERROR; |
| // TODO: Logging - wrong parameter set |
| } |
| return id; |
| } |
| /** |
| * deletes a user, gets the ID from the "id" parameter that was submitted |
| * with the HTTP request |
| * |
| * @return String - either SUCCESS or ERROR constant |
| */ |
| public String delete() |
| { |
| int id = getIdParameter(); |
| // Check for malicious ID values |
| if (id > 0) |
| { |