View Javadoc

1   /**
2    * Copyright 2005-2013 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.krms.impl.ui;
17  
18  import org.kuali.rice.kns.service.KNSServiceLocator;
19  import org.kuali.rice.krad.service.BusinessObjectService;
20  import org.kuali.rice.krad.service.KRADServiceLocator;
21  import org.kuali.rice.krms.api.repository.proposition.PropositionParameterType;
22  import org.kuali.rice.krms.api.repository.proposition.PropositionType;
23  import org.kuali.rice.krms.impl.repository.PropositionBo;
24  import org.kuali.rice.krms.impl.repository.PropositionParameterBo;
25  import org.kuali.rice.krms.impl.repository.TermBo;
26  
27  import java.util.List;
28  
29  /**
30   * abstract data class for the rule tree {@link Node}s
31   * 
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   *
34   */
35  public class SimplePropositionEditNode extends RuleTreeNode {
36  
37      private static final long serialVersionUID = -5650654824214437325L;
38  
39      public static final String NODE_TYPE = "ruleTreeNode simplePropositionEditNode";
40      protected String parameterDisplayString;
41  
42      public SimplePropositionEditNode(PropositionBo proposition){
43          super(proposition);
44          setupParameterDisplayString();
45      }
46      
47      private void setupParameterDisplayString(){
48          if (proposition != null && proposition.getPropositionTypeCode().equalsIgnoreCase(PropositionType.SIMPLE.getCode())){
49              // Simple Propositions should have 3 parameters ordered in reverse polish notation.
50              // TODO: enhance to get term names for term type parameters.
51              List<PropositionParameterBo> parameters = proposition.getParameters();
52              if (parameters != null && parameters.size() == 3){
53                  setParameterDisplayString(getParamValue(parameters.get(0)) 
54                          + " " + getParamValue(parameters.get(2))
55                          + " " + getParamValue(parameters.get(1)));
56              } else {
57                  // should not happen
58              }
59          }
60      }
61      
62      private String getParamValue(PropositionParameterBo prop){
63          if (PropositionParameterType.TERM.getCode().equalsIgnoreCase(prop.getParameterType())){
64              //TODO: use termBoService
65              String termName = "";
66              String termId = prop.getValue();
67              if (termId != null && termId.length() > 0){
68                  TermBo term = getBoService().findBySinglePrimaryKey(TermBo.class,termId);
69                  if (term != null){
70                      termName = term.getSpecification().getName();
71                  }
72              }
73              return termName;
74          } else {
75              return prop.getValue();
76          }
77      }
78      /**
79       * @return the parameterDisplayString
80       */
81      public String getParameterDisplayString() {
82          return this.parameterDisplayString;
83      }
84  
85      /**
86       * @param parameterDisplayString the parameterDisplayString to set
87       */
88      public void setParameterDisplayString(String parameterDisplayString) {
89          this.parameterDisplayString = parameterDisplayString;
90      }
91  
92      public BusinessObjectService getBoService() {
93          return KNSServiceLocator.getBusinessObjectService();
94      }
95      
96  }