View Javadoc

1   /**
2    * Copyright 2005-2014 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 org.apache.commons.lang.StringUtils;
19  import org.hibernate.annotations.Fetch;
20  import org.hibernate.annotations.FetchMode;
21  import org.hibernate.annotations.GenericGenerator;
22  import org.hibernate.annotations.Parameter;
23  import org.kuali.rice.kew.api.KewApiConstants;
24  import org.kuali.rice.kew.api.extension.ExtensionDefinition;
25  import org.kuali.rice.kew.api.extension.ExtensionDefinitionContract;
26  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
27  
28  import javax.persistence.Basic;
29  import javax.persistence.CascadeType;
30  import javax.persistence.Column;
31  import javax.persistence.Entity;
32  import javax.persistence.FetchType;
33  import javax.persistence.GeneratedValue;
34  import javax.persistence.Id;
35  import javax.persistence.Lob;
36  import javax.persistence.NamedQueries;
37  import javax.persistence.NamedQuery;
38  import javax.persistence.OneToMany;
39  import javax.persistence.Table;
40  import javax.persistence.Transient;
41  import java.util.ArrayList;
42  import java.util.HashMap;
43  import java.util.List;
44  import java.util.Map;
45  
46  
47  /**
48   * Model bean defining a rule attribute.  Includes the classname of the attribute
49   * class, as well as it's name and other information.
50   *
51   * @author Kuali Rice Team (rice.collab@kuali.org)
52   */
53  @Entity
54  @Table(name="KREW_RULE_ATTR_T")
55  //@Sequence(name="KREW_RTE_TMPL_S", property="id")
56  @NamedQueries({
57    @NamedQuery(name="RuleAttribute.FindById",  query="select ra from RuleAttribute ra where ra.ruleAttributeId = :ruleAttributeId"),
58    @NamedQuery(name="RuleAttribute.FindByName",  query="select ra from RuleAttribute ra where ra.name = :name"),
59    @NamedQuery(name="RuleAttribute.FindByClassName",  query="select ra from RuleAttribute ra where ra.className = :className"),
60    @NamedQuery(name="RuleAttribute.GetAllRuleAttributes",  query="select ra from RuleAttribute ra")
61  })
62  public class RuleAttribute extends PersistableBusinessObjectBase implements ExtensionDefinitionContract {
63  
64  	private static final long serialVersionUID = 1027673603158346349L;
65  
66  	@Id
67  	@GeneratedValue(generator="KREW_RTE_TMPL_S")
68  	@GenericGenerator(name="KREW_RTE_TMPL_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
69  			@Parameter(name="sequence_name",value="KREW_RTE_TMPL_S"),
70  			@Parameter(name="value_column",value="id")
71  	})
72  	@Column(name="RULE_ATTR_ID")
73  	private String id;
74      @Column(name="NM")
75  	private String name;
76      @Column(name="LBL")
77  	private String label;
78      @Column(name="RULE_ATTR_TYP_CD")
79  	private String type;
80      @Column(name="CLS_NM")
81  	private String resourceDescriptor;
82      @Column(name="DESC_TXT")
83  	private String description;
84      @Lob
85  	@Basic(fetch=FetchType.LAZY)
86  	@Column(name="XML")
87  	private String xmlConfigData;
88  
89      @Column(name="APPL_ID")
90  	private String applicationId;
91      
92      @OneToMany(fetch=FetchType.EAGER,cascade={CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.MERGE},
93             targetEntity=RuleTemplateAttributeBo.class, mappedBy="ruleAttribute")
94      @Fetch(value=FetchMode.SELECT)
95  	private List ruleTemplateAttributes;
96      @Transient
97      private List validValues;
98      
99      // 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 }