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.kew.rule.bo; 017 018import org.apache.commons.lang.StringUtils; 019import org.hibernate.annotations.Fetch; 020import org.hibernate.annotations.FetchMode; 021import org.hibernate.annotations.GenericGenerator; 022import org.hibernate.annotations.Parameter; 023import org.kuali.rice.kew.api.KewApiConstants; 024import org.kuali.rice.kew.api.extension.ExtensionDefinition; 025import org.kuali.rice.kew.api.extension.ExtensionDefinitionContract; 026import org.kuali.rice.krad.bo.PersistableBusinessObjectBase; 027 028import javax.persistence.Basic; 029import javax.persistence.CascadeType; 030import javax.persistence.Column; 031import javax.persistence.Entity; 032import javax.persistence.FetchType; 033import javax.persistence.GeneratedValue; 034import javax.persistence.Id; 035import javax.persistence.Lob; 036import javax.persistence.NamedQueries; 037import javax.persistence.NamedQuery; 038import javax.persistence.OneToMany; 039import javax.persistence.Table; 040import javax.persistence.Transient; 041import java.util.ArrayList; 042import java.util.HashMap; 043import java.util.List; 044import java.util.Map; 045 046 047/** 048 * Model bean defining a rule attribute. Includes the classname of the attribute 049 * class, as well as it's name and other information. 050 * 051 * @author Kuali Rice Team (rice.collab@kuali.org) 052 */ 053@Entity 054@Table(name="KREW_RULE_ATTR_T") 055//@Sequence(name="KREW_RTE_TMPL_S", property="id") 056@NamedQueries({ 057 @NamedQuery(name="RuleAttribute.FindById", query="select ra from RuleAttribute ra where ra.ruleAttributeId = :ruleAttributeId"), 058 @NamedQuery(name="RuleAttribute.FindByName", query="select ra from RuleAttribute ra where ra.name = :name"), 059 @NamedQuery(name="RuleAttribute.FindByClassName", query="select ra from RuleAttribute ra where ra.className = :className"), 060 @NamedQuery(name="RuleAttribute.GetAllRuleAttributes", query="select ra from RuleAttribute ra") 061}) 062public class RuleAttribute extends PersistableBusinessObjectBase implements ExtensionDefinitionContract { 063 064 private static final long serialVersionUID = 1027673603158346349L; 065 066 @Id 067 @GeneratedValue(generator="KREW_RTE_TMPL_S") 068 @GenericGenerator(name="KREW_RTE_TMPL_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={ 069 @Parameter(name="sequence_name",value="KREW_RTE_TMPL_S"), 070 @Parameter(name="value_column",value="id") 071 }) 072 @Column(name="RULE_ATTR_ID") 073 private String id; 074 @Column(name="NM") 075 private String name; 076 @Column(name="LBL") 077 private String label; 078 @Column(name="RULE_ATTR_TYP_CD") 079 private String type; 080 @Column(name="CLS_NM") 081 private String resourceDescriptor; 082 @Column(name="DESC_TXT") 083 private String description; 084 @Lob 085 @Basic(fetch=FetchType.LAZY) 086 @Column(name="XML") 087 private String xmlConfigData; 088 089 @Column(name="APPL_ID") 090 private String applicationId; 091 092 @OneToMany(fetch=FetchType.EAGER,cascade={CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.MERGE}, 093 targetEntity=RuleTemplateAttributeBo.class, mappedBy="ruleAttribute") 094 @Fetch(value=FetchMode.SELECT) 095 private List ruleTemplateAttributes; 096 @Transient 097 private List validValues; 098 099 // required to be lookupable 100 @Transient 101 private String returnUrl; 102 103 public RuleAttribute() { 104 ruleTemplateAttributes = new ArrayList(); 105 validValues = new ArrayList(); 106 } 107 108 public List getValidValues() { 109 return validValues; 110 } 111 public void setValidValues(List ruleAttributeValidValues) { 112 this.validValues = ruleAttributeValidValues; 113 } 114 public List getRuleTemplateAttributes() { 115 return ruleTemplateAttributes; 116 } 117 public void setRuleTemplateAttributes(List ruleTemplateAttributes) { 118 this.ruleTemplateAttributes = ruleTemplateAttributes; 119 } 120 public String getDescription() { 121 return description; 122 } 123 public void setDescription(String description) { 124 this.description = description; 125 } 126 public String getLabel() { 127 return label; 128 } 129 public void setLabel(String label) { 130 this.label = label; 131 } 132 133 public String getName() { 134 return name; 135 } 136 public void setName(String name) { 137 this.name = name; 138 } 139 public String getId() { 140 return id; 141 } 142 public void setId(String id) { 143 this.id = id; 144 } 145 public String getType() { 146 return type; 147 } 148 public void setType(String type) { 149 this.type = type; 150 } 151 152 /** 153 * @return Returns the resourceDescriptor. 154 */ 155 public String getResourceDescriptor() { 156 return resourceDescriptor; 157 } 158 /** 159 * @param resourceDescriptor The className to set. 160 */ 161 public void setResourceDescriptor(String resourceDescriptor) { 162 this.resourceDescriptor = resourceDescriptor; 163 } 164 165 public String getRuleAttributeActionsUrl() { 166 return "<a href=\"RuleAttributeReport.do?id="+ id +"\" >report</a>"; 167 } 168 169 public String getReturnUrl() { 170 return returnUrl; 171 } 172 public void setReturnUrl(String returnUrl) { 173 this.returnUrl = returnUrl; 174 } 175 176 public String getXmlConfigData() { 177 return xmlConfigData; 178 } 179 180 @Override 181 public Map<String, String> getConfiguration() { 182 Map<String, String> config = new HashMap<String, String>(); 183 if (StringUtils.isNotBlank(getXmlConfigData())) { 184 config.put(KewApiConstants.ATTRIBUTE_XML_CONFIG_DATA, getXmlConfigData()); 185 } 186 return config; 187 } 188 189 public void setXmlConfigData(String xmlConfigData) { 190 this.xmlConfigData = xmlConfigData; 191 } 192 193 @Override 194 public String getApplicationId() { 195 return applicationId; 196 } 197 198 public void setApplicationId(String applicationId) { 199 this.applicationId = applicationId; 200 } 201 202 public boolean isWorkflowAttribute() { 203 return isWorkflowAttribute(getType()); 204 } 205 206 public static boolean isWorkflowAttribute(String type) { 207 return KewApiConstants.RULE_ATTRIBUTE_TYPE.equals(type) || 208 KewApiConstants.RULE_XML_ATTRIBUTE_TYPE.equals(type); 209 } 210 211 public static ExtensionDefinition to(RuleAttribute ruleAttribute) { 212 if (ruleAttribute == null) { 213 return null; 214 } 215 return ExtensionDefinition.Builder.create(ruleAttribute).build(); 216 } 217 218 public static RuleAttribute from(ExtensionDefinition im) { 219 if (im == null) { 220 return null; 221 } 222 RuleAttribute bo = new RuleAttribute(); 223 bo.setApplicationId(im.getApplicationId()); 224 bo.setDescription(im.getDescription()); 225 bo.setResourceDescriptor(im.getResourceDescriptor()); 226 bo.setId(im.getId()); 227 bo.setLabel(im.getLabel()); 228 bo.setType(im.getType()); 229 bo.setVersionNumber(im.getVersionNumber()); 230 bo.setXmlConfigData(im.getConfiguration().get(KewApiConstants.ATTRIBUTE_XML_CONFIG_DATA)); 231 232 return bo; 233 } 234}