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.ken.bo;
017
018import org.hibernate.annotations.GenericGenerator;
019import org.hibernate.annotations.Parameter;
020import org.hibernate.annotations.Type;
021import org.kuali.rice.ken.api.notification.NotificationContentType;
022import org.kuali.rice.ken.api.notification.NotificationContentTypeContract;
023import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
024
025import javax.persistence.Column;
026import javax.persistence.Entity;
027import javax.persistence.GeneratedValue;
028import javax.persistence.Id;
029import javax.persistence.Table;
030
031/**
032 * This class represents the different types of Notification content that the system can handle.  
033 * For example, and instance of content type could be "Alert" or "Event".
034 * @author Kuali Rice Team (rice.collab@kuali.org)
035 */
036@Entity
037@Table(name="KREN_CNTNT_TYP_T")
038public class NotificationContentTypeBo extends PersistableBusinessObjectBase implements NotificationContentTypeContract {
039    @Id
040    @GeneratedValue(generator="KREN_CNTNT_TYP_S")
041        @GenericGenerator(name="KREN_CNTNT_TYP_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
042                        @Parameter(name="sequence_name",value="KREN_CNTNT_TYP_S"),
043                        @Parameter(name="value_column",value="id")
044        })
045        @Column(name="CNTNT_TYP_ID")
046        private Long id;
047    @Column(name="NM", nullable=false)
048        private String name;
049    @Type(type="true_false")
050    private boolean current = true;
051    @Column(name="CNTNT_TYP_VER_NBR", nullable=false)
052    private Integer version = Integer.valueOf(0);
053    @Column(name="DESC_TXT", nullable=false)
054        private String description;
055    @Column(name="NMSPC_CD", nullable=false)
056        private String namespace;
057    @Column(name="XSD", nullable=false, length=4096)
058        private String xsd;
059    @Column(name="XSL", nullable=false, length=4096)
060        private String xsl;
061
062    /**
063     * Constructs a NotificationContentType instance.
064     */
065    public NotificationContentTypeBo() {
066    }
067
068    /**
069     * Gets the description attribute. 
070     * @return Returns the description.
071     */
072    public String getDescription() {
073        return description;
074    }
075
076    /**
077     * Sets the description attribute value.
078     * @param description The description to set.
079     */
080    public void setDescription(String description) {
081        this.description = description;
082    }
083
084    /**
085     * Gets the id attribute. 
086     * @return Returns the id.
087     */
088    public Long getId() {
089        return id;
090    }
091
092    /**
093     * Sets the id attribute value.
094     * @param id The id to set.
095     */
096    public void setId(Long id) {
097        this.id = id;
098    }
099
100    /**
101     * Gets the name attribute. 
102     * @return Returns the name.
103     */
104    public String getName() {
105        return name;
106    }
107
108    /**
109     * @return whether this is the current version
110     */
111    public boolean isCurrent() {
112        return this.current;
113    }
114
115    /**
116     * @param current whether this is the current version
117     */
118    public void setCurrent(boolean current) {
119        this.current = current;
120    }
121
122    /**
123     * @return the version
124     */
125    public Integer getVersion() {
126        return this.version;
127    }
128
129    /**
130     * @param version the version to set
131     */
132    public void setVersion(Integer version) {
133        this.version = version;
134    }
135
136    /**
137     * Sets the name attribute value.
138     * @param name The name to set.
139     */
140    public void setName(String name) {
141        this.name = name;
142    }
143
144    /**
145     * Gets the namespace attribute. 
146     * @return Returns the namespace.
147     */
148    public String getNamespace() {
149        return namespace;
150    }
151
152    /**
153     * Sets the namespace attribute value.
154     * @param namespace The namespace to set.
155     */
156    public void setNamespace(String namespace) {
157        this.namespace = namespace;
158    }
159
160    /**
161     * Gets the xsd attribute. The value of this field is used to validate a notification's content field dynamically.
162     * @return Returns the xsd.
163     */
164    public String getXsd() {
165        return xsd;
166    }
167
168    /**
169     * Sets the xsd attribute value.  The value of this field is used to validate a notification's content field dynamically.
170     * @param xsd The xsd to set.
171     */
172    public void setXsd(String xsd) {
173        this.xsd = xsd;
174    }
175
176    /**
177     * Gets the xsl attribute. The value of this field is used to render a notification's contents dynamically.
178     * @return Returns the xsl.
179     */
180    public String getXsl() {
181        return xsl;
182    }
183
184    /**
185     * Sets the xsl attribute value.  The value of this field is used to render a notification's contents dynamically.
186     * @param xsl The xsl to set.
187     */
188    public void setXsl(String xsl) {
189        this.xsl = xsl;
190    }
191
192    /**
193     * Converts a mutable bo to its immutable counterpart
194     * @param bo the mutable business object
195     * @return the immutable object
196     */
197    public static NotificationContentType to(NotificationContentTypeBo bo) {
198        if (bo == null) {
199            return null;
200        }
201
202        return NotificationContentType.Builder.create(bo).build();
203    }
204
205    /**
206     * Converts a immutable object to its mutable counterpart
207     * @param im immutable object
208     * @return the mutable bo
209     */
210    public static NotificationContentTypeBo from(NotificationContentType im) {
211        if (im == null) {
212            return null;
213        }
214
215        NotificationContentTypeBo bo = new NotificationContentTypeBo();
216        bo.setId(im.getId());
217        bo.setVersionNumber(im.getVersionNumber());
218        bo.setObjectId(im.getObjectId());
219        bo.setName(im.getName());
220        bo.setDescription(im.getDescription());
221
222        bo.setCurrent(im.isCurrent());
223        bo.setVersion(im.getVersion());
224        bo.setNamespace(im.getNamespace());
225        bo.setXsd(im.getXsd());
226        bo.setXsl(im.getXsl());
227        return bo;
228    }
229}