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.krms.impl.repository;
17  
18  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
19  import org.kuali.rice.krad.service.KRADServiceLocator;
20  import org.kuali.rice.krad.service.SequenceAccessorService;
21  import org.kuali.rice.krms.api.repository.language.NaturalLanguageTemplateAttribute;
22  import org.kuali.rice.krms.api.repository.language.NaturalLanguageTemplateAttributeContract;
23  import org.kuali.rice.krms.api.repository.type.KrmsAttributeDefinitionContract;
24  
25  /**
26   * The mutable implementation of the @{link NaturalLanguageTemplateAttributeContract} interface, the counterpart to the immutable implementation {@link NaturalLanguageTemplateAttribute}.
27   * @author Kuali Rice Team (rice.collab@kuali.org)
28   * 
29   */
30  public class NaturalLanguageTemplateAttributeBo
31      extends PersistableBusinessObjectBase
32      implements NaturalLanguageTemplateAttributeContract
33  {
34  
35      private String naturalLanguageTemplateId;
36      private Long versionNumber;
37      private String value;
38      private String attributeDefinitionId;
39      private KrmsAttributeDefinitionContract attributeDefinition;
40      private String id;
41      private SequenceAccessorService sequenceAccessorService;
42  
43      /**
44       * Default Constructor
45       * 
46       */
47      public NaturalLanguageTemplateAttributeBo() {
48      }
49  
50      @Override
51      public String getNaturalLanguageTemplateId() {
52          return this.naturalLanguageTemplateId;
53      }
54  
55      @Override
56      public Long getVersionNumber() {
57          return this.versionNumber;
58      }
59  
60      @Override
61      public String getValue() {
62          return this.value;
63      }
64  
65      @Override
66      public String getAttributeDefinitionId() {
67          return this.attributeDefinitionId;
68      }
69  
70      @Override
71      public KrmsAttributeDefinitionContract getAttributeDefinition() {
72          return this.attributeDefinition;
73      }
74  
75      @Override
76      public String getId() {
77          return this.id;
78      }
79  
80      /**
81       * Sets the value of naturalLanguageTemplateId on this builder to the given value.
82       * 
83       * @param naturalLanguageTemplateId the naturalLanguageTemplateId value to set.
84       * 
85       */
86      public void setNaturalLanguageTemplateId(String naturalLanguageTemplateId) {
87          this.naturalLanguageTemplateId = naturalLanguageTemplateId;
88      }
89  
90      /**
91       * Sets the value of versionNumber on this builder to the given value.
92       * 
93       * @param versionNumber the versionNumber value to set.
94       * 
95       */
96      public void setVersionNumber(Long versionNumber) {
97          this.versionNumber = versionNumber;
98      }
99  
100     /**
101      * Sets the value of value on this builder to the given value.
102      * 
103      * @param value the value value to set.
104      * 
105      */
106     public void setValue(String value) {
107         this.value = value;
108     }
109 
110     /**
111      * Sets the value of attributeDefinitionId on this builder to the given value.
112      * 
113      * @param attributeDefinitionId the attributeDefinitionId value to set.
114      * 
115      */
116     public void setAttributeDefinitionId(String attributeDefinitionId) {
117         this.attributeDefinitionId = attributeDefinitionId;
118     }
119 
120     /**
121      * Sets the value of attributeDefinition on this builder to the given value.
122      * 
123      * @param attributeDefinition the attributeDefinition value to set.
124      * 
125      */
126     public void setAttributeDefinition(KrmsAttributeDefinitionContract attributeDefinition) {
127         this.attributeDefinition = attributeDefinition;
128     }
129 
130     /**
131      * Sets the value of id on this builder to the given value.
132      * 
133      * @param id the id value to set.
134      * 
135      */
136     public void setId(String id) {
137         this.id = id;
138     }
139 
140     /**
141      * Converts a mutable {@link NaturalLanguageTemplateAttributeBo} to its immutable counterpart, {@link NaturalLanguageTemplateAttribute}.
142      * @param naturalLanguageTemplateAttributeBo the mutable business object.
143      * @return a {@link NaturalLanguageTemplateAttribute} the immutable object.
144      * 
145      */
146     public static NaturalLanguageTemplateAttribute to(NaturalLanguageTemplateAttributeBo naturalLanguageTemplateAttributeBo) {
147         if (naturalLanguageTemplateAttributeBo == null) { return null; }
148         return NaturalLanguageTemplateAttribute.Builder.create(naturalLanguageTemplateAttributeBo).build();
149     }
150 
151     /**
152      * Converts a immutable {@link NaturalLanguageTemplateAttribute} to its mutable {@link NaturalLanguageTemplateAttributeBo} counterpart.
153      * @param naturalLanguageTemplateAttribute the immutable object.
154      * @return a {@link NaturalLanguageTemplateAttributeBo} the mutable NaturalLanguageTemplateAttributeBo.
155      * 
156      */
157     public static org.kuali.rice.krms.impl.repository.NaturalLanguageTemplateAttributeBo from(NaturalLanguageTemplateAttribute naturalLanguageTemplateAttribute) {
158         if (naturalLanguageTemplateAttribute == null) return null;
159         NaturalLanguageTemplateAttributeBo naturalLanguageTemplateAttributeBo = new NaturalLanguageTemplateAttributeBo();
160         naturalLanguageTemplateAttributeBo.setNaturalLanguageTemplateId(naturalLanguageTemplateAttribute.getNaturalLanguageTemplateId());
161         naturalLanguageTemplateAttributeBo.setVersionNumber(naturalLanguageTemplateAttribute.getVersionNumber());
162         naturalLanguageTemplateAttributeBo.setValue(naturalLanguageTemplateAttribute.getValue());
163         naturalLanguageTemplateAttributeBo.setAttributeDefinitionId(naturalLanguageTemplateAttribute.getAttributeDefinitionId());
164         naturalLanguageTemplateAttributeBo.setAttributeDefinition(naturalLanguageTemplateAttribute.getAttributeDefinition());
165         naturalLanguageTemplateAttributeBo.setId(naturalLanguageTemplateAttribute.getId());
166         // TODO collections, etc.
167         return naturalLanguageTemplateAttributeBo;
168     }
169 
170     /**
171      * Returns the next available id for the given table and class.
172      * @return String the next available id for the given table and class.
173      * 
174      */
175     private String getNewId(String table, Class clazz) {
176         if (sequenceAccessorService == null) {
177             sequenceAccessorService = KRADServiceLocator.getSequenceAccessorService();
178         }
179         Long id = sequenceAccessorService.getNextAvailableSequenceNumber(table, clazz);
180         return id.toString();
181     }
182 
183     /**
184      * Set the SequenceAccessorService, useful for testing.
185      * @param sas SequenceAccessorService to use for getNewId.
186      * 
187      */
188     public void setSequenceAccessorService(SequenceAccessorService sas) {
189         sequenceAccessorService = sas;
190     }
191 
192     public SequenceAccessorService getSequenceAccessorService() {
193         return sequenceAccessorService;
194     }
195 
196 }