public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
MyWorkspaceForm myWorkspaceForm = (MyWorkspaceForm) form;
// TODO regarder le ActionSupport pour struts de spring
ProjectService projectService = CoreObjectFactory.getProjectService();
Set projectSet = projectService.findForAUser(((User) request.getSession().getAttribute("user")).getPersistanceId());
List projects = new ArrayList(projectSet);
// Positionnement d'un projet par défaut.... si il en existe un dans la
// liste...
// et si ce n'est pas déjà fait... et s'il n'y a rien en session
if (projects.size() > 0 & myWorkspaceForm.getProjectId() == 0 & request.getSession().getAttribute("basicProject.persistanceId") == null || ((Integer) request.getSession().getAttribute("basicProject.persistanceId")).intValue() == 0){
myWorkspaceForm.setProjectId( ((Project)projects.get(0)).getPersistanceId());
myWorkspaceForm.setProjectName( ((Project)projects.get(0)).getName());
} // si un project est en session et que rien n'est dans le form
else if (projects.size() > 0 & myWorkspaceForm.getProjectId() == 0 & request.getSession().getAttribute("basicProject.persistanceId") != null && ((Integer) request.getSession().getAttribute("basicProject.persistanceId")).intValue() != 0){
for (Iterator iterator = projects.iterator(); iterator.hasNext();) {
Project basicProject = (Project) iterator.next();
if (basicProject.getPersistanceId() == ((Integer) request.getSession().getAttribute("basicProject.persistanceId")).intValue()) {
myWorkspaceForm.setProjectId(basicProject.getPersistanceId());
myWorkspaceForm.setProjectName(basicProject.getName());
}
}
}
// si une sélection est faite dans la liste
else if (projects.size() > 0 & myWorkspaceForm.getProjectId() > 0){
for (Iterator iterator = projects.iterator(); iterator.hasNext();) {
Project basicProject = (Project) iterator.next();
if (basicProject.getPersistanceId() == myWorkspaceForm.getProjectId()) {
myWorkspaceForm.setProjectId(basicProject.getPersistanceId());
myWorkspaceForm.setProjectName(basicProject.getName());
}
}
}
// mise en session de l'id du projet et du nom
request.getSession().setAttribute("basicProject.persistanceId", Integer.valueOf(myWorkspaceForm.getProjectId()));
request.getSession().setAttribute("basicProject.name", myWorkspaceForm.getProjectName());
// set the list of projects in the request
request.setAttribute("projects", projects);
this.displayProjectPlanning(request, myWorkspaceForm);