* mainTemplate.jsp - Moved application name to back for better bookmarks * Terms.java - Added relationship links * Relationships: - Added term links * General: - Implemented history for term+relationship create and update (TODO: also for delete, using flag) - Removed unnecessary interfaces - Unifiorm method names in actions and DAO - Unified UI and actions (only one template for CRUD of an object) - Removed edit=false assignment in favor of redirection
/trunk/src/ch/ffhs/webE/action/RelationshipAction.java |
---|
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; |
} |
} |
/trunk/src/ch/ffhs/webE/action/RelationshipTypeAction.java |
---|
8,7 → 8,6 |
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; |
24,8 → 23,12 |
private RelationshipType relType = new RelationshipType(); |
private List<RelationshipType> relTypeList = new ArrayList<RelationshipType>(); |
private final RelationshipTypeDAO relTypeDAO = new RelationshipTypeDAOImpl(); |
private final RelationshipTypeDAO relTypeDAO = new RelationshipTypeDAO(); |
public boolean edit = false; |
public boolean added = false; |
public RelationshipType savedRelType; |
@Override |
public RelationshipType getModel() |
{ |
34,13 → 37,13 |
public String addOrUpdate() |
{ |
this.relTypeDAO.saveOrUpdateRelType(this.relType); |
this.relTypeDAO.saveOrUpdate(this.relType); |
return Action.SUCCESS; |
} |
public String list() |
{ |
this.relTypeList = this.relTypeDAO.getRelTypes(); |
this.relTypeList = this.relTypeDAO.getList(); |
return Action.SUCCESS; |
} |
48,16 → 51,18 |
{ |
int id = this.getIdParameter(); |
String result = Action.ERROR; |
if (id > 0) |
{ |
this.relType = this.relTypeDAO.getRelTypeById(id); |
return Action.SUCCESS; |
this.relType = this.relTypeDAO.getById(id); |
this.edit = true; |
result = Action.SUCCESS; |
} |
else |
{ |
return Action.ERROR; |
this.list(); |
return result; |
} |
} |
/** |
* Gets the ID Parameter for update / delete requests |
95,7 → 100,7 |
// Check for malicious ID values |
if (id > 0) |
{ |
this.relTypeDAO.deleteRelationshipType(id); |
this.relTypeDAO.delete(id); |
return Action.SUCCESS; |
} |
else |
/trunk/src/ch/ffhs/webE/action/TermAction.java |
---|
4,13 → 4,17 |
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.TermDAOImpl; |
import ch.ffhs.webE.dao.UserDAOImpl; |
import ch.ffhs.webE.dao.HistoryDAO; |
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.Term; |
32,8 → 36,8 |
private Term term = new Term(); |
private List<Term> termList = new ArrayList<Term>(); |
private final TermDAOImpl termDAO = new TermDAOImpl(); |
private final UserDAOImpl userDAO = new UserDAOImpl(); |
private final TermDAO termDAO = new TermDAO(); |
private final UserDAO userDAO = new UserDAO(); |
/** |
* Session object |
59,6 → 63,10 |
*/ |
public Term savedTerm; |
private final HistoryDAO historyDAO = new HistoryDAO(); |
private Set<History> history; |
/* |
* (non-Javadoc) |
* |
76,7 → 84,7 |
*/ |
public String list() |
{ |
this.termList = this.termDAO.getTerms(); |
this.termList = this.termDAO.getList(); |
return Action.SUCCESS; |
} |
87,24 → 95,41 |
*/ |
public String save() |
{ |
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 term */ |
ObjectEntity obj = new ObjectEntity(user, |
new ObjectType(ObjectType.TERM), user, null, new Date(), false, |
this.term, null, null); |
obj = new ObjectEntity(user, new ObjectType(ObjectType.TERM), user, null, |
now, false, this.term, null, null); |
this.term.setObject(obj); |
this.added = true; |
action = ActionType.ADD; |
} |
else |
{ |
obj = new ObjectEntity(); |
obj.setId(this.term.getObjectId()); |
action = ActionType.RENAME; |
} |
this.edit = false; |
String result = Action.SUCCESS; |
if (!this.termDAO.saveOrUpdate(this.term)) |
if (this.termDAO.saveOrUpdate(this.term)) |
{ |
String comment = this.request.getParameter("comment"); |
History historyRecord = new History(user, new ActionType(action), obj, |
this.term.getName(), comment, now); |
this.historyDAO.saveOrUpdate(historyRecord); |
} |
else |
{ |
result = Action.ERROR; |
} |
127,7 → 152,7 |
String result = Action.ERROR; |
if (id > 0) |
{ |
this.term = this.termDAO.getTermById(id); |
this.term = this.termDAO.getById(id); |
if (this.term != null) |
{ |
this.edit = true; |
155,7 → 180,7 |
String result = Action.SUCCESS; |
if (id > 0) |
{ |
this.termDAO.deleteTerm(id); |
this.termDAO.delete(id); |
} |
else |
{ |
222,4 → 247,21 |
{ |
this.termList = termList; |
} |
/** |
* @return the histories |
*/ |
public Set<History> getHistories() |
{ |
return this.history; |
} |
/** |
* @param histories |
* the histories to set |
*/ |
public void setHistories(Set<History> histories) |
{ |
this.history = histories; |
} |
} |
/trunk/src/ch/ffhs/webE/action/LoginAction.java |
---|
2,7 → 2,7 |
import java.util.Map; |
import ch.ffhs.webE.dao.UserDAOImpl; |
import ch.ffhs.webE.dao.UserDAO; |
import ch.ffhs.webE.domain.User; |
import com.opensymphony.xwork2.Action; |
15,7 → 15,7 |
private static final long serialVersionUID = 1799753056277211344L; |
private final User user = new User(); |
private final UserDAOImpl userDAO = new UserDAOImpl(); |
private final UserDAO userDAO = new UserDAO(); |
/* Form fields */ |
private String userName; |
84,7 → 84,7 |
public String verifyUser(String username, String password) |
{ |
// DB Query |
User u = this.userDAO.searchUsername(username); |
User u = this.userDAO.getByUsername(username); |
// User does not exist |
if (u == null) |
/trunk/src/ch/ffhs/webE/action/UserAction.java |
---|
7,7 → 7,7 |
import org.apache.struts2.StrutsStatics; |
import ch.ffhs.webE.dao.UserDAOImpl; |
import ch.ffhs.webE.dao.UserDAO; |
import ch.ffhs.webE.domain.User; |
import com.opensymphony.xwork2.Action; |
22,8 → 22,12 |
private User user = new User(); |
private List<User> userList = new ArrayList<User>(); |
private final UserDAOImpl userDAO = new UserDAOImpl(); |
private final UserDAO userDAO = new UserDAO(); |
public boolean edit = false; |
public boolean added = false; |
public User savedUser; |
@Override |
public User getModel() |
{ |
31,24 → 35,29 |
} |
/** |
* Executes the DB query to save the user |
* DB query for userList |
* |
* @return |
* @return SUCCESS |
*/ |
public String addOrUpdate() |
public String list() |
{ |
this.userDAO.saveOrUpdateUser(this.user); |
this.userList = this.userDAO.getList(); |
return Action.SUCCESS; |
} |
/** |
* DB query for userList |
* Executes the DB query to save the user |
* |
* @return SUCCESS |
* @return |
*/ |
public String list() |
public String save() |
{ |
this.userList = this.userDAO.listUser(); |
this.userDAO.saveOrUpdate(this.user); |
this.savedUser = this.user; |
this.user = null; |
this.list(); |
return Action.SUCCESS; |
} |
56,16 → 65,18 |
{ |
int id = this.getIdParameter(); |
String result = Action.ERROR; |
if (id > 0) |
{ |
this.user = this.userDAO.listUserById(id); |
return Action.SUCCESS; |
this.user = this.userDAO.getById(id); |
this.edit = true; |
result = Action.SUCCESS; |
} |
else |
{ |
return Action.ERROR; |
this.list(); |
return result; |
} |
} |
/** |
* Gets the ID Parameter for update / delete requests |
104,7 → 115,7 |
// Check for malicious ID values |
if (id > 0) |
{ |
this.userDAO.deleteUser(id); |
this.userDAO.delete(id); |
return Action.SUCCESS; |
} |
else |