001    /**
002     * Copyright 2005-2013 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.rice.krad.web.controller;
017    
018    import org.apache.commons.lang.StringUtils;
019    import org.kuali.rice.coreservice.framework.parameter.ParameterService;
020    import org.kuali.rice.coreservice.framework.CoreFrameworkServiceLocator;
021    import org.kuali.rice.krad.util.KRADConstants;
022    import org.kuali.rice.krad.web.form.UifFormBase;
023    import org.springframework.stereotype.Controller;
024    import org.springframework.web.bind.annotation.ModelAttribute;
025    import org.springframework.web.bind.annotation.RequestMapping;
026    import org.springframework.web.bind.annotation.RequestParam;
027    import org.springframework.web.servlet.ModelAndView;
028    
029    import javax.servlet.http.HttpServletRequest;
030    
031    /**
032     * Loads the module locked view when a user accesses a module which has been locked for maintenance
033     *
034     * @author Kuali Rice Team (rice.collab@kuali.org)
035     */
036    @Controller
037    public class ModuleLockedController extends UifControllerBase {
038        
039        public static final String MODULE_PARAMETER = "moduleNamespace";
040        
041        @Override
042        protected UifFormBase createInitialForm(HttpServletRequest request) {
043            return new UifFormBase();
044        }
045    
046        /**
047         * Retrieves the module locked message test from a system parameter and then returns the message view
048         */
049        @RequestMapping(value = "/module-locked")
050        public ModelAndView moduleLocked(@ModelAttribute("KualiForm") UifFormBase form,
051                @RequestParam(value = MODULE_PARAMETER, required = true) String moduleNamespaceCode) {
052            ParameterService parameterSerivce = CoreFrameworkServiceLocator.getParameterService();
053            
054            String messageParamComponentCode = KRADConstants.DetailTypes.ALL_DETAIL_TYPE;
055            String messageParamName = KRADConstants.SystemGroupParameterNames.OLTP_LOCKOUT_MESSAGE_PARM;
056            String lockoutMessage = parameterSerivce.getParameterValueAsString(moduleNamespaceCode,
057                    messageParamComponentCode, messageParamName);
058    
059            if (StringUtils.isBlank(lockoutMessage)) {
060                String defaultMessageParamName = KRADConstants.SystemGroupParameterNames.OLTP_LOCKOUT_DEFAULT_MESSAGE;
061                lockoutMessage = parameterSerivce.getParameterValueAsString(KRADConstants.KNS_NAMESPACE,
062                        messageParamComponentCode, defaultMessageParamName);
063            }
064            
065            return getMessageView(form, "Module Locked", lockoutMessage);
066        }
067    
068    }