Subversion Repositories WebE

Compare Revisions

Last modification

Ignore whitespace Rev 32 → Rev 33

/trunk/src/ch/ffhs/webE/dao/UserDAOImpl.java
6,129 → 6,130
import org.hibernate.Session;
import org.hibernate.Transaction;
 
import ch.ffhs.webE.domain.User;
 
import com.googlecode.s2hibernate.struts2.plugin.annotations.SessionTarget;
import com.googlecode.s2hibernate.struts2.plugin.annotations.TransactionTarget;
import ch.ffhs.webE.domain.*;
 
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()
/**
* 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
{
List<User> user = null;
try
{
user = session.createQuery("from User").list();
}
catch (Exception e)
{
e.printStackTrace();
}
user = this.session.createQuery("from User").list();
}
catch (Exception e)
{
e.printStackTrace();
}
 
// If no user was checked, return an empty list to mitigate null pointer
// exceptions
if (user == null)
{
user = new ArrayList<User>();
}
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;
}
 
/**
* Executes the query to save the user
*
* @param User
* Domain object to be saved
* @return void
*/
@Override
public void saveOrUpdateUser(User user)
/**
* Executes the query to save the user
*
* @param User
* Domain object to be saved
* @return void
*/
@Override
public void saveOrUpdateUser(User user)
{
try
{
try
{
session.saveOrUpdate(user);
}
catch (Exception e)
{
transaction.rollback();
e.printStackTrace();
}
this.session.saveOrUpdate(user);
}
catch (Exception e)
{
this.transaction.rollback();
e.printStackTrace();
}
}
 
/**
* Used to delete a user.
*
* @param int userId
*/
@Override
public void deleteUser(int userId)
/**
* Used to delete a user.
*
* @param int userId
*/
@Override
public void deleteUser(int userId)
{
try
{
try
{
User user = (User) session.get(User.class, userId);
session.delete(user);
}
catch (Exception e)
{
transaction.rollback();
e.printStackTrace();
}
User user = (User) this.session.get(User.class, userId);
this.session.delete(user);
}
catch (Exception e)
{
this.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)
/**
* 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 = 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;
user = (User) this.session
.createQuery("FROM User " + "WHERE username = :username")
.setParameter("username", username).uniqueResult();
}
catch (Exception e)
{
// TODO: Log error
}
return user;
}
 
/**
* Used to list a single user by Id.
*/
@Override
public User listUserById(int userId)
/**
* Used to list a single user by Id.
*/
@Override
public User listUserById(int userId)
{
User user = null;
try
{
User user = null;
try
{
user = (User) session.get(User.class, userId);
}
catch (Exception e)
{
e.printStackTrace();
}
return user;
user = (User) this.session.get(User.class, userId);
}
catch (Exception e)
{
e.printStackTrace();
}
return user;
}
}
/trunk/src/ch/ffhs/webE/dao/TermDAO.java
17,12 → 17,6
List<Term> listTerm();
 
/**
* @param termName
* @return
*/
Term searchTerm(String termName);
 
/**
* Delete a term
*
* @param termId
31,10 → 25,12
void deleteTerm(int termId);
 
/**
* Retrieves a term by ID
*
* @param termId
* @return
*/
Term listTermById(int termId);
Term getTermById(int termId);
 
/**
* Executes the query to save the term
41,6 → 37,7
*
* @param term
* Domain object to be saved
* @return <code>true</code> if successful, <code>false</code> otherwise
*/
void saveOrUpdate(Term term);
boolean saveOrUpdate(Term term);
}
/trunk/src/ch/ffhs/webE/dao/TermDAOImpl.java
42,7 → 42,7
List<Term> term = null;
try
{
term = this.session.createQuery("FROM term").list(); //$NON-NLS-1$
term = this.session.createQuery("from Term").list(); //$NON-NLS-1$
}
catch (Exception e)
{
57,6 → 57,7
{
term = new ArrayList<Term>();
}
 
return term;
}
 
65,16 → 66,19
*
* @see ch.ffhs.webE.dao.TermDAO#saveOrUpdate(ch.ffhs.webE.domain.Term)
*/
public void saveOrUpdate(Term term)
public boolean saveOrUpdate(Term term)
{
try
{
term.setObjectId(term.getObjectId());
this.session.saveOrUpdate(term);
return true;
}
catch (Exception e)
{
this.transaction.rollback();
e.printStackTrace();
return false;
}
}
 
87,8 → 91,8
{
try
{
Term user = (Term) this.session.get(Term.class, termId);
this.session.delete(user);
Term term = (Term) this.session.get(Term.class, termId);
this.session.delete(term);
}
catch (Exception e)
{
97,43 → 101,17
}
}
 
/**
* Returns a single user with this user name (used for login)
/*
* (non-Javadoc)
*
* @param termName
* Term name
* @return User: Returns a user object if something is found. If not, null is
* returned
* @see ch.ffhs.webE.dao.TermDAO#getTermById(int)
*/
public Term searchTerm(String termName)
public Term getTermById(int termId)
{
Term term = null;
 
/* Exec query */
try
{
term = (Term) this.session
.createQuery("FROM User " + "WHERE username = :username") //$NON-NLS-1$ //$NON-NLS-2$
.setParameter("username", termName).uniqueResult(); //$NON-NLS-1$
}
catch (Exception e)
{
/* TODO: Log error */
}
return term;
}
 
/**
* List a term by ID
*
* @param termId
* @return
*/
public Term listTermById(int termId)
{
Term term = null;
try
{
term = (Term) this.session.get(Term.class, termId);
}
catch (Exception e)
140,6 → 118,7
{
e.printStackTrace();
}
 
return term;
}
}
/trunk/src/ch/ffhs/webE/domain/Object.java
File deleted
Property changes:
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
Index: ffhs/webE/domain/History.java
===================================================================
--- ffhs/webE/domain/History.java (revision 32)
+++ ffhs/webE/domain/History.java (revision 33)
@@ -25,7 +25,7 @@
private Integer id;
private User user;
private ActionType actionType;
- private Object object;
+ private ObjectEntity object;
private String value;
private String comment;
private Date date;
@@ -33,7 +33,7 @@
public History() {
}
- public History(User user, ActionType actionType, Object object, Date date) {
+ public History(User user, ActionType actionType, ObjectEntity object, Date date) {
this.user = user;
this.actionType = actionType;
this.object = object;
@@ -40,7 +40,7 @@
this.date = date;
}
- public History(User user, ActionType actionType, Object object,
+ public History(User user, ActionType actionType, ObjectEntity object,
String value, String comment, Date date) {
this.user = user;
this.actionType = actionType;
@@ -83,11 +83,11 @@
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "objects_id", nullable = false)
- public Object getObject() {
+ public ObjectEntity getObject() {
return this.object;
}
- public void setObject(Object object) {
+ public void setObject(ObjectEntity object) {
this.object = object;
}
/trunk/src/ch/ffhs/webE/domain/Relationship.java
26,7 → 26,7
 
private int objectId;
private Term termByTermTo;
private Object object;
private ObjectEntity object;
private RelationshipType relationshipType;
private Term termByTermFrom;
 
33,7 → 33,7
public Relationship() {
}
 
public Relationship(Term termByTermTo, Object object,
public Relationship(Term termByTermTo, ObjectEntity object,
RelationshipType relationshipType, Term termByTermFrom) {
this.termByTermTo = termByTermTo;
this.object = object;
65,11 → 65,11
 
@OneToOne(fetch = FetchType.LAZY)
@PrimaryKeyJoinColumn
public Object getObject() {
public ObjectEntity getObject() {
return this.object;
}
 
public void setObject(Object object) {
public void setObject(ObjectEntity object) {
this.object = object;
}
 
/trunk/src/ch/ffhs/webE/domain/ObjectEntity.java
0,0 → 1,272
package ch.ffhs.webE.domain;
 
// Generated 19.12.2010 14:46:08 by Hibernate Tools 3.4.0.Beta1
 
import static javax.persistence.GenerationType.IDENTITY;
 
import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
 
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
 
/**
* ObjectEntity generated by hbm2java
*/
@Entity
@Table(name = "object", catalog = "webengineering")
public class ObjectEntity implements Serializable
{
/**
* Version ID for serialization
*/
private static final long serialVersionUID = 1L;
 
/* Persistent fields */
private Integer id;
private User userByEditorId;
private ObjectType objectType;
private User userByOwnerId;
private Date locked;
private Date modified;
private Boolean deleted;
private Term term;
private Set<History> histories = new HashSet<History>(0);
private Relationship relationship;
 
/**
*
*/
public ObjectEntity()
{
}
 
/**
* @param userByEditorId
* @param objectType
* @param userByOwnerId
*/
public ObjectEntity(User userByEditorId, ObjectType objectType,
User userByOwnerId)
{
this.userByEditorId = userByEditorId;
this.objectType = objectType;
this.userByOwnerId = userByOwnerId;
}
 
/**
* @param userByEditorId
* @param objectType
* @param userByOwnerId
* @param locked
* @param modified
* @param deleted
* @param term
* @param histories
* @param relationship
*/
public ObjectEntity(User userByEditorId, ObjectType objectType,
User userByOwnerId, Date locked, Date modified, Boolean deleted,
Term term, Set<History> histories, Relationship relationship)
{
this.userByEditorId = userByEditorId;
this.objectType = objectType;
this.userByOwnerId = userByOwnerId;
this.locked = locked;
this.modified = modified;
this.deleted = deleted;
this.term = term;
this.histories = histories;
this.relationship = relationship;
}
 
/**
* @return
*/
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public Integer getId()
{
return this.id;
}
 
/**
* @param id
*/
public void setId(Integer id)
{
this.id = id;
}
 
/**
* @return
*/
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "editor_id", nullable = false)
public User getUserByEditorId()
{
return this.userByEditorId;
}
 
/**
* @param userByEditorId
*/
public void setUserByEditorId(User userByEditorId)
{
this.userByEditorId = userByEditorId;
}
 
/**
* @return
*/
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "object_type_id", nullable = false)
public ObjectType getObjectType()
{
return this.objectType;
}
 
/**
* @param objectType
*/
public void setObjectType(ObjectType objectType)
{
this.objectType = objectType;
}
 
/**
* @return
*/
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "owner_id", nullable = false)
public User getUserByOwnerId()
{
return this.userByOwnerId;
}
 
/**
* @param userByOwnerId
*/
public void setUserByOwnerId(User userByOwnerId)
{
this.userByOwnerId = userByOwnerId;
}
 
/**
* @return
*/
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "locked", length = 19)
public Date getLocked()
{
return this.locked;
}
 
/**
* @param locked
*/
public void setLocked(Date locked)
{
this.locked = locked;
}
 
/**
* @return
*/
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "modified", length = 19)
public Date getModified()
{
return this.modified;
}
 
/**
* @param modified
*/
public void setModified(Date modified)
{
this.modified = modified;
}
 
/**
* @return
*/
@Column(name = "deleted")
public Boolean getDeleted()
{
return this.deleted;
}
 
/**
* @param deleted
*/
public void setDeleted(Boolean deleted)
{
this.deleted = deleted;
}
 
/**
* @return
*/
@OneToOne(fetch = FetchType.LAZY, mappedBy = "object")
public Term getTerm()
{
return this.term;
}
 
/**
* @param term
*/
public void setTerm(Term term)
{
this.term = term;
}
 
/**
* @return
*/
@OneToMany(fetch = FetchType.LAZY, mappedBy = "object")
public Set<History> getHistories()
{
return this.histories;
}
 
/**
* @param histories
*/
public void setHistories(Set<History> histories)
{
this.histories = histories;
}
 
/**
* @return
*/
@OneToOne(fetch = FetchType.LAZY, mappedBy = "object")
public Relationship getRelationship()
{
return this.relationship;
}
 
/**
* @param relationship
*/
public void setRelationship(Relationship relationship)
{
this.relationship = relationship;
}
 
}
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: ffhs/webE/domain/Term.java
===================================================================
--- ffhs/webE/domain/Term.java (revision 32)
+++ ffhs/webE/domain/Term.java (revision 33)
@@ -2,8 +2,11 @@
// Generated 19.12.2010 14:46:08 by Hibernate Tools 3.4.0.Beta1
+import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
+
+import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
@@ -13,7 +16,9 @@
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
+import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;
+
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;
@@ -22,81 +27,139 @@
*/
@Entity
@Table(name = "term", catalog = "webengineering", uniqueConstraints = @UniqueConstraint(columnNames = "name"))
-public class Term implements java.io.Serializable {
+public class Term implements Serializable
+{
+ /**
+ * Version ID for serialization
+ */
+ private static final long serialVersionUID = 1L;
- private int objectId;
- private Object object;
- private String name;
- private Set<Relationship> relationshipsForTermTo = new HashSet<Relationship>(
- 0);
- private Set<Relationship> relationshipsForTermFrom = new HashSet<Relationship>(
- 0);
+ @Transient
+ private int objectId;
- public Term() {
- }
+ private ObjectEntity object;
+ private String name;
+ private Set<Relationship> relationshipsForTermTo = new HashSet<Relationship>(
+ 0);
+ private Set<Relationship> relationshipsForTermFrom = new HashSet<Relationship>(
+ 0);
- public Term(Object object) {
- this.object = object;
- }
+ /**
+ * No-op constructor
+ */
+ public Term()
+ {
+ }
- public Term(Object object, String name,
- Set<Relationship> relationshipsForTermTo,
- Set<Relationship> relationshipsForTermFrom) {
- this.object = object;
- this.name = name;
- this.relationshipsForTermTo = relationshipsForTermTo;
- this.relationshipsForTermFrom = relationshipsForTermFrom;
- }
+ /**
+ * @param object
+ */
+ public Term(ObjectEntity object)
+ {
+ this.object = object;
+ }
- @GenericGenerator(name = "generator", strategy = "foreign", parameters = @Parameter(name = "property", value = "object"))
- @Id
- @GeneratedValue(generator = "generator")
- @Column(name = "object_id", unique = true, nullable = false)
- public int getObjectId() {
- return this.objectId;
- }
+ /**
+ * @param object
+ * @param name
+ * @param relationshipsForTermTo
+ * @param relationshipsForTermFrom
+ */
+ public Term(ObjectEntity object, String name,
+ Set<Relationship> relationshipsForTermTo,
+ Set<Relationship> relationshipsForTermFrom)
+ {
+ this.object = object;
+ this.name = name;
+ this.relationshipsForTermTo = relationshipsForTermTo;
+ this.relationshipsForTermFrom = relationshipsForTermFrom;
+ }
- public void setObjectId(int objectId) {
- this.objectId = objectId;
- }
+ /**
+ * @return
+ */
+ @GenericGenerator(name = "generator", strategy = "foreign", parameters = @Parameter(name = "property", value = "object"))
+ @Id
+ @GeneratedValue(generator = "generator")
+ @Column(name = "object_id", unique = true, nullable = false)
+ public int getObjectId()
+ {
+ return this.objectId;
+ }
- @OneToOne(fetch = FetchType.LAZY)
- @PrimaryKeyJoinColumn
- public Object getObject() {
- return this.object;
- }
+ /**
+ * @param objectId
+ */
+ public void setObjectId(int objectId)
+ {
+ this.objectId = objectId;
+ }
- public void setObject(Object object) {
- this.object = object;
- }
+ /**
+ * @return ObjectEntity domain object
+ */
+ @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
+ @PrimaryKeyJoinColumn
+ public ObjectEntity getObject()
+ {
+ return this.object;
+ }
- @Column(name = "name", unique = true)
- public String getName() {
- return this.name;
- }
+ /**
+ * @param object
+ */
+ public void setObject(ObjectEntity object)
+ {
+ this.object = object;
+ }
- public void setName(String name) {
- this.name = name;
- }
+ /**
+ * @return
+ */
+ @Column(name = "name", unique = true)
+ public String getName()
+ {
+ return this.name;
+ }
- @OneToMany(fetch = FetchType.LAZY, mappedBy = "termByTermTo")
- public Set<Relationship> getRelationshipsForTermTo() {
- return this.relationshipsForTermTo;
- }
+ /**
+ * @param name
+ */
+ public void setName(String name)
+ {
+ this.name = name;
+ }
- public void setRelationshipsForTermTo(
- Set<Relationship> relationshipsForTermTo) {
- this.relationshipsForTermTo = relationshipsForTermTo;
- }
+ @OneToMany(fetch = FetchType.LAZY, mappedBy = "termByTermTo")
+ public Set<Relationship> getRelationshipsForTermTo()
+ {
+ return this.relationshipsForTermTo;
+ }
- @OneToMany(fetch = FetchType.LAZY, mappedBy = "termByTermFrom")
- public Set<Relationship> getRelationshipsForTermFrom() {
- return this.relationshipsForTermFrom;
- }
+ /**
+ * @param relationshipsForTermTo
+ */
+ public void setRelationshipsForTermTo(Set<Relationship> relationshipsForTermTo)
+ {
+ this.relationshipsForTermTo = relationshipsForTermTo;
+ }
- public void setRelationshipsForTermFrom(
- Set<Relationship> relationshipsForTermFrom) {
- this.relationshipsForTermFrom = relationshipsForTermFrom;
- }
+ /**
+ * @return
+ */
+ @OneToMany(fetch = FetchType.LAZY, mappedBy = "termByTermFrom")
+ public Set<Relationship> getRelationshipsForTermFrom()
+ {
+ return this.relationshipsForTermFrom;
+ }
+ /**
+ * @param relationshipsForTermFrom
+ */
+ public void setRelationshipsForTermFrom(
+ Set<Relationship> relationshipsForTermFrom)
+ {
+ this.relationshipsForTermFrom = relationshipsForTermFrom;
+ }
+
}
/trunk/src/ch/ffhs/webE/domain/ObjectType.java
4,6 → 4,7
 
import java.util.HashSet;
import java.util.Set;
 
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
17,51 → 18,65
*/
@Entity
@Table(name = "object_type", catalog = "webengineering", uniqueConstraints = @UniqueConstraint(columnNames = "name"))
public class ObjectType implements java.io.Serializable {
public class ObjectType implements java.io.Serializable
{
/**
* ObjectEntity type ID for a term
*/
public static final int TERM = 1;
 
private int objectTypeId;
private String name;
private Set<Object> objects = new HashSet<Object>(0);
private int objectTypeId;
private String name;
private Set<ObjectEntity> objects = new HashSet<ObjectEntity>(0);
 
public ObjectType() {
}
public ObjectType()
{
}
 
public ObjectType(int objectTypeId) {
this.objectTypeId = objectTypeId;
}
public ObjectType(int objectTypeId)
{
this.objectTypeId = objectTypeId;
}
 
public ObjectType(int objectTypeId, String name, Set<Object> objects) {
this.objectTypeId = objectTypeId;
this.name = name;
this.objects = objects;
}
public ObjectType(int objectTypeId, String name, Set<ObjectEntity> objects)
{
this.objectTypeId = objectTypeId;
this.name = name;
this.objects = objects;
}
 
@Id
@Column(name = "object_type_id", unique = true, nullable = false)
public int getObjectTypeId() {
return this.objectTypeId;
}
@Id
@Column(name = "object_type_id", unique = true, nullable = false)
public int getObjectTypeId()
{
return this.objectTypeId;
}
 
public void setObjectTypeId(int objectTypeId) {
this.objectTypeId = objectTypeId;
}
public void setObjectTypeId(int objectTypeId)
{
this.objectTypeId = objectTypeId;
}
 
@Column(name = "name", unique = true, length = 45)
public String getName() {
return this.name;
}
@Column(name = "name", unique = true, length = 45)
public String getName()
{
return this.name;
}
 
public void setName(String name) {
this.name = name;
}
public void setName(String name)
{
this.name = name;
}
 
@OneToMany(fetch = FetchType.LAZY, mappedBy = "objectType")
public Set<Object> getObjects() {
return this.objects;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "objectType")
public Set<ObjectEntity> getObjects()
{
return this.objects;
}
 
public void setObjects(Set<Object> objects) {
this.objects = objects;
}
public void setObjects(Set<ObjectEntity> objects)
{
this.objects = objects;
}
 
}
/trunk/src/ch/ffhs/webE/domain/User.java
2,13 → 2,15
 
// Generated 19.12.2010 14:46:08 by Hibernate Tools 3.4.0.Beta1
 
import static javax.persistence.GenerationType.IDENTITY;
 
import java.util.HashSet;
import java.util.Set;
 
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
19,121 → 21,147
*/
@Entity
@Table(name = "user", catalog = "webengineering", uniqueConstraints = @UniqueConstraint(columnNames = "username"))
public class User implements java.io.Serializable {
public class User implements java.io.Serializable
{
/**
* Version ID for serialization
*/
private static final long serialVersionUID = 1L;
 
private Integer id;
private String username;
private String password;
private String firstname;
private String lastname;
private boolean admin;
private Set<Object> objectsForOwnerId = new HashSet<Object>(0);
private Set<Object> objectsForEditorId = new HashSet<Object>(0);
private Set<History> histories = new HashSet<History>(0);
private Integer id;
private String username;
private String password;
private String firstname;
private String lastname;
private boolean admin;
private Set<ObjectEntity> objectsForOwnerId = new HashSet<ObjectEntity>(0);
private Set<ObjectEntity> objectsForEditorId = new HashSet<ObjectEntity>(0);
private Set<History> histories = new HashSet<History>(0);
 
public User() {
}
public User()
{
}
 
public User(String username, String password, boolean admin) {
this.username = username;
this.password = password;
this.admin = admin;
}
public User(String username, String password, boolean admin)
{
this.username = username;
this.password = password;
this.admin = admin;
}
 
public User(String username, String password, String firstname,
String lastname, boolean admin, Set<Object> objectsForOwnerId,
Set<Object> objectsForEditorId, Set<History> histories) {
this.username = username;
this.password = password;
this.firstname = firstname;
this.lastname = lastname;
this.admin = admin;
this.objectsForOwnerId = objectsForOwnerId;
this.objectsForEditorId = objectsForEditorId;
this.histories = histories;
}
public User(String username, String password, String firstname,
String lastname, boolean admin, Set<ObjectEntity> objectsForOwnerId,
Set<ObjectEntity> objectsForEditorId, Set<History> histories)
{
this.username = username;
this.password = password;
this.firstname = firstname;
this.lastname = lastname;
this.admin = admin;
this.objectsForOwnerId = objectsForOwnerId;
this.objectsForEditorId = objectsForEditorId;
this.histories = histories;
}
 
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public Integer getId() {
return this.id;
}
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public Integer getId()
{
return this.id;
}
 
public void setId(Integer id) {
this.id = id;
}
public void setId(Integer id)
{
this.id = id;
}
 
@Column(name = "username", unique = true, nullable = false)
public String getUsername() {
return this.username;
}
@Column(name = "username", unique = true, nullable = false)
public String getUsername()
{
return this.username;
}
 
public void setUsername(String username) {
this.username = username;
}
public void setUsername(String username)
{
this.username = username;
}
 
@Column(name = "password", nullable = false, length = 32)
public String getPassword() {
return this.password;
}
@Column(name = "password", nullable = false, length = 32)
public String getPassword()
{
return this.password;
}
 
public void setPassword(String password) {
this.password = password;
}
public void setPassword(String password)
{
this.password = password;
}
 
@Column(name = "firstname", length = 45)
public String getFirstname() {
return this.firstname;
}
@Column(name = "firstname", length = 45)
public String getFirstname()
{
return this.firstname;
}
 
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public void setFirstname(String firstname)
{
this.firstname = firstname;
}
 
@Column(name = "lastname", length = 45)
public String getLastname() {
return this.lastname;
}
@Column(name = "lastname", length = 45)
public String getLastname()
{
return this.lastname;
}
 
public void setLastname(String lastname) {
this.lastname = lastname;
}
public void setLastname(String lastname)
{
this.lastname = lastname;
}
 
@Column(name = "admin", nullable = false)
public boolean isAdmin() {
return this.admin;
}
@Column(name = "admin", nullable = false)
public boolean isAdmin()
{
return this.admin;
}
 
public void setAdmin(boolean admin) {
this.admin = admin;
}
public void setAdmin(boolean admin)
{
this.admin = admin;
}
 
@OneToMany(fetch = FetchType.LAZY, mappedBy = "userByOwnerId")
public Set<Object> getObjectsForOwnerId() {
return this.objectsForOwnerId;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "userByOwnerId")
public Set<ObjectEntity> getObjectsForOwnerId()
{
return this.objectsForOwnerId;
}
 
public void setObjectsForOwnerId(Set<Object> objectsForOwnerId) {
this.objectsForOwnerId = objectsForOwnerId;
}
public void setObjectsForOwnerId(Set<ObjectEntity> objectsForOwnerId)
{
this.objectsForOwnerId = objectsForOwnerId;
}
 
@OneToMany(fetch = FetchType.LAZY, mappedBy = "userByEditorId")
public Set<Object> getObjectsForEditorId() {
return this.objectsForEditorId;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "userByEditorId")
public Set<ObjectEntity> getObjectsForEditorId()
{
return this.objectsForEditorId;
}
 
public void setObjectsForEditorId(Set<Object> objectsForEditorId) {
this.objectsForEditorId = objectsForEditorId;
}
public void setObjectsForEditorId(Set<ObjectEntity> objectsForEditorId)
{
this.objectsForEditorId = objectsForEditorId;
}
 
@OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
public Set<History> getHistories() {
return this.histories;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
public Set<History> getHistories()
{
return this.histories;
}
 
public void setHistories(Set<History> histories) {
this.histories = histories;
}
public void setHistories(Set<History> histories)
{
this.histories = histories;
}
 
}
/trunk/src/ch/ffhs/webE/action/TermAction.java
1,15 → 1,20
package ch.ffhs.webE.action;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
 
import org.apache.struts2.StrutsStatics;
 
import ch.ffhs.webE.dao.TermDAO;
import ch.ffhs.webE.dao.TermDAOImpl;
import ch.ffhs.webE.dao.UserDAOImpl;
import ch.ffhs.webE.domain.ObjectEntity;
import ch.ffhs.webE.domain.ObjectType;
import ch.ffhs.webE.domain.Term;
import ch.ffhs.webE.domain.User;
 
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
23,12 → 28,18
*/
public class TermAction extends ActionSupport implements ModelDriven<Term>
{
private static final long serialVersionUID = -6659925652584240539L;
private static final long serialVersionUID = 1L;
 
private Term term = new Term();
private List<Term> termList = new ArrayList<Term>();
private final TermDAO termDAO = new TermDAOImpl();
private final TermDAOImpl termDAO = new TermDAOImpl();
private final UserDAOImpl userDAO = new UserDAOImpl();
 
/**
* Session object
*/
Map<String, Object> session = ActionContext.getContext().getSession();
 
/*
* (non-Javadoc)
*
44,14 → 55,23
*
* @return {@link Action#SUCCESS}
*/
public String addOrUpdate()
public String add()
{
this.termDAO.saveOrUpdate(this.term);
return Action.SUCCESS;
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);
if (this.termDAO.saveOrUpdate(this.term))
{
return Action.SUCCESS;
}
 
return Action.ERROR;
}
 
/**
* DB query for userList
* DB query for term list
*
* @return SUCCESS
*/
71,13 → 91,14
 
if (id > 0)
{
this.term = this.termDAO.listTermById(id);
return Action.SUCCESS;
this.term = this.termDAO.getTermById(id);
if (this.term != null)
{
return Action.SUCCESS;
}
}
else
{
return Action.ERROR;
}
 
return Action.ERROR;
}
 
/**
/trunk/src/ch/ffhs/webE/action/LoginAction.java
2,10 → 2,10
 
import java.util.Map;
 
import ch.ffhs.webE.dao.UserDAO;
import ch.ffhs.webE.dao.UserDAOImpl;
import ch.ffhs.webE.domain.User;
 
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
13,115 → 13,125
public class LoginAction extends ActionSupport implements ModelDriven<User>
{
 
private static final long serialVersionUID = 1799753056277211344L;
private User user = new User();
private UserDAO userDAO = new UserDAOImpl();
private static final long serialVersionUID = 1799753056277211344L;
private final User user = new User();
private final UserDAOImpl userDAO = new UserDAOImpl();
 
// Form fields
private String userName;
private String pw;
/* Form fields */
private String userName;
private String pw;
 
// Session Object
Map<String, Object> session = ActionContext.getContext().getSession();
/**
* JSP session object
*/
Map<String, Object> session = ActionContext.getContext().getSession();
 
public LoginAction()
{
}
/**
*
*/
public LoginAction()
{
}
 
public String doLogin()
public String doLogin()
{
 
// If password or user name are empty, the login fails.
if ("".equals(this.getUserName()) || "".equals(this.getPw())
|| this.getUserName() == null || this.getPw() == null)
{
 
// If password or user name are empty, the login fails.
if ("".equals(getUserName()) || "".equals(getPw())
|| getUserName() == null || getPw() == null)
{
addFieldError("userName", "Falscher Username oder Passwort");
return ERROR;
}
 
String verifiedUser = verifyUser(getUserName(), getPw());
if (verifiedUser.equals("failed"))
{
addFieldError("userName", "Falscher Username oder Passwort");
return ERROR;
}
else
{
 
// Put user name, password into session
session.put("username", getUserName());
session.put("pw", getPw());
return verifiedUser;
}
this.addFieldError("userName", "Falscher Username oder Passwort");
return Action.ERROR;
}
 
/**
* Logout ausführen. Zerstört die Daten in der Session
* @return String
*/
public String doLogout()
String verifiedUser = this.verifyUser(this.getUserName(), this.getPw());
if (verifiedUser.equals("failed"))
{
//Kill Session content
ActionContext.getContext().getSession().clear();
return SUCCESS;
this.addFieldError("userName", "Falscher Username oder Passwort");
return Action.ERROR;
}
 
/**
* Verify user credentials
*
* @param String
* username: User name
* @param String
* password: Password (hashed)
* @return
*/
public String verifyUser(String username, String password)
else
{
// DB Query
User u = userDAO.searchUsername(username);
 
// User does not exist
if (u == null)
return ERROR;
// Put user name, password into session
this.session.put("username", this.getUserName());
this.session.put("pw", this.getPw());
return verifiedUser;
}
}
 
// User password does not match
if (!u.getPassword().equals(password))
return ERROR;
/**
* Logout ausf�hren. Zerst�rt die Daten in der Session
*
* @return String
*/
public String doLogout()
{
// Kill Session content
ActionContext.getContext().getSession().clear();
return Action.SUCCESS;
}
 
// User credentials are fine, check for admin rights
if (u.isAdmin())
{
return "admin";
}
else
{
return "user";
}
}
/**
* 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 = this.userDAO.searchUsername(username);
 
public String getUserName()
// User does not exist
if (u == null)
{
return userName;
return Action.ERROR;
}
 
public void setUserName(String userName)
// User password does not match
if (!u.getPassword().equals(password))
{
this.userName = userName;
return Action.ERROR;
}
 
public String getPw()
// User credentials are fine, check for admin rights
if (u.isAdmin())
{
return pw;
return "admin";
}
 
public void setPw(String pw)
else
{
this.pw = pw;
return "user";
}
}
 
@Override
public User getModel()
{
return user;
}
public String getUserName()
{
return this.userName;
}
 
public void setUserName(String userName)
{
this.userName = userName;
}
 
public String getPw()
{
return this.pw;
}
 
public void setPw(String pw)
{
this.pw = pw;
}
 
@Override
public User getModel()
{
return this.user;
}
}
/trunk/src/ch/ffhs/webE/action/UserAction.java
5,135 → 5,135
 
import javax.servlet.http.HttpServletRequest;
 
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.StrutsStatics;
 
import ch.ffhs.webE.dao.UserDAOImpl;
import ch.ffhs.webE.domain.User;
 
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import ch.ffhs.webE.dao.UserDAO;
import ch.ffhs.webE.dao.UserDAOImpl;
 
import ch.ffhs.webE.domain.User;
 
public class UserAction extends ActionSupport implements ModelDriven<User>
{
 
private static final long serialVersionUID = -6659925652584240539L;
private static final long serialVersionUID = 1L;
 
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 final UserDAOImpl userDAO = new UserDAOImpl();
 
@Override
public User getModel()
{
return user;
}
@Override
public User getModel()
{
return this.user;
}
 
/**
* Executes the DB query to save the user
*
* @return
*/
public String addOrUpdate()
/**
* Executes the DB query to save the user
*
* @return
*/
public String addOrUpdate()
{
this.userDAO.saveOrUpdateUser(this.user);
return Action.SUCCESS;
}
 
/**
* DB query for userList
*
* @return SUCCESS
*/
public String list()
{
this.userList = this.userDAO.listUser();
return Action.SUCCESS;
}
 
public String edit()
{
int id = this.getIdParameter();
 
if (id > 0)
{
userDAO.saveOrUpdateUser(user);
return SUCCESS;
this.user = this.userDAO.listUserById(id);
return Action.SUCCESS;
}
 
/**
* DB query for userList
*
* @return SUCCESS
*/
public String list()
else
{
userList = userDAO.listUser();
return SUCCESS;
return Action.ERROR;
}
}
 
public String edit()
/**
* 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()
{
HttpServletRequest request = (HttpServletRequest) ActionContext
.getContext().get(StrutsStatics.HTTP_REQUEST);
 
int id = -1;
try
{
int id = getIdParameter();
 
if (id > 0)
{
user = userDAO.listUserById(id);
return SUCCESS;
}
else
{
return ERROR;
}
id = Integer.parseInt(request.getParameter("id"));
}
 
/**
* 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()
catch (Exception e)
{
HttpServletRequest request = (HttpServletRequest) ActionContext
.getContext().get(ServletActionContext.HTTP_REQUEST);
 
int id = -1;
try
{
id = Integer.parseInt(request.getParameter("id"));
}
catch (Exception e)
{
// TODO: Logging - wrong parameter set
}
 
return id;
// TODO: Logging - wrong parameter set
}
 
/**
* 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()
{
return id;
}
 
int id = getIdParameter();
/**
* 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()
{
 
// Check for malicious ID values
if (id > 0)
{
userDAO.deleteUser(id);
return SUCCESS;
}
else
{
return ERROR;
}
}
int id = this.getIdParameter();
 
/*
* Standard getters and setters
*/
 
public User getUser()
// Check for malicious ID values
if (id > 0)
{
return user;
this.userDAO.deleteUser(id);
return Action.SUCCESS;
}
 
public void setUser(User user)
else
{
this.user = user;
return Action.ERROR;
}
}
 
public List<User> getUserList()
{
return userList;
}
/*
* Standard getters and setters
*/
 
public void setUserList(List<User> userList)
{
this.userList = userList;
}
public User getUser()
{
return this.user;
}
 
public void setUser(User user)
{
this.user = user;
}
 
public List<User> getUserList()
{
return this.userList;
}
 
public void setUserList(List<User> userList)
{
this.userList = userList;
}
}