Merge branch 'feature' into develop
This commit is contained in:
commit
081cfac35a
resources/db_update_scripts
src
main/java/se/su/dsv/scipro
checklists/panels
data/dataobjects
springdata
supervisor/pages
test/java/se/su/dsv/scipro/springdata
@ -0,0 +1,12 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS `CheckList_userLastOpenDate` (
|
||||||
|
`CheckList_id` bigint(20) NOT NULL,
|
||||||
|
`userLastOpenDate` datetime DEFAULT NULL,
|
||||||
|
`userLastOpenDate_KEY` bigint(20) NOT NULL,
|
||||||
|
PRIMARY KEY (`CheckList_id`,`userLastOpenDate_KEY`),
|
||||||
|
KEY `FKF7E07AB26D025A9` (`userLastOpenDate_KEY`),
|
||||||
|
KEY `FKF7E07AB21F327355` (`CheckList_id`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||||
|
|
||||||
|
ALTER TABLE `CheckList_userLastOpenDate`
|
||||||
|
ADD CONSTRAINT `FKF7E07AB21F327355` FOREIGN KEY (`CheckList_id`) REFERENCES `checklist` (`id`),
|
||||||
|
ADD CONSTRAINT `FKF7E07AB26D025A9` FOREIGN KEY (`userLastOpenDate_KEY`) REFERENCES `user` (`id`);
|
@ -7,23 +7,23 @@ import org.apache.wicket.model.Model;
|
|||||||
import org.apache.wicket.model.PropertyModel;
|
import org.apache.wicket.model.PropertyModel;
|
||||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||||
import org.odlabs.wiquery.ui.dialog.Dialog;
|
import org.odlabs.wiquery.ui.dialog.Dialog;
|
||||||
|
import se.su.dsv.scipro.SciProSession;
|
||||||
import se.su.dsv.scipro.checklists.panels.AnswerDialogPanel.AnswerDialog;
|
|
||||||
import se.su.dsv.scipro.data.dao.interfaces.CheckListAnswerDao;
|
import se.su.dsv.scipro.data.dao.interfaces.CheckListAnswerDao;
|
||||||
import se.su.dsv.scipro.data.dao.interfaces.CheckListQuestionDao;
|
import se.su.dsv.scipro.data.dao.interfaces.CheckListQuestionDao;
|
||||||
import se.su.dsv.scipro.data.dataobjects.CheckListAnswer;
|
import se.su.dsv.scipro.data.dataobjects.CheckListAnswer;
|
||||||
import se.su.dsv.scipro.data.dataobjects.CheckListQuestion;
|
import se.su.dsv.scipro.data.dataobjects.CheckListQuestion;
|
||||||
import se.su.dsv.scipro.data.dataobjects.User;
|
import se.su.dsv.scipro.data.dataobjects.User;
|
||||||
import se.su.dsv.scipro.data.enums.CheckListQuestionAnswer;
|
import se.su.dsv.scipro.data.enums.CheckListQuestionAnswer;
|
||||||
|
import se.su.dsv.scipro.springdata.services.ChecklistService;
|
||||||
|
|
||||||
public class AnswerDialogPanel extends Panel {
|
public class AnswerDialogPanel extends Panel {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private AnswerDialog dialog;
|
private AnswerDialog dialog;
|
||||||
|
|
||||||
public AnswerDialogPanel(String id, User currentUser) {
|
public AnswerDialogPanel(String id, User currentUser, Long checklistId) {
|
||||||
super(id);
|
super(id);
|
||||||
dialog = new AnswerDialog("answerDialog", currentUser);
|
dialog = new AnswerDialog("answerDialog", currentUser, checklistId);
|
||||||
add(dialog);
|
add(dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,35 +32,42 @@ public class AnswerDialogPanel extends Panel {
|
|||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
@SpringBean
|
@SpringBean
|
||||||
private CheckListAnswerDao checkListAnswerDao;
|
private CheckListAnswerDao checkListAnswerDao;
|
||||||
|
private Long checklistId;
|
||||||
|
|
||||||
|
|
||||||
@SpringBean
|
@SpringBean
|
||||||
private CheckListQuestionDao checkListQuestionDao;
|
private CheckListQuestionDao checkListQuestionDao;
|
||||||
private final User currentUser;
|
private final User currentUser;
|
||||||
|
|
||||||
public AnswerDialog(String id, User currentUser) {
|
public AnswerDialog(String id, User currentUser, Long checklistId) {
|
||||||
super(id);
|
super(id);
|
||||||
|
this.checklistId = checklistId;
|
||||||
this.currentUser = currentUser;
|
this.currentUser = currentUser;
|
||||||
setModal(true);
|
setModal(true);
|
||||||
setAutoOpen(false);
|
setAutoOpen(false);
|
||||||
setWidth(400);
|
setWidth(400);
|
||||||
setHeight(400);
|
setHeight(400);
|
||||||
add(new AnswerForm("answerForm"));
|
add(new AnswerForm("answerForm", checklistId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dialogContent(CheckListQuestion clq) {
|
public void dialogContent(CheckListQuestion clq) {
|
||||||
setTitle(clq.getQuestion());
|
setTitle(clq.getQuestion());
|
||||||
replace(new AnswerForm("answerForm", clq));
|
replace(new AnswerForm("answerForm", clq, checklistId));
|
||||||
}
|
}
|
||||||
|
|
||||||
private class AnswerForm extends Form<Void> {
|
private class AnswerForm extends Form<Void> {
|
||||||
|
|
||||||
|
@SpringBean
|
||||||
|
private ChecklistService checklistService;
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private TrafficLightPanel trafficLights;
|
private TrafficLightPanel trafficLights;
|
||||||
private CheckListQuestion clq;
|
private CheckListQuestion clq;
|
||||||
private CheckListAnswer answer;
|
private CheckListAnswer answer;
|
||||||
private TextArea<String> commentArea;
|
private TextArea<String> commentArea;
|
||||||
private String comment;
|
private String comment;
|
||||||
|
|
||||||
public AnswerForm(String id, CheckListQuestion clq) {
|
public AnswerForm(String id, CheckListQuestion clq, Long checklistId) {
|
||||||
super(id);
|
super(id);
|
||||||
setMultiPart(true);
|
setMultiPart(true);
|
||||||
answer = clq.getAnswerFromUser(currentUser);
|
answer = clq.getAnswerFromUser(currentUser);
|
||||||
@ -81,7 +88,7 @@ public class AnswerDialogPanel extends Panel {
|
|||||||
add(commentArea);
|
add(commentArea);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AnswerForm(String id) {
|
public AnswerForm(String id, Long checklistId) {
|
||||||
super(id);
|
super(id);
|
||||||
add(new TrafficLightPanel("trafficLights"));
|
add(new TrafficLightPanel("trafficLights"));
|
||||||
add(new TextArea<String>("commentArea"));
|
add(new TextArea<String>("commentArea"));
|
||||||
@ -96,6 +103,7 @@ public class AnswerDialogPanel extends Panel {
|
|||||||
clq = checkListQuestionDao.reLoad(clq);
|
clq = checkListQuestionDao.reLoad(clq);
|
||||||
clq.addAnswer(checkListAnswerDao.save(clAnswer));
|
clq.addAnswer(checkListAnswerDao.save(clAnswer));
|
||||||
clq = checkListQuestionDao.save(clq);
|
clq = checkListQuestionDao.save(clq);
|
||||||
|
checklistService.updateUserLastOpenDate(checklistService.findOne(checklistId), SciProSession.get().getUser());
|
||||||
setResponsePage(getPage());
|
setResponsePage(getPage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package se.su.dsv.scipro.checklists.panels;
|
package se.su.dsv.scipro.checklists.panels;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.wicket.PageParameters;
|
import org.apache.wicket.PageParameters;
|
||||||
import org.apache.wicket.ajax.AjaxRequestTarget;
|
import org.apache.wicket.ajax.AjaxRequestTarget;
|
||||||
import org.apache.wicket.ajax.markup.html.AjaxLink;
|
import org.apache.wicket.ajax.markup.html.AjaxLink;
|
||||||
@ -16,27 +14,21 @@ import org.apache.wicket.model.IModel;
|
|||||||
import org.apache.wicket.model.LoadableDetachableModel;
|
import org.apache.wicket.model.LoadableDetachableModel;
|
||||||
import org.apache.wicket.model.Model;
|
import org.apache.wicket.model.Model;
|
||||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||||
|
|
||||||
import se.su.dsv.scipro.SciProSession;
|
import se.su.dsv.scipro.SciProSession;
|
||||||
import se.su.dsv.scipro.data.controllers.CheckListController;
|
import se.su.dsv.scipro.data.controllers.CheckListController;
|
||||||
import se.su.dsv.scipro.data.dao.interfaces.CheckListDao;
|
import se.su.dsv.scipro.data.dao.interfaces.*;
|
||||||
import se.su.dsv.scipro.data.dao.interfaces.ChecklistCategoryDao;
|
import se.su.dsv.scipro.data.dataobjects.*;
|
||||||
import se.su.dsv.scipro.data.dao.interfaces.ProjectDao;
|
|
||||||
import se.su.dsv.scipro.data.dao.interfaces.ProjectScheduleEventDao;
|
|
||||||
import se.su.dsv.scipro.data.dao.interfaces.RoleDao;
|
|
||||||
import se.su.dsv.scipro.data.dataobjects.CheckList;
|
|
||||||
import se.su.dsv.scipro.data.dataobjects.CheckListAnswer;
|
|
||||||
import se.su.dsv.scipro.data.dataobjects.CheckListQuestion;
|
|
||||||
import se.su.dsv.scipro.data.dataobjects.Project;
|
|
||||||
import se.su.dsv.scipro.data.dataobjects.ProjectScheduleEvent;
|
|
||||||
import se.su.dsv.scipro.data.enums.CheckListQuestionAnswer;
|
import se.su.dsv.scipro.data.enums.CheckListQuestionAnswer;
|
||||||
import se.su.dsv.scipro.data.enums.CheckListRole;
|
import se.su.dsv.scipro.data.enums.CheckListRole;
|
||||||
import se.su.dsv.scipro.icons.ImageObject;
|
import se.su.dsv.scipro.icons.ImageObject;
|
||||||
import se.su.dsv.scipro.project.pages.ProjectViewCheckListPage;
|
import se.su.dsv.scipro.project.pages.ProjectViewCheckListPage;
|
||||||
|
import se.su.dsv.scipro.springdata.services.ChecklistService;
|
||||||
import se.su.dsv.scipro.supervisor.pages.SupervisorChecklistPage;
|
import se.su.dsv.scipro.supervisor.pages.SupervisorChecklistPage;
|
||||||
import se.su.dsv.scipro.supervisor.pages.SupervisorViewCheckListPage;
|
import se.su.dsv.scipro.supervisor.pages.SupervisorViewCheckListPage;
|
||||||
import se.su.dsv.scipro.util.JavascriptEventConfirmation;
|
import se.su.dsv.scipro.util.JavascriptEventConfirmation;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Fredrik Norberg fnorbe@dsv.su.se
|
* @author Fredrik Norberg fnorbe@dsv.su.se
|
||||||
*
|
*
|
||||||
@ -53,6 +45,8 @@ public class ListCheckListPanel extends Panel {
|
|||||||
private RoleDao roleDao;
|
private RoleDao roleDao;
|
||||||
@SpringBean
|
@SpringBean
|
||||||
private ProjectScheduleEventDao pseDao;
|
private ProjectScheduleEventDao pseDao;
|
||||||
|
@SpringBean
|
||||||
|
private ChecklistService checklistService;
|
||||||
|
|
||||||
@SpringBean
|
@SpringBean
|
||||||
CheckListController checkListController;
|
CheckListController checkListController;
|
||||||
@ -91,7 +85,18 @@ public class ListCheckListPanel extends Panel {
|
|||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
@Override
|
@Override
|
||||||
protected void populateItem(final ListItem<CheckList> item) {
|
protected void populateItem(final ListItem<CheckList> item) {
|
||||||
Label listName = new Label("listName", item.getModel().getObject().getName());
|
|
||||||
|
|
||||||
|
Label listName;
|
||||||
|
|
||||||
|
if (checklistService.hasChangedSinceUserLastOpenDate(item.getModelObject(), SciProSession.get().getUser())){
|
||||||
|
listName = new Label("listName", item.getModel().getObject().getName() + " *NEW ANSWER*");
|
||||||
|
} else {
|
||||||
|
listName = new Label("listName", item.getModel().getObject().getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
final CheckList cl = item.getModelObject();
|
final CheckList cl = item.getModelObject();
|
||||||
final PageParameters pp = new PageParameters();
|
final PageParameters pp = new PageParameters();
|
||||||
pp.put("checklist", cl.getId());
|
pp.put("checklist", cl.getId());
|
||||||
|
@ -1,14 +1,8 @@
|
|||||||
package se.su.dsv.scipro.checklists.panels;
|
package se.su.dsv.scipro.checklists.panels;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.wicket.ajax.AjaxRequestTarget;
|
import org.apache.wicket.ajax.AjaxRequestTarget;
|
||||||
import org.apache.wicket.ajax.markup.html.AjaxLink;
|
import org.apache.wicket.ajax.markup.html.AjaxLink;
|
||||||
import org.apache.wicket.behavior.AttributeAppender;
|
import org.apache.wicket.behavior.AttributeAppender;
|
||||||
import org.apache.wicket.behavior.SimpleAttributeModifier;
|
|
||||||
import org.apache.wicket.extensions.markup.html.basic.SmartLinkLabel;
|
import org.apache.wicket.extensions.markup.html.basic.SmartLinkLabel;
|
||||||
import org.apache.wicket.markup.ComponentTag;
|
import org.apache.wicket.markup.ComponentTag;
|
||||||
import org.apache.wicket.markup.html.WebMarkupContainer;
|
import org.apache.wicket.markup.html.WebMarkupContainer;
|
||||||
@ -23,28 +17,27 @@ import org.apache.wicket.model.LoadableDetachableModel;
|
|||||||
import org.apache.wicket.model.Model;
|
import org.apache.wicket.model.Model;
|
||||||
import org.apache.wicket.model.PropertyModel;
|
import org.apache.wicket.model.PropertyModel;
|
||||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||||
|
|
||||||
import se.su.dsv.scipro.SciProSession;
|
import se.su.dsv.scipro.SciProSession;
|
||||||
import se.su.dsv.scipro.components.SciProTooltipBehavior;
|
import se.su.dsv.scipro.components.SciProTooltipBehavior;
|
||||||
import se.su.dsv.scipro.data.dao.interfaces.CheckListDao;
|
import se.su.dsv.scipro.data.dao.interfaces.CheckListDao;
|
||||||
import se.su.dsv.scipro.data.dao.interfaces.ProjectDao;
|
import se.su.dsv.scipro.data.dao.interfaces.ProjectDao;
|
||||||
import se.su.dsv.scipro.data.dataobjects.CheckList;
|
import se.su.dsv.scipro.data.dataobjects.*;
|
||||||
import se.su.dsv.scipro.data.dataobjects.CheckListAnswer;
|
|
||||||
import se.su.dsv.scipro.data.dataobjects.CheckListQuestion;
|
|
||||||
import se.su.dsv.scipro.data.dataobjects.FileDescription;
|
|
||||||
import se.su.dsv.scipro.data.dataobjects.Member;
|
|
||||||
import se.su.dsv.scipro.data.dataobjects.Project;
|
|
||||||
import se.su.dsv.scipro.data.dataobjects.ProjectScheduleEvent;
|
|
||||||
import se.su.dsv.scipro.data.dataobjects.User;
|
|
||||||
import se.su.dsv.scipro.data.enums.CheckListQuestionAnswer;
|
import se.su.dsv.scipro.data.enums.CheckListQuestionAnswer;
|
||||||
import se.su.dsv.scipro.data.enums.CheckListRole;
|
import se.su.dsv.scipro.data.enums.CheckListRole;
|
||||||
import se.su.dsv.scipro.repository.FileRepository;
|
import se.su.dsv.scipro.repository.FileRepository;
|
||||||
|
import se.su.dsv.scipro.springdata.services.ChecklistService;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ViewCheckListPanel extends Panel {
|
public class ViewCheckListPanel extends Panel {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private AnswerDialogPanel answerDialog;
|
private AnswerDialogPanel answerDialog;
|
||||||
|
private Long checklistId;
|
||||||
|
|
||||||
@SpringBean
|
@SpringBean
|
||||||
private CheckListDao checkListDao;
|
private CheckListDao checkListDao;
|
||||||
@ -54,12 +47,17 @@ public class ViewCheckListPanel extends Panel {
|
|||||||
|
|
||||||
@SpringBean
|
@SpringBean
|
||||||
private ProjectDao projectDao;
|
private ProjectDao projectDao;
|
||||||
|
|
||||||
|
@SpringBean
|
||||||
|
private ChecklistService checklistService;
|
||||||
|
|
||||||
private Project project;
|
private Project project;
|
||||||
private CheckList checkList;
|
private CheckList checkList;
|
||||||
|
|
||||||
public ViewCheckListPanel(final String id, final Long checkListId) {
|
public ViewCheckListPanel(final String id, final Long checkListId) {
|
||||||
super(id);
|
super(id);
|
||||||
|
this.checklistId = checkListId;
|
||||||
|
checklistService.updateUserLastOpenDate(checklistService.findOne(checkListId), SciProSession.get().getUser());
|
||||||
LoadableDetachableModel<CheckListModel> checkListModel =
|
LoadableDetachableModel<CheckListModel> checkListModel =
|
||||||
new LoadableDetachableModel<CheckListModel>() {
|
new LoadableDetachableModel<CheckListModel>() {
|
||||||
|
|
||||||
@ -86,7 +84,7 @@ public class ViewCheckListPanel extends Panel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initComponents(final IModel<CheckListModel> checkListModel) {
|
private void initComponents(final IModel<CheckListModel> checkListModel) {
|
||||||
answerDialog = new AnswerDialogPanel("answerDialog", getCurrentUser());
|
answerDialog = new AnswerDialogPanel("answerDialog", getCurrentUser(), checklistId);
|
||||||
add(answerDialog);
|
add(answerDialog);
|
||||||
|
|
||||||
ListView<CheckListQuestion> checkListQuestions =
|
ListView<CheckListQuestion> checkListQuestions =
|
||||||
|
@ -4,8 +4,7 @@ import org.hibernate.annotations.Cache;
|
|||||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -39,7 +38,18 @@ public class CheckList extends DomainObject {
|
|||||||
|
|
||||||
@ManyToMany
|
@ManyToMany
|
||||||
private List<ChecklistCategory> categories = new ArrayList<ChecklistCategory>();
|
private List<ChecklistCategory> categories = new ArrayList<ChecklistCategory>();
|
||||||
|
|
||||||
|
@ElementCollection(fetch=FetchType.EAGER)
|
||||||
|
private Map<User, Date> userLastOpenDate = new HashMap<User, Date>();
|
||||||
|
|
||||||
|
public Map<User, Date> getUserLastOpenDate() {
|
||||||
|
return userLastOpenDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserLastOpenDate(Map<User, Date> userLastOpenDate) {
|
||||||
|
this.userLastOpenDate = userLastOpenDate;
|
||||||
|
}
|
||||||
|
|
||||||
public CheckList() {
|
public CheckList() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
package se.su.dsv.scipro.springdata.repos;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import se.su.dsv.scipro.data.dataobjects.CheckList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: fred-fri
|
||||||
|
* date: 2012 03 26
|
||||||
|
*/
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public interface ChecklistRepo extends JpaRepository<CheckList, Long>, QueryDslPredicateExecutor<CheckList> {
|
||||||
|
|
||||||
|
//nothing here yet
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
package se.su.dsv.scipro.springdata.serviceimpls;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import se.su.dsv.scipro.data.dataobjects.CheckList;
|
||||||
|
import se.su.dsv.scipro.data.dataobjects.CheckListAnswer;
|
||||||
|
import se.su.dsv.scipro.data.dataobjects.CheckListQuestion;
|
||||||
|
import se.su.dsv.scipro.data.dataobjects.User;
|
||||||
|
import se.su.dsv.scipro.springdata.repos.ChecklistRepo;
|
||||||
|
import se.su.dsv.scipro.springdata.services.ChecklistService;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: fred-fri
|
||||||
|
* date: 2012 03 26
|
||||||
|
*/
|
||||||
|
@Service ( "checklistService" )
|
||||||
|
@Transactional ( readOnly = true )
|
||||||
|
public class ChecklistServiceImpl extends AbstractQueryService<CheckList, Long> implements ChecklistService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ChecklistRepo checklistRepo;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public ChecklistServiceImpl(
|
||||||
|
@Qualifier("checklistRepo")
|
||||||
|
ChecklistRepo checklistRepo) {
|
||||||
|
super(checklistRepo, checklistRepo);
|
||||||
|
System.out.println("BLA BLA");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional ( readOnly = false )
|
||||||
|
public CheckList updateUserLastOpenDate(CheckList checklist, User user) {
|
||||||
|
checklist.getUserLastOpenDate().put(user, new Date());
|
||||||
|
return checklistRepo.save(checklist);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasChangedSinceUserLastOpenDate(CheckList checklist, User user) {
|
||||||
|
if (checklist.getUserLastOpenDate().get(user)==null){
|
||||||
|
checklist = updateUserLastOpenDate(checklist, user);
|
||||||
|
}
|
||||||
|
for (CheckListQuestion clq : checklist.getQuestions()){
|
||||||
|
for (CheckListAnswer cla : clq.getAnswers()){
|
||||||
|
if (cla.getLastModified().after(checklist.getUserLastOpenDate().get(user))){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package se.su.dsv.scipro.springdata.services;
|
||||||
|
|
||||||
|
import se.su.dsv.scipro.data.dataobjects.CheckList;
|
||||||
|
import se.su.dsv.scipro.data.dataobjects.User;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: fred-fri
|
||||||
|
* date: 2012 03 26
|
||||||
|
*/
|
||||||
|
//@Component
|
||||||
|
public interface ChecklistService extends CrudService<CheckList, Long>, QueryService<CheckList, Long> {
|
||||||
|
|
||||||
|
public CheckList updateUserLastOpenDate(CheckList checklist, User user);
|
||||||
|
|
||||||
|
public boolean hasChangedSinceUserLastOpenDate(CheckList checklist, User user);
|
||||||
|
|
||||||
|
}
|
@ -3,9 +3,9 @@
|
|||||||
xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
|
xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
|
||||||
<body>
|
<body>
|
||||||
<wicket:extend>
|
<wicket:extend>
|
||||||
<div class="span-10 colborder">
|
<div class="span-13 colborder">
|
||||||
<h5 class="peer-title">Checklists added to project</h5>
|
<h5 class="peer-title">Checklists added to project</h5>
|
||||||
<div class="span-10 last">
|
<div class="span-13 last">
|
||||||
<div wicket:id="listCheckListPanel"></div>
|
<div wicket:id="listCheckListPanel"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
208
src/test/java/se/su/dsv/scipro/springdata/TestChecklist.java
Normal file
208
src/test/java/se/su/dsv/scipro/springdata/TestChecklist.java
Normal file
@ -0,0 +1,208 @@
|
|||||||
|
package se.su.dsv.scipro.springdata;
|
||||||
|
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.annotation.Rollback;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import se.su.dsv.scipro.data.dao.interfaces.CheckListAnswerDao;
|
||||||
|
import se.su.dsv.scipro.data.dao.interfaces.CheckListQuestionDao;
|
||||||
|
import se.su.dsv.scipro.data.dao.interfaces.ProjectDao;
|
||||||
|
import se.su.dsv.scipro.data.dataobjects.*;
|
||||||
|
import se.su.dsv.scipro.data.enums.CheckListQuestionAnswer;
|
||||||
|
import se.su.dsv.scipro.match.facade.ApplicationPeriodFacade;
|
||||||
|
import se.su.dsv.scipro.springdata.services.*;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration(inheritLocations = false, locations = {
|
||||||
|
"classpath:test-applicationContext.xml"
|
||||||
|
})
|
||||||
|
public class TestChecklist {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserService userService;
|
||||||
|
@Autowired
|
||||||
|
private ProjectIdeaService projectIdeaService;
|
||||||
|
@Autowired
|
||||||
|
private ProjectClassService projectClassService;
|
||||||
|
@Autowired
|
||||||
|
private RoleService roleService;
|
||||||
|
@Autowired
|
||||||
|
private ApplicationPeriodFacade applicationPeriodFacade;
|
||||||
|
@Autowired
|
||||||
|
private MatchService matchService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ProjectDao projectDao;
|
||||||
|
@Autowired
|
||||||
|
private ChecklistService checklistService;
|
||||||
|
@Autowired
|
||||||
|
private CheckListQuestionDao checkListQuestionDao;
|
||||||
|
@Autowired
|
||||||
|
private CheckListAnswerDao checkListAnswerDao;
|
||||||
|
|
||||||
|
private User employee1;
|
||||||
|
private Employee employee1Role;
|
||||||
|
private ProjectClass bachelor;
|
||||||
|
private Project project;
|
||||||
|
|
||||||
|
private List<CheckList> checkLists;
|
||||||
|
private CheckList checkList;
|
||||||
|
|
||||||
|
private List<CheckListQuestion> checkListQuestions;
|
||||||
|
private CheckListQuestion checkListQuestion;
|
||||||
|
|
||||||
|
private List<CheckListAnswer> checkListAnswers;
|
||||||
|
private CheckListAnswer checkListAnswer;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void startTransaction() throws Exception {
|
||||||
|
|
||||||
|
employee1 = new User();
|
||||||
|
employee1 = userService.save(employee1);
|
||||||
|
|
||||||
|
employee1Role = new Employee();
|
||||||
|
employee1Role.setUser(employee1);
|
||||||
|
employee1Role = (Employee) roleService.save(employee1Role);
|
||||||
|
|
||||||
|
bachelor = new ProjectClass(ProjectClass.BACHELOR, "Bachelor", "Bachelor degree thesis project");
|
||||||
|
bachelor = projectClassService.save(bachelor);
|
||||||
|
|
||||||
|
project = new Project();
|
||||||
|
project.setHeadSupervisor(employee1Role);
|
||||||
|
project.setTitle("project");
|
||||||
|
project.setProjectClass(bachelor);
|
||||||
|
project = projectDao.save(project);
|
||||||
|
|
||||||
|
checkListAnswers = new ArrayList<CheckListAnswer>();
|
||||||
|
checkListAnswer = new CheckListAnswer();
|
||||||
|
checkListAnswer.setAnswer(CheckListQuestionAnswer.GREEN);
|
||||||
|
checkListAnswer.setUser(employee1);
|
||||||
|
checkListAnswer = checkListAnswerDao.save(checkListAnswer);
|
||||||
|
checkListAnswers.add(checkListAnswer);
|
||||||
|
|
||||||
|
checkListQuestions = new ArrayList<CheckListQuestion>();
|
||||||
|
checkListQuestion = new CheckListQuestion();
|
||||||
|
checkListQuestion.setQuestion("question?");
|
||||||
|
checkListQuestion.setQuestionNumber(1);
|
||||||
|
checkListQuestion.setAnswers(checkListAnswers);
|
||||||
|
checkListQuestion = checkListQuestionDao.save(checkListQuestion);
|
||||||
|
checkListQuestions.add(checkListQuestion);
|
||||||
|
|
||||||
|
checkLists = new ArrayList<CheckList>();
|
||||||
|
checkList = new CheckList();
|
||||||
|
checkList.setName("checklist");
|
||||||
|
checkList.setProject(project);
|
||||||
|
checkList.setQuestions(checkListQuestions);
|
||||||
|
checkList = checklistService.save(checkList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Transactional
|
||||||
|
@Rollback
|
||||||
|
public void testStuff() {
|
||||||
|
Assert.assertTrue(
|
||||||
|
checkList.getQuestions()!=null
|
||||||
|
&& !checkList.getQuestions().isEmpty()
|
||||||
|
&& checkList.getQuestions().get(0)!=null
|
||||||
|
&& checkList.getQuestions().get(0).getAnswers() != null
|
||||||
|
&& !checkList.getQuestions().get(0).getAnswers().isEmpty()
|
||||||
|
&& checkList.getQuestions().get(0).getAnswers().get(0) != null
|
||||||
|
&& checkList.getQuestions().get(0).getAnswers().get(0).getAnswer() != null
|
||||||
|
&& checkList.getQuestions().get(0).getAnswers().get(0).getAnswer().equals(CheckListQuestionAnswer.GREEN)
|
||||||
|
&& checkList.getUserLastOpenDate().get(employee1) == null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If we run method with user, getUserLastOpenUpdate for user should no longer be null.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@Transactional
|
||||||
|
@Rollback
|
||||||
|
public void testhasChangedSinceUserLastOpenDate1() {
|
||||||
|
checklistService.hasChangedSinceUserLastOpenDate(checkList, employee1);
|
||||||
|
Assert.assertNotSame(null, checkList.getUserLastOpenDate().get(employee1));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If we run method, the date should get updated.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@Transactional
|
||||||
|
@Rollback
|
||||||
|
public void testupdateUserLastOpenDate2() {
|
||||||
|
|
||||||
|
checkList = checklistService.updateUserLastOpenDate(checkList, employee1);
|
||||||
|
Date oldDate = checkList.getUserLastOpenDate().get(employee1);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Thread.sleep(10);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
|
||||||
|
}
|
||||||
|
|
||||||
|
checkList = checklistService.updateUserLastOpenDate(checkList, employee1);
|
||||||
|
Date newDate = checkList.getUserLastOpenDate().get(employee1);
|
||||||
|
|
||||||
|
Assert.assertTrue(oldDate.before(newDate));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User has not yet opened the checklist with the new functionality. We have no way of knowing
|
||||||
|
* when the user last opened the checklist, so method should return false.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@Transactional
|
||||||
|
@Rollback
|
||||||
|
public void testhasChangedSinceUserLastOpenDate2() {
|
||||||
|
Assert.assertFalse(checklistService.hasChangedSinceUserLastOpenDate(checkList, employee1));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We run the update method. Since the updated date will be newer than the lastModified of
|
||||||
|
* the checklistanswer, the method should return false.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@Transactional
|
||||||
|
@Rollback
|
||||||
|
public void testhasChangedSinceUserLastOpenDate3() {
|
||||||
|
checkList = checklistService.updateUserLastOpenDate(checkList, employee1);
|
||||||
|
Assert.assertFalse(checklistService.hasChangedSinceUserLastOpenDate(checkList, employee1));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We run the update method to get a date. Then we set an answers lastModified to a later date.
|
||||||
|
* The method should return true, since this would mean changes have been made after the user
|
||||||
|
* last opened the checklist.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@Transactional
|
||||||
|
@Rollback
|
||||||
|
public void testhasChangedSinceUserLastOpenDate4() {
|
||||||
|
|
||||||
|
checkList = checklistService.updateUserLastOpenDate(checkList, employee1);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Thread.sleep(10);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
|
||||||
|
}
|
||||||
|
|
||||||
|
checkListAnswer.setLastModified(new Date());
|
||||||
|
checkListAnswerDao.save(checkListAnswer);
|
||||||
|
|
||||||
|
Assert.assertTrue(checklistService.hasChangedSinceUserLastOpenDate(checkList, employee1));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user