001    /**
002     * Copyright 2005-2011 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     */
016    package org.kuali.rice.kew.rule;
017    
018    import org.hibernate.annotations.GenericGenerator;
019    import org.hibernate.annotations.Parameter;
020    import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
021    import org.kuali.rice.kew.api.rule.RuleTemplateOptionContract;
022    import org.kuali.rice.kew.rule.bo.RuleTemplateBo;
023    import org.kuali.rice.kew.service.KEWServiceLocator;
024    import org.kuali.rice.krad.bo.BusinessObjectBase;
025    import org.kuali.rice.krad.service.KRADServiceLocator;
026    
027    import javax.persistence.Column;
028    import javax.persistence.Entity;
029    import javax.persistence.FetchType;
030    import javax.persistence.GeneratedValue;
031    import javax.persistence.Id;
032    import javax.persistence.JoinColumn;
033    import javax.persistence.ManyToOne;
034    import javax.persistence.Table;
035    import javax.persistence.Version;
036    
037    /**
038     * Defines default values and other preset information for a {@link RuleBaseValues} 
039     * which is based off of the associated {@link org.kuali.rice.kew.rule.bo.RuleTemplateBo}.
040     * 
041     * @see RuleBaseValues
042     * @see org.kuali.rice.kew.rule.bo.RuleTemplateBo
043     *
044     * @author Kuali Rice Team (rice.collab@kuali.org)
045     */
046    @Entity
047    @Table(name="KREW_RULE_TMPL_OPTN_T")
048    //@Sequence(name="KREW_RULE_TMPL_OPTN_S", property="id")
049    public class RuleTemplateOptionBo extends BusinessObjectBase implements RuleTemplateOptionContract {
050    
051            private static final long serialVersionUID = 8913119135197149224L;
052            @Id
053            @GeneratedValue(generator="KREW_RULE_TMPL_OPTN_S")
054            @GenericGenerator(name="KREW_RULE_TMPL_OPTN_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
055                            @Parameter(name="sequence_name",value="KREW_RULE_TMPL_OPTN_S"),
056                            @Parameter(name="value_column",value="id")
057            })
058            @Column(name="RULE_TMPL_OPTN_ID")
059            private String id;
060        @Column(name="RULE_TMPL_ID", insertable=false, updatable=false)
061            private String ruleTemplateId;
062        @Column(name="KEY_CD")
063            private String code;
064        @Column(name="VAL")
065            private String value;
066        @Version
067            @Column(name="VER_NBR")
068            private Long versionNumber;
069    
070        @ManyToOne(fetch=FetchType.EAGER)
071            @JoinColumn(name="RULE_TMPL_ID")
072            private RuleTemplateBo ruleTemplate;
073        
074        public RuleTemplateOptionBo(){}
075        
076        public RuleTemplateOptionBo(String key, String value){
077            this.code = key;
078            this.value = value;
079        }
080    
081        //@PrePersist
082        public void beforeInsert(){
083            OrmUtils.populateAutoIncValue(this, KEWServiceLocator.getEntityManagerFactory().createEntityManager());
084        }
085        @Override
086        public String getCode() {
087            return code;
088        }
089    
090        public void setCode(String code) {
091            this.code = code;
092        }
093        @Override
094        public Long getVersionNumber() {
095            return versionNumber;
096        }
097    
098        public void setVersionNumber(Long versionNumber) {
099            this.versionNumber = versionNumber;
100        }
101    
102        public RuleTemplateBo getRuleTemplate() {
103            return ruleTemplate;
104        }
105    
106        public void setRuleTemplate(RuleTemplateBo ruleTemplate) {
107            this.ruleTemplate = ruleTemplate;
108        }
109        @Override
110        public String getRuleTemplateId() {
111            return ruleTemplateId;
112        }
113    
114        public void setRuleTemplateId(String ruleTemplateId) {
115            this.ruleTemplateId = ruleTemplateId;
116        }
117        @Override
118        public String getId() {
119            return id;
120        }
121    
122        public void setId(String id) {
123            this.id = id;
124        }
125    
126        @Override
127        public String getValue() {
128            return value;
129        }
130    
131        public void setValue(String value) {
132            this.value = value;
133        }
134    
135        @Override
136        public void refresh() {
137            KRADServiceLocator.getPersistenceService().retrieveNonKeyFields(this);
138        }
139    }
140