Merge branch 'checklists' of ssh://git.dsv.su.se/git/scipro/personal/fn into checklists

* 'checklists' of ssh://git.dsv.su.se/git/scipro/personal/fn:
  checklist data classes
This commit is contained in:
Fredrik Norberg 2011-07-27 16:49:33 +02:00
commit 2a433f5cc5
6 changed files with 202 additions and 118 deletions

@ -1,7 +1,11 @@
package se.su.dsv.scipro.data.dao.interfaces;
import java.util.List;
import se.su.dsv.scipro.data.dataobjects.CheckList;
import se.su.dsv.scipro.data.dataobjects.Project;
public interface CheckListDao extends Dao<CheckList> {
public List<CheckList> findCheckLists(final Project project);
}

@ -1,9 +1,20 @@
package se.su.dsv.scipro.data.dao.jpa;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceException;
import javax.persistence.TypedQuery;
import org.hibernate.ejb.QueryHints;
import org.springframework.orm.jpa.JpaCallback;
import org.springframework.stereotype.Repository;
import se.su.dsv.scipro.data.dao.interfaces.CheckListDao;
import se.su.dsv.scipro.data.dataobjects.CheckList;
import se.su.dsv.scipro.data.dataobjects.Project;
/**
*
@ -12,10 +23,28 @@ import se.su.dsv.scipro.data.dataobjects.CheckList;
*/
@Repository("checkListDao")
public class CheckListDaoJPAImp extends AbstractDaoJPAImp<CheckList>
implements CheckListDao {
public class CheckListDaoJPAImp extends AbstractDaoJPAImp<CheckList> implements CheckListDao {
public CheckListDaoJPAImp() {
super(CheckList.class);
}
public List<CheckList> findCheckLists(final Project project) {
return getJpaTemplate().execute(new JpaCallback<List<CheckList>>() {
public List<CheckList> doInJpa(EntityManager em) throws PersistenceException {
String q = "select s " + "from CheckList s " + "where s.project = :project";
TypedQuery<CheckList> query = em.createQuery(q, CheckList.class);
query.setParameter("project", project);
query.setHint(QueryHints.HINT_CACHEABLE, "true");
try {
return query.getResultList();
} catch (NoResultException e) {
return new ArrayList<CheckList>();
}
}
});
}
}

@ -1,6 +1,7 @@
package se.su.dsv.scipro.data.dataobjects;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
import javax.persistence.Cacheable;
import javax.persistence.Column;
@ -8,49 +9,52 @@ import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Sort;
import org.hibernate.annotations.SortType;
/**
* @author Fredrik Norberg fnorbe@dsv.su.se
*
*
* @author Fredrik Norberg fnorbe@dsv.su.se
*
*/
@Entity
@Table(name="checklist")
@Table(name = "checklist")
@Cacheable(true)
@Cache(usage= CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) //Hibernate
public abstract class CheckList extends LazyDeletableDomainObject{
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
// Hibernate
public class CheckList extends DomainObject {
private static final long serialVersionUID = 2959377496669050427L;
@Id
@GeneratedValue
private Long id;
@Column(nullable=false)
@Column(nullable = false)
private String name;
@ManyToOne(optional = false)
private Project project;
@ManyToOne(optional=false)
private User creator;
@Column(nullable=false)
private List<CheckListQuestion> questions;
@Column(nullable=false)
private ProjectClass level;
public CheckList() {}
public CheckList(String name, User creator, ProjectClass level) {
this.name = name;
this.creator = creator;
this.level = level;
@OneToMany
@Sort(type = SortType.NATURAL)
private SortedSet<CheckListQuestion> questions = new TreeSet<CheckListQuestion>();
public CheckList() {
}
public CheckList(String name, Project project) {
this.name = name;
this.project = project;
}
public Long getId() {
return id;
}
@ -59,66 +63,59 @@ public abstract class CheckList extends LazyDeletableDomainObject{
this.id = id;
}
public String getname() {
return name;
}
public String getName(final int characters) {
String result = name;
if(name.length() > characters)
result = name.substring(0, characters)+"..";
return result;
}
public void setName(String name) {
this.name = name;
}
public void setCreator(User creator) {
this.creator = creator;
}
public User getCreator() {
return creator;
}
public List<CheckListQuestion> getquestions(){
/**
* @return the questions
*/
public SortedSet<CheckListQuestion> getQuestions() {
return questions;
}
public void setquestions(List<CheckListQuestion> questions){
this.questions=questions;
/**
* @param questions
* the questions to set
*/
public void setQuestions(SortedSet<CheckListQuestion> questions) {
this.questions = questions;
}
public void setLevel(ProjectClass level){
this.level = level;
/**
* @return the project
*/
public Project getProject() {
return project;
}
public ProjectClass getLevel(){
return level;
/**
* @param project the project to set
*/
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 (obj instanceof CheckList){
if (obj instanceof CheckList) {
CheckList other = (CheckList) obj;
if (id == null) {
if (other.id != null)
return false;
@ -130,11 +127,11 @@ public abstract class CheckList extends LazyDeletableDomainObject{
return false;
}
@Override
public String toString() {
return getname();
/**
* @return the name
*/
public String getName() {
return name;
}
}

@ -1,53 +1,55 @@
package se.su.dsv.scipro.data.dataobjects;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.TypedQuery;
import org.apache.wicket.markup.html.panel.Panel;
import se.su.dsv.scipro.data.enums.CheckListQuestionAnswer;
import se.su.dsv.scipro.data.enums.EventStatus;
import se.su.dsv.scipro.schedule.baseevent.panels.EventScheduleDetailsPanel;
import se.su.dsv.scipro.util.IAjaxCallback;
/**
* @author Fredrik Norberg fnorbe@dsv.su.se
*
* @author Fredrik Norberg fnorbe@dsv.su.se
*
*/
@Entity
@Table(name="checklist_answer")
public class CheckListAnswer extends DomainObject{
@Table(name = "checklist_answer")
public class CheckListAnswer extends DomainObject {
private static final long serialVersionUID = 2959377496669050427L;
@Id
@GeneratedValue
private Long id;
@Enumerated(EnumType.STRING)
@Column(nullable=false)
private CheckListQuestionAnswer answer;
@ManyToOne
@ManyToOne(optional=false)
private User user;
public CheckListAnswer() {}
@Lob
private String comment;
public CheckListAnswer() {
}
public CheckListAnswer(User user, CheckListQuestionAnswer answer) {
this.user = user;
this.answer = answer;
}
public CheckListAnswer(User user, CheckListQuestionAnswer answer, String comment) {
this.user = user;
this.answer = answer;
this.comment = comment;
}
public CheckListQuestionAnswer getAnswer() {
return answer;
}
@ -71,27 +73,43 @@ public class CheckListAnswer extends DomainObject{
public void setId(Long id) {
this.id = id;
}
/**
* @return the comment
*/
public String getComment() {
return comment;
}
/**
* @param comment the comment to set
*/
public void setComment(String comment) {
this.comment = comment;
}
@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 (obj instanceof CheckListAnswer){
if (obj instanceof CheckListAnswer) {
CheckListAnswer other = (CheckListAnswer) obj;
if (id == null) {
if (other.id != null)
return false;

@ -1,5 +1,6 @@
package se.su.dsv.scipro.data.dataobjects;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Cacheable;
@ -18,37 +19,37 @@ import org.hibernate.annotations.CacheConcurrencyStrategy;
* @author Fredrik Norberg - fnorbe@dsv.su.se
*/
@Entity
@Table(name="checklist_question")
@Table(name = "checklist_question")
@Cacheable(true)
@Cache(usage= CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) //Hibernate
public abstract class CheckListQuestion extends DomainObject
implements Comparable<CheckListQuestion> {
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class CheckListQuestion extends DomainObject implements
Comparable<CheckListQuestion> {
private static final long serialVersionUID = 2959377496669050427L;
@Id
@GeneratedValue
private Long id;
@Lob
@Column(nullable=false)
@Column(nullable = false)
private String question;
@Column(nullable=false)
@Column(nullable = false)
private int questionNumber;
@OneToMany
List<CheckListAnswer> answers;
public CheckListQuestion() {}
private List<CheckListAnswer> answers = new ArrayList<CheckListAnswer>(1);
public CheckListQuestion() {
}
public CheckListQuestion(String question) {
this.question = question;
questionNumber = answers.size() + 1;
}
public String getQuestion() {
return question;
}
@ -64,7 +65,7 @@ public abstract class CheckListQuestion extends DomainObject
public void setQuestionNumber(int questionNumber) {
this.questionNumber = questionNumber;
}
public Long getId() {
return id;
}
@ -72,27 +73,43 @@ public abstract class CheckListQuestion extends DomainObject
public void setId(Long id) {
this.id = id;
}
/**
* @return the answers
*/
public List<CheckListAnswer> getAnswers() {
return answers;
}
/**
* @param answers the answers to set
*/
public void setAnswers(List<CheckListAnswer> answers) {
this.answers = answers;
}
@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 (obj instanceof CheckListQuestion){
if (obj instanceof CheckListQuestion) {
CheckListQuestion other = (CheckListQuestion) obj;
if (id == null) {
if (other.id != null)
return false;
@ -111,6 +128,6 @@ public abstract class CheckListQuestion extends DomainObject
@Override
public int compareTo(CheckListQuestion other) {
return questionNumber - other.questionNumber;
return other.questionNumber - questionNumber;
}
}

@ -1,5 +1,6 @@
package se.su.dsv.scipro.data.dataobjects;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Column;
@ -30,11 +31,14 @@ public class CheckListTemplate extends DomainObject {
@Lob
@ElementCollection
List<String> questions;
private List<String> questions = new ArrayList<String>(1);
@ManyToOne(optional=false)
private User creator;
@ManyToOne(optional=false)
private ProjectClass level;
public CheckListTemplate() {}
public CheckListTemplate(String name, User creator) {
@ -74,6 +78,21 @@ public class CheckListTemplate extends DomainObject {
this.questions = questions;
}
/**
* @return the level
*/
public ProjectClass getLevel() {
return level;
}
/**
* @param level the level to set
*/
public void setLevel(ProjectClass level) {
this.level = level;
}
@Override
public int hashCode() {
final int weight = 31;