implemented administration of relationship type (edit and delete are not yet working)
/trunk/WebContent/admin/relTypeAdd.jsp |
---|
File deleted |
\ No newline at end of file |
Property changes: |
Deleted: svn:mime-type |
## -1 +0,0 ## |
-text/plain |
\ No newline at end of property |
Index: WebContent/admin/relTypeList.jsp |
=================================================================== |
--- WebContent/admin/relTypeList.jsp (revision 26) |
+++ WebContent/admin/relTypeList.jsp (nonexistent) |
@@ -1,35 +0,0 @@ |
-<%@taglib uri="/struts-tags" prefix="s"%> |
-<html> |
-<head> |
-<title>Beziehungstypen bearbeiten</title> |
-</head> |
-<body> |
- |
-<h1>Beziehungstypen</h1> |
-<p>Hier können Sie die Beziehungstypen anpassen.</p> |
- |
-<s:if test="relTypeList.size() == 0"> |
-<p>Keine Benutzer gefunden</p> |
-</s:if> |
-<table> |
- <tr> |
- <th>Bezeichnung nach A</th> |
- <th>Bezeichnung nach B</th> |
- </tr> |
-<s:iterator value="relTypeList" status="stat"> |
- <tr> |
- <td><s:property value="nameFrom" /></td> |
- <td><s:property value="nameTo" /></td> |
- |
- <td><s:url id="editURL" action="editRelType"> |
- <s:param name="id" value="%{id}"></s:param> |
- </s:url> <s:a href="%{editURL}">Ändern</s:a></td> |
- <td><s:url id="deleteURL" action="deleteRelType"> |
- <s:param name="id" value="%{id}"></s:param> |
- </s:url> <s:a href="%{deleteURL}">Löschen</s:a></td> |
- </tr> |
-</s:iterator> |
-</table> |
- |
-</body> |
-</html> |
\ No newline at end of file |
/WebContent/admin/relTypeList.jsp |
---|
Property changes: |
Deleted: svn:mime-type |
## -1 +0,0 ## |
-text/plain |
\ No newline at end of property |
Index: WebContent/admin/relTypeAddForm.jsp |
=================================================================== |
--- WebContent/admin/relTypeAddForm.jsp (revision 26) |
+++ WebContent/admin/relTypeAddForm.jsp (nonexistent) |
@@ -1,16 +0,0 @@ |
-<%@taglib uri="/struts-tags" prefix="s"%> |
-<html> |
-<head> |
-<title>Beziehungstyp erstellen</title> |
-</head> |
-<body> |
- |
-<h1>Beziehungstyp hinzufügen</h1> |
-<p>Bitte geben Sie die Daten für den Beziehungstypen ein</p> |
-<s:form action="doRelTypeAdd"> |
- <s:textfield name="nameFrom" label="Name vom Ausgangspunkt (z.B. ist Vater von)" /> |
- <s:textfield name="nameTo" label="Name vom Zielpunkt (z.B. ist Sohn von)" /> |
- <s:submit value="Add" /> |
-</s:form> |
-</body> |
-</html> |
/WebContent/admin/relTypeAddForm.jsp |
---|
Property changes: |
Deleted: svn:mime-type |
## -1 +0,0 ## |
-text/plain |
\ No newline at end of property |
Index: WebContent/admin/nav.jsp |
=================================================================== |
--- WebContent/admin/nav.jsp (revision 26) |
+++ WebContent/admin/nav.jsp (revision 25) |
@@ -13,13 +13,13 @@ |
</li> |
<li> |
- Beziehungstypen |
+ Beziehungen |
<ul> |
<li> |
- <a href="relTypeAddForm">Hinzufügen</a> |
+ <a href="">Hinzufügen</a> |
</li> |
<li> |
- <a href="relTypeList">Ändern, Löschen</a> |
+ <a href="">Ändern, Löschen</a> |
</li> |
</ul> |
</li> |
/trunk/src/struts.xml |
---|
14,8 → 14,6 |
<!-- Admin environment --> |
<package name="admin" namespace="/admin" extends="hibernate-default"> |
<!-- User management --> |
<action name="userAddForm"> |
<result>/admin/userAddForm.jsp</result> |
</action> |
31,25 → 29,6 |
<action name="deleteUser" method="delete" class="ch.ffhs.webE.action.UserAction"> |
<result name="success" type="redirect">/admin/userList</result> |
</action> |
<!-- Relationship Type management --> |
<action name="relTypeList" method="list" class="ch.ffhs.webE.action.RelationshipTypeAction"> |
<result name="success">/admin/relTypeList.jsp</result> |
</action> |
<action name="relTypeAddForm"> |
<result>/admin/relTypeAddForm.jsp</result> |
</action> |
<action name="doRelTypeAdd" method="add" class="ch.ffhs.webE.action.RelationshipTypeAction"> |
<result name="success" type="redirect">/admin/relTypeList</result> |
</action> |
<action name="deleteRelType" method="delete" class="ch.ffhs.webE.action.RelationshipTypeAction"> |
<result name="success" type="redirect">/admin/relTypeList</result> |
</action> |
</package> |
/trunk/src/ch/ffhs/webE/action/RelationshipTypeAction.java |
---|
File deleted |
\ No newline at end of file |
Property changes: |
Deleted: svn:mime-type |
## -1 +0,0 ## |
-text/plain |
\ No newline at end of property |
Index: src/ch/ffhs/webE/action/LoginAction.java |
=================================================================== |
--- src/ch/ffhs/webE/action/LoginAction.java (revision 26) |
+++ src/ch/ffhs/webE/action/LoginAction.java (revision 25) |
@@ -1,5 +1,6 @@ |
package ch.ffhs.webE.action; |
+ |
import java.util.Map; |
import ch.ffhs.webE.dao.UserDAO; |
@@ -10,111 +11,91 @@ |
import com.opensymphony.xwork2.ActionSupport; |
import com.opensymphony.xwork2.ModelDriven; |
-public class LoginAction extends ActionSupport implements ModelDriven<User> |
-{ |
+public class LoginAction extends ActionSupport implements ModelDriven<User>{ |
+ |
+ private static final long serialVersionUID = 1799753056277211344L; |
+ private User user = new User(); |
+ private UserDAO userDAO = new UserDAOImpl(); |
+ |
+ //Form fields |
+ private String userName ; |
+ private String pw; |
+ |
+ //Session Object |
+ Map<String, Object> session = ActionContext.getContext().getSession(); |
+ |
- private static final long serialVersionUID = 1799753056277211344L; |
- private User user = new User(); |
- private UserDAO userDAO = new UserDAOImpl(); |
+ public LoginAction() { |
+ } |
+ |
+ public String doLogin() { |
+ |
+ //If password or user name are empty, the login fails. |
+ if("".equals(getUserName()) || "".equals(getPw()) || getUserName() == null || getPw() == null) { |
+ return ERROR; |
+ } |
+ |
+ String verifiedUser = verifyUser(getUserName(), getPw()); |
+ if(verifiedUser.equals("failed")) { |
+ return ERROR; |
+ } else { |
+ |
+ //Put user name, password into session |
+ session.put("username", getUserName()); |
+ session.put("pw", getPw()); |
+ return verifiedUser; |
+ } |
+ } |
+ |
+ public String doLogout() { |
+ //TODO: Kill session content for logout |
+ return SUCCESS; |
+ } |
+ |
+ /** |
+ * Verify user credentials |
+ * @param String username: User name |
+ * @param String password: Password (hashed) |
+ * @return |
+ */ |
+ public String verifyUser(String username, String password) { |
+ //DB Query |
+ User u = userDAO.searchUsername(username); |
+ |
+ //User does not exist |
+ if(u == null) |
+ return ERROR; |
+ |
+ //User password does not match |
+ if(!u.getPassword().equals(password)) |
+ return ERROR; |
+ |
+ //User credentials are fine, check for admin rights |
+ if(u.isAdmin()) { |
+ return "admin"; |
+ } else { |
+ return "user"; |
+ } |
+ } |
+ |
+ public String getUserName() { |
+ return userName; |
+ } |
- // Form fields |
- private String userName; |
- private String pw; |
+ public void setUserName(String userName) { |
+ this.userName = userName; |
+ } |
+ |
+ public String getPw() { |
+ return pw; |
+ } |
- // Session Object |
- Map<String, Object> session = ActionContext.getContext().getSession(); |
+ public void setPw(String pw) { |
+ this.pw = pw; |
+ } |
- public LoginAction() |
- { |
- } |
- |
- public String doLogin() |
- { |
- |
- // If password or user name are empty, the login fails. |
- if ("".equals(getUserName()) || "".equals(getPw()) |
- || getUserName() == null || getPw() == null) |
- { |
- return ERROR; |
- } |
- |
- String verifiedUser = verifyUser(getUserName(), getPw()); |
- if (verifiedUser.equals("failed")) |
- { |
- return ERROR; |
- } |
- else |
- { |
- |
- // Put user name, password into session |
- session.put("username", getUserName()); |
- session.put("pw", getPw()); |
- return verifiedUser; |
- } |
- } |
- |
- public String doLogout() |
- { |
- // TODO: Kill session content for logout |
- return SUCCESS; |
- } |
- |
- /** |
- * Verify user credentials |
- * |
- * @param String |
- * username: User name |
- * @param String |
- * password: Password (hashed) |
- * @return |
- */ |
- public String verifyUser(String username, String password) |
- { |
- // DB Query |
- User u = userDAO.searchUsername(username); |
- |
- // User does not exist |
- if (u == null) |
- return ERROR; |
- |
- // User password does not match |
- if (!u.getPassword().equals(password)) |
- return ERROR; |
- |
- // User credentials are fine, check for admin rights |
- if (u.isAdmin()) |
- { |
- return "admin"; |
- } |
- else |
- { |
- return "user"; |
- } |
- } |
- |
- public String getUserName() |
- { |
- return userName; |
- } |
- |
- public void setUserName(String userName) |
- { |
- this.userName = userName; |
- } |
- |
- public String getPw() |
- { |
- return pw; |
- } |
- |
- public void setPw(String pw) |
- { |
- this.pw = pw; |
- } |
- |
- @Override |
- public User getModel() |
- { |
- return user; |
- } |
+ @Override |
+ public User getModel() { |
+ return user; |
+ } |
} |
/trunk/src/ch/ffhs/webE/action/UserAction.java |
---|
15,98 → 15,50 |
import ch.ffhs.webE.domain.User; |
public class UserAction extends ActionSupport implements ModelDriven<User> |
{ |
public class UserAction extends ActionSupport implements ModelDriven<User> { |
private static final long serialVersionUID = -6659925652584240539L; |
private static final long serialVersionUID = -6659925652584240539L; |
private User user = new User(); |
private List<User> userList = new ArrayList<User>(); |
private UserDAO userDAO = new UserDAOImpl(); |
private User user = new User(); |
private List<User> userList = new ArrayList<User>(); |
private UserDAO userDAO = new UserDAOImpl(); |
@Override |
public User getModel() |
{ |
return user; |
} |
@Override |
public User getModel() { |
return user; |
} |
/** |
* Executes the DB query to save the user |
* |
* @return |
*/ |
public String add() |
{ |
userDAO.saveUser(user); |
return SUCCESS; |
} |
public String add() { |
userDAO.saveUser(user); |
return SUCCESS; |
} |
/** |
* DB query for userList |
* |
* @return SUCCESS |
*/ |
public String list() |
{ |
userList = userDAO.listUser(); |
return SUCCESS; |
} |
public String list() { |
userList = userDAO.listUser(); |
return SUCCESS; |
} |
/** |
* 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() |
{ |
HttpServletRequest request = (HttpServletRequest) ActionContext |
.getContext().get(ServletActionContext.HTTP_REQUEST); |
public User getUser() { |
return user; |
} |
int id = 0; |
try |
{ |
id = Integer.parseInt(request.getParameter("id")); |
} |
catch (Exception e) |
{ |
return ERROR; |
} |
public void setUser(User user) { |
this.user = user; |
} |
// Check for malicious ID values |
if (id > 0) |
{ |
userDAO.deleteUser(id); |
return SUCCESS; |
} |
else |
{ |
return ERROR; |
} |
} |
public List<User> getUserList() { |
return userList; |
} |
/* |
* Standard getters and setters |
*/ |
public void setUserList(List<User> userList) { |
this.userList = userList; |
} |
public User getUser() |
{ |
return user; |
} |
public String delete() { |
HttpServletRequest request = (HttpServletRequest) ActionContext |
.getContext().get(ServletActionContext.HTTP_REQUEST); |
userDAO.deleteUser(Integer.parseInt(request.getParameter("id"))); |
return SUCCESS; |
} |
public void setUser(User user) |
{ |
this.user = user; |
} |
public List<User> getUserList() |
{ |
return userList; |
} |
public void setUserList(List<User> userList) |
{ |
this.userList = userList; |
} |
} |
/trunk/src/ch/ffhs/webE/action/UserForm.java |
---|
0,0 → 1,73 |
package ch.ffhs.webE.action; |
import javax.servlet.http.HttpServletRequest; |
import org.apache.struts2.components.ActionError; |
import org.apache.struts2.dispatcher.mapper.ActionMapping; |
import com.opensymphony.xwork2.ActionSupport; |
public class UserForm extends ActionSupport { |
private static final long serialVersionUID = 2574972467250197244L; |
private String username; |
private String password; |
private String firstname; |
private String lastname; |
private boolean admin; |
public void reset(ActionMapping mapping, HttpServletRequest request) { |
this.username = null; |
this.password = null; |
this.firstname = null; |
this.lastname = null; |
this.admin = false; |
} |
public void validate() { |
} |
// Getter and setters |
public String getUsername() { |
return username; |
} |
public void setUsername(String username) { |
this.username = username; |
} |
public String getPassword() { |
return password; |
} |
public void setPassword(String password) { |
this.password = password; |
} |
public String getFirstname() { |
return firstname; |
} |
public void setFirstname(String firstname) { |
this.firstname = firstname; |
} |
public String getLastname() { |
return lastname; |
} |
public void setLastname(String lastname) { |
this.lastname = lastname; |
} |
public boolean isAdmin() { |
return admin; |
} |
public void setAdmin(boolean admin) { |
this.admin = admin; |
} |
} |
Property changes: |
Added: svn:mime-type |
## -0,0 +1 ## |
+text/plain |
\ No newline at end of property |
Index: src/ch/ffhs/webE/dao/RelationshipTypeDAO.java |
=================================================================== |
--- src/ch/ffhs/webE/dao/RelationshipTypeDAO.java (revision 26) |
+++ src/ch/ffhs/webE/dao/RelationshipTypeDAO.java (nonexistent) |
@@ -1,15 +0,0 @@ |
-package ch.ffhs.webE.dao; |
- |
-import java.util.List; |
- |
-import ch.ffhs.webE.domain.RelationshipType; |
- |
-public interface RelationshipTypeDAO { |
- |
- List<RelationshipType> listRelationshipTypes(); |
- |
- boolean saveRelationshipType(RelationshipType relType); |
- |
- boolean deleteRelationshipType(int relTypeID); |
- |
-} |
/src/ch/ffhs/webE/dao/RelationshipTypeDAO.java |
---|
Property changes: |
Deleted: svn:mime-type |
## -1 +0,0 ## |
-text/plain |
\ No newline at end of property |
Index: src/ch/ffhs/webE/dao/RelationshipTypeDAOImpl.java |
=================================================================== |
--- src/ch/ffhs/webE/dao/RelationshipTypeDAOImpl.java (revision 26) |
+++ src/ch/ffhs/webE/dao/RelationshipTypeDAOImpl.java (nonexistent) |
@@ -1,97 +0,0 @@ |
-package ch.ffhs.webE.dao; |
- |
-import java.util.ArrayList; |
-import java.util.List; |
- |
-import org.hibernate.Session; |
-import org.hibernate.Transaction; |
- |
-import com.googlecode.s2hibernate.struts2.plugin.annotations.SessionTarget; |
-import com.googlecode.s2hibernate.struts2.plugin.annotations.TransactionTarget; |
-import ch.ffhs.webE.domain.*; |
- |
-public class RelationshipTypeDAOImpl implements RelationshipTypeDAO |
-{ |
- |
- @SessionTarget |
- Session session; |
- @TransactionTarget |
- Transaction transaction; |
- |
- /** |
- * Gets a list of all the relationshipTypes in the database. |
- * |
- * @return List of all the users. In case of a problem, an empty list is |
- * returned. |
- */ |
- @SuppressWarnings("unchecked") |
- @Override |
- public List<RelationshipType> listRelationshipTypes() |
- { |
- |
- List<RelationshipType> relType = null; |
- |
- try |
- { |
- relType = session.createQuery("from RelationshipType").list(); |
- } |
- catch (Exception e) |
- { |
- // TODO: Logging |
- } |
- |
- if (relType == null) |
- { |
- relType = new ArrayList<RelationshipType>(); |
- } |
- |
- return relType; |
- } |
- |
- /** |
- * used to save a relationship type |
- * |
- * @param RelationshipType |
- * relType: A filled DAO |
- * @return Boolean indicating success or error in saving the |
- * relationshipType |
- */ |
- @Override |
- public boolean saveRelationshipType(RelationshipType relType) |
- { |
- try |
- { |
- session.save(relType); |
- return true; |
- } |
- catch (Exception e) |
- { |
- transaction.rollback(); |
- return false; |
- // TODO: Logging |
- } |
- } |
- |
- /** |
- * Used to delete a relationship type. |
- * |
- * @param int RelationshipType ID |
- * @return boolean indicating success or error in the query execution |
- */ |
- @Override |
- public boolean deleteRelationshipType(int relTypeID) |
- { |
- try |
- { |
- User user = (User) session.get(RelationshipType.class, relTypeID); |
- session.delete(user); |
- return true; |
- } |
- catch (Exception e) |
- { |
- transaction.rollback(); |
- // TODO: Logging |
- return false; |
- } |
- } |
-} |
/src/ch/ffhs/webE/dao/RelationshipTypeDAOImpl.java |
---|
Property changes: |
Deleted: svn:mime-type |
## -1 +0,0 ## |
-text/plain |
\ No newline at end of property |
Index: src/ch/ffhs/webE/dao/UserDAOImpl.java |
=================================================================== |
--- src/ch/ffhs/webE/dao/UserDAOImpl.java (revision 26) |
+++ src/ch/ffhs/webE/dao/UserDAOImpl.java (revision 25) |
@@ -1,6 +1,5 @@ |
package ch.ffhs.webE.dao; |
-import java.util.ArrayList; |
import java.util.List; |
import org.hibernate.Session; |
@@ -10,106 +9,67 @@ |
import com.googlecode.s2hibernate.struts2.plugin.annotations.TransactionTarget; |
import ch.ffhs.webE.domain.*; |
-public class UserDAOImpl implements UserDAO |
-{ |
+public class UserDAOImpl implements UserDAO { |
- @SessionTarget |
- Session session; |
- @TransactionTarget |
- Transaction transaction; |
+ @SessionTarget |
+ Session session; |
+ @TransactionTarget |
+ Transaction transaction; |
- /** |
- * Creates a list of all the registered users |
- * |
- * @return an ArrayList with all the users - in case of a problem, an empty |
- * list is returned |
- */ |
- @SuppressWarnings("unchecked") |
- @Override |
- public List<User> listUser() |
- { |
- List<User> user = null; |
- try |
- { |
- user = session.createQuery("from User").list(); |
- } |
- catch (Exception e) |
- { |
- e.printStackTrace(); |
- } |
+ @SuppressWarnings("unchecked") |
+ @Override |
+ public List<User> listUser() { |
+ List<User> user = null; |
+ try { |
+ user = session.createQuery("from User").list(); |
+ } catch (Exception e) { |
+ e.printStackTrace(); |
+ } |
+ return user; |
+ } |
- //If no user was checked, return an empty list to mitigate null pointer exceptions |
- if (user == null) |
- { |
- user = new ArrayList<User>(); |
- } |
- return user; |
- } |
+ @Override |
+ public void saveUser(User user) { |
+ try { |
+ session.save(user); |
+ } catch (Exception e) { |
+ transaction.rollback(); |
+ e.printStackTrace(); |
+ } |
+ } |
- /** |
- * Executes the query to save the user |
- * |
- * @param User |
- * Domain object to be saved |
- * @return void |
- */ |
- @Override |
- public void saveUser(User user) |
- { |
- try |
- { |
- session.save(user); |
- } |
- catch (Exception e) |
- { |
- transaction.rollback(); |
- e.printStackTrace(); |
- } |
- } |
+ /** |
+ * Used to delete a user. |
+ */ |
+ @Override |
+ public void deleteUser(int userId) { |
+ try { |
+ User user = (User) session.get(User.class, userId); |
+ session.delete(user); |
+ } catch (Exception e) { |
+ transaction.rollback(); |
+ e.printStackTrace(); |
+ } |
+ } |
- /** |
- * Used to delete a user. |
- * |
- * @param int userId |
- */ |
- @Override |
- public void deleteUser(int userId) |
- { |
- try |
- { |
- User user = (User) session.get(User.class, userId); |
- session.delete(user); |
- } |
- catch (Exception e) |
- { |
- transaction.rollback(); |
- e.printStackTrace(); |
- } |
- } |
+ /** |
+ * Returns a single user with this user name (used for login) |
+ * |
+ * @param username |
+ * : String - entire user name |
+ * @return User: Returns a user object if something is found. If not, null |
+ * is returned |
+ */ |
+ public User searchUsername(String username) { |
+ User user = null; |
- /** |
- * Returns a single user with this user name (used for login) |
- * |
- * @param username |
- * : String - entire user name |
- * @return User: Returns a user object if something is found. If not, null |
- * is returned |
- */ |
- public User searchUsername(String username) |
- { |
- User user = null; |
- |
- //Exec query |
- try |
- { |
- user = (User) session |
- .createQuery("FROM User " + "WHERE username = :username") |
- .setParameter("username", username).uniqueResult(); |
- } |
- catch (Exception e) |
- { |
- // TODO: Log error |
- } |
- return user; |
- } |
+ try { |
+ user = (User) session |
+ .createQuery("FROM User " + "WHERE username = :username") |
+ .setParameter("username", username).uniqueResult(); |
+ } catch (Exception e) { |
+ // TODO: Log error |
+ } |
+ return user; |
+ } |
} |