View Javadoc
1   /**
2    * Copyright 2005-2015 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.krms.impl.repository;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.core.api.mo.common.Versioned;
20  import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
21  import org.kuali.rice.krms.api.repository.term.TermResolverDefinition;
22  
23  import javax.persistence.Column;
24  import javax.persistence.Entity;
25  import javax.persistence.GeneratedValue;
26  import javax.persistence.Id;
27  import javax.persistence.JoinColumn;
28  import javax.persistence.ManyToOne;
29  import javax.persistence.Table;
30  import javax.persistence.Version;
31  import java.io.Serializable;
32  
33  @Entity
34  @Table(name = "KRMS_TERM_RSLVR_PARM_SPEC_T")
35  public class TermResolverParameterSpecificationBo implements Versioned, Serializable {
36  
37      private static final long serialVersionUID = 1l;
38  
39      @PortableSequenceGenerator(name = "KRMS_TERM_RSLVR_PARM_SPEC_S")
40      @GeneratedValue(generator = "KRMS_TERM_RSLVR_PARM_SPEC_S")
41      @Id
42      @Column(name = "TERM_RSLVR_PARM_SPEC_ID")
43      private String id;
44  
45      @Column(name = "NM")
46      private String name;
47  
48      @Version
49      @Column(name="VER_NBR", length=8)
50      protected Long versionNumber;
51  
52      @ManyToOne()
53      @JoinColumn(name = "TERM_RSLVR_ID", referencedColumnName = "TERM_RSLVR_ID")
54      private TermResolverBo termResolver;
55  
56      /**
57       * Converts a mutable bo to it's immutable counterpart
58       *
59       * @param bo the mutable business object
60       * @return the immutable object
61       */
62      public static String to(TermResolverParameterSpecificationBo bo) {
63          if (bo == null) {
64              return null;
65          }
66  
67          return bo.name;
68      }
69  
70      /**
71       * Converts a immutable object to it's mutable bo counterpart
72       *
73       * @param resolver immutable object
74       * @param name
75       * @return the mutable bo
76       */
77      public static TermResolverParameterSpecificationBo from(TermResolverDefinition resolver, String name) {
78          if (resolver == null) {
79              return null;
80          }
81  
82          if (StringUtils.isBlank(name)) {
83              return null;
84          }
85  
86          TermResolverParameterSpecificationBo bo = new TermResolverParameterSpecificationBo();
87  
88          // we won't set termResolver here, it gets set in TermResolver.from
89  
90          bo.name = name;
91  
92          return bo;
93      }
94  
95      public String getId() {
96          return id;
97      }
98  
99      public void setId(String id) {
100         this.id = id;
101     }
102 
103     public String getTermResolverId() {
104         if (termResolver != null) {
105             return termResolver.getId();
106         }
107 
108         return null;
109     }
110 
111     public String getName() {
112         return name;
113     }
114 
115     public void setName(String name) {
116         this.name = name;
117     }
118 
119     public Long getVersionNumber() {
120         return versionNumber;
121     }
122 
123     public void setVersionNumber(Long versionNumber) {
124         this.versionNumber = versionNumber;
125     }
126 
127     public TermResolverBo getTermResolver() {
128         return termResolver;
129     }
130 
131     public void setTermResolver(TermResolverBo termResolver) {
132         this.termResolver = termResolver;
133     }
134 }