001/**
002 * Copyright 2005-2014 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 */
016package org.kuali.rice.krad.web.controller;
017
018import org.apache.commons.lang.StringUtils;
019import org.kuali.rice.coreservice.framework.parameter.ParameterService;
020import org.kuali.rice.coreservice.framework.CoreFrameworkServiceLocator;
021import org.kuali.rice.krad.util.KRADConstants;
022import org.kuali.rice.krad.web.form.UifFormBase;
023import org.springframework.stereotype.Controller;
024import org.springframework.web.bind.annotation.ModelAttribute;
025import org.springframework.web.bind.annotation.RequestMapping;
026import org.springframework.web.bind.annotation.RequestParam;
027import org.springframework.web.servlet.ModelAndView;
028
029import 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
037public class ModuleLockedController extends UifControllerBase {
038    
039    public static final String MODULE_PARAMETER = "moduleNamespace";
040    
041    @Override
042    protected UifFormBase createInitialForm() {
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    @MethodAccessible
050    @RequestMapping(value = "/module-locked")
051    public ModelAndView moduleLocked(@ModelAttribute("KualiForm") UifFormBase form,
052            @RequestParam(value = MODULE_PARAMETER, required = true) String moduleNamespaceCode) {
053        ParameterService parameterSerivce = CoreFrameworkServiceLocator.getParameterService();
054        
055        String messageParamComponentCode = KRADConstants.DetailTypes.ALL_DETAIL_TYPE;
056        String messageParamName = KRADConstants.SystemGroupParameterNames.OLTP_LOCKOUT_MESSAGE_PARM;
057        String lockoutMessage = parameterSerivce.getParameterValueAsString(moduleNamespaceCode,
058                messageParamComponentCode, messageParamName);
059
060        if (StringUtils.isBlank(lockoutMessage)) {
061            String defaultMessageParamName = KRADConstants.SystemGroupParameterNames.OLTP_LOCKOUT_DEFAULT_MESSAGE;
062            lockoutMessage = parameterSerivce.getParameterValueAsString(KRADConstants.KNS_NAMESPACE,
063                    messageParamComponentCode, defaultMessageParamName);
064        }
065        
066        return getMessageView(form, "Module Locked", lockoutMessage);
067    }
068
069}