Subversion Repositories WebE

Compare Revisions

Last modification

Ignore whitespace Rev 35 → Rev 34

/trunk/src/ch/ffhs/webE/action/RelationshipAction.java
49,26 → 49,9
*/
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)
*
80,20 → 63,19
}
 
/**
* DB query for relationship list
* Prepares to add a relationship
*
* @return SUCCESS
* @return
*/
public String list()
public String add()
{
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 relationship
* Executes the DB query to save the user
*
* @return {@link Action#SUCCESS}
*/
106,33 → 88,33
this.relationship.setRelationshipType(this.relationshipTypeDAO
.getRelTypeById(Integer.parseInt(this.request.getParameter("type"))));
 
User user = this.userDAO.searchUsername((String) this.session
.get("username"));
 
if ("false".equals(this.request.getParameter("edit")))
if (!"1".equals(this.request.getParameter("edit")))
{
/* Add a new relationship */
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);
this.added = true;
}
 
this.edit = false;
 
String result = Action.SUCCESS;
if (!this.relationshipDAO.saveOrUpdate(this.relationship))
if (this.relationshipDAO.saveOrUpdate(this.relationship))
{
result = Action.ERROR;
return Action.SUCCESS;
}
 
this.setModifiedRelationship(this.relationship);
this.setRelationship(null);
return Action.ERROR;
}
 
this.list();
 
return result;
/**
* DB query for relationship list
*
* @return SUCCESS
*/
public String list()
{
this.relationshipList = this.relationshipDAO.listRelationships();
return Action.SUCCESS;
}
 
/**
143,20 → 125,36
{
int id = this.getIdParameter();
 
String result = Action.ERROR;
if (id > 0)
{
this.setRelationship(this.relationshipDAO.getRelationshipById(id));
if (this.getRelationship() != null)
this.relationship = this.relationshipDAO.getRelationshipById(id);
if (this.relationship != null)
{
this.edit = true;
result = Action.SUCCESS;
return Action.SUCCESS;
}
}
 
this.list();
return Action.ERROR;
}
 
return result;
/**
* 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;
}
 
/**
167,46 → 165,25
*/
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
{
result = Action.ERROR;
return Action.ERROR;
}
 
this.list();
 
return result;
}
 
/**
* Gets the ID Parameter for update / delete requests
*
* @return int from the ID request. If not set or wrong, it gives back -1
/*
* Standard getters and setters
*/
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
*/
274,21 → 251,4
{
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;
}
}
/trunk/src/ch/ffhs/webE/action/TermAction.java
40,25 → 40,9
*/
Map<String, Object> session = ActionContext.getContext().getSession();
 
/**
* @var <code>true</code> if the term is edited/renamed, <code>false</code>
* otherwise
*/
public boolean edit = false;
 
/**
* @var <code>true</code> if a term 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)
*/
public Term savedTerm;
 
/*
* (non-Javadoc)
*
70,17 → 54,6
}
 
/**
* DB query for term list
*
* @return SUCCESS
*/
public String list()
{
this.termList = this.termDAO.getTerms();
return Action.SUCCESS;
}
 
/**
* Executes the DB query to save the user
*
* @return {@link Action#SUCCESS}
87,33 → 60,33
*/
public String save()
{
User user = this.userDAO.searchUsername((String) this.session
.get("username"));
 
if ("false".equals(this.request.getParameter("edit")))
if (!"1".equals(this.request.getParameter("edit")))
{
/* Add a new term */
User user = this.userDAO.searchUsername((String) this.session
.get("username"));
ObjectEntity obj = new ObjectEntity(user,
new ObjectType(ObjectType.TERM), user, null, new Date(), false,
this.term, null, null);
this.term.setObject(obj);
this.added = true;
}
 
this.edit = false;
 
String result = Action.SUCCESS;
if (!this.termDAO.saveOrUpdate(this.term))
if (this.termDAO.saveOrUpdate(this.term))
{
result = Action.ERROR;
return Action.SUCCESS;
}
 
this.savedTerm = this.term;
this.term = null;
return Action.ERROR;
}
 
this.list();
 
return result;
/**
* DB query for term list
*
* @return SUCCESS
*/
public String list()
{
this.termList = this.termDAO.getTerms();
return Action.SUCCESS;
}
 
/**
124,24 → 97,41
{
int id = this.getIdParameter();
 
String result = Action.ERROR;
if (id > 0)
{
this.term = this.termDAO.getTermById(id);
if (this.term != null)
{
this.edit = true;
result = Action.SUCCESS;
this.term.edit = true;
return Action.SUCCESS;
}
}
 
this.list();
return Action.ERROR;
}
 
return result;
/**
* 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 term, gets the ID from the "id" parameter that was submitted with
* deletes a user, gets the ID from the "id" parameter that was submitted with
* the HTTP request
*
* @return String - either SUCCESS or ERROR constant
152,43 → 142,21
int id = this.getIdParameter();
 
/* Check for malicious ID values */
String result = Action.SUCCESS;
if (id > 0)
{
this.termDAO.deleteTerm(id);
return Action.SUCCESS;
}
else
{
result = Action.ERROR;
return Action.ERROR;
}
 
this.list();
 
return result;
}
 
/**
* Gets the ID Parameter for update / delete requests
*
* @return int from the ID request. If not set or wrong, it gives back -1
/*
* Standard getters and setters
*/
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 term edited with this instance
*/