View Javadoc

1   /**
2    * Copyright 2004-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.hr.core.service;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.coreservice.api.parameter.EvaluationOperator;
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.parameter.ParameterService;
23  import org.springframework.beans.factory.InitializingBean;
24  
25  /**
26   * Publishes the DocHandler url prefix when the app starts up.
27   * 
28   * Originally from Kuali Coeus.
29   *
30   * @author Kuali Research Administration Team (kualidev@oncourse.iu.edu)
31   */
32  public class DocHandlerUrlPrefixPublishingServiceImpl implements DocHandlerUrlPrefixPublishingService, InitializingBean {
33      
34      private String parameterApplicationId;
35      private String parameterNamespaceCode;
36      private String parameterTypeCode;
37      private String parameterComponentCode;
38  	private String parameterName;
39      private String parameterValue;
40  
41      private ParameterService parameterService;
42      
43      public String getParameterApplicationId() {
44          return parameterApplicationId;
45      }
46  
47      public void setParameterApplicationId(String parameterApplicationId) {
48          this.parameterApplicationId = parameterApplicationId;
49      }
50      
51      public String getParameterNamespaceCode() {
52          return parameterNamespaceCode;
53      }
54      
55      public void setParameterNamespaceCode(String parameterNamespaceCode) {
56          this.parameterNamespaceCode = parameterNamespaceCode;
57      }
58      
59      public String getParameterTypeCode() {
60          return parameterTypeCode;
61      }
62  
63      public void setParameterTypeCode(String parameterTypeCode) {
64          this.parameterTypeCode = parameterTypeCode;
65      }
66      
67      public String getParameterComponentCode() {
68          return parameterComponentCode;
69      }
70  
71      public void setParameterComponentCode(String parameterComponentCode) {
72          this.parameterComponentCode = parameterComponentCode;
73      }
74      
75      public String getParameterName() {
76          return parameterName;
77      }
78      
79      public void setParameterName(String parameterName) {
80          this.parameterName = parameterName;
81      }
82  
83      public String getParameterValue() {
84          return parameterValue;
85      }
86  
87      public void setParameterValue(String parameterValue) {
88          this.parameterValue = parameterValue;
89      }
90  
91      public void setParameterService(ParameterService parameterService) {
92          this.parameterService = parameterService;
93      }
94      
95      @Override
96      public void afterPropertiesSet() throws Exception {
97          publishDocHandlerUrlPrefix();
98      }
99      
100     @Override
101     public void publishDocHandlerUrlPrefix() {
102         ParameterType.Builder parameterType = ParameterType.Builder.create(parameterTypeCode);
103         Parameter.Builder parameter = Parameter.Builder.create(parameterApplicationId, parameterNamespaceCode, parameterComponentCode, parameterName, parameterType);
104         parameter.setDescription("KPME docHandler Prefix");
105         parameter.setValue(parameterValue);
106         parameter.setEvaluationOperator(EvaluationOperator.ALLOW);
107         Parameter existingParameter = parameterService.getParameter(parameterNamespaceCode, parameterComponentCode, parameterName);
108         if (existingParameter == null) {
109             parameterService.createParameter(parameter.build());
110         } else if(!StringUtils.equals(existingParameter.getValue(), parameterValue)) {
111             parameter.setObjectId(existingParameter.getObjectId());
112             parameter.setVersionNumber(existingParameter.getVersionNumber());
113             parameterService.updateParameter(parameter.build());
114         } 
115     }  
116 
117 }