40,9 → 40,25 |
*/ |
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) |
* |
54,6 → 70,17 |
} |
|
/** |
* 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} |
60,33 → 87,33 |
*/ |
public String save() |
{ |
if (!"1".equals(this.request.getParameter("edit"))) |
User user = this.userDAO.searchUsername((String) this.session |
.get("username")); |
|
if ("false".equals(this.request.getParameter("edit"))) |
{ |
User user = this.userDAO.searchUsername((String) this.session |
.get("username")); |
/* Add a new term */ |
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; |
} |
|
if (this.termDAO.saveOrUpdate(this.term)) |
this.edit = false; |
|
String result = Action.SUCCESS; |
if (!this.termDAO.saveOrUpdate(this.term)) |
{ |
return Action.SUCCESS; |
result = Action.ERROR; |
} |
|
return Action.ERROR; |
} |
this.savedTerm = this.term; |
this.term = null; |
|
/** |
* DB query for term list |
* |
* @return SUCCESS |
*/ |
public String list() |
{ |
this.termList = this.termDAO.getTerms(); |
return Action.SUCCESS; |
this.list(); |
|
return result; |
} |
|
/** |
97,41 → 124,24 |
{ |
int id = this.getIdParameter(); |
|
String result = Action.ERROR; |
if (id > 0) |
{ |
this.term = this.termDAO.getTermById(id); |
if (this.term != null) |
{ |
this.term.edit = true; |
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$ |
} |
catch (Exception e) |
{ |
/* TODO: Logging - wrong parameter set */ |
} |
|
return id; |
return result; |
} |
|
/** |
* deletes a user, gets the ID from the "id" parameter that was submitted with |
* deletes a term, gets the ID from the "id" parameter that was submitted with |
* the HTTP request |
* |
* @return String - either SUCCESS or ERROR constant |
142,21 → 152,43 |
int id = this.getIdParameter(); |
|
/* Check for malicious ID values */ |
String result = Action.SUCCESS; |
if (id > 0) |
{ |
this.termDAO.deleteTerm(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 term edited with this instance |
*/ |