Lade till alla Project-relaterade klasser och skrev om eventDao till SciPro events. Lade created och lastModified i DomainObject

git-svn-id: svn://svn.dsv.su.se/scipro/scipro/trunk@44 73ecded7-942e-4092-bab0-0e58ef0ee984
This commit is contained in:
dan-kjel 2011-02-01 17:30:20 +00:00
parent 7f48de7c27
commit 2483a2f89c
11 changed files with 537 additions and 40 deletions

@ -1,6 +1,10 @@
package se.su.dsv.scipro.data.dataobjects;
import java.util.Date;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import org.apache.wicket.IClusterable;
/**
@ -13,6 +17,35 @@ public abstract class DomainObject implements IClusterable{
private static final long serialVersionUID = 1L;
private Date dateCreated;
private Date lastModified;
abstract public Long getId();
@PreUpdate
@PrePersist
public void updateTimeStamps() {
lastModified = new Date();
if (dateCreated==null) {
dateCreated = new Date();
}
}
public Date getDateCreated() {
return dateCreated;
}
public void setDateCreated(Date dateCreated) {
this.dateCreated = dateCreated;
}
public Date getLastModified() {
return lastModified;
}
public void setLastModified(Date lastModified) {
this.lastModified = lastModified;
}
}

@ -13,7 +13,7 @@ import org.hibernate.annotations.CacheConcurrencyStrategy;
@Entity
@Cacheable(true)
@Cache(usage= CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) //Hibernate specific
public class Employee extends Role {
public class Employee extends ProjectTeamMember {
private static final long serialVersionUID = -2570983581219033271L;

@ -1,28 +1,51 @@
package se.su.dsv.scipro.data.dataobjects;
import java.util.Date;
import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
/**
* @author Richard Wilkinson - richard.wilkinson@jweekend.com
* @author Dan Kjellman - <dan-kjel@dsv.su.se>
*
*/
@Entity
@Table(name="event")
public class Event extends DomainObject {
@Cacheable(true)
@Cache(usage= CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Event extends LazyDeletableDomainObject implements Comparable<Event>{
private static final long serialVersionUID = 2959377496669050427L;
@Id
@GeneratedValue
private Long id;
@Column(nullable=false)
private String title;
private String location;
@Lob
private String description;
private boolean done = false;
@Column(nullable=false)
private Date dueDate;
@ManyToOne(optional=false)
private ProjectSchedule projectSchedule;
public Event() {}
public Long getId() {
return id;
}
@ -38,55 +61,76 @@ public class Event extends DomainObject {
public void setTitle(String title) {
this.title = title;
}
public String getLocation() {
return location;
public String getDescription() {
return description;
}
public void setLocation(String location) {
this.location = location;
public void setDescription(String description) {
this.description = description;
}
public boolean isDone() {
return done;
}
public void setDone(boolean done) {
this.done = done;
}
public Date getDueDate() {
return dueDate;
}
public void setDueDate(Date dueDate) {
this.dueDate = dueDate;
}
public ProjectSchedule getProjectSchedule() {
return projectSchedule;
}
public void setProjectSchedule(ProjectSchedule projectSchedule) {
this.projectSchedule = projectSchedule;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result
+ ((location == null) ? 0 : location.hashCode());
result = prime * result + ((title == null) ? 0 : title.hashCode());
final int weight = 31;
int result = 17;
result = weight * result + ((id == null) ? 0 : (int) (id ^ (id >>> 32)));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
if (this.getClass() != obj.getClass())
return false;
Event other = (Event) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
if (location == null) {
if (other.location != null)
return false;
} else if (!location.equals(other.location))
return false;
if (title == null) {
if (other.title != null)
return false;
} else if (!title.equals(other.title))
return false;
return true;
}
@Override
public String toString() {
return String.format("Event [id=%s, location=%s, title=%s]", id, location, title);
return String.format("Event [id=%s, title=%s, description=%s due-date=%s]", id, title, description, dueDate);
}
@Override
public int compareTo(Event other) {
return (int) (dueDate.getTime() - other.dueDate.getTime());
}
}

@ -28,9 +28,4 @@ public abstract class LazyDeletableDomainObject extends DomainObject implements
public boolean isDeleted() {
return deleted;
}
}

@ -0,0 +1,168 @@
package se.su.dsv.scipro.data.dataobjects;
import java.util.Set;
import java.util.TreeSet;
import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import se.su.dsv.scipro.data.enums.ProjectStatus;
@Entity
@Table(name="project")
@Cacheable(true)
@Cache(usage= CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Project extends DomainObject implements Comparable<Project> {
private static final long serialVersionUID = 9071570648984376188L;
@Id
@GeneratedValue
private Long id;
@OneToOne
private ProjectSchedule projectSchedule;
@Column(unique=true)
private Long identifier;
private String title;
@ManyToMany
private Set<Student> projectParticipants = new TreeSet<Student>();
@OneToMany(mappedBy="project")
private Set<ProjectFollower> projectFollowers = new TreeSet<ProjectFollower>();
@ManyToOne
private Employee headSupervisor;
@Enumerated(EnumType.STRING)
private ProjectStatus projectStatus = ProjectStatus.ACTIVE;
public Project() {}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public ProjectSchedule getProjectSchedule() {
return projectSchedule;
}
public void setProjectSchedule(ProjectSchedule projectSchedule) {
this.projectSchedule = projectSchedule;
}
public Long getIdentifier() {
return identifier;
}
public void setIdentifier(Long identifier) {
this.identifier = identifier;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Set<Student> getProjectParticipants() {
return new TreeSet<Student>(projectParticipants);
}
public void setProjectParticipants(TreeSet<Student> projectParticipants) {
this.projectParticipants = projectParticipants;
}
public Set<ProjectFollower> getProjectFollowers() {
return new TreeSet<ProjectFollower>(projectFollowers);
}
public void setProjectFollowers(TreeSet<ProjectFollower> projectFollowers) {
this.projectFollowers = projectFollowers;
}
public Employee getHeadSupervisor() {
return headSupervisor;
}
public void setHeadSupervisor(Employee headSupervisor) {
this.headSupervisor = headSupervisor;
}
public ProjectStatus getProjectStatus() {
return projectStatus;
}
public void setProjectStatus(ProjectStatus projectStatus) {
this.projectStatus = projectStatus;
}
public void addProjectParticipant(Student s){
projectParticipants.add(s);
}
@Override
public int hashCode() {
final int weight = 31;
int result = 17;
result = weight * result + ((id == null) ? 0 : (int) (id ^ (id >>> 32)));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (this.getClass() != obj.getClass())
return false;
Project other = (Project) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
return true;
}
@Override
public int compareTo(Project other){
return title.compareTo(other.title);
}
@Override
public String toString(){
return String.format("Project id=%s, Title=%s, Status=%s", id, title, projectStatus);
}
}

@ -0,0 +1,112 @@
package se.su.dsv.scipro.data.dataobjects;
import javax.persistence.Cacheable;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import se.su.dsv.scipro.data.enums.ProjectTeamMemberRoles;
@Entity
@Table(name="project_follower", uniqueConstraints={@UniqueConstraint(columnNames={"project_id","follower_id"}, name = "follower_is_unique")})
@Cacheable(true)
@Cache(usage= CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class ProjectFollower extends LazyDeletableDomainObject implements Comparable<ProjectFollower> {
private static final long serialVersionUID = -2965166136445565739L;
@Id
@GeneratedValue
private Long id;
@ManyToOne
private ProjectTeamMember follower;
@Enumerated(EnumType.STRING)
private ProjectTeamMemberRoles projectRole;
@ManyToOne
private Project project;
public ProjectFollower(){}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public ProjectTeamMember getFollower() {
return follower;
}
public void setFollower(ProjectTeamMember follower) {
this.follower = follower;
}
public ProjectTeamMemberRoles getProjectRole() {
return projectRole;
}
public void setProjectRole(ProjectTeamMemberRoles projectRole) {
this.projectRole = projectRole;
}
public Project getProject() {
return project;
}
public void setProject(Project project) {
this.project = project;
}
@Override
public int hashCode() {
final int weight = 31;
int result = 17;
result = weight * result + ((id == null) ? 0 : (int) (id ^ (id >>> 32)));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (this.getClass() != obj.getClass())
return false;
ProjectFollower other = (ProjectFollower) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
return true;
}
@Override
public String toString() {
return String.format("Follower [id=%s, User=%s, ProjectRole=%s]", id, follower.getUser().getEmailAddress(), projectRole);
}
@Override
public int compareTo(ProjectFollower other) {
return follower.getUser().compareTo(other.follower.getUser());
}
}

@ -0,0 +1,107 @@
package se.su.dsv.scipro.data.dataobjects;
import java.util.Set;
import java.util.TreeSet;
import javax.persistence.Cacheable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
@Entity
@Table(name="project_schedule")
@Cacheable(true)
@Cache(usage= CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class ProjectSchedule extends DomainObject {
private static final long serialVersionUID = 8376107388429819674L;
@Id
@GeneratedValue
private Long id;
@OneToMany(mappedBy="projectSchedule")
private Set<Event> events = new TreeSet<Event>();
@OneToOne(optional=false)
private Project project;
private boolean locked = false;
public ProjectSchedule() {}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Set<Event> getEvents() {
return events;
}
public void setEvents(Set<Event> events) {
this.events = events;
}
public boolean isLocked() {
return locked;
}
public void setLocked(boolean locked) {
this.locked = locked;
}
public Project getProject() {
return project;
}
public void setProject(Project project) {
this.project = project;
}
@Override
public int hashCode() {
final int weight = 31;
int result = 17;
result = weight * result + ((id == null) ? 0 : (int) (id ^ (id >>> 32)));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (this.getClass() != obj.getClass())
return false;
ProjectSchedule other = (ProjectSchedule) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
return true;
}
@Override
public String toString() {
return String.format("ProjectSchedule [id=%s, Locked=%s, EventCount=%s]", id, locked, events.size());
}
}

@ -0,0 +1,10 @@
package se.su.dsv.scipro.data.dataobjects;
import javax.persistence.Entity;
@Entity
public abstract class ProjectTeamMember extends Role {
private static final long serialVersionUID = 1136134974610396923L;
}

@ -15,7 +15,7 @@ import javax.persistence.UniqueConstraint;
@DiscriminatorColumn(name = "rolename", discriminatorType = DiscriminatorType.STRING, length = 8)
@Table(name="role", uniqueConstraints={@UniqueConstraint(columnNames={"user_id","rolename"}, name = "role_is_unique")})
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
public abstract class Role extends LazyDeletableDomainObject {
public abstract class Role extends LazyDeletableDomainObject implements Comparable<Role> {
private static final long serialVersionUID = 1L;
@ -92,5 +92,13 @@ public abstract class Role extends LazyDeletableDomainObject {
tmp = tmp + " (" + user.getEmailAddress() + ")";
return tmp;
}
/**
* Compares the owner (user) of the role (alphabetically on names)
*/
@Override
public int compareTo(Role other){
return user.compareTo(other.user);
}
}

@ -2,7 +2,6 @@ package se.su.dsv.scipro.data.dataobjects;
import javax.persistence.Cacheable;
import javax.persistence.Entity;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
@ -16,6 +15,5 @@ import org.hibernate.annotations.CacheConcurrencyStrategy;
public class Student extends Role {
private static final long serialVersionUID = 6274323425191904206L;
}

@ -4,7 +4,6 @@ import java.util.HashSet;
import java.util.Set;
import javax.persistence.Cacheable;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
@ -14,6 +13,7 @@ import javax.persistence.Table;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
/**
* @author Martin Peters - mpeters@dsv.su.se
*
@ -22,7 +22,7 @@ import org.hibernate.annotations.CacheConcurrencyStrategy;
@Table(name="user")
@Cacheable(true)
@Cache(usage= CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) //Hibernate specific
public class User extends LazyDeletableDomainObject {
public class User extends LazyDeletableDomainObject implements Comparable<User> {
private static final long serialVersionUID = 8116476815877870372L;
@ -132,5 +132,27 @@ public class User extends LazyDeletableDomainObject {
return true;
}
@Override
public int compareTo(User other){
if(lastName != null){
if(other.lastName != null){
int lastNameResult = lastName.compareTo(other.lastName);
if(lastNameResult == 0){
if(firstName != null){
if(other.firstName != null){
return firstName.compareTo(other.firstName);
}
return 1;
}
}
return lastNameResult;
}
} else if (other.lastName != null){
return -1;
}
return 0;
}
}