View Javadoc
1   /**
2    * Copyright 2005-2016 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;
17  
18  import org.apache.commons.lang.ObjectUtils;
19  import org.kuali.rice.kew.api.rule.RuleExpression;
20  import org.kuali.rice.kew.api.rule.RuleExpressionContract;
21  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
22  import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
23  
24  import javax.persistence.Column;
25  import javax.persistence.Entity;
26  import javax.persistence.GeneratedValue;
27  import javax.persistence.Id;
28  import javax.persistence.Table;
29  
30  /**
31   * BO for rule expressions 
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   */
34  @Entity
35  @Table(name="KREW_RULE_EXPR_T")
36  //@Sequence(name="KREW_RULE_EXPR_S", property="id")
37  public class RuleExpressionDef extends PersistableBusinessObjectBase implements RuleExpressionContract {
38      
39      /**
40       * Primary key
41       */
42      @Id
43      @PortableSequenceGenerator(name="KREW_RULE_EXPR_S")
44      @GeneratedValue(generator="KREW_RULE_EXPR_S")
45  	@Column(name="RULE_EXPR_ID")
46  	private String id;
47      /**
48       * The type of the expression
49       */
50      @Column(name="TYP")
51  	private String type;
52      /**
53       * The content of the expression
54       */
55      @Column(name="RULE_EXPR", nullable=true)
56  	private String expression;
57      /**
58       * @return the id
59       */
60      public String getId() {
61          return this.id;
62      }
63      /**
64       * @param id the id to set
65       */
66      public void setId(String id) {
67          this.id = id;
68      }
69      /**
70       * @return the type
71       */
72      public String getType() {
73          return this.type;
74      }
75      /**
76       * @param type the type to set
77       */
78      public void setType(String type) {
79          this.type = type;
80      }
81      /**
82       * @return the expression
83       */
84      public String getExpression() {
85          return this.expression;
86      }
87      /**
88       * @param expression the expression to set
89       */
90      public void setExpression(String expression) {
91          this.expression = expression;
92      }
93  
94      /**
95       * Returns whether the object is an <i>equivalent</i> rule expression, i.e.
96       * the type and expression are the same.  This is necessary for rule duplicate
97       * detection.
98       * @see java.lang.Object#equals(java.lang.Object)
99       */
100     @Override
101     public boolean equals(Object obj) {
102         if (obj == null) return false;
103         if (!(obj instanceof RuleExpressionDef)) return false;
104         RuleExpressionDef arg = (RuleExpressionDef) obj;
105         return ObjectUtils.equals(type, arg.getType()) && ObjectUtils.equals(expression, arg.getExpression());
106     }
107 
108     /**
109      * Converts a mutable bo to its immutable counterpart
110      * @param bo the mutable business object
111      * @return the immutable object
112      */
113     public static org.kuali.rice.kew.api.rule.RuleExpression to(RuleExpressionDef bo) {
114         if (bo == null) {
115             return null;
116         }
117 
118         return RuleExpression.Builder.create(bo).build();
119     }
120 
121     /**
122      * Converts a immutable object to its mutable counterpart
123      * @param im immutable object
124      * @return the mutable bo
125      */
126     public static RuleExpressionDef from(RuleExpression im) {
127         if (im == null) {
128             return null;
129         }
130 
131         RuleExpressionDef bo = new RuleExpressionDef();
132         bo.setId(im.getId());
133         bo.setType(im.getType());
134         bo.setExpression(im.getExpression());
135         bo.setVersionNumber(im.getVersionNumber());
136         bo.setObjectId(im.getObjectId());
137 
138         return bo;
139     }
140 }