View Javadoc
1   /**
2    * Copyright 2005-2016 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.labs.parameter;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.coreservice.api.CoreServiceApiServiceLocator;
20  import org.kuali.rice.coreservice.api.parameter.Parameter;
21  import org.kuali.rice.coreservice.api.parameter.ParameterKey;
22  import org.kuali.rice.krad.util.KRADConstants;
23  import org.kuali.rice.krad.web.controller.UifControllerBase;
24  import org.kuali.rice.krad.web.form.UifFormBase;
25  import org.springframework.stereotype.Controller;
26  import org.springframework.web.bind.annotation.ModelAttribute;
27  import org.springframework.web.bind.annotation.RequestMapping;
28  import org.springframework.web.servlet.ModelAndView;
29  
30  /**
31   * Controller for the Parameter utility.
32   *
33   * @author Kuali Rice Team (rice.collab@kuali.org)
34   */
35  @Controller
36  @RequestMapping(value = "/parameter")
37  public class ParameterController extends UifControllerBase {
38  
39      @Override
40      protected ParameterForm createInitialForm() {
41          return new ParameterForm();
42      }
43  
44      @RequestMapping(params = "methodToCall=update")
45      public ModelAndView update(@ModelAttribute("KualiForm") UifFormBase form) {
46          ParameterForm parameterForm = (ParameterForm) form;
47  
48          String applicationId = KRADConstants.DEFAULT_PARAMETER_APPLICATION_ID;
49          String namespaceCode = parameterForm.getNamespaceCode();
50          String componentCode = parameterForm.getComponentCode();
51          String parameterName = parameterForm.getParameterName();
52  
53          Parameter parameter = null;
54  
55          if (StringUtils.isNotBlank(applicationId) && StringUtils.isNotBlank(namespaceCode)
56              && StringUtils.isNotBlank(componentCode) && StringUtils.isNotBlank(parameterName)) {
57              ParameterKey key = ParameterKey.create(applicationId, namespaceCode, componentCode, parameterName);
58              parameter = CoreServiceApiServiceLocator.getParameterRepositoryService().getParameter(key);
59          }
60  
61          if (parameter != null) {
62              Parameter.Builder builder = Parameter.Builder.create(parameter);
63              builder.setValue(parameterForm.getParameterValue());
64  
65              CoreServiceApiServiceLocator.getParameterRepositoryService().updateParameter(builder.build());
66          }
67  
68          return getModelAndView(form);
69      }
70  }