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