001/** 002 * Copyright 2005-2017 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.data.DataObjectService; 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 {@link org.kuali.rice.krms.impl.ui.RuleTreeNode}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 = getDataObjectService().find(TermBo.class, termId); 068 069 if (term != null){ 070 termName = term.getSpecification().getName(); 071 } 072 } 073 return termName; 074 } else { 075 return prop.getValue(); 076 } 077 } 078 /** 079 * @return the parameterDisplayString 080 */ 081 public String getParameterDisplayString() { 082 return this.parameterDisplayString; 083 } 084 085 /** 086 * @param parameterDisplayString the parameterDisplayString to set 087 */ 088 public void setParameterDisplayString(String parameterDisplayString) { 089 this.parameterDisplayString = parameterDisplayString; 090 } 091 092 public DataObjectService getDataObjectService() { 093 return KRADServiceLocator.getDataObjectService(); 094 } 095 096}