Subversion Repositories WebE

Compare Revisions

Last modification

Ignore whitespace Rev 35 → Rev 37

/trunk/src/ch/ffhs/webE/dao/TermDAOImpl.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: webE/dao/RelationshipTypeDAOImpl.java
===================================================================
--- webE/dao/RelationshipTypeDAOImpl.java (revision 35)
+++ webE/dao/RelationshipTypeDAOImpl.java (nonexistent)
@@ -1,118 +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> getRelTypes()
- {
-
- 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 saveOrUpdateRelType(RelationshipType relType)
- {
- try
- {
- session.saveOrUpdate(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
- {
- RelationshipType relType = (RelationshipType) session.get(
- RelationshipType.class, relTypeID);
- session.delete(relType);
- return true;
- }
- catch (Exception e)
- {
- transaction.rollback();
- // TODO: Logging
- return false;
- }
- }
-
- /**
- * Used to get a relationship type by ID
- */
- @Override
- public RelationshipType getRelTypeById(int relTypeID)
- {
- RelationshipType relType = null;
- try
- {
- relType = (RelationshipType) session.get(RelationshipType.class,
- relTypeID);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- // TODO: Logging
- }
- return relType;
- }
-}
/webE/dao/RelationshipTypeDAOImpl.java
Property changes:
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
Index: webE/dao/UserDAOImpl.java
===================================================================
--- webE/dao/UserDAOImpl.java (revision 35)
+++ webE/dao/UserDAOImpl.java (nonexistent)
@@ -1,135 +0,0 @@
-package ch.ffhs.webE.dao;
-
-import java.util.ArrayList;
-import java.util.List;
-
-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;
-
-public class UserDAOImpl implements UserDAO
-{
-
- @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 = 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;
- }
-
- /**
- * Executes the query to save the user
- *
- * @param User
- * Domain object to be saved
- * @return void
- */
- @Override
- public void saveOrUpdateUser(User user)
- {
- try
- {
- 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)
- {
- try
- {
- 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)
- {
- User user = null;
-
- // Exec query
- try
- {
- 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)
- {
- User user = null;
- try
- {
- user = (User) this.session.get(User.class, userId);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- return user;
- }
-}
\ No newline at end of file
/webE/dao/UserDAOImpl.java
Property changes:
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
Index: webE/dao/RelationshipDAOImpl.java
===================================================================
--- webE/dao/RelationshipDAOImpl.java (revision 35)
+++ webE/dao/RelationshipDAOImpl.java (nonexistent)
@@ -1,130 +0,0 @@
-package ch.ffhs.webE.dao;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.hibernate.Session;
-import org.hibernate.Transaction;
-
-import ch.ffhs.webE.domain.Relationship;
-
-import com.googlecode.s2hibernate.struts2.plugin.annotations.SessionTarget;
-import com.googlecode.s2hibernate.struts2.plugin.annotations.TransactionTarget;
-
-/**
- * Implements the Database Access Object for terms
- *
- * @author Thomas Lahn
- */
-public class RelationshipDAOImpl
-{
- /**
- * Database session
- */
- @SessionTarget
- Session session;
-
- /**
- * Database transaction
- */
- @TransactionTarget
- Transaction transaction;
-
- /**
- * Creates a list of all relationships
- *
- * @return an ArrayList with all the relationshops - in case of a problem, an
- * empty list is returned
- */
- @SuppressWarnings("unchecked")
- public List<Relationship> getRelationshipList()
- {
- List<Relationship> relationship = null;
- try
- {
- relationship = this.session.createQuery("from Relationship").list(); //$NON-NLS-1$
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
-
- /*
- * If no relationship was checked, return an empty list to mitigate null
- * pointer exceptions
- */
- if (relationship == null)
- {
- relationship = new ArrayList<Relationship>();
- }
-
- return relationship;
- }
-
- /**
- * Executes the query to save the relationship
- *
- * @param relationship
- * Domain object to be saved
- * @return <code>true</code> if successful, <code>false</code> otherwise
- */
- public boolean saveOrUpdate(Relationship relationship)
- {
- try
- {
- relationship.setObjectId(relationship.getObjectId());
- this.session.saveOrUpdate(relationship);
- return true;
- }
- catch (Exception e)
- {
- this.transaction.rollback();
- e.printStackTrace();
- return false;
- }
- }
-
- /**
- * Delete a relationship
- *
- * @param id
- * Relationship ID
- */
- public void deleteRelationship(int id)
- {
- try
- {
- Relationship relationship = (Relationship) this.session.get(
- Relationship.class, id);
- this.session.delete(relationship);
- }
- catch (Exception e)
- {
- this.transaction.rollback();
- e.printStackTrace();
- }
- }
-
- /**
- * Retrieves a relationship by ID
- *
- * @param id
- * Term ID
- * @return The relationship with this <var>id</var>
- */
- public Relationship getRelationshipById(int id)
- {
- Relationship relationship = null;
-
- try
- {
- relationship = (Relationship) this.session.get(Relationship.class, id);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
-
- return relationship;
- }
-}
\ No newline at end of file
/webE/dao/RelationshipDAOImpl.java
Property changes:
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
Index: webE/dao/UserDAO.java
===================================================================
--- webE/dao/UserDAO.java (revision 35)
+++ webE/dao/UserDAO.java (revision 37)
@@ -1,19 +1,134 @@
package ch.ffhs.webE.dao;
+import java.util.ArrayList;
import java.util.List;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+
import ch.ffhs.webE.domain.User;
-public interface UserDAO
+import com.googlecode.s2hibernate.struts2.plugin.annotations.SessionTarget;
+import com.googlecode.s2hibernate.struts2.plugin.annotations.TransactionTarget;
+
+public class UserDAO
{
- List<User> listUser();
+ @SessionTarget
+ Session session;
+ @TransactionTarget
+ Transaction transaction;
- User searchUsername(String username);
+ /**
+ * 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")
+ public List<User> getList()
+ {
+ List<User> user = null;
+ try
+ {
+ user = this.session.createQuery("from User").list();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
- void deleteUser(int userId);
+ // If no user was checked, return an empty list to mitigate null pointer
+ // exceptions
+ if (user == null)
+ {
+ user = new ArrayList<User>();
+ }
+ return user;
+ }
- User listUserById(int userId);
+ /**
+ * Executes the query to save the user
+ *
+ * @param user
+ * Domain object to be saved
+ * @return void
+ */
+ public void saveOrUpdate(User user)
+ {
+ try
+ {
+ this.session.saveOrUpdate(user);
+ }
+ catch (Exception e)
+ {
+ this.transaction.rollback();
+ e.printStackTrace();
+ }
+ }
- void saveOrUpdateUser(User user);
-}
+ /**
+ * Used to delete a user.
+ *
+ * @param userId
+ */
+ public void delete(int userId)
+ {
+ try
+ {
+ 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 getByUsername(String username)
+ {
+ User user = null;
+
+ // Exec query
+ try
+ {
+ 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.
+ *
+ * @param userId
+ * @return
+ */
+ public User getById(int userId)
+ {
+ User user = null;
+ try
+ {
+ user = (User) this.session.get(User.class, userId);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return user;
+ }
+}
\ No newline at end of file
/trunk/src/ch/ffhs/webE/dao/HistoryDAO.java
0,0 → 1,88
/**
*
*/
package ch.ffhs.webE.dao;
 
import java.util.ArrayList;
import java.util.List;
 
import org.hibernate.Session;
import org.hibernate.Transaction;
 
import ch.ffhs.webE.domain.History;
 
import com.googlecode.s2hibernate.struts2.plugin.annotations.SessionTarget;
import com.googlecode.s2hibernate.struts2.plugin.annotations.TransactionTarget;
 
/**
* @author pelinux
*
*/
public class HistoryDAO
{
/**
* Database session
*/
@SessionTarget
Session session;
 
/**
* Database transaction
*/
@TransactionTarget
Transaction transaction;
 
/**
* Executes the query to save the history record
*
* @param history
* Domain object to be saved
* @return <code>true</code> if successful, <code>false</code> otherwise
*/
public boolean saveOrUpdate(History history)
{
try
{
history.setId(history.getId());
this.session.saveOrUpdate(history);
return true;
}
catch (Exception e)
{
this.transaction.rollback();
e.printStackTrace();
return false;
}
}
 
/**
* Returns a list of all terms
*
* @return an ArrayList with all the terms - in case of a problem, an empty
* list is returned
*/
@SuppressWarnings("unchecked")
public List<History> getList()
{
List<History> history = null;
try
{
history = this.session.createQuery("from History").list(); //$NON-NLS-1$
}
catch (Exception e)
{
e.printStackTrace();
}
 
/*
* If no term was checked, return an empty list to mitigate null pointer
* exceptions
*/
if (history == null)
{
history = new ArrayList<History>();
}
 
return history;
}
}
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: webE/dao/RelationshipDAO.java
===================================================================
--- webE/dao/RelationshipDAO.java (nonexistent)
+++ webE/dao/RelationshipDAO.java (revision 37)
@@ -0,0 +1,130 @@
+package ch.ffhs.webE.dao;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+
+import ch.ffhs.webE.domain.Relationship;
+
+import com.googlecode.s2hibernate.struts2.plugin.annotations.SessionTarget;
+import com.googlecode.s2hibernate.struts2.plugin.annotations.TransactionTarget;
+
+/**
+ * Implements the Database Access Object for terms
+ *
+ * @author Thomas Lahn
+ */
+public class RelationshipDAO
+{
+ /**
+ * Database session
+ */
+ @SessionTarget
+ Session session;
+
+ /**
+ * Database transaction
+ */
+ @TransactionTarget
+ Transaction transaction;
+
+ /**
+ * Creates a list of all relationships
+ *
+ * @return an ArrayList with all the relationshops - in case of a problem, an
+ * empty list is returned
+ */
+ @SuppressWarnings("unchecked")
+ public List<Relationship> getList()
+ {
+ List<Relationship> relationship = null;
+ try
+ {
+ relationship = this.session.createQuery("from Relationship").list(); //$NON-NLS-1$
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ /*
+ * If no relationship was checked, return an empty list to mitigate null
+ * pointer exceptions
+ */
+ if (relationship == null)
+ {
+ relationship = new ArrayList<Relationship>();
+ }
+
+ return relationship;
+ }
+
+ /**
+ * Executes the query to save the relationship
+ *
+ * @param relationship
+ * Domain object to be saved
+ * @return <code>true</code> if successful, <code>false</code> otherwise
+ */
+ public boolean saveOrUpdate(Relationship relationship)
+ {
+ try
+ {
+ relationship.setObjectId(relationship.getObjectId());
+ this.session.saveOrUpdate(relationship);
+ return true;
+ }
+ catch (Exception e)
+ {
+ this.transaction.rollback();
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ /**
+ * Delete a relationship
+ *
+ * @param id
+ * Relationship ID
+ */
+ public void delete(int id)
+ {
+ try
+ {
+ Relationship relationship = (Relationship) this.session.get(
+ Relationship.class, id);
+ this.session.delete(relationship);
+ }
+ catch (Exception e)
+ {
+ this.transaction.rollback();
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Retrieves a relationship by ID
+ *
+ * @param id
+ * Term ID
+ * @return The relationship with this <var>id</var>
+ */
+ public Relationship getById(int id)
+ {
+ Relationship relationship = null;
+
+ try
+ {
+ relationship = (Relationship) this.session.get(Relationship.class, id);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ return relationship;
+ }
+}
\ No newline at end of file
/webE/dao/RelationshipDAO.java
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: webE/dao/RelationshipTypeDAO.java
===================================================================
--- webE/dao/RelationshipTypeDAO.java (revision 35)
+++ webE/dao/RelationshipTypeDAO.java (revision 37)
@@ -1,16 +1,130 @@
package ch.ffhs.webE.dao;
+import java.util.ArrayList;
import java.util.List;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+
import ch.ffhs.webE.domain.RelationshipType;
-public interface RelationshipTypeDAO {
+import com.googlecode.s2hibernate.struts2.plugin.annotations.SessionTarget;
+import com.googlecode.s2hibernate.struts2.plugin.annotations.TransactionTarget;
- List<RelationshipType> getRelTypes();
+/**
+ * Data Access Object class for {@link RelationshipType}s
+ *
+ * @author Thomas Lahn
+ */
+public class RelationshipTypeDAO
+{
- boolean deleteRelationshipType(int relTypeID);
-
- RelationshipType getRelTypeById(int relTypeID);
+ /**
+ * Hibernate session target
+ */
+ @SessionTarget
+ Session session;
- boolean saveOrUpdateRelType(RelationshipType relType);
+ /**
+ * Hibernate transaction target
+ */
+ @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")
+ public List<RelationshipType> getList()
+ {
+
+ List<RelationshipType> relType = null;
+
+ try
+ {
+ relType = this.session.createQuery("from RelationshipType").list(); //$NON-NLS-1$
+ }
+ catch (Exception e)
+ {
+ // TODO: Logging
+ }
+
+ if (relType == null)
+ {
+ relType = new ArrayList<RelationshipType>();
+ }
+
+ return relType;
+ }
+
+ /**
+ * Saves or updates a relationship type
+ *
+ * @param relType
+ * A filled domain object
+ * @return Boolean indicating success or error in saving the relationshipType
+ */
+ public boolean saveOrUpdate(RelationshipType relType)
+ {
+ try
+ {
+ this.session.saveOrUpdate(relType);
+ return true;
+ }
+ catch (Exception e)
+ {
+ this.transaction.rollback();
+ return false;
+ // TODO: Logging
+ }
+ }
+
+ /**
+ * Delete a relationship type
+ *
+ * @param relTypeId
+ * Relationship type ID
+ * @return boolean indicating success or error in the query execution
+ */
+ public boolean delete(int relTypeId)
+ {
+ try
+ {
+ RelationshipType relType = (RelationshipType) this.session.get(
+ RelationshipType.class, relTypeId);
+ this.session.delete(relType);
+ return true;
+ }
+ catch (Exception e)
+ {
+ this.transaction.rollback();
+ // TODO: Logging
+ return false;
+ }
+ }
+
+ /**
+ * Used to get a relationship type by ID
+ *
+ * @param relTypeID
+ * @return
+ */
+ public RelationshipType getById(int relTypeID)
+ {
+ RelationshipType relType = null;
+ try
+ {
+ relType = (RelationshipType) this.session.get(RelationshipType.class,
+ relTypeID);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ // TODO: Logging
+ }
+ return relType;
+ }
}
/trunk/src/ch/ffhs/webE/dao/TermDAO.java
1,28 → 1,108
package ch.ffhs.webE.dao;
 
import java.util.ArrayList;
import java.util.List;
 
import org.hibernate.Session;
import org.hibernate.Transaction;
 
import ch.ffhs.webE.domain.Term;
 
import com.googlecode.s2hibernate.struts2.plugin.annotations.SessionTarget;
import com.googlecode.s2hibernate.struts2.plugin.annotations.TransactionTarget;
 
/**
* Defines methods all term DAO implementations must implement
* Implements the Database Access Object for terms
*
* @author pelinux
* @author Thomas Lahn
*/
public interface TermDAO
public class TermDAO
{
/**
* @return
* Database session
*/
List<Term> getTerms();
@SessionTarget
Session session;
 
/**
* Database transaction
*/
@TransactionTarget
Transaction transaction;
 
/**
* Returns a list of all terms
*
* @return an ArrayList with all the terms - in case of a problem, an empty
* list is returned
*/
@SuppressWarnings("unchecked")
public List<Term> getList()
{
List<Term> term = null;
try
{
term = this.session.createQuery("from Term").list(); //$NON-NLS-1$
}
catch (Exception e)
{
e.printStackTrace();
}
 
/*
* If no term was checked, return an empty list to mitigate null pointer
* exceptions
*/
if (term == null)
{
term = new ArrayList<Term>();
}
 
return term;
}
 
/**
* Executes the query to save the term
*
* @param term
* Domain object to be saved
* @return <code>true</code> if successful, <code>false</code> otherwise
*/
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;
}
}
 
/**
* Delete a term
*
* @param termId
* Term ID
*/
void deleteTerm(int termId);
public void delete(int termId)
{
try
{
Term term = (Term) this.session.get(Term.class, termId);
this.session.delete(term);
}
catch (Exception e)
{
this.transaction.rollback();
e.printStackTrace();
}
}
 
/**
* Retrieves a term by ID
30,14 → 110,19
* @param termId
* @return
*/
Term getTermById(int termId);
public Term getById(int termId)
{
Term term = null;
 
/**
* Executes the query to save the term
*
* @param term
* Domain object to be saved
* @return <code>true</code> if successful, <code>false</code> otherwise
*/
boolean saveOrUpdate(Term term);
}
try
{
term = (Term) this.session.get(Term.class, termId);
}
catch (Exception e)
{
e.printStackTrace();
}
 
return term;
}
}
/trunk/src/ch/ffhs/webE/domain/ActionType.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;
18,47 → 20,78
*/
@Entity
@Table(name = "action_type", catalog = "webengineering")
public class ActionType implements java.io.Serializable {
public class ActionType implements java.io.Serializable
{
/**
* History action ID for adding an item
*/
public static final int ADD = 1;
 
private Integer id;
private String name;
private Set<History> histories = new HashSet<History>(0);
/**
* History action ID for renaming a term
*/
public static final int RENAME = 2;
 
public ActionType() {
}
/**
* History action ID for modifying a relationship
*/
public static final int MODIFY = 3;
 
public ActionType(String name, Set<History> histories) {
this.name = name;
this.histories = histories;
}
private int id;
private String name;
private Set<History> histories = new HashSet<History>(0);
 
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public Integer getId() {
return this.id;
}
public ActionType()
{
}
 
public void setId(Integer id) {
this.id = id;
}
/**
* @param id
*/
public ActionType(int id)
{
this.setId(id);
}
 
@Column(name = "name", length = 45)
public String getName() {
return this.name;
}
public ActionType(String name, Set<History> histories)
{
this.setName(name);
this.setHistories(histories);
}
 
public void setName(String name) {
this.name = name;
}
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public int getId()
{
return this.id;
}
 
@OneToMany(fetch = FetchType.LAZY, mappedBy = "actionType")
public Set<History> getHistories() {
return this.histories;
}
public void setId(int id)
{
this.id = id;
}
 
public void setHistories(Set<History> histories) {
this.histories = histories;
}
@Column(name = "name", length = 45)
public String getName()
{
return this.name;
}
 
public void setName(String name)
{
this.name = name;
}
 
@OneToMany(fetch = FetchType.LAZY, mappedBy = "actionType")
public Set<History> getHistories()
{
return this.histories;
}
 
public void setHistories(Set<History> histories)
{
this.histories = histories;
}
 
}
/trunk/src/ch/ffhs/webE/domain/History.java
2,12 → 2,14
 
// Generated 19.12.2010 14:46:08 by Hibernate Tools 3.4.0.Beta1
 
import static javax.persistence.GenerationType.IDENTITY;
 
import java.util.Date;
 
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.JoinColumn;
import javax.persistence.ManyToOne;
20,103 → 22,185
*/
@Entity
@Table(name = "history", catalog = "webengineering")
public class History implements java.io.Serializable {
public class History implements java.io.Serializable
{
/**
* Serialization version ID
*/
private static final long serialVersionUID = 1L;
 
private Integer id;
private User user;
private ActionType actionType;
private ObjectEntity object;
private String value;
private String comment;
private Date date;
private int id;
private User user;
private ActionType actionType;
private ObjectEntity object;
private String value;
private String comment;
private Date date;
 
public History() {
}
/**
*
*/
public History()
{
}
 
public History(User user, ActionType actionType, ObjectEntity object, Date date) {
this.user = user;
this.actionType = actionType;
this.object = object;
this.date = date;
}
/**
* @param user
* @param actionType
* @param object
* @param date
*/
public History(User user, ActionType actionType, ObjectEntity object,
Date date)
{
this.user = user;
this.actionType = actionType;
this.object = object;
this.date = date;
}
 
public History(User user, ActionType actionType, ObjectEntity object,
String value, String comment, Date date) {
this.user = user;
this.actionType = actionType;
this.object = object;
this.value = value;
this.comment = comment;
this.date = date;
}
/**
* @param user
* @param actionType
* @param object
* @param value
* @param comment
* @param date
*/
public History(User user, ActionType actionType, ObjectEntity object,
String value, String comment, Date date)
{
this.user = user;
this.actionType = actionType;
this.object = object;
this.value = value;
this.comment = comment;
this.date = date;
}
 
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public Integer getId() {
return this.id;
}
/**
* @return
*/
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public int getId()
{
return this.id;
}
 
public void setId(Integer id) {
this.id = id;
}
/**
* @param id
*/
public void setId(int id)
{
this.id = id;
}
 
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", nullable = false)
public User getUser() {
return this.user;
}
/**
* @return
*/
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", nullable = false)
public User getUser()
{
return this.user;
}
 
public void setUser(User user) {
this.user = user;
}
/**
* @param user
*/
public void setUser(User user)
{
this.user = user;
}
 
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "action_type_id", nullable = false)
public ActionType getActionType() {
return this.actionType;
}
/**
* @return
*/
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "action_type_id", nullable = false)
public ActionType getActionType()
{
return this.actionType;
}
 
public void setActionType(ActionType actionType) {
this.actionType = actionType;
}
/**
* @param actionType
*/
public void setActionType(ActionType actionType)
{
this.actionType = actionType;
}
 
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "objects_id", nullable = false)
public ObjectEntity getObject() {
return this.object;
}
/**
* @return
*/
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "objects_id", nullable = false)
public ObjectEntity getObject()
{
return this.object;
}
 
public void setObject(ObjectEntity object) {
this.object = object;
}
/**
* @param object
*/
public void setObject(ObjectEntity object)
{
this.object = object;
}
 
@Column(name = "value", length = 45)
public String getValue() {
return this.value;
}
/**
* @return
*/
@Column(name = "value", length = 45)
public String getValue()
{
return this.value;
}
 
public void setValue(String value) {
this.value = value;
}
/**
* @param value
*/
public void setValue(String value)
{
this.value = value;
}
 
@Column(name = "comment")
public String getComment() {
return this.comment;
}
/**
* @return
*/
@Column(name = "comment")
public String getComment()
{
return this.comment;
}
 
public void setComment(String comment) {
this.comment = comment;
}
/**
* @param comment
*/
public void setComment(String comment)
{
this.comment = comment;
}
 
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "date", nullable = false, length = 19)
public Date getDate() {
return this.date;
}
/**
* @return
*/
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "date", nullable = false, length = 19)
public Date getDate()
{
return this.date;
}
 
public void setDate(Date date) {
this.date = date;
}
/**
* @param date
*/
public void setDate(Date date)
{
this.date = date;
}
 
}
/trunk/src/ch/ffhs/webE/domain/ObjectEntity.java
22,6 → 22,8
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
 
import org.hibernate.annotations.OrderBy;
 
/**
* ObjectEntity generated by hbm2java
*/
43,7 → 45,7
private Date modified;
private Boolean deleted;
private Term term;
private Set<History> histories = new HashSet<History>(0);
private Set<History> history = new HashSet<History>(0);
private Relationship relationship;
 
/**
74,7 → 76,7
* @param modified
* @param deleted
* @param term
* @param histories
* @param history
* @param relationship
*/
public ObjectEntity(User userByEditorId, ObjectType objectType,
88,7 → 90,7
this.modified = modified;
this.deleted = deleted;
this.term = term;
this.histories = histories;
this.history = histories;
this.relationship = relationship;
}
 
239,17 → 241,18
* @return
*/
@OneToMany(fetch = FetchType.LAZY, mappedBy = "object")
public Set<History> getHistories()
@OrderBy(clause = "date DESC")
public Set<History> getHistory()
{
return this.histories;
return this.history;
}
 
/**
* @param histories
* @param history
*/
public void setHistories(Set<History> histories)
public void setHistory(Set<History> history)
{
this.histories = histories;
this.history = history;
}
 
/**
/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,15 → 51,17
{
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;
}
 
/**
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,15 → 65,17
{
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;
}
 
/**
104,7 → 115,7
// Check for malicious ID values
if (id > 0)
{
this.userDAO.deleteUser(id);
this.userDAO.delete(id);
return Action.SUCCESS;
}
else