package pt.estgp.estgweb.web.controllers.questionarios;
import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import pt.estgp.estgweb.domain.DomainObjectFactory;
import pt.estgp.estgweb.domain.QuestionarioImpl;
import pt.estgp.estgweb.domain.UserSessionImpl;
import pt.estgp.estgweb.domain.utils.SimpleClearanceRuledSupport;
import pt.estgp.estgweb.web.UserSessionProxy;
import pt.estgp.estgweb.web.controllers.ApplicationDispatchController;
import pt.estgp.estgweb.web.form.questionarios.QuestionarioForm;
import pt.estgp.estgweb.web.form.questionarios.QuestionarioMessage;
import pt.estgp.estgweb.web.utils.RequestUtils;
import pt.utl.ist.berserk.logic.serviceManager.IServiceManager;
import pt.utl.ist.berserk.logic.serviceManager.ServiceManager;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @author Jorge Machado
* @date 26/Fev/2008
* @time 18:01:54
* @see pt.estgp.estgweb.web
*/
public class QuestionarioController
extends ApplicationDispatchController
{
private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger =
1.5.0/docs/api/java/util/logging/Logger.html">Logger.
getLogger(QuestionarioController.
class);
public ActionForward startNew
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response
)
throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable
{
QuestionarioForm frm =
(QuestionarioForm
) form
;
frm.
getQuestionario().
setClearanceRuledSupport(new SimpleClearanceRuledSupport
());
frm.
getQuestionario().
getClearanceRuledSupport().
addClearance(QuestionarioImpl.
QuestionarioClearancesOperation.
QUESTIONARIO_SAVE_FORM.
name(),
(UserSessionImpl
) UserSessionProxy.
loadUserSessionFromRequest(request
));
frm.
getQuestionario().
getClearanceRuledSupport().
addClearance(QuestionarioImpl.
QuestionarioClearancesOperation.
QUESTIONARIO_SAVE_ANSWER_PROCESSOR.
name(),
(UserSessionImpl
) UserSessionProxy.
loadUserSessionFromRequest(request
));
return mapping.
findForward("newEdit");
}
public ActionForward save
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response
)
throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable
{
QuestionarioForm frm =
(QuestionarioForm
) form
;
IServiceManager sm = ServiceManager.
getInstance();
1.5.0/docs/api/java/lang/String.html">String[] names =
{"questionario"};
5+0%2Fdocs%2Fapi+Object">Object[] args =
{frm.
getQuestionario()};
1.5.0/docs/api/java/lang/String.html">String service = frm.
getQuestionario().
getId() <=
0 ? "NewQuestionarioForm":
"saveQuestionarioForm";
QuestionarioImpl affected =
(QuestionarioImpl
) sm.
execute(RequestUtils.
getRequester(request, response
),service,args,names
);
frm.
setQuestionario(affected
);
return mapping.
findForward("list");
}
public ActionForward refresh
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response
)
throws ServletException
{
QuestionarioForm frm =
(QuestionarioForm
) form
;
frm.
setShowQuestionarioForm(true);
return mapping.
findForward("newEdit");
}
public ActionForward form
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response
)
throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable
{
QuestionarioForm frm =
(QuestionarioForm
) form
;
IServiceManager sm = ServiceManager.
getInstance();
1.5.0/docs/api/java/lang/String.html">String[] names =
{"questionarioId"};
5+0%2Fdocs%2Fapi+Object">Object[] args =
{frm.
getQuestionario().
getId()};
QuestionarioImpl q =
(QuestionarioImpl
) sm.
execute(RequestUtils.
getRequester(request, response
),
"loadQuestionarioAdmin",args,names
);
frm.
setQuestionario(q
);
if(q.
getQuestionarioHistoryDrive() ==
null)
{
q.
setQuestionarioHistoryDrive(DomainObjectFactory.
createQuestionarioHistoryDriveImpl());
}
frm.
setShowQuestionarioForm(true);
return mapping.
findForward("newEdit");
}
public ActionForward startAfetacoes
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response
)
throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable
{
QuestionarioForm frm =
(QuestionarioForm
) form
;
IServiceManager sm = ServiceManager.
getInstance();
1.5.0/docs/api/java/lang/String.html">String[] names =
{"questionarioId"};
5+0%2Fdocs%2Fapi+Object">Object[] args =
{frm.
getQuestionario().
getId()};
QuestionarioImpl affected =
(QuestionarioImpl
) sm.
execute(RequestUtils.
getRequester(request, response
),
"SetQuestionarioAssignDetailsState",args,names
);
frm.
setQuestionario(affected
);
return mapping.
findForward("admin");
}
public ActionForward deleteQuestionario
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response
)
throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable
{
QuestionarioForm frm =
(QuestionarioForm
) form
;
IServiceManager sm = ServiceManager.
getInstance();
1.5.0/docs/api/java/lang/String.html">String[] names =
{"questionarioId"};
5+0%2Fdocs%2Fapi+Object">Object[] args =
{frm.
getQuestionario().
getId()};
QuestionarioImpl affected =
(QuestionarioImpl
) sm.
execute(RequestUtils.
getRequester(request, response
),
"DeleteQuestionario",args,names
);
frm.
setQuestionario(affected
);
return mapping.
findForward("list");
}
public ActionForward putInAssignedAnwsers
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response
)
throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable
{
QuestionarioForm frm =
(QuestionarioForm
) form
;
long questionarioId
;
if(request.
getParameter("questionarioId")!=
null)
questionarioId =
1.5.0/docs/api/java/lang/Long.html">Long.
parseLong(request.
getParameter("questionarioId"));
else
questionarioId = frm.
getQuestionario().
getId();
IServiceManager sm = ServiceManager.
getInstance();
1.5.0/docs/api/java/lang/String.html">String[] names =
{"questionarioId"};
5+0%2Fdocs%2Fapi+Object">Object[] args =
{questionarioId
};
QuestionarioImpl affected =
(QuestionarioImpl
) sm.
execute(RequestUtils.
getRequester(request, response
),
"QuestionarioPutAssignedAnswers",args,names
);
frm.
setQuestionario(affected
);
return mapping.
findForward("admin");
}
public ActionForward revertAssignationDetails
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response
)
throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable
{
QuestionarioForm frm =
(QuestionarioForm
) form
;
long questionarioId
;
if(request.
getParameter("questionarioId")!=
null)
questionarioId =
1.5.0/docs/api/java/lang/Long.html">Long.
parseLong(request.
getParameter("questionarioId"));
else
questionarioId = frm.
getQuestionario().
getId();
IServiceManager sm = ServiceManager.
getInstance();
1.5.0/docs/api/java/lang/String.html">String[] names =
{"questionarioId"};
5+0%2Fdocs%2Fapi+Object">Object[] args =
{questionarioId
};
QuestionarioImpl affected =
(QuestionarioImpl
) sm.
execute(RequestUtils.
getRequester(request, response
),
"QuestionarioRevertAssignationDetails",args,names
);
frm.
setQuestionario(affected
);
return mapping.
findForward("admin");
}
public ActionForward stopProcessement
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response
)
throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable
{
QuestionarioForm frm =
(QuestionarioForm
) form
;
long questionarioId
;
if(request.
getParameter("questionarioId")!=
null)
questionarioId =
1.5.0/docs/api/java/lang/Long.html">Long.
parseLong(request.
getParameter("questionarioId"));
else
questionarioId = frm.
getQuestionario().
getId();
IServiceManager sm = ServiceManager.
getInstance();
1.5.0/docs/api/java/lang/String.html">String[] names =
{"questionarioId"};
5+0%2Fdocs%2Fapi+Object">Object[] args =
{questionarioId
};
QuestionarioImpl affected =
(QuestionarioImpl
) sm.
execute(RequestUtils.
getRequester(request, response
),
"QuestionarioStopProcessement",args,names
);
frm.
setQuestionario(affected
);
return mapping.
findForward("admin");
}
public ActionForward startProcessement
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response
)
throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable
{
QuestionarioForm frm =
(QuestionarioForm
) form
;
long questionarioId
;
if(request.
getParameter("questionarioId")!=
null)
questionarioId =
1.5.0/docs/api/java/lang/Long.html">Long.
parseLong(request.
getParameter("questionarioId"));
else
questionarioId = frm.
getQuestionario().
getId();
IServiceManager sm = ServiceManager.
getInstance();
1.5.0/docs/api/java/lang/String.html">String[] names =
{"questionarioId"};
5+0%2Fdocs%2Fapi+Object">Object[] args =
{questionarioId
};
QuestionarioImpl affected =
(QuestionarioImpl
) sm.
execute(RequestUtils.
getRequester(request, response
),
"QuestionarioStartProcessement",args,names
);
frm.
setQuestionario(affected
);
return mapping.
findForward("admin");
}
/********
* EMAILS QUESTIONARIO
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Throwable
*/
public ActionForward sendEmailQuestionario
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response
)
throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable
{
QuestionarioMessage frm =
(QuestionarioMessage
) form
;
IServiceManager sm = ServiceManager.
getInstance();
1.5.0/docs/api/java/lang/String.html">String[] names =
{"onlyNotAnswered",
"id",
"msg",
"emailFrom",
"personFrom",
"subject"};
5+0%2Fdocs%2Fapi+Object">Object[] args =
{
frm.
isOnlyNotAnswered(),
frm.
getCursoAfetoOrUnidadeAfetaOrQuestionarioAfetoId(),
frm.
getMessage(),
frm.
getFromEmail(),
frm.
getFromPerson(),
frm.
getSubject()
};
int size =
(1.5.0/docs/api/java/lang/Integer.html">Integer) sm.
execute(RequestUtils.
getRequester(request, response
),
"QuestionarioSendMessage",args,names
);
addMessage
(request,
"submit.todo.message.success",
"" + size
);
return mapping.
findForward("success");
}
public ActionForward sendEmailQuestionarioCursoAfeto
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response
)
throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable
{
QuestionarioMessage frm =
(QuestionarioMessage
) form
;
IServiceManager sm = ServiceManager.
getInstance();
1.5.0/docs/api/java/lang/String.html">String[] names =
{"onlyNotAnswered",
"id",
"msg",
"emailFrom",
"personFrom",
"subject"};
5+0%2Fdocs%2Fapi+Object">Object[] args =
{
frm.
isOnlyNotAnswered(),
frm.
getCursoAfetoOrUnidadeAfetaOrQuestionarioAfetoId(),
frm.
getMessage(),
frm.
getFromEmail(),
frm.
getFromPerson(),
frm.
getSubject()
};
int size =
(1.5.0/docs/api/java/lang/Integer.html">Integer) sm.
execute(RequestUtils.
getRequester(request, response
),
"QuestionarioSendMessageCursoAfeto",args,names
);
addMessage
(request,
"submit.todo.message.success",
"" + size
);
return mapping.
findForward("success");
}
public ActionForward sendEmailQuestionarioUnidadeAfeta
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response
)
throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable
{
QuestionarioMessage frm =
(QuestionarioMessage
) form
;
IServiceManager sm = ServiceManager.
getInstance();
1.5.0/docs/api/java/lang/String.html">String[] names =
{"onlyNotAnswered",
"id",
"msg",
"emailFrom",
"personFrom",
"subject"};
5+0%2Fdocs%2Fapi+Object">Object[] args =
{
frm.
isOnlyNotAnswered(),
frm.
getCursoAfetoOrUnidadeAfetaOrQuestionarioAfetoId(),
frm.
getMessage(),
frm.
getFromEmail(),
frm.
getFromPerson(),
frm.
getSubject()
};
int size =
(1.5.0/docs/api/java/lang/Integer.html">Integer) sm.
execute(RequestUtils.
getRequester(request, response
),
"QuestionarioSendMessageUnidadeAfeta",args,names
);
addMessage
(request,
"submit.todo.message.success",
"" + size
);
return mapping.
findForward("success");
}
}