001/** 002 * Copyright 2005-2016 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 */ 016package org.kuali.rice.krms.impl.ui; 017 018import org.kuali.rice.krad.service.BusinessObjectService; 019import org.kuali.rice.krad.service.KRADServiceLocator; 020import org.kuali.rice.krms.api.repository.proposition.PropositionParameterType; 021import org.kuali.rice.krms.api.repository.proposition.PropositionType; 022import org.kuali.rice.krms.impl.repository.PropositionBo; 023import org.kuali.rice.krms.impl.repository.PropositionParameterBo; 024import org.kuali.rice.krms.impl.repository.TermBo; 025 026import java.util.List; 027 028/** 029 * abstract data class for the rule tree {@link Node}s 030 * 031 * @author Kuali Rice Team (rice.collab@kuali.org) 032 * 033 */ 034public class SimplePropositionEditNode extends RuleTreeNode { 035 036 private static final long serialVersionUID = -5650654824214437325L; 037 038 public static final String NODE_TYPE = "ruleTreeNode simplePropositionEditNode"; 039 protected String parameterDisplayString; 040 041 public SimplePropositionEditNode(PropositionBo proposition){ 042 super(proposition); 043 setupParameterDisplayString(); 044 } 045 046 private void setupParameterDisplayString(){ 047 if (proposition != null && proposition.getPropositionTypeCode().equalsIgnoreCase(PropositionType.SIMPLE.getCode())){ 048 // Simple Propositions should have 3 parameters ordered in reverse polish notation. 049 // TODO: enhance to get term names for term type parameters. 050 List<PropositionParameterBo> parameters = proposition.getParameters(); 051 if (parameters != null && parameters.size() == 3){ 052 setParameterDisplayString(getParamValue(parameters.get(0)) 053 + " " + getParamValue(parameters.get(2)) 054 + " " + getParamValue(parameters.get(1))); 055 } else { 056 // should not happen 057 } 058 } 059 } 060 061 private String getParamValue(PropositionParameterBo prop){ 062 if (PropositionParameterType.TERM.getCode().equalsIgnoreCase(prop.getParameterType())){ 063 //TODO: use termBoService 064 String termName = ""; 065 String termId = prop.getValue(); 066 if (termId != null && termId.length() > 0){ 067 TermBo term = getBoService().findBySinglePrimaryKey(TermBo.class,termId); 068 if (term != null){ 069 termName = term.getSpecification().getName(); 070 } 071 } 072 return termName; 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}