added some custom validation logic to supervisor idea submission to display appropriate feedback messages if number of students doesnt match specified project level
This commit is contained in:
parent
461120728d
commit
cf8c7f61e5
src/main/java/se/su/dsv/scipro
springdata
supervisor/panels
@ -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;
|
||||
|
@ -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;
|
||||
@ -147,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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user