Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/ServerListAction.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/ServerListAction.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/ServerListAction.java (revision 6ed3a2d80b1f6bb914d36fce3f5a5c0225e2c976) @@ -0,0 +1,70 @@ +/**************************************************************** + * Copyright (C) 2006 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ +package org.lamsfoundation.lams.admin.web; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.struts.action.Action; +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; +import org.lamsfoundation.lams.integration.service.IIntegrationService; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; + +/** + *
+ * View Source + *
+ * + * @author Fei Yang + */ + +/** + * struts doclets + * + * @struts.action path="/serverlist" validate="false" + * + * @struts.action-forward name="serverlist" path=".serverlist" + */ +public class ServerListAction extends Action { + + private static IIntegrationService service; + + public ActionForward execute(ActionMapping mapping, + ActionForm form, + HttpServletRequest request, + HttpServletResponse response) throws Exception{ + request.setAttribute("servers", getService().getAllExtServerOrgMaps()); + return mapping.findForward("serverlist"); + } + + private IIntegrationService getService(){ + if(service == null){ + WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet().getServletContext()); + service = (IIntegrationService)ctx.getBean("integrationService"); + } + return service; + } +} Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/ServerMaintainAction.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/ServerMaintainAction.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/ServerMaintainAction.java (revision 6ed3a2d80b1f6bb914d36fce3f5a5c0225e2c976) @@ -0,0 +1,146 @@ +/**************************************************************** + * Copyright (C) 2006 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ +package org.lamsfoundation.lams.admin.web; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.beanutils.BeanUtils; +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; +import org.apache.struts.action.DynaActionForm; +import org.lamsfoundation.lams.integration.ExtServerOrgMap; +import org.lamsfoundation.lams.integration.service.IIntegrationService; +import org.lamsfoundation.lams.integration.service.IntegrationService; +import org.lamsfoundation.lams.usermanagement.Organisation; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +import org.lamsfoundation.lams.util.MessageService; +import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.web.action.LamsDispatchAction; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; + +/** + *+ * View Source + *
+ * + * @author Fei Yang + */ +/** + * struts doclets + * + * @struts.action path="/servermaintain" parameter="method" name="ServerOrgMapForm" scope="request" validate="false" + * @struts.action-forward name="servermaintain" path=".servermaintain" + * @struts.action-forward name="serverlist" path="/serverlist.do" + */ +public class ServerMaintainAction extends LamsDispatchAction { + + private static IIntegrationService service; + + private static MessageService messageService; + + private MessageService getMessageService() { + if (messageService == null) { + WebApplicationContext ctx = WebApplicationContextUtils + .getRequiredWebApplicationContext(getServlet().getServletContext()); + messageService = (MessageService) ctx.getBean("adminMessageService"); + + } + return messageService; + } + + private IIntegrationService getService(){ + if(service == null){ + WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet().getServletContext()); + service = (IIntegrationService)ctx.getBean("integrationService"); + } + return service; + } + + @SuppressWarnings("unchecked") + public ActionForward edit(ActionMapping mapping, + ActionForm form, + HttpServletRequest request, + HttpServletResponse response) throws Exception{ + IUserManagementService userManagementService = ((IntegrationService)getService()).getService(); + Map+ * View Source + *
+ * + * @author Fei Yang + */ +/** + * struts doclets + * + * @struts.action path="/serversave" input=".servermaintain" + * name="ServerOrgMapForm" scope="request" validate="false" + * @struts.action-forward name="success" path="/serverlist.do" + */ +public class ServerSaveAction extends Action { + + private static IIntegrationService service; + + private static MessageService messageService; + + private IIntegrationService getService() { + if (service == null) { + WebApplicationContext ctx = WebApplicationContextUtils + .getRequiredWebApplicationContext(getServlet().getServletContext()); + service = (IIntegrationService) ctx.getBean("integrationService"); + } + return service; + } + + private MessageService getMessageService() { + if (messageService == null) { + WebApplicationContext ctx = WebApplicationContextUtils + .getRequiredWebApplicationContext(getServlet().getServletContext()); + messageService = (MessageService) ctx.getBean("adminMessageService"); + + } + return messageService; + } + + @SuppressWarnings("unchecked") + public ActionForward execute(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) throws Exception { + + if (isCancelled(request)) { + return mapping.findForward("success"); + } + + DynaActionForm serverOrgMapForm = (DynaActionForm) form; + ActionMessages errors = new ActionMessages(); + String[] requiredFields = { "serverid", "serverkey", "servername", "prefix", "userinfoUrl", "timeoutUrl" }; + for (String requiredField : requiredFields) { + if (StringUtils.trimToNull(serverOrgMapForm.getString(requiredField)) == null) { + errors.add(requiredField, new ActionMessage("error.required", getMessageService().getMessage("sysadmin."+requiredField))); + } + } + Organisation org = null; + IUserManagementService userManagementService = ((IntegrationService)getService()).getService(); + UserDTO user = (UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER); + if((Boolean)serverOrgMapForm.get("newOrg")){ + String orgName = serverOrgMapForm.getString("orgName"); + if(StringUtils.trimToNull(orgName)==null){ + errors.add("orgId",new ActionMessage("error.required", getMessageService().getMessage("sysadmin.organisation"))); + }else{ + org = new Organisation(); + org.setName(orgName); + org.setParentOrganisation(userManagementService.getRootOrganisation()); + org.setOrganisationType((OrganisationType)userManagementService.findById(OrganisationType.class,OrganisationType.ROOT_TYPE)); + org.setOrganisationState((OrganisationState)userManagementService.findById(OrganisationState.class,OrganisationState.ACTIVE)); + String defaultLocale = Configuration.get(ConfigurationKeys.SERVER_LANGUAGE); + SupportedLocale locale = userManagementService.getSupportedLocale(defaultLocale.substring(0,2),defaultLocale.substring(3)); + org.setLocale(locale); + userManagementService.saveOrganisation(org, user.getUserID()); + serverOrgMapForm.set("orgId", org.getOrganisationId()); + serverOrgMapForm.set("newOrg", false); + serverOrgMapForm.set("orgName", null); + } + }else{ + Integer orgId = (Integer)serverOrgMapForm.get("orgId"); + if(orgId.equals(-1)){ + errors.add("orgId",new ActionMessage("error.required", getMessageService().getMessage("sysadmin.organisation"))); + }else{ + org = (Organisation)((IntegrationService)getService()).getService().findById(Organisation.class, orgId); + } + } + Integer sid = (Integer) serverOrgMapForm.get("sid"); + if(errors.isEmpty()){//check duplication + String[] uniqueFields = {"serverid","prefix"}; + for(String uniqueField : uniqueFields){ + List list = userManagementService.findByProperty(ExtServerOrgMap.class,uniqueField,serverOrgMapForm.get(uniqueField)); + if(list!=null && list.size()>0){ + if(sid.equals(-1)){//new map + errors.add(uniqueField, new ActionMessage("error.not.unique", getMessageService().getMessage("sysadmin."+uniqueField) )); + }else{ + ExtServerOrgMap map = (ExtServerOrgMap)list.get(0); + if(!map.getSid().equals(sid)){ + errors.add(uniqueField, new ActionMessage("error.not.unique", getMessageService().getMessage("sysadmin."+uniqueField) )); + } + } + + } + } + } + if (errors.isEmpty()) { + ExtServerOrgMap map = null; + if (sid.equals(-1)) { + map = new ExtServerOrgMap(); + BeanUtils.copyProperties(map, serverOrgMapForm); + map.setSid(null); + } else { + map = getService().getExtServerOrgMap(sid); + BeanUtils.copyProperties(map, serverOrgMapForm); + } + map.setOrganisation(org); + getService().saveExtServerOrgMap(map); + return mapping.findForward("success"); + } else { + saveErrors(request, errors); + Map