deletion of projects no longer results in errors
This commit is contained in:
parent
2658a51490
commit
7d294432c0
src/main/java/se/su/dsv/scipro
@ -4,6 +4,7 @@ import java.util.Date;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -11,32 +12,37 @@ import se.su.dsv.scipro.data.dao.interfaces.CheckListDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.CheckListQuestionDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.CheckListTemplateDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.ProjectDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserSettingsDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.CheckList;
|
||||
import se.su.dsv.scipro.data.dataobjects.CheckListQuestion;
|
||||
import se.su.dsv.scipro.data.dataobjects.CheckListTemplate;
|
||||
import se.su.dsv.scipro.data.dataobjects.ChecklistCategory;
|
||||
import se.su.dsv.scipro.data.dataobjects.Project;
|
||||
import se.su.dsv.scipro.data.dataobjects.ProjectClass;
|
||||
import se.su.dsv.scipro.data.dataobjects.Student;
|
||||
import se.su.dsv.scipro.data.enums.ProjectStatus;
|
||||
import se.su.dsv.scipro.data.enums.StateOfMind;
|
||||
|
||||
@Component
|
||||
public class ProjectFacade {
|
||||
|
||||
|
||||
@Autowired
|
||||
private CheckListTemplateDao checkListTemplateDao;
|
||||
|
||||
|
||||
@Autowired
|
||||
private CheckListDao checkListDao;
|
||||
|
||||
|
||||
@Autowired
|
||||
private CheckListQuestionDao checkListQuestionDao;
|
||||
|
||||
|
||||
@Autowired
|
||||
private UserSettingsDao userSettingsDao;
|
||||
|
||||
@Autowired
|
||||
private ProjectDao projectDao;
|
||||
@Autowired
|
||||
private CheckListTemplateDao checklistTemplateDao;
|
||||
|
||||
|
||||
public void completedProjectStatus(Project project){
|
||||
if (project!=null){
|
||||
project = projectDao.reLoad(project);
|
||||
@ -47,38 +53,49 @@ public class ProjectFacade {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void deleteProject(Project project){
|
||||
project = projectDao.reLoad(project);
|
||||
for (Student s : project.getProjectParticipants()){
|
||||
if (userSettingsDao.getUserSettings(s.getUser()).getActiveProject()!=null && userSettingsDao.getUserSettings(s.getUser()).getActiveProject().equals(project)){
|
||||
userSettingsDao.getUserSettings(s.getUser()).setActiveProject(null);
|
||||
userSettingsDao.save(userSettingsDao.getUserSettings(s.getUser()));
|
||||
}
|
||||
}
|
||||
projectDao.delete(project);
|
||||
}
|
||||
|
||||
public void generateChecklists(Project project){
|
||||
List<CheckListTemplate> templates;
|
||||
project = projectDao.reLoad(project);
|
||||
|
||||
|
||||
if(project.getProjectClass().getCode().equals(ProjectClass.BACHELOR)){
|
||||
templates = checkListTemplateDao.findTemplatesByCategory("Bachelor");
|
||||
}else{
|
||||
templates = checkListTemplateDao.findTemplatesByCategory("Master");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
for(CheckListTemplate template : templates){
|
||||
|
||||
|
||||
List<CheckList> addedCheckLists = project.getCheckLists(); //list with all the checklist already added to the project
|
||||
|
||||
|
||||
boolean alreadyAdded = false;
|
||||
|
||||
|
||||
for (CheckList check : addedCheckLists){ //loop through the list
|
||||
if (check.getName().equals(template.getName())){ //if the name of the template we want to add already exists as a checklist
|
||||
alreadyAdded = true; //set the boolean to true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!alreadyAdded){ //if its NOT already added, then add a new checklist based on the template
|
||||
|
||||
|
||||
CheckListTemplate clt2 = checklistTemplateDao.reLoad(template);
|
||||
List<ChecklistCategory> categoryList = new ArrayList<ChecklistCategory>();
|
||||
for(ChecklistCategory cc : clt2.getCategories()){
|
||||
categoryList.add(cc);
|
||||
}
|
||||
|
||||
|
||||
CheckList cl = new CheckList(template.getName(), project, categoryList);
|
||||
for(String question : template.getQuestions()){
|
||||
CheckListQuestion clQuestion = new CheckListQuestion(question, cl.getNumberOfQuestions());
|
||||
@ -87,10 +104,10 @@ public class ProjectFacade {
|
||||
}
|
||||
cl.setCategories(template.getCategories());
|
||||
project.addCheckList(checkListDao.save(cl));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
projectDao.save(project);
|
||||
}
|
||||
|
||||
|
@ -45,8 +45,8 @@
|
||||
<th>Supervisor</th>
|
||||
<th>Reviewer</th>
|
||||
<th>Status</th>
|
||||
<th class="rounded-right-top">Edit</th>
|
||||
<!-- <th class="rounded-right-top">Delete</th> -->
|
||||
<th>Edit</th>
|
||||
<th class="rounded-right-top">Delete</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tfoot>
|
||||
@ -64,12 +64,12 @@
|
||||
<td wicket:id="statusLabel">Other role</td>
|
||||
<!-- <td wicket:id="editLabel">Other role</td> -->
|
||||
<td><a href="#" wicket:id="testLink">Edit</a></td>
|
||||
<!-- <td><a href="#" wicket:id="deleteLink">Delete</a></td> -->
|
||||
<td><a href="#" wicket:id="deleteLink">Delete</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td wicket:id="emptyLabel" colspan="7"></td>
|
||||
<td wicket:id="emptyLabel" colspan="8"></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
@ -21,6 +21,7 @@ import se.su.dsv.scipro.admin.pages.ProjectManagementPage;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.Dao.SortableParams.Sort;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.ProjectDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.Project;
|
||||
import se.su.dsv.scipro.data.facade.ProjectFacade;
|
||||
import se.su.dsv.scipro.dataproviders.NewProjectDataProvider;
|
||||
import se.su.dsv.scipro.reusable.DatesPanel;
|
||||
import se.su.dsv.scipro.reusable.FilterProjectClassPanel;
|
||||
@ -29,9 +30,9 @@ import se.su.dsv.scipro.reusable.FilterStringPanel;
|
||||
import se.su.dsv.scipro.security.auth.roles.Roles;
|
||||
|
||||
public class ProjectManagementPanel extends Panel {
|
||||
|
||||
|
||||
@SpringBean
|
||||
private ProjectDao projectDao;
|
||||
private ProjectFacade projectFacade;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ -130,18 +131,16 @@ public class ProjectManagementPanel extends Panel {
|
||||
};
|
||||
item.add(testLink);
|
||||
|
||||
// AjaxLink deleteLink = new AjaxLink<Void>("deleteLink"){
|
||||
// private static final long serialVersionUID = 1L;
|
||||
// @Override
|
||||
// public void onClick(AjaxRequestTarget target) {
|
||||
// Project p2 = projectDao.reLoad(p);
|
||||
// projectDao.delete(p2);
|
||||
// ajaxRefresh(target);
|
||||
// }
|
||||
//
|
||||
// };
|
||||
// item.add(deleteLink);
|
||||
//>>>>>>> cascade
|
||||
AjaxLink deleteLink = new AjaxLink<Void>("deleteLink"){
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Override
|
||||
public void onClick(AjaxRequestTarget target) {
|
||||
projectFacade.deleteProject(p);
|
||||
ajaxRefresh(target);
|
||||
}
|
||||
|
||||
};
|
||||
item.add(deleteLink);
|
||||
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user