Merge branch 'm3_employee_targets' into develop

This commit is contained in:
Emil Siverhall 2012-07-30 08:51:50 +02:00
commit 1e0bac8a56
15 changed files with 333 additions and 85 deletions

@ -11,7 +11,7 @@ CREATE TABLE `supervisoridea` (
`creator_id` bigint(20) NOT NULL,
`project_id` bigint(20) DEFAULT NULL,
`projectClass_id` bigint(20) NOT NULL,
`applicationPeriod_id` bigint(20) NOT NULL,
`applicationPeriod_id` bigint(20) DEFAULT NULL,
`description` varchar(4000) NOT NULL,
`requirements` varchar(1024) NOT NULL,
`ideaStatus` varchar(255) DEFAULT NULL,
@ -21,7 +21,7 @@ CREATE TABLE `supervisoridea` (
KEY `IDEAPERIODKEY` (`applicationPeriod_id`),
KEY `IDEACREATORKEY` (`creator_id`),
CONSTRAINT `IDEAPROJECTCLASSKEY` FOREIGN KEY (`projectClass_id`) REFERENCES `project_class` (`id`),
CONSTRAINT `IDEAPERIODKEY` FOREIGN KEY (`applicationPeriod_id`) REFERENCES `applicationperiod` (`id`),
CONSTRAINT `IDEAPERIODKEY` FOREIGN KEY (`applicationPeriod_id`) REFERENCES `ApplicationPeriod` (`id`),
CONSTRAINT `IDEAPROJECTKEY` FOREIGN KEY (`project_id`) REFERENCES `project` (`id`),
CONSTRAINT `IDEACREATORKEY` FOREIGN KEY (`creator_id`) REFERENCES `role` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
@ -48,7 +48,7 @@ CREATE TABLE `idea_student` (
CONSTRAINT `fk_supervisoridea_id` FOREIGN KEY (`supervisoridea_id`) REFERENCES `supervisoridea` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
ALTER TABLE `applicationperiod` ADD `courseStartDate` datetime NOT NULL;
ALTER TABLE `ApplicationPeriod` ADD `courseStartDate` datetime NOT NULL;
CREATE TABLE `researcharea` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,

@ -3,6 +3,9 @@
<body>
<wicket:extend>
<div class="span-24 last append-bottom">
<div wicket:id="abstractDialog">
<div wicket:id="abstractDialogPanel"></div>
</div>
<div wicket:id="ideaSub"></div>
</div>
<wicket:child/>

@ -1,21 +1,37 @@
package se.su.dsv.scipro.project.pages;
import java.util.List;
import javax.servlet.http.Cookie;
import org.apache.wicket.PageParameters;
import org.apache.wicket.ajax.AbstractAjaxTimerBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.panel.EmptyPanel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.protocol.http.WebRequest;
import org.apache.wicket.protocol.http.WebResponse;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.apache.wicket.util.time.Duration;
import org.odlabs.wiquery.ui.dialog.Dialog;
import se.su.dsv.scipro.SciProSession;
import se.su.dsv.scipro.data.DomainObjectDetachableModel;
import se.su.dsv.scipro.data.dao.interfaces.ProjectDao;
import se.su.dsv.scipro.data.dataobjects.Project;
import se.su.dsv.scipro.data.dataobjects.Student;
import se.su.dsv.scipro.data.dataobjects.User;
import se.su.dsv.scipro.match.dataobject.SupervisorIdea;
import se.su.dsv.scipro.match.dataobject.Idea.IdeaStatus;
import se.su.dsv.scipro.project.panels.AcceptIdeaDialogPanel;
import se.su.dsv.scipro.project.panels.CompleteIdeaDialogPanel;
import se.su.dsv.scipro.project.panels.ProjectIdeaTabMenuPanel;
import se.su.dsv.scipro.project.panels.ProjectSubTabMenuPanel;
import se.su.dsv.scipro.springdata.services.StudentService;
import se.su.dsv.scipro.springdata.services.SupervisorIdeaService;
/**
*
* @author Martin Peters - mpeters@dsv.su.se
@ -25,6 +41,12 @@ public abstract class AbstractProjectIdeaPage extends ProjectPage {
public static final String COOKIE_KEY = "authorLastVisitedPID";
@SpringBean
private SupervisorIdeaService ideaService;
@SpringBean
private StudentService studentService;
private Dialog dialog;
public AbstractProjectIdeaPage(PageParameters pp) {
super(pp);
@ -32,7 +54,75 @@ public abstract class AbstractProjectIdeaPage extends ProjectPage {
* This is the submenu
*/
add(new ProjectIdeaTabMenuPanel("ideaSub", this.getClass()));
/**
* Pop up dialog if author is part of a project
*/
addDialog();
checkForUnconfirmedIdeas(getUser());
}
private void addDialog() {
dialog = new Dialog("abstractDialog");
dialog.setModal(true);
dialog.setAutoOpen(false);
dialog.setWidth(500);
dialog.setHeight(600);
dialog.add(new EmptyPanel("abstractDialogPanel"));
add(dialog);
}
private void checkForUnconfirmedIdeas(final User currentUser) {
boolean hasUnconfirmed = ideaService.hasTakenIdeas(currentUser, false);
if(hasUnconfirmed) {
Student author = studentService.findByUser(currentUser);
final List<SupervisorIdea> ideas = ideaService.findIdeas(IdeaStatus.TAKEN, author, false);
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("abstractDialogPanel",Model.of(ideas.get(0)), currentUser, true));
dialog.setTitle("Supervisor project idea");
target.addComponent(dialog);
dialog.open(target);
stop();
}
});
}
}
else {
checkForConfirmedIdeas(currentUser);
}
}
private void checkForConfirmedIdeas(final User currentUser) {
boolean hasConfirmed = ideaService.hasTakenIdeas(currentUser, true);
if(hasConfirmed){
Student author = studentService.findByUser(currentUser);
final List<SupervisorIdea> ideas = ideaService.findIdeas(IdeaStatus.TAKEN, author, true);
add(new AbstractAjaxTimerBehavior(Duration.milliseconds(1)) {
private static final long serialVersionUID = 8249890924500999472L;
@Override
protected void onTimer(AjaxRequestTarget target) {
dialog.replace(new CompleteIdeaDialogPanel("abstractDialogPanel",Model.of(ideas.get(0))));
dialog.setWidth(550);
dialog.setHeight(700);
dialog.setTitle("Selected supervisor project idea");
target.addComponent(dialog);
dialog.open(target);
stop();
}
});
} else
System.out.println("No confirmed ideas");
}
}

@ -22,7 +22,7 @@
<b>Partner:</b><br />
<div wicket:id="partnerPanel"></div>
</wicket:enclosure>
<span class="right"><input type="submit" wicket:id="selectButton" value="Select project"/></span>
<span class="right"><input type="submit" wicket:id="selectButton" value="Select project idea"/></span>
</div>
</form>
</wicket:panel>

@ -44,7 +44,6 @@ public class ProjectIdeaOverviewPanel extends Panel {
super(id);
addDialog();
addDataTable(currentUser);
checkForUnconfirmedIdeas(currentUser);
add(new FilterForm("form"));
}
@ -75,7 +74,7 @@ public class ProjectIdeaOverviewPanel extends Panel {
@Override
public Iterator<SupervisorIdea> getIterator() {
return ideaService.findByStatusAndParams(IdeaStatus.WAITING, params, new PageRequest(getTable().getCurrentPage(), getTable().getRowsPerPage(), getSort())).iterator();
return ideaService.findByStatusAndCapabilities(IdeaStatus.WAITING, params, new PageRequest(getTable().getCurrentPage(), getTable().getRowsPerPage(), getSort())).iterator();
}
@Override
@ -101,58 +100,7 @@ public class ProjectIdeaOverviewPanel extends Panel {
});
}
private void checkForUnconfirmedIdeas(final User currentUser) {
boolean hasUnconfirmed = ideaService.hasTakenIdeas(currentUser, false);
if(hasUnconfirmed) {
Student author = studentService.findByUser(currentUser);
final List<SupervisorIdea> ideas = ideaService.findIdeas(IdeaStatus.TAKEN, author, false);
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)), currentUser, true));
dialog.setTitle("Supervisor project idea");
target.addComponent(dialog);
dialog.open(target);
stop();
}
});
}
}
else {
checkForConfirmedIdeas(currentUser);
}
}
private void checkForConfirmedIdeas(final User currentUser) {
boolean hasConfirmed = ideaService.hasTakenIdeas(currentUser, true);
if(hasConfirmed){
Student author = studentService.findByUser(currentUser);
final List<SupervisorIdea> ideas = ideaService.findIdeas(IdeaStatus.TAKEN, author, true);
add(new AbstractAjaxTimerBehavior(Duration.milliseconds(1)) {
private static final long serialVersionUID = 8249890924500999472L;
@Override
protected void onTimer(AjaxRequestTarget target) {
dialog.replace(new CompleteIdeaDialogPanel("dialogPanel",Model.of(ideas.get(0))));
dialog.setWidth(550);
dialog.setHeight(700);
dialog.setTitle("Selected supervisor project idea");
target.addComponent(dialog);
dialog.open(target);
stop();
}
});
} else
System.out.println("No confirmed ideas");
}
private class FilterForm extends Form<Void> {
private static final long serialVersionUID = -5646495880236201368L;

@ -26,6 +26,7 @@ import se.su.dsv.scipro.match.dataobject.Watson;
import se.su.dsv.scipro.springdata.repos.SupervisorIdeaRepo;
import se.su.dsv.scipro.springdata.services.StudentService;
import se.su.dsv.scipro.springdata.services.SupervisorIdeaService;
import se.su.dsv.scipro.springdata.services.SupervisorService;
import com.mysema.query.BooleanBuilder;
import com.mysema.query.types.Predicate;
@ -39,6 +40,8 @@ public class SupervisorIdeaServiceImpl extends AbstractQueryService<SupervisorId
private SupervisorIdeaRepo supervisorIdeaRepo;
@Resource
private StudentService studentService;
@Resource
private SupervisorService supervisorService;
private int MAX_PARTNERS = 1;
@ -197,6 +200,11 @@ public class SupervisorIdeaServiceImpl extends AbstractQueryService<SupervisorId
return supervisorIdeaRepo.findAll(byStatus(status).and(levelFilter(params.getLevels())), pageable);
}
@Override
public Page<SupervisorIdea> findByStatusAndCapabilities(IdeaStatus status, FilterParams params, Pageable pageable) {
return supervisorIdeaRepo.findAll(byStatus(status).and(capabilityFilter(params.getLevels())), pageable);
}
@Override
public List<SupervisorIdea> findByStatusAndAuthor(IdeaStatus status, Student author) {
@ -214,6 +222,29 @@ public class SupervisorIdeaServiceImpl extends AbstractQueryService<SupervisorId
return levelFilter(params.getLevels()).and(bySupervisor(params.getSupervisor()));
}
private Predicate inSupervisorList(List<Employee> list) {
return QSupervisorIdea.supervisorIdea.creator.in(list);
}
private BooleanBuilder capabilityFilter(Collection<ProjectClass> levels){
BooleanBuilder e = new BooleanBuilder();
if (levels != null && !levels.isEmpty()) {
for (ProjectClass level : levels) {
List<Employee> list = supervisorService
.getSupervisorsWithinLimits(level);
if (list.isEmpty()) { // If no capable supervisors exist, make
// sure no ideas is returned.
return e.and(QSupervisorIdea.supervisorIdea.projectClass.isNull());
} else
e.or(byLevel(level).and(inSupervisorList(list)));
}
return e;
} else {
return e.and(QSupervisorIdea.supervisorIdea.projectClass.isNull());
}
}
private BooleanBuilder levelFilter(Collection<ProjectClass> levels){
BooleanBuilder e = new BooleanBuilder();
if(levels!=null && !levels.isEmpty()){
@ -250,4 +281,9 @@ public class SupervisorIdeaServiceImpl extends AbstractQueryService<SupervisorId
return supervisorIdeaRepo.count(byStatus(status));
}
@Override
public Long countIdeas(IdeaStatus status, Employee supervisor, ProjectClass pc) {
return supervisorIdeaRepo.count(byStatus(status).and(bySupervisor(supervisor)).and(byLevel(pc)));
}
}

@ -1,20 +1,27 @@
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.Employee;
import se.su.dsv.scipro.data.dataobjects.User;
import se.su.dsv.scipro.springdata.repos.SupervisorRepo;
import se.su.dsv.scipro.springdata.services.SupervisorService;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.math.BigInteger;
import java.util.*;
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.Employee;
import se.su.dsv.scipro.data.dataobjects.ProjectClass;
import se.su.dsv.scipro.data.dataobjects.User;
import se.su.dsv.scipro.match.dataobject.Availability;
import se.su.dsv.scipro.match.dataobject.Idea.IdeaStatus;
import se.su.dsv.scipro.springdata.repos.SupervisorRepo;
import se.su.dsv.scipro.springdata.services.ProjectClassService;
import se.su.dsv.scipro.springdata.services.SupervisorIdeaService;
import se.su.dsv.scipro.springdata.services.SupervisorService;
@Service ( "supervisorService" )
@Transactional ( readOnly = true )
@ -22,7 +29,11 @@ public class SupervisorServiceImpl extends AbstractQueryService<Employee, Long>
@Resource
private SupervisorRepo supervisorRepo;
@Resource
private ProjectClassService projectClassService;
@Resource
private SupervisorIdeaService ideaService;
@PersistenceContext
private EntityManager em;
@ -116,4 +127,32 @@ public class SupervisorServiceImpl extends AbstractQueryService<Employee, Long>
public Employee findByUser(User user) {
return supervisorRepo.findByUser(user);
}
@Override
public List<Employee> getSupervisorsWithinLimits(ProjectClass pc) {
List<Employee> supervisors = supervisorRepo.findAll();
List<Employee> result = new ArrayList<Employee>();
for (Employee e : supervisors) {
Availability a = getAvailability(e, pc);
if(a.getNumMatched() < a.getNumCapable())
result.add(e);
}
return result;
}
@Override
public List<Availability> getAvailabilities(Employee supervisor) {
List<Availability> list = new ArrayList<Availability>();
for(ProjectClass pc : projectClassService.findAllActive())
list.add(getAvailability(supervisor, pc));
return list;
}
@Override
public Availability getAvailability(Employee supervisor, ProjectClass pc) {
Integer projectLimit = supervisor.getCapabilities().getProjectLimit(pc);
long activeProjectIdeas = ideaService.countIdeas(IdeaStatus.TAKEN, supervisor, pc);
return new Availability(supervisor, activeProjectIdeas, projectLimit, pc);
}
}

@ -21,10 +21,12 @@ public interface SupervisorIdeaService extends GenericService<SupervisorIdea, Lo
Page<SupervisorIdea> findAll(FilterParams params, Pageable pageable);
Page<SupervisorIdea> findByStatus(IdeaStatus status, Pageable pageable);
Page<SupervisorIdea> findByStatusAndParams(IdeaStatus status, FilterParams params, Pageable pageable);
Page<SupervisorIdea> findByStatusAndCapabilities(IdeaStatus status, FilterParams params, Pageable pageable);
List<SupervisorIdea> findByStatusAndAuthor(IdeaStatus status, Student author);
List<SupervisorIdea> findIdeas(IdeaStatus status, Student author, boolean confirmed);
Long countByStatus(IdeaStatus status);
Long countIdeas(IdeaStatus status, Employee supervisor, ProjectClass pc);
void saveSupervisorCreatedIdea(IModel<SupervisorIdea> model, Employee creator, SortedSet<Student> students);
void deleteWaitingIdea(IModel<SupervisorIdea> model);

@ -1,10 +1,12 @@
package se.su.dsv.scipro.springdata.services;
import se.su.dsv.scipro.data.dataobjects.Employee;
import se.su.dsv.scipro.data.dataobjects.User;
import java.util.List;
import se.su.dsv.scipro.data.dataobjects.Employee;
import se.su.dsv.scipro.data.dataobjects.ProjectClass;
import se.su.dsv.scipro.data.dataobjects.User;
import se.su.dsv.scipro.match.dataobject.Availability;
/**
* fred-fri
* date: 2012 03 26
@ -15,4 +17,8 @@ public interface SupervisorService extends GenericService<Employee,Long>, QueryS
public List<Employee> findSupervisorBySQL(String keywordTypeName, String sortOrder);
public Employee findByUser(User user);
List<Employee> getSupervisorsWithinLimits(ProjectClass pc);
List<Availability> getAvailabilities(Employee supervisor);
Availability getAvailability(Employee supervisor, ProjectClass pc);
}

@ -3,11 +3,8 @@
xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
<body>
<wicket:extend>
<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>
<div wicket:id="feedback"></div>
<div wicket:id="availabilityPanel" class="append-bottom"></div>
<button wicket:id="ideaLink">Create new project idea</button>
<div class="prepend-top" wicket:id="ideaPanel"></div>
</wicket:extend>

@ -7,6 +7,7 @@ import org.apache.wicket.markup.html.panel.FeedbackPanel;
import se.su.dsv.scipro.security.auth.Authorization;
import se.su.dsv.scipro.security.auth.roles.Roles;
import se.su.dsv.scipro.supervisor.panels.SupervisorAvailabilityPanel;
import se.su.dsv.scipro.supervisor.panels.SupervisorProjectIdeaOverviewPanel;
@Authorization(authorizedRoles={Roles.SYSADMIN})
@ -18,6 +19,7 @@ public class SupervisorProjectIdeaStartPage extends AbstractSupervisorProjectIde
super(pp);
add(feedbackPanel = new FeedbackPanel("feedback"));
feedbackPanel.setOutputMarkupId(true);
add(new SupervisorAvailabilityPanel("availabilityPanel", getUser()));
add(new SupervisorProjectIdeaOverviewPanel("ideaPanel", getUser()));
addSubmissionPageLink();

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
</head>
<body>
<wicket:panel>
<div class="info-box rounded-box last">
<p>Application period is open from xxxx-xx-xx to xxxx-xx-xx and the course start for the application period is xxxx-xx-xx</p>
<p>
According to the settings entered by admin, you should supervise <span wicket:id="targets"></span> projects.
</p>
You are currently supervising <span wicket:id="current"></span> projects.
</div>
</wicket:panel>
</body>
</html>

@ -0,0 +1,40 @@
package se.su.dsv.scipro.supervisor.panels;
import java.util.ArrayList;
import java.util.List;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import se.su.dsv.scipro.data.dataobjects.Employee;
import se.su.dsv.scipro.data.dataobjects.User;
import se.su.dsv.scipro.match.dataobject.Availability;
import se.su.dsv.scipro.springdata.services.SupervisorService;
import com.google.common.base.Joiner;
public class SupervisorAvailabilityPanel extends Panel {
private static final long serialVersionUID = -9010467449322120267L;
@SpringBean
private SupervisorService supervisorService;
public SupervisorAvailabilityPanel(String id, final User loggedInUser) {
super(id);
Employee supervisor = supervisorService.findByUser(loggedInUser);
List<Availability> targets = supervisorService.getAvailabilities(supervisor);
List<String> targetStrings = new ArrayList<String>();
List<String> takenStrings = new ArrayList<String>();
for(Availability a : targets) {
targetStrings.add(a.getNumCapable() + " " + a.getProjectClass().getName().toLowerCase());
takenStrings.add(a.getNumMatched() + " " + a.getProjectClass().getName().toLowerCase());
}
add(new Label("targets", Joiner.on(", ").join(targetStrings)));
add(new Label("current", Joiner.on(", ").join(takenStrings)));
}
}

@ -1,6 +1,7 @@
package se.su.dsv.scipro.springdata;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@ -11,8 +12,11 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import se.su.dsv.scipro.data.dao.interfaces.UserDao;
import se.su.dsv.scipro.data.dataobjects.Employee;
import se.su.dsv.scipro.data.dataobjects.ProjectClass;
import se.su.dsv.scipro.data.dataobjects.User;
import se.su.dsv.scipro.match.dao.interfaces.KeywordTypeDao;
import se.su.dsv.scipro.match.dataobject.Availability;
import se.su.dsv.scipro.springdata.services.ProjectClassService;
import se.su.dsv.scipro.springdata.services.SupervisorService;
import java.util.*;
@ -28,6 +32,8 @@ public class TestSupervisor {
@Autowired
private SupervisorService supervisorService;
@Autowired
private ProjectClassService projectClassService;
@Autowired
private UserDao userDao;
@ -45,6 +51,27 @@ public class TestSupervisor {
return supervisorService.save(employee);
}
@Test
@Transactional
@Rollback
public void testSupervisorAvailabilities() {
ProjectClass bachelor = new ProjectClass(ProjectClass.BACHELOR, "Bachelor", "Bachelor degree thesis project");
bachelor = projectClassService.save(bachelor);
ProjectClass master = new ProjectClass(ProjectClass.MASTER, "Master", "Master degree thesis project");
master = projectClassService.save(master);
Employee employee1 = getEmployee("Head", "Supervisor", "supervisor@scipro.se");
employee1.getCapabilities().setMaxProjects(bachelor, 1);
employee1.getCapabilities().setMaxProjects(master, 2);
Availability availability = supervisorService.getAvailability(employee1, bachelor);
Availability availability2 = supervisorService.getAvailability(employee1, master);
Assert.assertEquals(new Availability(employee1, 0L, 1, bachelor), availability);
Assert.assertEquals(new Availability(employee1, 0L, 2, master), availability2);
}
/**
* Test for getting supervisors in sorted order based on last name in ascending order.
*/

@ -67,7 +67,7 @@ public class TestSupervisorIdea {
private User authorUser1, authorUser2, supervisorUser, supervisorUser2, unconfirmedUser;
private Student author1, author2, unconfirmedAuthor;
private Employee supervisor, supervisor2;
private SupervisorIdea waitingBachelorIdea, waitingMasterIdea, takenBachelorIdea, completedMasterIdea;
private SupervisorIdea waitingBachelorIdea, waitingMasterIdea, takenBachelorIdea, completedMasterIdea, waitingBachelor2, waitingMaster2, waitingBachelor3;
private ApplicationPeriod bachelorPeriod, masterPeriod;
private Keyword keyword1, keyword2;
@ -106,6 +106,9 @@ public class TestSupervisorIdea {
waitingMasterIdea = newIdea(master, masterPeriod, supervisor, IdeaStatus.WAITING);
takenBachelorIdea = newIdea(bachelor, bachelorPeriod, supervisor, IdeaStatus.TAKEN);
completedMasterIdea = newIdea(master, masterPeriod, supervisor, IdeaStatus.COMPLETED);
waitingBachelor2 = newIdea(bachelor, bachelorPeriod, supervisor2, IdeaStatus.WAITING);
waitingBachelor3 = newIdea(bachelor, bachelorPeriod, supervisor2, IdeaStatus.WAITING);
waitingMaster2 = newIdea(master, masterPeriod, supervisor2, IdeaStatus.WAITING);
}
@ -115,7 +118,7 @@ public class TestSupervisorIdea {
public void testFindIdeasByStatus() {
Page<SupervisorIdea> waitingIdeaPage = ideaService.findByStatus(IdeaStatus.WAITING, new PageRequest(0, 10));
List<SupervisorIdea> waitingIdeasList = waitingIdeaPage.getContent();
Assert.assertEquals(Arrays.asList(new SupervisorIdea[]{waitingBachelorIdea, waitingMasterIdea}), waitingIdeasList);
Assert.assertEquals(Arrays.asList(new SupervisorIdea[]{waitingBachelorIdea, waitingMasterIdea, waitingBachelor2, waitingBachelor3, waitingMaster2}), waitingIdeasList);
Page<SupervisorIdea> takenIdeaPage = ideaService.findByStatus(IdeaStatus.TAKEN, new PageRequest(0, 10));
List<SupervisorIdea> takenIdeasList = takenIdeaPage.getContent();
@ -138,14 +141,14 @@ public class TestSupervisorIdea {
Page<SupervisorIdea> waitingBachelors = ideaService.findByStatusAndParams(IdeaStatus.WAITING, params, new PageRequest(0, 10));
List<SupervisorIdea> waitingIdeasList = waitingBachelors.getContent();
Assert.assertEquals(Arrays.asList(new SupervisorIdea[]{waitingBachelorIdea}), waitingIdeasList);
Assert.assertEquals(Arrays.asList(new SupervisorIdea[]{waitingBachelorIdea, waitingBachelor2, waitingBachelor3}), waitingIdeasList);
levelSet.add(master);
params.setLevels(levelSet);
Page<SupervisorIdea> waitingBachelorAndMasters = ideaService.findByStatusAndParams(IdeaStatus.WAITING, params, new PageRequest(0, 10));
List<SupervisorIdea> waitingIdeas = waitingBachelorAndMasters.getContent();
Assert.assertEquals(Arrays.asList(new SupervisorIdea[]{waitingBachelorIdea, waitingMasterIdea}), waitingIdeas);
Assert.assertEquals(Arrays.asList(new SupervisorIdea[]{waitingBachelorIdea, waitingMasterIdea, waitingBachelor2, waitingBachelor3, waitingMaster2}), waitingIdeas);
}
@Test
@ -185,10 +188,10 @@ public class TestSupervisorIdea {
@Transactional
@Rollback
public void testSaveSupervisorCreatedIdea() {
Assert.assertEquals(new Long(2), ideaService.countByStatus(IdeaStatus.WAITING));
Assert.assertEquals(new Long(5), ideaService.countByStatus(IdeaStatus.WAITING));
IModel<SupervisorIdea> model = newIdeaModel(bachelor);
ideaService.saveSupervisorCreatedIdea(model, supervisor, new TreeSet<Student>());
Assert.assertEquals(new Long(3), ideaService.countByStatus(IdeaStatus.WAITING));
Assert.assertEquals(new Long(6), ideaService.countByStatus(IdeaStatus.WAITING));
}
@ -214,17 +217,17 @@ public class TestSupervisorIdea {
public void testDeleteWaitingIdea() {
Iterable<SupervisorIdea> ideas = ideaService.findAll();
List<SupervisorIdea> ideaList = constructList(ideas);
Assert.assertEquals(4, ideaList.size());
Assert.assertEquals(7, ideaList.size());
ideaService.deleteWaitingIdea(Model.of(takenBachelorIdea)); //Should not be deleted.
ideas = ideaService.findAll();
ideaList = constructList(ideas);
Assert.assertEquals(4, ideaList.size());
Assert.assertEquals(7, ideaList.size());
ideaService.deleteWaitingIdea(Model.of(waitingBachelorIdea)); //Should be deleted.
ideas = ideaService.findAll();
ideaList = constructList(ideas);
Assert.assertEquals(3, ideaList.size());
Assert.assertEquals(6, ideaList.size());
}
/**
@ -278,6 +281,44 @@ public class TestSupervisorIdea {
}
@Test
@Transactional
@Rollback
public void testShowOnlyWaitingIdeasBySupervisorsWithinLimits() {
Set<ProjectClass> levels = new HashSet<ProjectClass>();
levels.add(bachelor);
levels.add(master);
FilterParams params = new FilterParams();
params.setLevels(levels);
supervisor.getCapabilities().setMaxProjects(bachelor, 1);
supervisor.getCapabilities().setMaxProjects(master, 1);
supervisor2.getCapabilities().setMaxProjects(bachelor, 1);
supervisor2.getCapabilities().setMaxProjects(master, 1);
Page<SupervisorIdea> ideaPage = ideaService.findByStatusAndCapabilities(IdeaStatus.WAITING, params, new PageRequest(0, 10));
List<SupervisorIdea> ideas = ideaPage.getContent();
Assert.assertEquals(Arrays.asList(new SupervisorIdea[]{waitingMasterIdea, waitingBachelor2, waitingBachelor3, waitingMaster2}), ideas);
supervisor.getCapabilities().setMaxProjects(bachelor, 5);
ideaPage = ideaService.findByStatusAndCapabilities(IdeaStatus.WAITING, params, new PageRequest(0, 10));
ideas = ideaPage.getContent();
Assert.assertEquals(Arrays.asList(new SupervisorIdea[]{waitingBachelorIdea, waitingMasterIdea, waitingBachelor2, waitingBachelor3, waitingMaster2}), ideas);
waitingBachelor2.setIdeaStatus(IdeaStatus.TAKEN);
ideaPage = ideaService.findByStatusAndCapabilities(IdeaStatus.WAITING, params, new PageRequest(0, 10));
ideas = ideaPage.getContent();
Assert.assertEquals(Arrays.asList(new SupervisorIdea[]{waitingBachelorIdea, waitingMasterIdea, waitingMaster2}), ideas);
supervisor2.getCapabilities().setMaxProjects(master, 0);
ideaPage = ideaService.findByStatusAndCapabilities(IdeaStatus.WAITING, params, new PageRequest(0, 10));
ideas = ideaPage.getContent();
Assert.assertEquals(Arrays.asList(new SupervisorIdea[]{waitingBachelorIdea, waitingMasterIdea}), ideas);
}
// HELPER METHODS
private SupervisorIdea newIdea(ProjectClass pc, ApplicationPeriod ap, Employee supervisor, IdeaStatus ideaStatus) {
SupervisorIdea idea = new SupervisorIdea();