1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
32
33
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 }