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;
017
018import org.apache.commons.lang.ObjectUtils;
019import org.hibernate.annotations.GenericGenerator;
020import org.hibernate.annotations.Parameter;
021import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
022import org.kuali.rice.kew.service.KEWServiceLocator;
023
024import javax.persistence.*;
025import java.io.Serializable;
026
027
028/**
029 * The value of an extension to a rule.  Essentially contains a
030 * key-value pair containing the key of the extension data and
031 * it's value.
032 * 
033 * @see RuleBaseValues
034 * @see RuleExtensionBo
035 *
036 * @author Kuali Rice Team (rice.collab@kuali.org)
037 */
038@Entity
039@Table(name="KREW_RULE_EXT_VAL_T")
040//@Sequence(name="KREW_RTE_TMPL_S", property="ruleExtensionValueId")
041public class RuleExtensionValue implements Serializable {
042
043        private static final long serialVersionUID = 8909789087052290261L;
044        @Id
045        @GeneratedValue(generator="KREW_RTE_TMPL_S")
046        @GenericGenerator(name="KREW_RTE_TMPL_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
047                        @Parameter(name="sequence_name",value="KREW_RTE_TMPL_S"),
048                        @Parameter(name="value_column",value="id")
049        })
050        @Column(name="RULE_EXT_VAL_ID")
051        private String ruleExtensionValueId;
052    @Column(name="RULE_EXT_ID", insertable=false, updatable=false)
053        private String ruleExtensionId;
054    @Column(name="VAL")
055        private String value;
056    @Column(name="KEY_CD")
057        private String key;
058    @Version
059        @Column(name="VER_NBR")
060        private Integer lockVerNbr;
061    
062    @ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST})
063        @JoinColumn(name="RULE_EXT_ID")
064        private RuleExtensionBo extension;
065    
066    public RuleExtensionValue() {
067    }
068    
069    public RuleExtensionValue(String key, String value) {
070        this.key = key;
071        this.value = value;
072    }
073    
074    //@PrePersist
075    public void beforeInsert(){
076        OrmUtils.populateAutoIncValue(this, KEWServiceLocator.getEntityManagerFactory().createEntityManager());
077    }
078    
079    public RuleExtensionBo getExtension() {
080        return extension;
081    }
082    public void setExtension(RuleExtensionBo extension) {
083        this.extension = extension;
084    }
085    public Integer getLockVerNbr() {
086        return lockVerNbr;
087    }
088    public void setLockVerNbr(Integer lockVerNbr) {
089        this.lockVerNbr = lockVerNbr;
090    }
091    public String getKey() {
092        return key;
093    }
094    public void setKey(String key) {
095        this.key = key;
096    }
097    public String getRuleExtensionId() {
098        return ruleExtensionId;
099    }
100    public void setRuleExtensionId(String ruleExtensionId) {
101        this.ruleExtensionId = ruleExtensionId;
102    }
103    public String getRuleExtensionValueId() {
104        return ruleExtensionValueId;
105    }
106    public void setRuleExtensionValueId(String ruleExtensionValueId) {
107        this.ruleExtensionValueId = ruleExtensionValueId;
108    }
109    public String getValue() {
110        return value;
111    }
112    public void setValue(String value) {
113        this.value = value;
114    }
115
116    public boolean equals(Object o) {
117        if (o == null) return false;
118        if (!(o instanceof RuleExtensionValue)) return false;
119        RuleExtensionValue pred = (RuleExtensionValue) o;
120        return ObjectUtils.equals(key, pred.key) && ObjectUtils.equals(value, pred.value);
121    }
122
123    public String toString() {
124        return "[RuleExtensionValue:"
125               +  " ruleExtensionValueId=" + ruleExtensionValueId
126               + ", ruleExtensionId=" + ruleExtensionId
127               + ", value=" + value
128               + ", key=" + key
129               + ", lockVerNbr=" + lockVerNbr
130               + "]";
131            
132    }
133}