package pt.estgp.estgweb.web.controllers.configuration;
import jomm.dao.impl.AbstractDao;
import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.json.JSONObject;
import pt.estgp.estgweb.domain.*;
import pt.estgp.estgweb.domain.dao.DaoFactory;
import pt.estgp.estgweb.web.UserSessionProxy;
import pt.estgp.estgweb.web.controllers.utils.AbstractWidgetAjaxController;
import pt.estgp.estgweb.web.form.configuration.ConfigurationGradesForm;
import pt.estgp.estgweb.web.form.configuration.ConfigurationsForm;
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 ConfigurationsController
extends AbstractWidgetAjaxController
{
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(ConfigurationsController.
class);
public ActionForward saveGrades
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response
)
throws ServletException
{
if(!UserSessionProxy.
loadUserSessionFromRequest(request
).
getUser().
isAdmin() && !UserSessionProxy.
loadUserSessionFromRequest(request
).
getUser().
hasRole("services"))
{
return mapping.
findForward("error401");
}
ConfigurationGradesForm f =
(ConfigurationGradesForm
) form
;
AbstractDao.
getCurrentSession().
beginTransaction();
for(ConfigurationGradesEpocaAvaliacao a: f.
getConfigurationGrades().
getEpocasAvaliacao())
{
if(a.
getId() > 0
)
{
ConfigurationGradesEpocaAvaliacao persist = DaoFactory.
getConfigurationGradesEpocaAvaliacaoDaoImpl().
load(a.
getId());
persist.
setCodigoEpoca(a.
getCodigoEpoca());
persist.
setCodigoMomento(a.
getCodigoMomento());
persist.
setObs(a.
getObs());
persist.
setDescricao(a.
getDescricao());
}
}
for(ConfigurationGradesStatusEpoca a: f.
getConfigurationGrades().
getStatusEpocas())
{
if(a.
getId() > 0
)
{
ConfigurationGradesStatusEpoca persist = DaoFactory.
getConfigurationGradesStatusEpocaDaoImpl().
load(a.
getId());
persist.
setStatus(a.
getStatus());
persist.
setObs(a.
getObs());
persist.
setDescricao(a.
getDescricao());
}
}
AbstractDao.
getCurrentSession().
getTransaction().
commit();
return mapping.
findForward("grades");
}
public ActionForward addEpocaAvaliacao
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response
)
throws ServletException
{
if(!UserSessionProxy.
loadUserSessionFromRequest(request
).
getUser().
isAdmin() && !UserSessionProxy.
loadUserSessionFromRequest(request
).
getUser().
hasRole("services"))
{
return mapping.
findForward("error401");
}
AbstractDao.
getCurrentSession().
beginTransaction();
ConfigurationGradesEpocaAvaliacao epoca = DomainObjectFactory.
createConfigurationGradesEpocaAvaliacaoImpl();
DaoFactory.
getConfigurationDaoImpl().
load().
getConfigurationGrades().
getEpocasAvaliacao().
add(epoca
);
DaoFactory.
getConfigurationGradesEpocaAvaliacaoDaoImpl().
save(epoca
);
AbstractDao.
getCurrentSession().
getTransaction().
commit();
return mapping.
findForward("grades");
}
public ActionForward addSatusEpoca
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response
)
throws ServletException
{
if(!UserSessionProxy.
loadUserSessionFromRequest(request
).
getUser().
isAdmin() && !UserSessionProxy.
loadUserSessionFromRequest(request
).
getUser().
hasRole("services"))
{
return mapping.
findForward("error401");
}
AbstractDao.
getCurrentSession().
beginTransaction();
ConfigurationGradesStatusEpoca status = DomainObjectFactory.
createConfigurationGradesStatusEpocaImpl();
DaoFactory.
getConfigurationDaoImpl().
load().
getConfigurationGrades().
getStatusEpoca().
add(status
);
DaoFactory.
getConfigurationGradesStatusEpocaDaoImpl().
save(status
);
AbstractDao.
getCurrentSession().
getTransaction().
commit();
return mapping.
findForward("grades");
}
public ActionForward deleteEpocaAvaliacao
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response
)
throws ServletException
{
if(!UserSessionProxy.
loadUserSessionFromRequest(request
).
getUser().
isAdmin() && !UserSessionProxy.
loadUserSessionFromRequest(request
).
getUser().
hasRole("services"))
{
return mapping.
findForward("error401");
}
ConfigurationGradesForm f =
(ConfigurationGradesForm
) form
;
AbstractDao.
getCurrentSession().
beginTransaction();
DaoFactory.
getConfigurationGradesEpocaAvaliacaoDaoImpl().
delete(f.
getId());
AbstractDao.
getCurrentSession().
getTransaction().
commit();
return mapping.
findForward("grades");
}
public ActionForward deleteStatusEpoca
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response
)
throws ServletException
{
if(!UserSessionProxy.
loadUserSessionFromRequest(request
).
getUser().
isAdmin() && !UserSessionProxy.
loadUserSessionFromRequest(request
).
getUser().
hasRole("services"))
{
return mapping.
findForward("error401");
}
ConfigurationGradesForm f =
(ConfigurationGradesForm
) form
;
AbstractDao.
getCurrentSession().
beginTransaction();
DaoFactory.
getConfigurationGradesStatusEpocaDaoImpl().
delete(f.
getId());
AbstractDao.
getCurrentSession().
getTransaction().
commit();
return mapping.
findForward("grades");
}
public ActionForward saveConfigsGerais
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response
)
throws ServletException
{
if(!UserSessionProxy.
loadUserSessionFromRequest(request
).
getUser().
isAdmin() && !UserSessionProxy.
loadUserSessionFromRequest(request
).
getUser().
hasRole("services"))
{
return mapping.
findForward("error401");
}
ConfigurationsForm f =
(ConfigurationsForm
) form
;
AbstractDao.
getCurrentSession().
beginTransaction();
1.5.0/docs/api/javax/security/auth/login/Configuration.html">Configuration configuration = DaoFactory.
getConfigurationDaoImpl().
load();
configuration.
setOpenInfoIntranet(f.
getConfiguration().
getOpenInfoIntranet());
configuration.
setInterfaceImportYear(f.
getConfiguration().
getInterfaceImportYear());
configuration.
setCourseReportImportYear(f.
getConfiguration().
getCourseReportImportYear());
configuration.
setCursosFicticios(f.
getConfiguration().
getCursosFicticios());
configuration.
setCourseUnitEvaluationActiveYear(f.
getConfiguration().
getCourseUnitEvaluationActiveYear());
configuration.
setCourseUnitEvaluationActiveDegrees(f.
getConfiguration().
getCourseUnitEvaluationActiveDegrees());
configuration.
setCourseUnitEvaluationActiveCourseIds(f.
getConfiguration().
getCourseUnitEvaluationActiveCourseIds());
AbstractDao.
getCurrentSession().
getTransaction().
commit();
return mapping.
getInputForward();
}
public JSONObject newConfigSeparator
(ActionForm form, HttpServletRequest request, HttpServletResponse response
) throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable {
IServiceManager sm = ServiceManager.
getInstance();
1.5.0/docs/api/java/lang/String.html">String[] names =
new 1.5.0/docs/api/java/lang/String.html">String[]{};
5+0%2Fdocs%2Fapi+Object">Object[] args =
new 5+0%2Fdocs%2Fapi+Object">Object[]{};
ConfigurationSeparatorImpl c =
(ConfigurationSeparatorImpl
) sm.
execute(RequestUtils.
getRequester(request, response
),
"NewConfigurationSeparator", args, names
);
JSONObject tJson = c.
toJsonObject();
addMessage
(request,
"config.new.configuration.separator.success");
return tJson
;
}
public JSONObject updateConfigSeparator
(ActionForm form,HttpServletRequest request, HttpServletResponse response
) throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable {
1.5.0/docs/api/java/lang/String.html">String configSeparatorJson = request.
getParameter("separatorJson");
IServiceManager sm = ServiceManager.
getInstance();
1.5.0/docs/api/java/lang/String.html">String[] names =
new 1.5.0/docs/api/java/lang/String.html">String[]{};
5+0%2Fdocs%2Fapi+Object">Object[] args =
new 5+0%2Fdocs%2Fapi+Object">Object[]{configSeparatorJson
};
ConfigurationSeparatorImpl s =
(ConfigurationSeparatorImpl
) sm.
execute(RequestUtils.
getRequester(request, response
),
"UpdateConfigurationSeparator", args, names
);
JSONObject tJson = s.
toJsonObject();
addMessage
(request,
"config.update.configuration.separator.success",s.
getName());
return tJson
;
}
public JSONObject removeConfigSeparator
(ActionForm form,HttpServletRequest request, HttpServletResponse response
) throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable {
1.5.0/docs/api/java/lang/String.html">String configSeparatorJson = request.
getParameter("separatorJson");
IServiceManager sm = ServiceManager.
getInstance();
1.5.0/docs/api/java/lang/String.html">String[] names =
new 1.5.0/docs/api/java/lang/String.html">String[]{};
5+0%2Fdocs%2Fapi+Object">Object[] args =
new 5+0%2Fdocs%2Fapi+Object">Object[]{configSeparatorJson
};
ConfigurationSeparatorImpl s =
(ConfigurationSeparatorImpl
) sm.
execute(RequestUtils.
getRequester(request, response
),
"RemoveConfigurationSeparator", args, names
);
JSONObject tJson = s.
toJsonObject();
addMessage
(request,
"config.removed.configuration.separator.success", s.
getName());
return tJson
;
}
}