0,0 → 1,254 |
package ch.ffhs.webE.action; |
|
import java.util.ArrayList; |
import java.util.Date; |
import java.util.List; |
import java.util.Map; |
|
import javax.servlet.http.HttpServletRequest; |
|
import org.apache.struts2.StrutsStatics; |
|
import ch.ffhs.webE.dao.RelationshipDAOImpl; |
import ch.ffhs.webE.dao.RelationshipTypeDAOImpl; |
import ch.ffhs.webE.dao.TermDAOImpl; |
import ch.ffhs.webE.dao.UserDAOImpl; |
import ch.ffhs.webE.domain.ObjectEntity; |
import ch.ffhs.webE.domain.ObjectType; |
import ch.ffhs.webE.domain.Relationship; |
import ch.ffhs.webE.domain.RelationshipType; |
import ch.ffhs.webE.domain.Term; |
import ch.ffhs.webE.domain.User; |
|
import com.opensymphony.xwork2.Action; |
import com.opensymphony.xwork2.ActionContext; |
import com.opensymphony.xwork2.ActionSupport; |
import com.opensymphony.xwork2.ModelDriven; |
|
/** |
* Implements actions applicable to relationship editing |
* |
* @author Thomas Lahn |
*/ |
public class RelationshipAction extends ActionSupport implements |
ModelDriven<Relationship> |
{ |
private static final long serialVersionUID = 1L; |
|
private List<RelationshipType> relationshipTypes = new ArrayList<RelationshipType>(); |
private final RelationshipTypeDAOImpl relationshipTypeDAO = new RelationshipTypeDAOImpl(); |
private List<Term> terms = new ArrayList<Term>(); |
private final TermDAOImpl termDAO = new TermDAOImpl(); |
private List<Relationship> relationshipList = new ArrayList<Relationship>(); |
private final RelationshipDAOImpl relationshipDAO = new RelationshipDAOImpl(); |
private final UserDAOImpl userDAO = new UserDAOImpl(); |
private Relationship relationship = new Relationship(); |
|
/** |
* Session object |
*/ |
Map<String, Object> session = ActionContext.getContext().getSession(); |
|
private final HttpServletRequest request = (HttpServletRequest) ActionContext |
.getContext().get(StrutsStatics.HTTP_REQUEST); |
|
/* |
* (non-Javadoc) |
* |
* @see com.opensymphony.xwork2.ModelDriven#getModel() |
*/ |
public Relationship getModel() |
{ |
return this.relationship; |
} |
|
/** |
* Prepares to add a relationship |
* |
* @return |
*/ |
public String add() |
{ |
this.setTerms(this.termDAO.getTerms()); |
this.setRelationshipTypes(this.relationshipTypeDAO.getRelTypes()); |
return Action.SUCCESS; |
} |
|
/** |
* Executes the DB query to save the user |
* |
* @return {@link Action#SUCCESS} |
*/ |
public String save() |
{ |
this.relationship.setTermFrom(this.termDAO.getTermById(Integer |
.parseInt(this.request.getParameter("term1")))); |
this.relationship.setTermTo(this.termDAO.getTermById(Integer |
.parseInt(this.request.getParameter("term2")))); |
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")); |
ObjectEntity obj = new ObjectEntity(user, new ObjectType( |
ObjectType.RELATIONSHIP), user, null, new Date(), false, null, null, |
this.relationship); |
this.relationship.setObject(obj); |
} |
|
if (this.relationshipDAO.saveOrUpdate(this.relationship)) |
{ |
return Action.SUCCESS; |
} |
|
return Action.ERROR; |
} |
|
/** |
* DB query for relationship list |
* |
* @return SUCCESS |
*/ |
public String list() |
{ |
this.relationshipList = this.relationshipDAO.listRelationships(); |
return Action.SUCCESS; |
} |
|
/** |
* @return {@link Action#SUCCESS} if <var>id</var> > 0, {@link Action#ERROR} |
* otherwise |
*/ |
public String edit() |
{ |
int id = this.getIdParameter(); |
|
if (id > 0) |
{ |
this.relationship = this.relationshipDAO.getRelationshipById(id); |
if (this.relationship != null) |
{ |
return Action.SUCCESS; |
} |
} |
|
return Action.ERROR; |
} |
|
/** |
* 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; |
} |
|
/** |
* 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 = this.getIdParameter(); |
|
/* Check for malicious ID values */ |
if (id > 0) |
{ |
this.relationshipDAO.deleteRelationship(id); |
return Action.SUCCESS; |
} |
else |
{ |
return Action.ERROR; |
} |
} |
|
/* |
* Standard getters and setters |
*/ |
|
/** |
* @return The relationship edited with this instance |
*/ |
public Relationship getRelationship() |
{ |
return this.relationship; |
} |
|
/** |
* @param relationship |
* The relationship edited with this instance |
*/ |
public void setRelationship(Relationship relationship) |
{ |
this.relationship = relationship; |
} |
|
/** |
* @return The list of terms edited with this instance |
*/ |
public List<Relationship> getRelationshipList() |
{ |
return this.relationshipList; |
} |
|
/** |
* @param relationshipList |
* The list of terms edited with this instance |
*/ |
public void setRelationshipList(List<Relationship> relationshipList) |
{ |
this.relationshipList = relationshipList; |
} |
|
/** |
* @return the relationshipTypes |
*/ |
public List<RelationshipType> getRelationshipTypes() |
{ |
return this.relationshipTypes; |
} |
|
/** |
* @param relationshipTypes |
* the relationshipTypes to set |
*/ |
public void setRelationshipTypes(List<RelationshipType> relationshipTypes) |
{ |
this.relationshipTypes = relationshipTypes; |
} |
|
/** |
* @return the terms |
*/ |
public List<Term> getTerms() |
{ |
return this.terms; |
} |
|
/** |
* @param terms |
* the terms to set |
*/ |
public void setTerms(List<Term> terms) |
{ |
this.terms = terms; |
} |
} |
Property changes: |
Added: svn:mime-type |
## -0,0 +1 ## |
+text/plain |
\ No newline at end of property |
Index: RelationshipTypeAction.java |
=================================================================== |
--- RelationshipTypeAction.java (revision 33) |
+++ RelationshipTypeAction.java (revision 34) |
@@ -5,12 +5,13 @@ |
import javax.servlet.http.HttpServletRequest; |
|
-import org.apache.struts2.ServletActionContext; |
+import org.apache.struts2.StrutsStatics; |
|
import ch.ffhs.webE.dao.RelationshipTypeDAO; |
import ch.ffhs.webE.dao.RelationshipTypeDAOImpl; |
import ch.ffhs.webE.domain.RelationshipType; |
|
+import com.opensymphony.xwork2.Action; |
import com.opensymphony.xwork2.ActionContext; |
import com.opensymphony.xwork2.ActionSupport; |
import com.opensymphony.xwork2.ModelDriven; |
@@ -23,38 +24,38 @@ |
|
private RelationshipType relType = new RelationshipType(); |
private List<RelationshipType> relTypeList = new ArrayList<RelationshipType>(); |
- private RelationshipTypeDAO relTypeDAO = new RelationshipTypeDAOImpl(); |
+ private final RelationshipTypeDAO relTypeDAO = new RelationshipTypeDAOImpl(); |
|
@Override |
public RelationshipType getModel() |
{ |
- return relType; |
+ return this.relType; |
} |
|
public String addOrUpdate() |
{ |
- relTypeDAO.saveOrUpdateRelType(relType); |
- return SUCCESS; |
+ this.relTypeDAO.saveOrUpdateRelType(this.relType); |
+ return Action.SUCCESS; |
} |
|
public String list() |
{ |
- relTypeList = relTypeDAO.listRelationshipTypes(); |
- return SUCCESS; |
+ this.relTypeList = this.relTypeDAO.getRelTypes(); |
+ return Action.SUCCESS; |
} |
|
public String edit() |
{ |
- int id = getIdParameter(); |
+ int id = this.getIdParameter(); |
|
if (id > 0) |
{ |
- relType = relTypeDAO.listRelTypeById(id); |
- return SUCCESS; |
+ this.relType = this.relTypeDAO.getRelTypeById(id); |
+ return Action.SUCCESS; |
} |
else |
{ |
- return ERROR; |
+ return Action.ERROR; |
} |
} |
|
@@ -66,7 +67,7 @@ |
private int getIdParameter() |
{ |
HttpServletRequest request = (HttpServletRequest) ActionContext |
- .getContext().get(ServletActionContext.HTTP_REQUEST); |
+ .getContext().get(StrutsStatics.HTTP_REQUEST); |
|
int id = -1; |
try |
@@ -89,17 +90,17 @@ |
*/ |
public String delete() |
{ |
- int id = getIdParameter(); |
+ int id = this.getIdParameter(); |
|
// Check for malicious ID values |
if (id > 0) |
{ |
- relTypeDAO.deleteRelationshipType(id); |
- return SUCCESS; |
+ this.relTypeDAO.deleteRelationshipType(id); |
+ return Action.SUCCESS; |
} |
else |
{ |
- return ERROR; |
+ return Action.ERROR; |
} |
} |
|
@@ -109,7 +110,7 @@ |
|
public RelationshipType getRelType() |
{ |
- return relType; |
+ return this.relType; |
} |
|
public void setRelType(RelationshipType relType) |
@@ -119,7 +120,7 @@ |
|
public List<RelationshipType> getRelTypeList() |
{ |
- return relTypeList; |
+ return this.relTypeList; |
} |
|
public void setRelTypeList(List<RelationshipType> relTypeList) |