View Javadoc
1   /**
2    * Copyright 2005-2014 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.component;
17  
18  import org.kuali.rice.coreservice.api.component.Component;
19  import org.kuali.rice.coreservice.api.component.ComponentContract;
20  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
21  import org.kuali.rice.krad.data.jpa.DisableVersioning;
22  import org.kuali.rice.krad.data.jpa.RemoveMapping;
23  import org.kuali.rice.krad.data.jpa.RemoveMappings;
24  
25  import javax.persistence.Column;
26  import javax.persistence.Entity;
27  import javax.persistence.Id;
28  import javax.persistence.IdClass;
29  import javax.persistence.Table;
30  
31  @IdClass(ComponentId.class)
32  @Entity
33  @Table(name = "KRCR_DRVD_CMPNT_T")
34  @DisableVersioning
35  @RemoveMappings({
36          @RemoveMapping(name = "versionNumber"),
37          @RemoveMapping(name = "objectId")
38  })
39  public class DerivedComponentBo extends PersistableBusinessObjectBase implements ComponentContract {
40  
41      @Id
42      @Column(name="NMSPC_CD")
43      private String namespaceCode;
44  
45      @Id
46      @Column(name="CMPNT_CD")
47      private String code;
48  
49      @Column(name="NM")
50      private String name;
51  
52      @Column(name="CMPNT_SET_ID")
53      private String componentSetId;
54  
55      @Override
56      public boolean isActive() {
57          return true;
58      }
59  
60      @Override
61      public String getNamespaceCode() {
62          return namespaceCode;
63      }
64  
65      public void setNamespaceCode(String namespaceCode) {
66          this.namespaceCode = namespaceCode;
67      }
68  
69      @Override
70      public String getCode() {
71          return code;
72      }
73  
74      public void setCode(String code) {
75          this.code = code;
76      }
77  
78      @Override
79      public String getName() {
80          return name;
81      }
82  
83      public void setName(String name) {
84          this.name = name;
85      }
86  
87      @Override
88      public String getComponentSetId() {
89          return componentSetId;
90      }
91  
92      public void setComponentSetId(String componentSetId) {
93          this.componentSetId = componentSetId;
94      }
95  
96      @Override
97      protected void preUpdate() {
98          // override to do nothing so that the object id doesn't get automatically set prior to an update
99      }
100 
101     /**
102      * Converts a mutable bo to its immutable counterpart
103      * @param bo the mutable business object
104      * @return the immutable object
105      */
106     public static Component to(DerivedComponentBo bo) {
107         if (bo == null) {
108             return null;
109         }
110         return Component.Builder.create(bo).build();
111     }
112 
113     /**
114      * Converts a immutable object to its mutable counterpart
115      * @param im immutable object
116      * @return the mutable bo
117      */
118     public static DerivedComponentBo from(Component im) {
119         if (im == null) {
120             return null;
121         }
122 
123         DerivedComponentBo bo = new DerivedComponentBo();
124         bo.code = im.getCode();
125         bo.name = im.getName();
126         bo.namespaceCode = im.getNamespaceCode();
127         bo.componentSetId = im.getComponentSetId();
128 
129         return bo;
130     }
131 
132     public static ComponentBo toComponentBo(DerivedComponentBo derivedComponentBo) {
133         if (derivedComponentBo == null) {
134             return null;
135         }
136         Component component = DerivedComponentBo.to(derivedComponentBo);
137         return ComponentBo.from(component);
138     }
139 }