Hela event och projektstruktur

git-svn-id: svn://svn.dsv.su.se/scipro/scipro/trunk@101 73ecded7-942e-4092-bab0-0e58ef0ee984
This commit is contained in:
dan-kjel 2011-02-11 08:10:28 +00:00
parent 6c97acb6ce
commit b01020c2ff
8 changed files with 194 additions and 43 deletions

@ -1,28 +1,32 @@
package se.su.dsv.scipro.data.dataobjects;
import java.util.Date;
import java.util.List;
import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.apache.wicket.markup.html.panel.Panel;
import se.su.dsv.scipro.data.dao.interfaces.AjaxFromDialogUpdatingListPanel;
import se.su.dsv.scipro.data.dao.interfaces.EventParticipant;
/**
* @author Dan Kjellman - <dan-kjel@dsv.su.se>
*
*/
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@Table(name="event")
@Cacheable(true)
@Cache(usage= CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Event extends LazyDeletableDomainObject implements Comparable<Event>{
public abstract class Event extends LazyDeletableDomainObject
implements Comparable<Event> {
private static final long serialVersionUID = 2959377496669050427L;
@ -35,14 +39,12 @@ public class Event extends LazyDeletableDomainObject implements Comparable<Event
@Lob
private String description;
private boolean done = false;
@ManyToOne(optional=true)
private Role creator;
@Column(nullable=false)
private Date dueDate;
@ManyToOne(optional=false)
private ProjectSchedule projectSchedule;
public Event() {}
@ -70,14 +72,6 @@ public class Event extends LazyDeletableDomainObject implements Comparable<Event
this.description = description;
}
public boolean isDone() {
return done;
}
public void setDone(boolean done) {
this.done = done;
}
public Date getDueDate() {
return dueDate;
}
@ -86,13 +80,15 @@ public class Event extends LazyDeletableDomainObject implements Comparable<Event
this.dueDate = dueDate;
}
public ProjectSchedule getProjectSchedule() {
return projectSchedule;
public void setCreator(Role creator) {
this.creator = creator;
}
public void setProjectSchedule(ProjectSchedule projectSchedule) {
this.projectSchedule = projectSchedule;
public Role getCreator() {
return creator;
}
public abstract List<EventParticipant> getEventParticipants();
@Override
public int hashCode() {
@ -133,4 +129,6 @@ public class Event extends LazyDeletableDomainObject implements Comparable<Event
public int compareTo(Event other) {
return (int) (dueDate.getTime() - other.dueDate.getTime());
}
public abstract Panel getSchedulePanel(String id, AjaxFromDialogUpdatingListPanel<Event> parent);
}

@ -0,0 +1,49 @@
package se.su.dsv.scipro.data.dataobjects;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import org.apache.wicket.markup.html.panel.Panel;
import se.su.dsv.scipro.data.dao.interfaces.AjaxFromDialogUpdatingListPanel;
import se.su.dsv.scipro.data.dao.interfaces.EventParticipant;
import se.su.dsv.scipro.schedule.panels.GroupEventPanel;
@Entity
@Table(name="group_event")
public class GroupEvent extends Event {
private static final long serialVersionUID = 1027497624747494476L;
@ManyToMany
private List<ProjectSchedule> projectSchedules = new ArrayList<ProjectSchedule>();
public List<ProjectSchedule> getProjectSchedules() {
return new ArrayList<ProjectSchedule>(projectSchedules);
}
public void setProjectSchedules(List<ProjectSchedule> projectSchedules) {
this.projectSchedules = projectSchedules;
}
public void addProjectSchedule(ProjectSchedule ps){
projectSchedules.add(ps);
}
public List<EventParticipant> getEventParticipants(){
List<EventParticipant> list = new ArrayList<EventParticipant>();
for(ProjectSchedule ps : projectSchedules){
list.add(ps.getProject());
}
return list;
}
public Panel getSchedulePanel(String id, AjaxFromDialogUpdatingListPanel<Event> parent){
return new GroupEventPanel(id, this, parent);
}
}

@ -8,8 +8,10 @@ import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
@ -19,13 +21,14 @@ import javax.persistence.Table;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import se.su.dsv.scipro.data.dao.interfaces.EventParticipant;
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> {
public class Project extends DomainObject implements Comparable<Project>, EventParticipant {
private static final long serialVersionUID = 9071570648984376188L;
@ -33,7 +36,7 @@ public class Project extends DomainObject implements Comparable<Project> {
@GeneratedValue
private Long id;
@OneToOne
@OneToOne(mappedBy="project")
private ProjectSchedule projectSchedule;
@Column(unique=true)
@ -41,7 +44,8 @@ public class Project extends DomainObject implements Comparable<Project> {
private String title;
@ManyToMany
@ManyToMany(fetch=FetchType.EAGER)
@JoinTable(name="project_student")
private Set<Student> projectParticipants = new TreeSet<Student>();
@OneToMany(mappedBy="project")
@ -91,7 +95,7 @@ public class Project extends DomainObject implements Comparable<Project> {
return new TreeSet<Student>(projectParticipants);
}
public void setProjectParticipants(TreeSet<Student> projectParticipants) {
public void setProjectParticipants(Set<Student> projectParticipants) {
this.projectParticipants = projectParticipants;
}
@ -123,6 +127,10 @@ public class Project extends DomainObject implements Comparable<Project> {
public void addProjectParticipant(Student s){
projectParticipants.add(s);
}
public String getEventParticipantAsString(){
return title;
}
@Override
public int hashCode() {
@ -161,7 +169,7 @@ public class Project extends DomainObject implements Comparable<Project> {
@Override
public String toString(){
return String.format("Project id=%s, Title=%s, Status=%s", id, title, projectStatus);
return String.format("Project id=%s, Title=%s, Status=%s, ScheduleId=%s", id, title, projectStatus, projectSchedule);
}

@ -0,0 +1,65 @@
package se.su.dsv.scipro.data.dataobjects;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javax.persistence.Entity;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.apache.wicket.markup.html.panel.Panel;
import se.su.dsv.scipro.data.dao.interfaces.AjaxFromDialogUpdatingListPanel;
import se.su.dsv.scipro.data.dao.interfaces.EventParticipant;
import se.su.dsv.scipro.schedule.panels.ProjectEventPanel;
@Entity
@Table(name="project_event")
public class ProjectEvent extends Event {
private static final long serialVersionUID = 8183387004042966762L;
@ManyToOne(optional=false)
private ProjectSchedule projectSchedule;
@ManyToMany
@JoinTable(name="project_event_student")
private Set<Student> participants;
private boolean done = false;
public ProjectSchedule getProjectSchedule() {
return projectSchedule;
}
public void setProjectSchedule(ProjectSchedule projectSchedule) {
this.projectSchedule = projectSchedule;
}
public Set<Student> getParticipants() {
return participants;
}
public void setParticipants(Set<Student> participants) {
this.participants = participants;
}
public boolean isDone() {
return done;
}
public void setDone(boolean done) {
this.done = done;
}
public List<EventParticipant> getEventParticipants() {
return new ArrayList<EventParticipant>(participants);
}
public Panel getSchedulePanel(String id, AjaxFromDialogUpdatingListPanel<Event> parent){
return new ProjectEventPanel(id, this, parent);
}
}

@ -7,6 +7,7 @@ import javax.persistence.Cacheable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
@ -27,15 +28,16 @@ public class ProjectSchedule extends DomainObject {
private Long id;
@OneToMany(mappedBy="projectSchedule")
private Set<Event> events = new TreeSet<Event>();
private Set<ProjectEvent> projectEvents = new TreeSet<ProjectEvent>();
@ManyToMany(mappedBy="projectSchedules")
private Set<GroupEvent> groupEvents = new TreeSet<GroupEvent>();
@OneToOne(optional=false)
private Project project;
private boolean locked = false;
public ProjectSchedule() {}
public Long getId() {
@ -46,14 +48,6 @@ public class ProjectSchedule extends DomainObject {
this.id = id;
}
public Set<Event> getEvents() {
return events;
}
public void setEvents(Set<Event> events) {
this.events = events;
}
public boolean isLocked() {
return locked;
}
@ -69,7 +63,23 @@ public class ProjectSchedule extends DomainObject {
public void setProject(Project project) {
this.project = project;
}
public Set<ProjectEvent> getProjectEvents() {
return projectEvents;
}
public void setProjectEvents(Set<ProjectEvent> projectEvents) {
this.projectEvents = projectEvents;
}
public Set<GroupEvent> getGroupEvents() {
return groupEvents;
}
public void setGroupEvents(Set<GroupEvent> groupEvents) {
this.groupEvents = groupEvents;
}
@Override
public int hashCode() {
final int weight = 31;
@ -102,6 +112,6 @@ public class ProjectSchedule extends DomainObject {
@Override
public String toString() {
return String.format("ProjectSchedule [id=%s, Locked=%s, EventCount=%s]", id, locked, events.size());
return String.format("ProjectSchedule [id=%s, Locked=%s, EventCount=%s, ProjectId=%s]", id, locked, projectEvents.size() + groupEvents.size(), project.getId());
}
}

@ -11,11 +11,13 @@ import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import se.su.dsv.scipro.data.dao.interfaces.EventParticipant;
@Entity
@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 implements Comparable<Role> {
public abstract class Role extends LazyDeletableDomainObject implements Comparable<Role>, EventParticipant {
private static final long serialVersionUID = 1L;
@ -54,6 +56,22 @@ public abstract class Role extends LazyDeletableDomainObject implements Comparab
return user;
}
public String getEventParticipantAsString(){
String str = "";
if(user.getFirstName() != null){
str += user.getFirstName();
}
if(user.getLastName() != null){
str += user.getLastName();
}
if(user.getEmailAddress() != null){
str += "(" + user.getEmailAddress() + ")";
}
return str;
}
@Override
public int hashCode() {
final int prime = 31;

@ -2,9 +2,12 @@ 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;
import se.su.dsv.scipro.data.dao.interfaces.EventParticipant;
/**
* @author Martin Peters - mpeters@se.su.dsv
*

@ -152,7 +152,7 @@ public class User extends LazyDeletableDomainObject implements Comparable<User>
return -1;
}
return 0;
return id.intValue() - other.id.intValue();
}
}