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