View Javadoc

1   /**
2    * Copyright 2005-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kew.rule.bo;
17  
18  import java.util.ArrayList;
19  import java.util.HashMap;
20  import java.util.List;
21  import java.util.Map;
22  
23  import javax.persistence.Basic;
24  import javax.persistence.CascadeType;
25  import javax.persistence.Column;
26  import javax.persistence.Entity;
27  import javax.persistence.FetchType;
28  import javax.persistence.GeneratedValue;
29  import javax.persistence.Id;
30  import javax.persistence.Lob;
31  import javax.persistence.NamedQueries;
32  import javax.persistence.NamedQuery;
33  import javax.persistence.OneToMany;
34  import javax.persistence.Table;
35  import javax.persistence.Transient;
36  
37  import org.apache.commons.lang.StringUtils;
38  import org.hibernate.annotations.Fetch;
39  import org.hibernate.annotations.FetchMode;
40  import org.hibernate.annotations.GenericGenerator;
41  import org.hibernate.annotations.Parameter;
42  import org.kuali.rice.kew.api.KewApiConstants;
43  import org.kuali.rice.kew.api.extension.ExtensionDefinition;
44  import org.kuali.rice.kew.api.extension.ExtensionDefinitionContract;
45  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
46  
47  
48  /**
49   * Model bean defining a rule attribute.  Includes the classname of the attribute
50   * class, as well as it's name and other information.
51   *
52   * @author Kuali Rice Team (rice.collab@kuali.org)
53   */
54  @Entity
55  @Table(name="KREW_RULE_ATTR_T")
56  //@Sequence(name="KREW_RTE_TMPL_S", property="id")
57  @NamedQueries({
58    @NamedQuery(name="RuleAttribute.FindById",  query="select ra from RuleAttribute ra where ra.ruleAttributeId = :ruleAttributeId"),
59    @NamedQuery(name="RuleAttribute.FindByName",  query="select ra from RuleAttribute ra where ra.name = :name"),
60    @NamedQuery(name="RuleAttribute.FindByClassName",  query="select ra from RuleAttribute ra where ra.className = :className"),
61    @NamedQuery(name="RuleAttribute.GetAllRuleAttributes",  query="select ra from RuleAttribute ra")
62  })
63  public class RuleAttribute extends PersistableBusinessObjectBase implements ExtensionDefinitionContract {
64  
65  	private static final long serialVersionUID = 1027673603158346349L;
66  
67  	@Id
68  	@GeneratedValue(generator="KREW_RTE_TMPL_S")
69  	@GenericGenerator(name="KREW_RTE_TMPL_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
70  			@Parameter(name="sequence_name",value="KREW_RTE_TMPL_S"),
71  			@Parameter(name="value_column",value="id")
72  	})
73  	@Column(name="RULE_ATTR_ID")
74  	private String id;
75      @Column(name="NM")
76  	private String name;
77      @Column(name="LBL")
78  	private String label;
79      @Column(name="RULE_ATTR_TYP_CD")
80  	private String type;
81      @Column(name="CLS_NM")
82  	private String resourceDescriptor;
83      @Column(name="DESC_TXT")
84  	private String description;
85      @Lob
86  	@Basic(fetch=FetchType.LAZY)
87  	@Column(name="XML")
88  	private String xmlConfigData;
89  
90      @Column(name="APPL_ID")
91  	private String applicationId;
92      
93      @OneToMany(fetch=FetchType.EAGER,cascade={CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.MERGE},
94             targetEntity=RuleTemplateAttributeBo.class, mappedBy="ruleAttribute")
95      @Fetch(value=FetchMode.SELECT)
96  	private List ruleTemplateAttributes;
97      @Transient
98      private List validValues;
99      
100     // required to be lookupable
101     @Transient
102     private String returnUrl;
103 
104     public RuleAttribute() {
105         ruleTemplateAttributes = new ArrayList();
106         validValues = new ArrayList();
107     }
108 
109     public List getValidValues() {
110         return validValues;
111     }
112     public void setValidValues(List ruleAttributeValidValues) {
113         this.validValues = ruleAttributeValidValues;
114     }
115     public List getRuleTemplateAttributes() {
116         return ruleTemplateAttributes;
117     }
118     public void setRuleTemplateAttributes(List ruleTemplateAttributes) {
119         this.ruleTemplateAttributes = ruleTemplateAttributes;
120     }
121     public String getDescription() {
122         return description;
123     }
124     public void setDescription(String description) {
125         this.description = description;
126     }
127     public String getLabel() {
128         return label;
129     }
130     public void setLabel(String label) {
131         this.label = label;
132     }
133 
134     public String getName() {
135         return name;
136     }
137     public void setName(String name) {
138         this.name = name;
139     }
140     public String getId() {
141         return id;
142     }
143     public void setId(String id) {
144         this.id = id;
145     }
146     public String getType() {
147         return type;
148     }
149     public void setType(String type) {
150         this.type = type;
151     }
152 
153     /**
154      * @return Returns the resourceDescriptor.
155      */
156     public String getResourceDescriptor() {
157       return resourceDescriptor;
158     }
159     /**
160      * @param resourceDescriptor The className to set.
161      */
162     public void setResourceDescriptor(String resourceDescriptor) {
163       this.resourceDescriptor = resourceDescriptor;
164     }
165     
166     public String getRuleAttributeActionsUrl() {
167         return "<a href=\"RuleAttributeReport.do?id="+ id +"\" >report</a>";
168     }
169     
170     public String getReturnUrl() {
171         return returnUrl;
172     }
173     public void setReturnUrl(String returnUrl) {
174         this.returnUrl = returnUrl;
175     }
176 
177 	public String getXmlConfigData() {
178 		return xmlConfigData;
179 	}
180 
181     @Override
182     public Map<String, String> getConfiguration() {
183         Map<String, String> config = new HashMap<String, String>();
184         if (StringUtils.isNotBlank(getXmlConfigData())) {
185             config.put(KewApiConstants.ATTRIBUTE_XML_CONFIG_DATA, getXmlConfigData());
186         }
187         return config;
188     }
189 
190 	public void setXmlConfigData(String xmlConfigData) {
191 		this.xmlConfigData = xmlConfigData;
192 	}
193 
194     @Override
195 	public String getApplicationId() {
196 		return applicationId;
197 	}
198 
199 	public void setApplicationId(String applicationId) {
200 		this.applicationId = applicationId;
201 	}
202 
203     public static ExtensionDefinition to(RuleAttribute ruleAttribute) {
204         if (ruleAttribute == null) {
205             return null;
206         }
207         return ExtensionDefinition.Builder.create(ruleAttribute).build();
208     }
209 
210     public static RuleAttribute from(ExtensionDefinition im) {
211         if (im == null) {
212             return null;
213         }
214         RuleAttribute bo = new RuleAttribute();
215         bo.setApplicationId(im.getApplicationId());
216         bo.setDescription(im.getDescription());
217         bo.setResourceDescriptor(im.getResourceDescriptor());
218         bo.setId(im.getId());
219         bo.setLabel(im.getLabel());
220         bo.setType(im.getType());
221         bo.setVersionNumber(im.getVersionNumber());
222         bo.setXmlConfigData(im.getConfiguration().get(KewApiConstants.ATTRIBUTE_XML_CONFIG_DATA));
223 
224         return bo;
225     }
226 }