001 package org.kuali.rice.krms.dto; 002 003 import org.apache.commons.lang.StringUtils; 004 import org.kuali.rice.krms.api.repository.proposition.PropositionDefinitionContract; 005 import org.kuali.rice.krms.api.repository.proposition.PropositionParameterContract; 006 import org.kuali.rice.krms.api.repository.term.TermDefinition; 007 import org.kuali.rice.krms.impl.ui.TermParameter; 008 009 import java.io.Serializable; 010 import java.util.ArrayList; 011 import java.util.HashMap; 012 import java.util.List; 013 import java.util.Map; 014 import java.util.UUID; 015 016 /** 017 * Created with IntelliJ IDEA. 018 * User: SW 019 * Date: 2012/12/03 020 * Time: 11:41 AM 021 * To change this template use File | Settings | File Templates. 022 */ 023 public class PropositionEditor implements PropositionDefinitionContract, Serializable { 024 025 private static final long serialVersionUID = 1L; 026 027 private String key; 028 029 private String id; 030 private String description; 031 private String ruleId; 032 private String compoundOpCode; 033 private String typeId; 034 private String propositionTypeCode; 035 private Long versionNumber; 036 037 private Map<String, String> naturalLanguage = new HashMap<String, String>(); 038 039 private List<PropositionParameterEditor> parameters; 040 private List<PropositionEditor> compoundEditors; 041 042 private TermEditor term; 043 private String termParameter; 044 private List<TermParameter> termParameterList = new ArrayList<TermParameter>(); 045 private String type; 046 private boolean editMode = false; 047 private boolean newProp = false; 048 049 private String newTermDescription = "new term " + UUID.randomUUID().toString(); 050 051 public PropositionEditor() { 052 super(); 053 } 054 055 /** 056 * Converts a immutable object to it's mutable bo counterpart 057 * 058 * @param definition immutable object 059 * @return the mutable bo 060 */ 061 public PropositionEditor(PropositionDefinitionContract definition) { 062 this.id = definition.getId(); 063 this.description = definition.getDescription(); 064 this.ruleId = definition.getRuleId(); 065 066 this.typeId = definition.getTypeId(); 067 this.propositionTypeCode = definition.getPropositionTypeCode(); 068 this.parameters = new ArrayList<PropositionParameterEditor>(); 069 for (PropositionParameterContract parm : definition.getParameters()) { 070 this.parameters.add(new PropositionParameterEditor(parm)); 071 } 072 this.compoundOpCode = definition.getCompoundOpCode(); 073 this.compoundEditors = new ArrayList<PropositionEditor>(); 074 for (PropositionDefinitionContract prop : definition.getCompoundComponents()) { 075 this.compoundEditors.add(createPropositionEditor(prop)); 076 } 077 this.versionNumber = definition.getVersionNumber(); 078 } 079 080 public String getKey() { 081 return key; 082 } 083 084 public void setKey(String key) { 085 this.key = key; 086 } 087 088 public String getId() { 089 return id; 090 } 091 092 public String getDescription() { 093 return description; 094 } 095 096 public String getCompoundOpCode() { 097 return compoundOpCode; 098 } 099 100 public void setId(String id) { 101 if (!StringUtils.isBlank(id)) { 102 this.id = id; 103 } 104 } 105 106 public void setDescription(String description) { 107 this.description = description; 108 } 109 110 public void setRuleId(String ruleId) { 111 this.ruleId = ruleId; 112 } 113 114 public void setCompoundOpCode(String compoundOpCode) { 115 this.compoundOpCode = compoundOpCode; 116 } 117 118 public void setParameters(List<PropositionParameterEditor> parameters) { 119 this.parameters = parameters; 120 } 121 122 public void setCompoundEditors(List<PropositionEditor> compoundEditors) { 123 this.compoundEditors = compoundEditors; 124 } 125 126 public List<PropositionEditor> getCompoundEditors() { 127 return compoundEditors; 128 } 129 130 @Override 131 public List<? extends PropositionDefinitionContract> getCompoundComponents() { 132 return compoundEditors; 133 } 134 135 public List<PropositionParameterEditor> getParameters() { 136 return parameters; 137 } 138 139 public String getTypeId() { 140 return typeId; 141 } 142 143 @Override 144 public String getRuleId() { 145 return this.ruleId; 146 } 147 148 public void setPropositionTypeCode(String propositionTypeCode) { 149 this.propositionTypeCode = propositionTypeCode; 150 } 151 152 @Override 153 public String getPropositionTypeCode() { 154 return propositionTypeCode; 155 } 156 157 public void setTypeId(String typeId) { 158 this.typeId = typeId; 159 } 160 161 public String getType() { 162 return type; 163 } 164 165 public void setType(String type) { 166 this.type = type; 167 } 168 169 public boolean isEditMode() { 170 return editMode; 171 } 172 173 public TermEditor getTerm() { 174 return term; 175 } 176 177 public void setTerm(TermEditor term) { 178 this.term = term; 179 } 180 181 public String getTermParameter() { 182 return termParameter; 183 } 184 185 public void setTermParameter(String termParameter) { 186 this.termParameter = termParameter; 187 } 188 189 public List<TermParameter> getTermParameterList() { 190 return termParameterList; 191 } 192 193 public void setTermParameterList(List<TermParameter> termParameterList) { 194 this.termParameterList = termParameterList; 195 } 196 197 public void setEditMode(boolean editMode) { 198 this.editMode = editMode; 199 } 200 201 @Override 202 public Long getVersionNumber() { 203 return this.versionNumber; 204 } 205 206 protected PropositionEditor createPropositionEditor(PropositionDefinitionContract definition) { 207 return new PropositionEditor(definition); 208 } 209 210 public String getNewTermDescription() { 211 return newTermDescription; 212 } 213 214 public boolean isNewProp() { 215 return newProp; 216 } 217 218 public void setNewProp(boolean newProp) { 219 this.newProp = newProp; 220 } 221 222 public Map<String, String> getNaturalLanguage() { 223 return naturalLanguage; 224 } 225 226 public void setNaturalLanguage(Map<String, String> naturalLanguage) { 227 this.naturalLanguage = naturalLanguage; 228 } 229 230 public Map<String, String> getNlParameters() { 231 return new HashMap<String, String>(); 232 } 233 234 public String getNaturalLanguageForUsage(String usage){ 235 String description = this.getNaturalLanguage().get(usage); 236 237 if (description == null){ 238 return StringUtils.EMPTY; 239 } 240 241 return description; 242 } 243 } 244 245