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,13 +9,16 @@ 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
*
*/
@ -22,8 +26,9 @@ import org.hibernate.annotations.CacheConcurrencyStrategy;
@Entity
@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;
@ -35,20 +40,19 @@ public abstract class CheckList extends LazyDeletableDomainObject{
private String name;
@ManyToOne(optional = false)
private User creator;
private Project project;
@Column(nullable=false)
private List<CheckListQuestion> questions;
@Column(nullable=false)
private ProjectClass level;
@OneToMany
@Sort(type = SortType.NATURAL)
private SortedSet<CheckListQuestion> questions = new TreeSet<CheckListQuestion>();
public CheckList() {}
public CheckList() {
}
public CheckList(String name, User creator, ProjectClass level) {
public CheckList(String name, Project project) {
this.name = name;
this.creator = creator;
this.level = level;
this.project = project;
}
public Long getId() {
@ -59,44 +63,37 @@ 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){
/**
* @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
@ -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,24 +1,16 @@
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
@ -35,19 +27,29 @@ public class CheckListAnswer extends DomainObject{
private Long id;
@Enumerated(EnumType.STRING)
@Column(nullable=false)
private CheckListQuestionAnswer answer;
@ManyToOne
@ManyToOne(optional=false)
private User user;
@Lob
private String comment;
public CheckListAnswer() {}
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;
}
@ -72,6 +74,22 @@ public class CheckListAnswer extends DomainObject{
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;

@ -1,5 +1,6 @@
package se.su.dsv.scipro.data.dataobjects;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Cacheable;
@ -18,13 +19,12 @@ import org.hibernate.annotations.CacheConcurrencyStrategy;
* @author Fredrik Norberg - fnorbe@dsv.su.se
*/
@Entity
@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;
@ -40,9 +40,10 @@ public abstract class CheckListQuestion extends DomainObject
private int questionNumber;
@OneToMany
List<CheckListAnswer> answers;
private List<CheckListAnswer> answers = new ArrayList<CheckListAnswer>(1);
public CheckListQuestion() {}
public CheckListQuestion() {
}
public CheckListQuestion(String question) {
this.question = question;
@ -73,6 +74,22 @@ public abstract class CheckListQuestion extends DomainObject
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;
@ -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;