001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.web.controllers.survey;
034:
035: import org.libresource.Libresource;
036:
037: import org.libresource.kernel.KernelConstants;
038: import org.libresource.kernel.LibresourceSecurityException;
039: import org.libresource.kernel.interfaces.KernelService;
040:
041: import org.libresource.survey.SurveyConstants;
042: import org.libresource.survey.ejb.model.SurveyResourceValue;
043: import org.libresource.survey.interfaces.LibresourceSurveyService;
044:
045: import org.libresource.web.Controller;
046:
047: import java.net.URI;
048:
049: import javax.servlet.http.HttpServletRequest;
050: import javax.servlet.http.HttpServletResponse;
051:
052: public class EditSurveyController implements Controller {
053: public Object process(URI uri, HttpServletRequest request,
054: HttpServletResponse response) throws Exception {
055: LibresourceSurveyService surveyService = (LibresourceSurveyService) Libresource
056: .getService(SurveyConstants.SERVICE);
057:
058: if (request.getParameter("cancel") != null) {
059: return uri;
060: }
061:
062: KernelService kernelService = (KernelService) Libresource
063: .getService(KernelConstants.SERVICE);
064:
065: if (!kernelService.checkSecurity(uri, KernelConstants.SERVICE)) {
066: throw new LibresourceSecurityException(uri,
067: KernelConstants.SERVICE);
068: }
069:
070: if (kernelService.checkIfOwner(uri)) {
071: request.setAttribute("owner", "true");
072: }
073:
074: // view the edition page
075: if (request.getParameter("question") == null) {
076: SurveyResourceValue surveyResourceValue = surveyService
077: .getSurvey(uri);
078: request.setAttribute("question", surveyResourceValue
079: .getQuestion());
080: request.setAttribute("state", surveyResourceValue
081: .getState());
082: request.setAttribute("displayMode", surveyResourceValue
083: .getDisplayMode());
084: request.setAttribute("options", surveyService
085: .getOptionsInSurvey(uri));
086:
087: return "/pages/modules/survey/editSurvey.jsp";
088: }
089:
090: // if the question is void
091: if (request.getParameter("question").trim().length() == 0) {
092: SurveyResourceValue surveyResourceValue = surveyService
093: .getSurvey(uri);
094: request.setAttribute("options", surveyService
095: .getOptionsInSurvey(uri));
096: request.setAttribute("state", surveyResourceValue
097: .getState());
098: request.setAttribute("displayMode", surveyResourceValue
099: .getDisplayMode());
100: request.setAttribute("error_question",
101: "A question for the survey is required");
102:
103: return "/pages/modules/survey/editSurvey.jsp";
104: }
105:
106: // edit the survey
107: surveyService.editSurvey(uri, request.getParameter("question"),
108: request.getParameter("displayMode"));
109:
110: if (request.getParameter("state").compareTo("closed") == 0) {
111: surveyService.closeSurvey(uri);
112: } else {
113: surveyService.openSurvey(uri);
114: }
115:
116: if (request.getParameter("apply") != null) {
117: SurveyResourceValue surveyResourceValue = surveyService
118: .getSurvey(uri);
119: request.setAttribute("question", surveyResourceValue
120: .getQuestion());
121: request.setAttribute("state", surveyResourceValue
122: .getState());
123: request.setAttribute("displayMode", surveyResourceValue
124: .getDisplayMode());
125: request.setAttribute("options", surveyService
126: .getOptionsInSurvey(uri));
127:
128: return "/pages/modules/survey/editSurvey.jsp";
129: }
130:
131: return uri;
132: }
133: }
|