added popup dialog for unconfirmed authors with accept and decline buttons. also some more changes to make the structure work with new idea participation objects and updated test class

This commit is contained in:
Emil Siverhall 2012-07-24 10:18:57 +02:00
parent 087dc6fb57
commit 5b5c5cb7f2
13 changed files with 270 additions and 47 deletions

@ -1,8 +1,10 @@
package se.su.dsv.scipro.project.pages;
import java.util.Iterator;
import java.util.List;
import org.apache.wicket.PageParameters;
import org.apache.wicket.ajax.AbstractAjaxTimerBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
@ -10,15 +12,18 @@ import org.apache.wicket.markup.html.panel.EmptyPanel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.apache.wicket.util.time.Duration;
import org.odlabs.wiquery.ui.dialog.Dialog;
import org.springframework.data.domain.PageRequest;
import se.su.dsv.scipro.data.dataobjects.Student;
import se.su.dsv.scipro.datatables.ClickableTitleColumn;
import se.su.dsv.scipro.datatables.project.GenericDataPanel;
import se.su.dsv.scipro.match.dataobject.SupervisorIdea;
import se.su.dsv.scipro.match.dataobject.Idea.IdeaStatus;
import se.su.dsv.scipro.match.dataobject.SupervisorIdea;
import se.su.dsv.scipro.project.panels.AcceptIdeaDialogPanel;
import se.su.dsv.scipro.springdata.services.GenericService;
import se.su.dsv.scipro.springdata.services.StudentService;
import se.su.dsv.scipro.springdata.services.SupervisorIdeaService;
@ -26,6 +31,8 @@ public class ProjectIdeaStartPage extends AbstractProjectIdeaPage {
@SpringBean
private SupervisorIdeaService ideaService;
@SpringBean
private StudentService studentService;
private Dialog dialog;
private GenericDataPanel<SupervisorIdea> genericDataPanel;
@ -33,14 +40,43 @@ public class ProjectIdeaStartPage extends AbstractProjectIdeaPage {
super(pp);
addDialog();
addDataTable();
checkForUnconfirmedIdeas();
}
private void checkForUnconfirmedIdeas() {
boolean hasUnconfirmed = ideaService.hasUnconfirmedIdea(getUser());
if(hasUnconfirmed) {
System.out.println("Unconfirmed idea available");
Student author = studentService.findByUser(getUser());
final List<SupervisorIdea> ideas = ideaService.findUnconfirmedIdeasByStatusAndAuthor(IdeaStatus.TAKEN, author);
if(ideas.size()>1)
System.out.println("More than one unconfirmed idea");
else {
add(new AbstractAjaxTimerBehavior(Duration.milliseconds(1)) {
private static final long serialVersionUID = 8249890924500999472L;
@Override
protected void onTimer(AjaxRequestTarget target) {
dialog.replace(new AcceptIdeaDialogPanel("dialogPanel",Model.of(ideas.get(0)), getUser(), true));
dialog.setTitle("Supervisor project idea");
target.addComponent(dialog);
dialog.open(target);
stop();
}
});
}
}
else
System.out.println("No ideas available");
}
private void addDialog() {
dialog = new Dialog("dialog");
dialog.setModal(true);
dialog.setAutoOpen(false);
dialog.setWidth(500);
dialog.setHeight(500);
dialog.setHeight(600);
dialog.add(new EmptyPanel("dialogPanel"));
add(dialog);
}
@ -77,7 +113,7 @@ public class ProjectIdeaStartPage extends AbstractProjectIdeaPage {
@Override
protected void onClick(IModel<SupervisorIdea> ideaModel,
AjaxRequestTarget pTarget) {
dialog.replace(new AcceptIdeaDialogPanel("dialogPanel", ideaModel, getUser()));
dialog.replace(new AcceptIdeaDialogPanel("dialogPanel", ideaModel, getUser(), false));
dialog.setTitle("Supervisor project idea");
pTarget.addComponent(dialog);
dialog.open(pTarget);

@ -7,6 +7,13 @@
<body>
<wicket:panel>
<form wicket:id="form">
<div wicket:id="unconfirmedContainer" >
<div class="info-box rounded-box last">
You have been selected as a partner to be the author for this project together with <span wicket:id="authorLabel"></span><br />
<input type="submit" wicket:id="partnerAccept" value="Accept"/>
<input type="submit" wicket:id="partnerDecline" value="Decline"/>
</div>
</div>
<div class="append-bottom"><b>Level: </b><br />
<span wicket:id="level"></span>
</div>

@ -5,6 +5,7 @@ import java.util.Set;
import java.util.TreeSet;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.basic.EnclosureContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
@ -33,9 +34,9 @@ public class AcceptIdeaDialogPanel extends Panel {
@SpringBean
private SupervisorService supervisorService;
public AcceptIdeaDialogPanel(String id, IModel<SupervisorIdea> model, final User mainAuthor) {
public AcceptIdeaDialogPanel(String id, IModel<SupervisorIdea> model, final User loggedInUser, boolean unconfirmed) {
super(id, model);
add(new AcceptIdeaForm("form", model, mainAuthor));
add(new AcceptIdeaForm("form", model, loggedInUser, unconfirmed));
}
private static final long serialVersionUID = 29731924490786784L;
@ -45,7 +46,7 @@ public class AcceptIdeaDialogPanel extends Panel {
private static final long serialVersionUID = -9118352523380756043L;
private AddRemoveStudentsPanel partnerPanel;
public AcceptIdeaForm(String id, final IModel<SupervisorIdea> model, final User mainAuthor) {
public AcceptIdeaForm(String id, final IModel<SupervisorIdea> model, final User loggedInUser, final boolean unconfirmed) {
super(id, model);
Employee ideaCreator = supervisorService.findOne(model.getObject().getCreator().getId());
add(new Label("level", model.getObject().getProjectClass().getName()));
@ -54,12 +55,47 @@ public class AcceptIdeaDialogPanel extends Panel {
add(new Label("description", model.getObject().getDescription()));
addResearchAreas(ideaCreator);
addKeywords(model);
addPartnerPanel(model);
addButton(model, mainAuthor);
addPartnerPanel(model, unconfirmed);
addUnconfirmedContainer(model, loggedInUser, unconfirmed);
addButton(model, loggedInUser, unconfirmed);
}
private void addUnconfirmedContainer(final IModel<SupervisorIdea> model, final User loggedInUser, final boolean unconfirmed) {
Label authorLabel = new Label("authorLabel", "Kalle");
authorLabel.setVisible(unconfirmed);
EnclosureContainer cont = new EnclosureContainer("unconfirmedContainer", authorLabel);
cont.add(authorLabel);
Button acceptButton = new Button("partnerAccept"){
private static final long serialVersionUID = -7001493750138777577L;
@Override
public void onSubmit(){
ideaService.partnerAcceptIdea(model, loggedInUser);
}
};
acceptButton.add(new JavascriptEventConfirmation("onClick", "Are you sure you want to be a part of this project?"));
Button declineButton = new Button("partnerDecline"){
private static final long serialVersionUID = -3519373023312617322L;
@Override
public void onSubmit(){
System.out.println("DECLINED?!?!?");
ideaService.partnerDeclineIdea(model);
}
};
declineButton.add(new JavascriptEventConfirmation("onClick", "Are you sure you want to decline this project idea?"));
cont.add(acceptButton);
cont.add(declineButton);
add(cont);
}
private void addResearchAreas(Employee ideaCreator) {
final Set<ResearchArea> areas = ideaCreator.getActiveResearchAreas();
ListView<ResearchArea> areaList = new ListView<ResearchArea>("researchAreas", new ArrayList<ResearchArea>(areas)) {
@ -90,7 +126,7 @@ public class AcceptIdeaDialogPanel extends Panel {
}
private void addPartnerPanel(IModel<SupervisorIdea> model) {
private void addPartnerPanel(IModel<SupervisorIdea> model, boolean unconfirmed) {
partnerPanel = new AddRemoveStudentsPanel("partnerPanel", new TreeSet<Student>()) {
private static final long serialVersionUID = 8432765543881357453L;
@ -99,19 +135,18 @@ public class AcceptIdeaDialogPanel extends Panel {
//do nothing
}
};
partnerPanel.setVisible(model.getObject().getProjectClass().getCode().equals(ProjectClass.BACHELOR));
partnerPanel.setVisible(model.getObject().getProjectClass().getCode().equals(ProjectClass.BACHELOR) && !unconfirmed);
add(partnerPanel);
}
private void addButton(final IModel<SupervisorIdea> model, final User mainAuthor) {
private void addButton(final IModel<SupervisorIdea> model, final User loggedInUser, final boolean unconfirmed) {
Button button = new Button("selectButton") {
private static final long serialVersionUID = 8805671593150004137L;
@Override
public void onSubmit() {
System.out.println(partnerPanel.getStudentSet());
if(ideaService.acceptIdea(model, mainAuthor, partnerPanel.getStudentSet())){
if(ideaService.acceptIdea(model, loggedInUser, partnerPanel.getStudentSet())){
System.out.println("COOL");
} else {
System.out.println("ERROR");
@ -121,6 +156,7 @@ public class AcceptIdeaDialogPanel extends Panel {
}
};
button.add(new JavascriptEventConfirmation("onClick", "Are you sure you want to select this project idea?"));
button.setVisible(!unconfirmed);
add(button);
}

@ -1,12 +1,27 @@
package se.su.dsv.scipro.springdata.repos;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.transaction.annotation.Transactional;
import se.su.dsv.scipro.data.dataobjects.Student;
import se.su.dsv.scipro.match.dataobject.SupervisorIdea;
import se.su.dsv.scipro.match.dataobject.Idea.IdeaStatus;
@Transactional(readOnly = true)
public interface SupervisorIdeaRepo extends JpaRepository<SupervisorIdea, Long>, QueryDslPredicateExecutor<SupervisorIdea> {
//Query for retrieving ideas based on author. Problems with implementing through QueryDSL with IdeaParticipation object
@Query("select idea from SupervisorIdea idea, Student author join idea.ideaParticipations ideaPart join author.ideaParticipations authorPart where ideaPart = authorPart and author = ?")
List<SupervisorIdea> findIdeasByAuthor(Student author);
//Query for retrieving ideas based on author and status. Problems with implementing through QueryDSL with IdeaParticipation object
@Query("select idea from SupervisorIdea idea, Student author join idea.ideaParticipations ideaPart join author.ideaParticipations authorPart where ideaPart = authorPart and author = ? and idea.ideaStatus = ?")
List<SupervisorIdea> findIdeasByAuthorAndStatus(Student author, IdeaStatus status);
@Query("select idea from SupervisorIdea idea, Student author join idea.ideaParticipations ideaPart join author.ideaParticipations authorPart where ideaPart = authorPart and author = ? and idea.ideaStatus = ? and ideaPart.confirmed = false")
List<SupervisorIdea> findUnconfirmedIdeasByAuthorAndStatus(Student author, IdeaStatus status);
}

@ -22,9 +22,9 @@ import se.su.dsv.scipro.data.dataobjects.ProjectClass;
import se.su.dsv.scipro.data.dataobjects.Student;
import se.su.dsv.scipro.data.dataobjects.User;
import se.su.dsv.scipro.match.dataobject.Idea.IdeaStatus;
import se.su.dsv.scipro.match.dataobject.IdeaParticipation;
import se.su.dsv.scipro.match.dataobject.QSupervisorIdea;
import se.su.dsv.scipro.match.dataobject.SupervisorIdea;
import se.su.dsv.scipro.peer.data.dataobjects.QPeerRequest;
import se.su.dsv.scipro.springdata.repos.SupervisorIdeaRepo;
import se.su.dsv.scipro.springdata.services.StudentService;
import se.su.dsv.scipro.springdata.services.SupervisorIdeaService;
@ -44,6 +44,8 @@ public class SupervisorIdeaServiceImpl extends AbstractQueryService<SupervisorId
@PersistenceContext
private EntityManager em;
private int MAX_PARTNERS = 1;
@Autowired
public SupervisorIdeaServiceImpl(
@Qualifier("supervisorIdeaRepo")
@ -59,14 +61,21 @@ public class SupervisorIdeaServiceImpl extends AbstractQueryService<SupervisorId
SupervisorIdea idea = model.getObject();
if(!students.isEmpty()) {
idea.setAuthors(students);
for(Student s : students) {
s = studentService.findOne(s.getId()); //Needed for lazy loading to work.
IdeaParticipation ip = new IdeaParticipation();
ip.setStudent(s);
ip.setSupervisorIdea(idea);
ip.setConfirmed(false);
s.addIdeaParticipation(ip);
}
idea.setIdeaStatus(IdeaStatus.TAKEN); //Should not be visible for selection if supervisor manually added students
} else {
idea.setIdeaStatus(IdeaStatus.WAITING);
}
idea.setCreator(creator);
idea = em.merge(idea);
save(idea);
}
@ -84,29 +93,61 @@ public class SupervisorIdeaServiceImpl extends AbstractQueryService<SupervisorId
@Transactional ( readOnly = false )
public boolean acceptIdea(IModel<SupervisorIdea> model, User mainAuthor,
SortedSet<Student> studentSet) {
if(studentSet.size()> 1){
if(studentSet.size()> MAX_PARTNERS){
return false;
} else {
SupervisorIdea idea = supervisorIdeaRepo.findOne(model.getObject().getId());
Student author = studentService.findByUser(mainAuthor);
idea.addAuthor(studentSet.first());
idea.addAuthor(author);
IdeaParticipation mainParticipation = new IdeaParticipation();
mainParticipation.setStudent(author);
mainParticipation.setSupervisorIdea(idea);
mainParticipation.setConfirmed(true);
author.addIdeaParticipation(mainParticipation);
for(Student s : studentSet) {
s = studentService.findOne(s.getId()); //Needed for lazy loading to work.
IdeaParticipation ip = new IdeaParticipation();
ip.setStudent(s);
ip.setSupervisorIdea(idea);
ip.setConfirmed(false);
s.addIdeaParticipation(ip);
}
idea.setIdeaStatus(IdeaStatus.TAKEN);
return true;
}
}
@Override
@Transactional (readOnly = false)
public void partnerAcceptIdea(IModel<SupervisorIdea> model, User loggedInUser) {
SupervisorIdea idea = supervisorIdeaRepo.findOne(model.getObject().getId());
Student author = studentService.findByUser(loggedInUser);
for (IdeaParticipation ip : idea.getIdeaParticipations())
if(ip.getStudent().equals(author))
ip.setConfirmed(true);
}
@Override
@Transactional ( readOnly = false )
public void partnerDeclineIdea(IModel<SupervisorIdea> model) {
SupervisorIdea idea = supervisorIdeaRepo.findOne(model.getObject().getId());
for (IdeaParticipation ip : idea.getIdeaParticipations()) {
Student s = ip.getStudent();
s.removeIdeaParticipation(ip);
}
idea.setIdeaStatus(IdeaStatus.WAITING);
}
@Override
@Transactional
public boolean hasUnconfirmedIdea(User authorUser) {
Student author = studentService.findByUser(authorUser);
// find ideas by status and user
List<SupervisorIdea> authorConnectedIdeas = findByStatusAndAuthor(IdeaStatus.TAKEN, author);
// check to see if author is confirmed. how?
if(!authorConnectedIdeas.isEmpty())
// find unconfirmed ideas by author
List<SupervisorIdea> unconfirmedIdeas = findUnconfirmedIdeasByStatusAndAuthor(IdeaStatus.TAKEN, author);
if(!unconfirmedIdeas.isEmpty())
return true;
else
return false;
@ -134,10 +175,16 @@ public class SupervisorIdeaServiceImpl extends AbstractQueryService<SupervisorId
@Override
public List<SupervisorIdea> findByStatusAndAuthor(IdeaStatus status, Student author) {
Iterable<SupervisorIdea> ideas = supervisorIdeaRepo.findAll(byStatus(status).and(byAuthor(author)));
return constructList(ideas);
List<SupervisorIdea> ideas = supervisorIdeaRepo.findIdeasByAuthorAndStatus(author, status);
return ideas;
}
@Override
public List<SupervisorIdea> findUnconfirmedIdeasByStatusAndAuthor(IdeaStatus status, Student author) {
List<SupervisorIdea> ideas = supervisorIdeaRepo.findUnconfirmedIdeasByAuthorAndStatus(author, status);
return ideas;
}
private Predicate predicateFromParams(FilterParams params) {
return levelFilter(params.getLevels()).and(bySupervisor(params.getSupervisor()));
}
@ -174,7 +221,8 @@ public class SupervisorIdeaServiceImpl extends AbstractQueryService<SupervisorId
}
private BooleanExpression byAuthor(Student author){
return QSupervisorIdea.supervisorIdea.authors.contains(author);
return QSupervisorIdea.supervisorIdea.ideaParticipations.any().pk.student.eq(author);
//return QSupervisorIdea.supervisorIdea.authors.contains(author);
}
@Override

@ -8,6 +8,7 @@ import java.util.SortedSet;
import org.apache.wicket.model.IModel;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import se.su.dsv.scipro.data.dataobjects.Employee;
import se.su.dsv.scipro.data.dataobjects.ProjectClass;
@ -21,12 +22,15 @@ public interface SupervisorIdeaService extends GenericService<SupervisorIdea, Lo
Page<SupervisorIdea> findAll(FilterParams params, Pageable pageable);
Page<SupervisorIdea> findByStatus(IdeaStatus status, Pageable pageable);
List<SupervisorIdea> findByStatusAndAuthor(IdeaStatus status, Student author);
List<SupervisorIdea> findUnconfirmedIdeasByStatusAndAuthor(IdeaStatus status, Student author);
Long countByStatus(IdeaStatus status);
void saveSupervisorCreatedIdea(IModel<SupervisorIdea> model, Employee creator, SortedSet<Student> students);
void deleteWaitingIdea(IModel<SupervisorIdea> model);
void partnerAcceptIdea(IModel<SupervisorIdea> model, User loggedInUser);
void partnerDeclineIdea(IModel<SupervisorIdea> model);
boolean acceptIdea(IModel<SupervisorIdea> model, User mainAuthor, SortedSet<Student> sortedSet);
boolean hasUnconfirmedIdea(User authorUser);
boolean isIdeaEditable(IModel<SupervisorIdea> model, User currentUser);

@ -3,7 +3,8 @@
xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
<body>
<wicket:extend>
<div wicket:id="editPanel"></div>
<h2>Create new/edit project idea</h2>
<div class="prepend-top" wicket:id="editPanel"></div>
</wicket:extend>
</body>
</html>

@ -19,12 +19,15 @@ public class SupervisorIdeaSubmissionPage extends
super(pp);
Long ideaId = pp.getAsLong("idea");
SupervisorIdea idea;
boolean readOnly = pp.getAsBoolean("readOnly");
if(ideaId!=null)
idea = ideaService.findOne(ideaId);
else {
idea = new SupervisorIdea();
}
add(new SupervisorEditIdeaPanel("editPanel", getUser(), new Model<SupervisorIdea>(idea)));
add(new SupervisorEditIdeaPanel("editPanel", getUser(), readOnly, new Model<SupervisorIdea>(idea)));
}

@ -3,9 +3,12 @@
xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
<body>
<wicket:extend>
<div class="info-box rounded-box last">This is a nice info box full of important information. Don't forget to read it. And then read it again.</div>
<div wicket:id="feedback"></div>
<button wicket:id="ideaLink">Create new</button>
<div class="info-box rounded-box last">
This info box should contain information about the current application period,
the supervisors target numbers and the supervisors current number of supervisions
</div>
<div wicket:id="feedback"></div>
<button wicket:id="ideaLink">Create new project idea</button>
<div class="prepend-top" wicket:id="ideaPanel"></div>
</wicket:extend>
</body>

@ -21,7 +21,9 @@ public class SupervisorProjectIdeaStartPage extends AbstractSupervisorProjectIde
}
private void addSubmissionPageLink() {
BookmarkablePageLink<Void> ideaLink = new BookmarkablePageLink<Void>("ideaLink", SupervisorIdeaSubmissionPage.class);
PageParameters pp = new PageParameters();
pp.put("readOnly", false);
BookmarkablePageLink<Void> ideaLink = new BookmarkablePageLink<Void>("ideaLink", SupervisorIdeaSubmissionPage.class, pp);
add(ideaLink);
}

@ -3,6 +3,8 @@ package se.su.dsv.scipro.supervisor.panels;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
@ -25,10 +27,12 @@ import org.apache.wicket.validation.validator.StringValidator;
import se.su.dsv.scipro.data.dataobjects.Employee;
import se.su.dsv.scipro.data.dataobjects.ProjectClass;
import se.su.dsv.scipro.data.dataobjects.ResearchArea;
import se.su.dsv.scipro.data.dataobjects.Student;
import se.su.dsv.scipro.data.dataobjects.User;
import se.su.dsv.scipro.keywords.KeywordContainer;
import se.su.dsv.scipro.keywords.SelectKeywordsPanel;
import se.su.dsv.scipro.match.dao.interfaces.KeywordTypeDao.TYPE;
import se.su.dsv.scipro.match.dataobject.IdeaParticipation;
import se.su.dsv.scipro.match.dataobject.Keyword;
import se.su.dsv.scipro.match.dataobject.SupervisorIdea;
import se.su.dsv.scipro.reusable.AddRemoveStudentsPanel;
@ -54,9 +58,9 @@ public class SupervisorEditIdeaPanel extends Panel {
@SpringBean
private SupervisorService supervisorService;
public SupervisorEditIdeaPanel(String id, User creator, IModel<SupervisorIdea> model) {
public SupervisorEditIdeaPanel(String id, User creator, boolean readOnly,IModel<SupervisorIdea> model) {
super(id, model);
add(new IdeaForm("form", model, creator));
add(new IdeaForm("form", model, creator).setEnabled(!readOnly));
}
private class IdeaForm extends Form<SupervisorIdea> {
@ -122,8 +126,12 @@ public class SupervisorEditIdeaPanel extends Panel {
oldKeywords.add(addedKeyword);
model.getObject().setKeywords(oldKeywords);
}
});
wmc.add(studentsPanel = new AddRemoveStudentsPanel("studentPanel", model.getObject().getAuthors()) {
});
SortedSet<Student> authors = new TreeSet<Student>();
for(IdeaParticipation ip : model.getObject().getIdeaParticipations()){
authors.add(ip.getStudent());
}
wmc.add(studentsPanel = new AddRemoveStudentsPanel("studentPanel", authors) {
private static final long serialVersionUID = 8432765543881357453L;
@Override
@ -145,7 +153,6 @@ public class SupervisorEditIdeaPanel extends Panel {
getSession().info("Idea successfully submitted");
} catch (Exception e) {
e.printStackTrace();
System.out.println("Exception time!!!");
}
}

@ -17,6 +17,7 @@ import org.springframework.data.domain.PageRequest;
import se.su.dsv.scipro.data.dataobjects.Employee;
import se.su.dsv.scipro.data.dataobjects.User;
import se.su.dsv.scipro.datatables.ClickableIconColumn;
import se.su.dsv.scipro.datatables.ClickableTitleColumn;
import se.su.dsv.scipro.datatables.project.GenericDataPanel;
import se.su.dsv.scipro.icons.ImageIcon;
import se.su.dsv.scipro.match.dataobject.SupervisorIdea;
@ -68,7 +69,18 @@ public class SupervisorProjectIdeaOverviewPanel extends Panel {
IColumn[] columns = new IColumn[7];
columns[0] = new PropertyColumn<SupervisorIdea>(Model.of("Date"), "dateCreated", "dateCreated");
columns[1] = new PropertyColumn<SupervisorIdea>(Model.of("Level"), "projectClass", "projectClass");
columns[2] = new PropertyColumn<SupervisorIdea>(Model.of("Title"), "title", "title");
columns[2] = new ClickableTitleColumn<SupervisorIdea>(Model.of("Title"), "title", "title") {
private static final long serialVersionUID = 4667741924987868274L;
@Override
protected void onClick(IModel<SupervisorIdea> clicked,
AjaxRequestTarget target) {
PageParameters pp = new PageParameters();
pp.put("idea", clicked.getObject().getId());
pp.put("readOnly", true);
setResponsePage(SupervisorIdeaSubmissionPage.class, pp);
}
};
columns[3] = new PropertyColumn<SupervisorIdea>(Model.of("Creator"), "creator.user.lastName", "creator");
columns[4] = new PropertyColumn<SupervisorIdea>(Model.of("Status"), "ideaStatus", "ideaStatus");
columns[5] = new ClickableIconColumn<SupervisorIdea>(Model.of("Edit"), null, ImageIcon.ICON_EDIT) {
@ -79,6 +91,7 @@ public class SupervisorProjectIdeaOverviewPanel extends Panel {
AjaxRequestTarget target) {
PageParameters pp = new PageParameters();
pp.put("idea", clicked.getObject().getId());
pp.put("readOnly", false);
setResponsePage(SupervisorIdeaSubmissionPage.class, pp);
}

@ -31,10 +31,12 @@ import se.su.dsv.scipro.match.dao.interfaces.KeywordDao;
import se.su.dsv.scipro.match.dao.interfaces.KeywordTypeDao;
import se.su.dsv.scipro.match.dataobject.ApplicationPeriod;
import se.su.dsv.scipro.match.dataobject.Idea.IdeaStatus;
import se.su.dsv.scipro.match.dataobject.IdeaParticipation;
import se.su.dsv.scipro.match.dataobject.Keyword;
import se.su.dsv.scipro.match.dataobject.KeywordType;
import se.su.dsv.scipro.match.dataobject.SupervisorIdea;
import se.su.dsv.scipro.match.facade.ApplicationPeriodFacade;
import se.su.dsv.scipro.springdata.repos.SupervisorIdeaRepo;
import se.su.dsv.scipro.springdata.services.ProjectClassService;
import se.su.dsv.scipro.springdata.services.RoleService;
import se.su.dsv.scipro.springdata.services.SupervisorIdeaService;
@ -135,14 +137,27 @@ public class TestSupervisorIdea {
ideas = ideaService.findByStatusAndAuthor(IdeaStatus.WAITING, author1);
Assert.assertTrue("List is not empty", ideas.isEmpty());
waitingBachelorIdea.addAuthor(author1);
IdeaParticipation ip = new IdeaParticipation();
ip.setStudent(author1);
ip.setSupervisorIdea(waitingBachelorIdea);
ip.setConfirmed(true);
author1.addIdeaParticipation(ip);
IdeaParticipation ip2 = new IdeaParticipation();
ip2.setStudent(author2);
ip2.setSupervisorIdea(waitingBachelorIdea);
ip2.setConfirmed(true);
author2.addIdeaParticipation(ip2);
ideas = ideaService.findByStatusAndAuthor(IdeaStatus.WAITING, author1);
Assert.assertTrue("Number of ideas is not 1", ideas.size()==1);
ideas = ideaService.findByStatusAndAuthor(IdeaStatus.WAITING, author2);
Assert.assertTrue("Number of ideas is not 1", ideas.size()==1);
ideas = ideaService.findByStatusAndAuthor(IdeaStatus.COMPLETED, author1);
Assert.assertTrue("List is not empty", ideas.isEmpty());
Assert.assertTrue("List is not empty", ideas.isEmpty());
}
@Test
@ -201,13 +216,46 @@ public class TestSupervisorIdea {
boolean shouldBeFalse = ideaService.hasUnconfirmedIdea(authorUser1);
Assert.assertFalse("Not false",shouldBeFalse);
//Do something
takenBachelorIdea.addAuthor(author2);
IdeaParticipation participation = new IdeaParticipation();
participation.setStudent(author2);
participation.setSupervisorIdea(takenBachelorIdea);
participation.setConfirmed(false);
author2.addIdeaParticipation(participation);
boolean shouldBeTrue = ideaService.hasUnconfirmedIdea(authorUser2);
Assert.assertTrue("Not true",shouldBeTrue);
}
@Test
@Transactional
@Rollback
public void testIdeaParticipations() {
IdeaParticipation participation = new IdeaParticipation();
participation.setStudent(author1);
participation.setSupervisorIdea(waitingBachelorIdea);
participation.setConfirmed(false);
author1.addIdeaParticipation(participation);
Assert.assertEquals(1, author1.getIdeaParticipations().size());
}
@Test
@Transactional
@Rollback
public void testRemoveIdeaParticipation() {
IdeaParticipation participation = new IdeaParticipation();
participation.setStudent(author1);
participation.setSupervisorIdea(waitingBachelorIdea);
participation.setConfirmed(false);
author1.addIdeaParticipation(participation);
Assert.assertEquals(1, author1.getIdeaParticipations().size());
author1.removeIdeaParticipation(participation);
Assert.assertEquals(0, author1.getIdeaParticipations().size());
}
// HELPER METHODS
private SupervisorIdea newIdea(ProjectClass pc, ApplicationPeriod ap, Employee supervisor, IdeaStatus ideaStatus) {