4,15 → 4,19 |
import java.util.Date; |
import java.util.List; |
import java.util.Map; |
import java.util.Set; |
|
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.dao.HistoryDAO; |
import ch.ffhs.webE.dao.RelationshipDAO; |
import ch.ffhs.webE.dao.RelationshipTypeDAO; |
import ch.ffhs.webE.dao.TermDAO; |
import ch.ffhs.webE.dao.UserDAO; |
import ch.ffhs.webE.domain.ActionType; |
import ch.ffhs.webE.domain.History; |
import ch.ffhs.webE.domain.ObjectEntity; |
import ch.ffhs.webE.domain.ObjectType; |
import ch.ffhs.webE.domain.Relationship; |
36,15 → 40,27 |
private static final long serialVersionUID = 1L; |
|
private List<RelationshipType> relationshipTypes = new ArrayList<RelationshipType>(); |
private final RelationshipTypeDAOImpl relationshipTypeDAO = new RelationshipTypeDAOImpl(); |
private final RelationshipTypeDAO relationshipTypeDAO = new RelationshipTypeDAO(); |
|
private List<Term> terms = new ArrayList<Term>(); |
private final TermDAOImpl termDAO = new TermDAOImpl(); |
private final TermDAO termDAO = new TermDAO(); |
|
private List<Relationship> relationshipList = new ArrayList<Relationship>(); |
private final RelationshipDAOImpl relationshipDAO = new RelationshipDAOImpl(); |
private final UserDAOImpl userDAO = new UserDAOImpl(); |
private Relationship relationship = new Relationship(); |
|
/** |
* The term that was just saved (added, renamed) |
*/ |
private Relationship modifiedRelationship; |
|
private final RelationshipDAO relationshipDAO = new RelationshipDAO(); |
|
private final UserDAO userDAO = new UserDAO(); |
|
private Set<History> history; |
private final HistoryDAO historyDAO = new HistoryDAO(); |
|
/** |
* Session object |
*/ |
Map<String, Object> session = ActionContext.getContext().getSession(); |
64,11 → 80,6 |
private final HttpServletRequest request = (HttpServletRequest) ActionContext |
.getContext().get(StrutsStatics.HTTP_REQUEST); |
|
/** |
* The term that was just saved (added, renamed) |
*/ |
private Relationship modifiedRelationship; |
|
/* |
* (non-Javadoc) |
* |
86,9 → 97,9 |
*/ |
public String list() |
{ |
this.setTerms(this.termDAO.getTerms()); |
this.setRelationshipTypes(this.relationshipTypeDAO.getRelTypes()); |
this.setRelationshipList(this.relationshipDAO.getRelationshipList()); |
this.setTerms(this.termDAO.getList()); |
this.setRelationshipTypes(this.relationshipTypeDAO.getList()); |
this.setRelationshipList(this.relationshipDAO.getList()); |
return Action.SUCCESS; |
} |
|
99,31 → 110,51 |
*/ |
public String save() |
{ |
this.relationship.setTermFrom(this.termDAO.getTermById(Integer |
this.relationship.setTermFrom(this.termDAO.getById(Integer |
.parseInt(this.request.getParameter("term1")))); |
this.relationship.setTermTo(this.termDAO.getTermById(Integer |
this.relationship.setTermTo(this.termDAO.getById(Integer |
.parseInt(this.request.getParameter("term2")))); |
this.relationship.setRelationshipType(this.relationshipTypeDAO |
.getRelTypeById(Integer.parseInt(this.request.getParameter("type")))); |
.getById(Integer.parseInt(this.request.getParameter("type")))); |
|
User user = this.userDAO.searchUsername((String) this.session |
User user = this.userDAO.getByUsername((String) this.session |
.get("username")); |
Date now = new Date(); |
ObjectEntity obj; |
int action = 0; |
|
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); |
obj = new ObjectEntity(user, new ObjectType(ObjectType.RELATIONSHIP), |
user, null, new Date(), false, null, null, this.relationship); |
this.relationship.setObject(obj); |
this.added = true; |
action = ActionType.ADD; |
} |
else |
{ |
obj = new ObjectEntity(); |
obj.setId(this.relationship.getObjectId()); |
action = ActionType.MODIFY; |
} |
|
this.edit = false; |
|
String result = Action.SUCCESS; |
if (!this.relationshipDAO.saveOrUpdate(this.relationship)) |
if (this.relationshipDAO.saveOrUpdate(this.relationship)) |
{ |
String comment = this.request.getParameter("comment"); |
|
History historyRecord = new History(user, new ActionType(action), obj, |
"(" + this.relationship.getTermFrom().getName() + ") (" |
+ this.relationship.getRelationshipType().getNameFrom() + ") (" |
+ this.relationship.getTermTo().getName() + ")", comment, now); |
|
this.historyDAO.saveOrUpdate(historyRecord); |
} |
else |
{ |
result = Action.ERROR; |
} |
|
146,7 → 177,7 |
String result = Action.ERROR; |
if (id > 0) |
{ |
this.setRelationship(this.relationshipDAO.getRelationshipById(id)); |
this.setRelationship(this.relationshipDAO.getById(id)); |
if (this.getRelationship() != null) |
{ |
this.edit = true; |
173,7 → 204,7 |
String result = Action.SUCCESS; |
if (id > 0) |
{ |
this.relationshipDAO.deleteRelationship(id); |
this.relationshipDAO.delete(id); |
} |
else |
{ |
291,4 → 322,21 |
{ |
this.modifiedRelationship = modifiedRelationship; |
} |
|
/** |
* @return the history |
*/ |
public Set<History> getHistory() |
{ |
return this.history; |
} |
|
/** |
* @param history |
* the history to set |
*/ |
public void setHistory(Set<History> history) |
{ |
this.history = history; |
} |
} |