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.coreservice.impl.style;
17  
18  import org.kuali.rice.coreservice.api.style.Style;
19  import org.kuali.rice.coreservice.api.style.StyleContract;
20  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
21  import org.kuali.rice.krad.data.jpa.converters.Boolean01BigDecimalConverter;
22  import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
23  
24  import javax.persistence.Column;
25  import javax.persistence.Convert;
26  import javax.persistence.Entity;
27  import javax.persistence.GeneratedValue;
28  import javax.persistence.Id;
29  import javax.persistence.NamedQuery;
30  import javax.persistence.Table;
31  
32  /**
33   * A BusinessObject implementation of the StyleContract which is mapped to the
34   * database for persistence.
35   *
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   */
38  @Entity
39  @Table(name="KRCR_STYLE_T")
40  @NamedQuery(name="StyleBo.findAllStyleNames",
41          query="SELECT sb.name FROM StyleBo sb where sb.active=true"
42  )
43  public class StyleBo extends PersistableBusinessObjectBase implements StyleContract {
44  
45      private static final long serialVersionUID = 2020611019976731725L;
46  
47      @Id
48      @Column(name="STYLE_ID")
49      @GeneratedValue(generator = "KREW_EDL_S")
50      @PortableSequenceGenerator(name = "KREW_EDL_S")
51      private String id;
52  
53      @Column(name="NM")
54      private String name;
55  
56      @Column(name="XML")
57      private String xmlContent;
58  
59      @Column(name="ACTV_IND")
60      @Convert(converter=Boolean01BigDecimalConverter.class)
61      boolean active = true;
62  
63      @Override
64      public String getId() {
65          return id;
66      }
67  
68      public void setId(String id) {
69          this.id = id;
70      }
71  
72      @Override
73      public String getName() {
74          return name;
75      }
76  
77      public void setName(String name) {
78          this.name = name;
79      }
80  
81      @Override
82      public String getXmlContent() {
83          return xmlContent;
84      }
85  
86      public void setXmlContent(String xmlContent) {
87          this.xmlContent = xmlContent;
88      }
89  
90      @Override
91      public boolean isActive() {
92          return active;
93      }
94  
95      public void setActive(boolean active) {
96          this.active = active;
97      }
98  
99      /**
100      * Converts the given StyleBo to a Style object.
101      *
102      * @param styleBo the StyleBo to convert
103      * @return the resulting Style object, or null if the given styleBo was null
104      */
105     public static Style to(StyleBo styleBo) {
106         if (styleBo == null) {
107             return null;
108         }
109         return Style.Builder.create(styleBo).build();
110     }
111 
112     /**
113      * Constructs a StyleBo from the given Style.
114      *
115      * @param style the Style to convert
116      * @return the resulting StyleBo object, or null if the given style was null
117      */
118     public static StyleBo from(Style style) {
119         if (style == null) {
120             return null;
121         }
122         StyleBo styleBo = new StyleBo();
123         styleBo.setId(style.getId());
124         styleBo.setName(style.getName());
125         styleBo.setXmlContent(style.getXmlContent());
126         styleBo.setActive(style.isActive());
127         styleBo.setVersionNumber(style.getVersionNumber());
128         styleBo.setObjectId(style.getObjectId());
129         return styleBo;
130     }
131 
132 }
133