Coverage Report - org.kuali.rice.krms.impl.ui.SimplePropositionNode
 
Classes in this File Line Coverage Branch Coverage Complexity
SimplePropositionNode
0%
0/19
0%
0/12
2.333
 
 1  
 /**
 2  
  * Copyright 2005-2011 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.service.BusinessObjectService;
 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.io.Serializable;
 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 SimplePropositionNode extends RuleTreeNode {
 36  
     private static final long serialVersionUID = -629088492909384804L;
 37  
     public static final String NODE_TYPE = "ruleTreeNode simplePropositionNode";
 38  
     protected String parameterDisplayString;
 39  
 
 40  
     public SimplePropositionNode(PropositionBo proposition){
 41  0
         super(proposition);
 42  0
         setupParameterDisplayString();
 43  0
     }
 44  
     
 45  
     private void setupParameterDisplayString(){
 46  0
         if (proposition != null && proposition.getPropositionTypeCode().equalsIgnoreCase(PropositionType.SIMPLE.getCode())){
 47  
             // Simple Propositions should have 3 parameters ordered in reverse polish notation.
 48  
             // TODO: enhance to get term names for term type parameters.
 49  0
             List<PropositionParameterBo> parameters = proposition.getParameters();
 50  0
             if (parameters != null && parameters.size() == 3){
 51  0
                 setParameterDisplayString(getParamValue(parameters.get(0)) 
 52  
                         + " " + getParamValue(parameters.get(2))
 53  
                         + " " + getParamValue(parameters.get(1)));
 54  
             } else {
 55  
                 // should not happen
 56  
             }
 57  
         }
 58  0
     }
 59  
     
 60  
     private String getParamValue(PropositionParameterBo prop){
 61  0
         if (PropositionParameterType.TERM.getCode().equalsIgnoreCase(prop.getParameterType())){
 62  
             //TODO: use termBoService
 63  0
             String termId = prop.getValue();
 64  0
             TermBo term = getBoService().findBySinglePrimaryKey(TermBo.class,termId);
 65  0
             if (term!=null){
 66  0
                 return term.getSpecification().getName();
 67  
             }
 68  0
             return "";
 69  
         } else {
 70  0
             return prop.getValue();
 71  
         }
 72  
     }
 73  
     /**
 74  
      * @return the parameterDisplayString
 75  
      */
 76  
     public String getParameterDisplayString() {
 77  0
         return this.parameterDisplayString;
 78  
     }
 79  
 
 80  
     /**
 81  
      * @param parameterDisplayString the parameterDisplayString to set
 82  
      */
 83  
     public void setParameterDisplayString(String parameterDisplayString) {
 84  0
         this.parameterDisplayString = parameterDisplayString;
 85  0
     }
 86  
 
 87  
     public BusinessObjectService getBoService() {
 88  0
         return KRADServiceLocator.getBusinessObjectService();
 89  
     }
 90  
     
 91  
 }