001 /**
002 * Copyright 2005-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.krms.impl.ui;
017
018 import org.kuali.rice.krad.service.BusinessObjectService;
019 import org.kuali.rice.krad.service.KRADServiceLocator;
020 import org.kuali.rice.krms.api.repository.proposition.PropositionParameterType;
021 import org.kuali.rice.krms.api.repository.proposition.PropositionType;
022 import org.kuali.rice.krms.impl.repository.PropositionBo;
023 import org.kuali.rice.krms.impl.repository.PropositionParameterBo;
024 import org.kuali.rice.krms.impl.repository.TermBo;
025
026 import java.io.Serializable;
027 import java.util.List;
028
029 /**
030 * abstract data class for the rule tree {@link Node}s
031 *
032 * @author Kuali Rice Team (rice.collab@kuali.org)
033 *
034 */
035 public class SimplePropositionNode extends RuleTreeNode {
036 private static final long serialVersionUID = -629088492909384804L;
037 public static final String NODE_TYPE = "ruleTreeNode simplePropositionNode";
038 protected String parameterDisplayString;
039
040 // needed for inquiry view
041 public SimplePropositionNode() {
042 }
043
044 public SimplePropositionNode(PropositionBo proposition){
045 super(proposition);
046 setupParameterDisplayString();
047 }
048
049 private void setupParameterDisplayString(){
050 if (proposition != null && proposition.getPropositionTypeCode().equalsIgnoreCase(PropositionType.SIMPLE.getCode())){
051 // Simple Propositions should have 3 parameters ordered in reverse polish notation.
052 // TODO: enhance to get term names for term type parameters.
053 List<PropositionParameterBo> parameters = proposition.getParameters();
054 if (parameters != null && parameters.size() == 3){
055 setParameterDisplayString(getParamValue(parameters.get(0))
056 + " " + getParamValue(parameters.get(2))
057 + " " + getParamValue(parameters.get(1)));
058 } else {
059 // should not happen
060 }
061 }
062 }
063
064 private String getParamValue(PropositionParameterBo prop){
065 if (PropositionParameterType.TERM.getCode().equalsIgnoreCase(prop.getParameterType())){
066 //TODO: use termBoService
067 String termId = prop.getValue();
068 TermBo term = getBoService().findBySinglePrimaryKey(TermBo.class,termId);
069 if (term!=null){
070 return term.getSpecification().getName();
071 }
072 return "";
073 } else {
074 return prop.getValue();
075 }
076 }
077 /**
078 * @return the parameterDisplayString
079 */
080 public String getParameterDisplayString() {
081 return this.parameterDisplayString;
082 }
083
084 /**
085 * @param parameterDisplayString the parameterDisplayString to set
086 */
087 public void setParameterDisplayString(String parameterDisplayString) {
088 this.parameterDisplayString = parameterDisplayString;
089 }
090
091 public BusinessObjectService getBoService() {
092 return KRADServiceLocator.getBusinessObjectService();
093 }
094
095 }