| 49,9 → 49,26 |
| */ |
| Map<String, Object> session = ActionContext.getContext().getSession(); |
| |
| /** |
| * @var <code>true</code> if the relationship is to be edited/renamed, |
| * <code>false</code> otherwise |
| */ |
| public boolean edit = false; |
| |
| /** |
| * @var <code>true</code> if a relationship was added, <code>false</code> |
| * otherwise |
| */ |
| public boolean added = false; |
| |
| private final HttpServletRequest request = (HttpServletRequest) ActionContext |
| .getContext().get(StrutsStatics.HTTP_REQUEST); |
| |
| /** |
| * The term that was just saved (added, renamed) |
| */ |
| private Relationship modifiedRelationship; |
| |
| /* |
| * (non-Javadoc) |
| * |
| 63,19 → 80,20 |
| } |
| |
| /** |
| * Prepares to add a relationship |
| * DB query for relationship list |
| * |
| * @return |
| * @return SUCCESS |
| */ |
| public String add() |
| public String list() |
| { |
| this.setTerms(this.termDAO.getTerms()); |
| this.setRelationshipTypes(this.relationshipTypeDAO.getRelTypes()); |
| this.setRelationshipList(this.relationshipDAO.getRelationshipList()); |
| return Action.SUCCESS; |
| } |
| |
| /** |
| * Executes the DB query to save the user |
| * Executes the DB query to save the relationship |
| * |
| * @return {@link Action#SUCCESS} |
| */ |
| 88,33 → 106,33 |
| this.relationship.setRelationshipType(this.relationshipTypeDAO |
| .getRelTypeById(Integer.parseInt(this.request.getParameter("type")))); |
| |
| if (!"1".equals(this.request.getParameter("edit"))) |
| { |
| User user = this.userDAO.searchUsername((String) this.session |
| .get("username")); |
| |
| if ("false".equals(this.request.getParameter("edit"))) |
| { |
| /* Add a new relationship */ |
| ObjectEntity obj = new ObjectEntity(user, new ObjectType( |
| ObjectType.RELATIONSHIP), user, null, new Date(), false, null, null, |
| this.relationship); |
| this.relationship.setObject(obj); |
| this.added = true; |
| } |
| |
| if (this.relationshipDAO.saveOrUpdate(this.relationship)) |
| this.edit = false; |
| |
| String result = Action.SUCCESS; |
| if (!this.relationshipDAO.saveOrUpdate(this.relationship)) |
| { |
| return Action.SUCCESS; |
| result = Action.ERROR; |
| } |
| |
| return Action.ERROR; |
| } |
| this.setModifiedRelationship(this.relationship); |
| this.setRelationship(null); |
| |
| /** |
| * DB query for relationship list |
| * |
| * @return SUCCESS |
| */ |
| public String list() |
| { |
| this.relationshipList = this.relationshipDAO.listRelationships(); |
| return Action.SUCCESS; |
| this.list(); |
| |
| return result; |
| } |
| |
| /** |
| 125,38 → 143,22 |
| { |
| int id = this.getIdParameter(); |
| |
| String result = Action.ERROR; |
| if (id > 0) |
| { |
| this.relationship = this.relationshipDAO.getRelationshipById(id); |
| if (this.relationship != null) |
| this.setRelationship(this.relationshipDAO.getRelationshipById(id)); |
| if (this.getRelationship() != null) |
| { |
| return Action.SUCCESS; |
| this.edit = true; |
| result = Action.SUCCESS; |
| } |
| } |
| |
| return Action.ERROR; |
| } |
| this.list(); |
| |
| /** |
| * Gets the ID Parameter for update / delete requests |
| * |
| * @return int from the ID request. If not set or wrong, it gives back -1 |
| */ |
| private int getIdParameter() |
| { |
| int id = -1; |
| try |
| { |
| id = Integer.parseInt(this.request.getParameter("id")); //$NON-NLS-1$ |
| return result; |
| } |
| catch (Exception e) |
| { |
| /* TODO: Logging - wrong parameter set */ |
| } |
| |
| return id; |
| } |
| |
| /** |
| * deletes a user, gets the ID from the "id" parameter that was submitted with |
| * the HTTP request |
| 165,25 → 167,46 |
| */ |
| public String delete() |
| { |
| |
| int id = this.getIdParameter(); |
| |
| /* Check for malicious ID values */ |
| String result = Action.SUCCESS; |
| if (id > 0) |
| { |
| this.relationshipDAO.deleteRelationship(id); |
| return Action.SUCCESS; |
| } |
| else |
| { |
| return Action.ERROR; |
| result = Action.ERROR; |
| } |
| |
| this.list(); |
| |
| return result; |
| } |
| |
| /* |
| * Standard getters and setters |
| /** |
| * Gets the ID Parameter for update / delete requests |
| * |
| * @return int from the ID request. If not set or wrong, it gives back -1 |
| */ |
| private int getIdParameter() |
| { |
| int id = -1; |
| try |
| { |
| id = Integer.parseInt(this.request.getParameter("id")); //$NON-NLS-1$ |
| } |
| catch (Exception e) |
| { |
| /* TODO: Logging - wrong parameter set */ |
| } |
| |
| return id; |
| } |
| |
| /* Standard getters and setters */ |
| |
| /** |
| * @return The relationship edited with this instance |
| */ |
| 251,4 → 274,21 |
| { |
| this.terms = terms; |
| } |
| |
| /** |
| * @return the modifiedRelationship |
| */ |
| public Relationship getModifiedRelationship() |
| { |
| return this.modifiedRelationship; |
| } |
| |
| /** |
| * @param modifiedRelationship |
| * the modifiedRelationship to set |
| */ |
| public void setModifiedRelationship(Relationship modifiedRelationship) |
| { |
| this.modifiedRelationship = modifiedRelationship; |
| } |
| } |