View Javadoc

1   /**
2    * Copyright 2005-2012 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.coreservice.web.parameter;
17  
18  
19  
20  import org.kuali.rice.coreservice.api.parameter.Parameter;
21  import org.kuali.rice.coreservice.api.parameter.ParameterType;
22  import org.kuali.rice.coreservice.framework.CoreFrameworkServiceLocator;
23  import org.kuali.rice.coreservice.impl.parameter.ParameterBo;
24  import org.kuali.rice.kns.maintenance.KualiMaintainableImpl;
25  
26     public class ParameterMaintenableImpl extends KualiMaintainableImpl {
27      private static final long serialVersionUID = 4914145799502207182L;
28  
29      @Override
30      public void saveDataObject() {
31              if (super.getDataObject() instanceof ParameterBo) {
32                  ParameterBo object  = (ParameterBo)getDataObject();
33  
34                  Parameter param = null;
35                  if(CoreFrameworkServiceLocator.getParameterService().parameterExists(object.getNamespaceCode(), object.getComponentCode(), object.getName())){
36                      param = CoreFrameworkServiceLocator.getParameterService().getParameter(object.getNamespaceCode(),object.getComponentCode(),object.getName()) ;
37                  }else{
38                      ParameterType.Builder builder = ParameterType.Builder.create(object.getParameterTypeCode());
39                      param =  CoreFrameworkServiceLocator.getParameterService().createParameter(Parameter.Builder.create(object.getApplicationId(),
40                                object.getNamespaceCode(),object.getComponentCode(), object.getName(), builder).build());
41                  }
42                  Parameter.Builder b = Parameter.Builder.create(param);
43                  b.setValue(object.getValue());
44                  b.setDescription(object.getDescription());
45                  b.setEvaluationOperator(object.getEvaluationOperator());
46                  b.setVersionNumber(object.getVersionNumber());
47                  CoreFrameworkServiceLocator.getParameterService().updateParameter(b.build()) ;
48  
49  
50  
51              } else {
52                  throw new RuntimeException(
53                          "Cannot update object of type: " + this.getDataObjectClass() + " with Parameter service");
54              }
55          }
56  
57  }