Merge branch 'm3_start_date' into develop

This commit is contained in:
Emil Siverhall 2012-08-03 12:21:44 +02:00
commit 1744c2ffa0
7 changed files with 38 additions and 31 deletions

@ -54,6 +54,9 @@ public class SupervisorIdeaServiceImpl extends AbstractQueryService<SupervisorId
private transient Logger logger = Logger.getLogger(SupervisorIdeaService.class);
private int MAX_PARTNERS = 1;
private int BACHELOR_STUDENTS = 2;
private int MAX_MASTER_STUDENTS = 1;
@Autowired
public SupervisorIdeaServiceImpl(
@ -67,7 +70,7 @@ public class SupervisorIdeaServiceImpl extends AbstractQueryService<SupervisorId
@Transactional ( readOnly = false )
public void saveSupervisorCreatedIdea(SupervisorIdea idea, Employee creator, SortedSet<Student> students) {
if(!students.isEmpty()) {
if(!students.isEmpty()) {
for(Student s : students) {
s = studentService.findOne(s.getId()); //Needed for lazy loading to work.
IdeaParticipation ip = new IdeaParticipation();
@ -172,6 +175,19 @@ public class SupervisorIdeaServiceImpl extends AbstractQueryService<SupervisorId
return new Pair<Boolean, String>(true,"Validation passed");
}
@Override
public Pair<Boolean, String> validateSupervisorIdeaSubmission(SupervisorIdea idea, SortedSet<Student> students) {
if(!students.isEmpty()) {
if(idea.getProjectClass().getCode().equals(ProjectClass.BACHELOR)&&students.size()!=BACHELOR_STUDENTS){
return new Pair<Boolean, String>(false, "Selected number of bachelor students is not allowed");
}
if(idea.getProjectClass().getCode().equals(ProjectClass.MASTER)&&students.size()>MAX_MASTER_STUDENTS){
return new Pair<Boolean, String>(false, "Selected number of master students is not allowed");
}
}
return new Pair<Boolean, String>(true, "Validation passed");
}
@Override
@Transactional (readOnly = false)
public void partnerAcceptIdea(SupervisorIdea idea, User loggedInUser) {

@ -46,6 +46,7 @@ public interface SupervisorIdeaService extends GenericService<SupervisorIdea, Lo
Pair<Boolean, String> validateIdeaAcceptance(SupervisorIdea idea, User loggedInUser, SortedSet<Student> students);
Pair<Boolean, String> validatePartnerAcceptance(User loggedInUser);
Pair<Boolean, String> validateSupervisorIdeaSubmission(SupervisorIdea idea, SortedSet<Student> students);
public static class FilterParams implements Serializable {
private static final long serialVersionUID = 4981420721152104292L;

@ -19,15 +19,13 @@ 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(), readOnly, new Model<SupervisorIdea>(idea)));
add(new SupervisorEditIdeaPanel("editPanel", getUser(), new Model<SupervisorIdea>(idea)));
}

@ -69,7 +69,7 @@ public class SupervisorMyProjectIdeasPage extends AbstractSupervisorProjectIdeaP
@Override
public IColumn[] getColumns() {
IColumn[] columns = new IColumn[3];
IColumn[] columns = new IColumn[4];
columns[0] = new PropertyColumn<ProjectIdea>(Model.of("Level"), "projectClass", "projectClass");
// columns[1] = new PropertyColumn<ProjectIdea>(Model.of("Title"), "title", "title");
@ -86,6 +86,7 @@ public class SupervisorMyProjectIdeasPage extends AbstractSupervisorProjectIdeaP
};
columns[2] = new DateColumn<ProjectIdea>(Model.of("Received"), "match.dateCreated", "match.dateCreated");
columns[3] = new DateColumn<ProjectIdea>(Model.of("Start date"),"applicationPeriod.courseStartDate", "applicationPeriod.courseStartDate");
return columns;
}

@ -4,7 +4,6 @@
<body>
<wicket:extend>
<div class="span-24 last">
<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>

@ -3,7 +3,6 @@ package se.su.dsv.scipro.supervisor.pages;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
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;
@ -13,12 +12,9 @@ import se.su.dsv.scipro.supervisor.panels.SupervisorProjectIdeaOverviewPanel;
@Authorization(authorizedRoles={Roles.SYSADMIN})
public class SupervisorProjectIdeaStartPage extends AbstractSupervisorProjectIdeaPage {
private FeedbackPanel feedbackPanel;
public SupervisorProjectIdeaStartPage(PageParameters pp) {
super(pp);
add(feedbackPanel = new FeedbackPanel("feedback"));
feedbackPanel.setOutputMarkupId(true);
add(new SupervisorAvailabilityPanel("availabilityPanel", getUser()));
add(new SupervisorProjectIdeaOverviewPanel("ideaPanel", getUser()));
addSubmissionPageLink();
@ -26,9 +22,7 @@ public class SupervisorProjectIdeaStartPage extends AbstractSupervisorProjectIde
}
private void addSubmissionPageLink() {
PageParameters pp = new PageParameters();
pp.put("readOnly", false);
BookmarkablePageLink<Void> ideaLink = new BookmarkablePageLink<Void>("ideaLink", SupervisorIdeaSubmissionPage.class, pp);
BookmarkablePageLink<Void> ideaLink = new BookmarkablePageLink<Void>("ideaLink", SupervisorIdeaSubmissionPage.class);
add(ideaLink);
}

@ -35,6 +35,7 @@ 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.peer.data.dao.controllers.Pair;
import se.su.dsv.scipro.reusable.AddRemoveStudentsPanel;
import se.su.dsv.scipro.springdata.services.ProjectClassService;
import se.su.dsv.scipro.springdata.services.SupervisorIdeaService;
@ -58,9 +59,9 @@ public class SupervisorEditIdeaPanel extends Panel {
@SpringBean
private SupervisorService supervisorService;
public SupervisorEditIdeaPanel(String id, User currentUser, boolean readOnly,IModel<SupervisorIdea> model) {
public SupervisorEditIdeaPanel(String id, User currentUser, IModel<SupervisorIdea> model) {
super(id, model);
add(new IdeaForm("form", model, currentUser, readOnly).setEnabled(!readOnly));
add(new IdeaForm("form", model, currentUser));
}
private class IdeaForm extends Form<SupervisorIdea> {
@ -76,7 +77,7 @@ public class SupervisorEditIdeaPanel extends Panel {
private KeywordContainer regularKwc;
private FeedbackPanel feedbackPanel;
public IdeaForm(String id, final IModel<SupervisorIdea> model, final User currentUser, final boolean readOnly) {
public IdeaForm(String id, final IModel<SupervisorIdea> model, final User currentUser) {
super(id, model);
@ -97,13 +98,8 @@ public class SupervisorEditIdeaPanel extends Panel {
descriptionField.add(StringValidator.minimumLength(10)); // Description needs to be at least 10 characters
final Employee ideaCreator = supervisorService.findByUser(currentUser);
Employee ideaSupervisor = model.getObject().getCreator();
Set<ResearchArea> areas;
if(readOnly)
areas = ideaSupervisor.getActiveResearchAreas();
else
areas = ideaCreator.getActiveResearchAreas();
Set<ResearchArea> areas = ideaCreator.getActiveResearchAreas();
ListView<ResearchArea> areaList = new ListView<ResearchArea>("researchAreas", new ArrayList<ResearchArea>(areas)) {
private static final long serialVersionUID = 1745649109195334927L;
@ -152,15 +148,17 @@ public class SupervisorEditIdeaPanel extends Panel {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
target.addComponent(feedbackPanel);
try {
ideaService.saveSupervisorCreatedIdea(model.getObject(), ideaCreator, studentsPanel.getStudentSet());
setResponsePage(SupervisorProjectIdeaStartPage.class);
getSession().info("Idea successfully submitted");
} catch (Exception e) {
e.printStackTrace();
}
Pair<Boolean, String> acceptance = ideaService.validateSupervisorIdeaSubmission(model.getObject(), studentsPanel.getStudentSet());
if(acceptance.head){
ideaService.saveSupervisorCreatedIdea(model.getObject(), ideaCreator, studentsPanel.getStudentSet());
setResponsePage(SupervisorProjectIdeaStartPage.class);
getSession().info("Idea successfully submitted");
} else {
getSession().error(acceptance.tail);
target.appendJavascript("window.scrollTo(0,0);");
}
target.addComponent(feedbackPanel);
}