View Javadoc

1   /**
2    * Copyright 2005-2013 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.reference.ReferenceObjectBinding;
22  import org.kuali.rice.krms.api.repository.reference.ReferenceObjectBindingContract;
23  
24  /**
25   * The mutable implementation of the @{link ReferenceObjectBindingContract} interface, the counterpart to the immutable implementation {@link ReferenceObjectBinding}.
26   * @author Kuali Rice Team (rice.collab@kuali.org)
27   * 
28   */
29  public class ReferenceObjectBindingBo
30      extends PersistableBusinessObjectBase
31      implements ReferenceObjectBindingContract
32  {
33  
34      private String collectionName;
35      private String krmsDiscriminatorType;
36      private String krmsObjectId;
37      private String namespace;
38      private String referenceDiscriminatorType;
39      private String referenceObjectId;
40      private String id;
41      private boolean active;
42      private Long versionNumber;
43      private SequenceAccessorService sequenceAccessorService;
44  
45      /**
46       * Default Constructor
47       * 
48       */
49      public ReferenceObjectBindingBo() {
50      }
51  
52      @Override
53      public String getCollectionName() {
54          return this.collectionName;
55      }
56  
57      @Override
58      public String getKrmsDiscriminatorType() {
59          return this.krmsDiscriminatorType;
60      }
61  
62      @Override
63      public String getKrmsObjectId() {
64          return this.krmsObjectId;
65      }
66  
67      @Override
68      public String getNamespace() {
69          return this.namespace;
70      }
71  
72      @Override
73      public String getReferenceDiscriminatorType() {
74          return this.referenceDiscriminatorType;
75      }
76  
77      @Override
78      public String getReferenceObjectId() {
79          return this.referenceObjectId;
80      }
81  
82      @Override
83      public String getId() {
84          return this.id;
85      }
86  
87      @Override
88      public boolean isActive() {
89          return this.active;
90      }
91  
92      @Override
93      public Long getVersionNumber() {
94          return this.versionNumber;
95      }
96  
97      /**
98       * Sets the value of collectionName on this builder to the given value.
99       * 
100      * @param collectionName the collectionName value to set.
101      * 
102      */
103     public void setCollectionName(String collectionName) {
104         this.collectionName = collectionName;
105     }
106 
107     /**
108      * Sets the value of krmsDiscriminatorType on this builder to the given value.
109      * 
110      * @param krmsDiscriminatorType the krmsDiscriminatorType value to set.
111      * 
112      */
113     public void setKrmsDiscriminatorType(String krmsDiscriminatorType) {
114         this.krmsDiscriminatorType = krmsDiscriminatorType;
115     }
116 
117     /**
118      * Sets the value of krmsObjectId on this builder to the given value.
119      * 
120      * @param krmsObjectId the krmsObjectId value to set.
121      * 
122      */
123     public void setKrmsObjectId(String krmsObjectId) {
124         this.krmsObjectId = krmsObjectId;
125     }
126 
127     /**
128      * Sets the value of namespace on this builder to the given value.
129      * 
130      * @param namespace the namespace value to set.
131      * 
132      */
133     public void setNamespace(String namespace) {
134         this.namespace = namespace;
135     }
136 
137     /**
138      * Sets the value of referenceDiscriminatorType on this builder to the given value.
139      * 
140      * @param referenceDiscriminatorType the referenceDiscriminatorType value to set.
141      * 
142      */
143     public void setReferenceDiscriminatorType(String referenceDiscriminatorType) {
144         this.referenceDiscriminatorType = referenceDiscriminatorType;
145     }
146 
147     /**
148      * Sets the value of referenceObjectId on this builder to the given value.
149      * 
150      * @param referenceObjectId the referenceObjectId value to set.
151      * 
152      */
153     public void setReferenceObjectId(String referenceObjectId) {
154         this.referenceObjectId = referenceObjectId;
155     }
156 
157     /**
158      * Sets the value of id on this builder to the given value.
159      * 
160      * @param id the id value to set.
161      * 
162      */
163     public void setId(String id) {
164         this.id = id;
165     }
166 
167     /**
168      * Sets the value of active on this builder to the given value.
169      * 
170      * @param active the active value to set.
171      * 
172      */
173     public void setActive(boolean active) {
174         this.active = active;
175     }
176 
177     /**
178      * Sets the value of versionNumber on this builder to the given value.
179      * 
180      * @param versionNumber the versionNumber value to set.
181      * 
182      */
183     public void setVersionNumber(Long versionNumber) {
184         this.versionNumber = versionNumber;
185     }
186 
187     /**
188      * Converts a mutable {@link ReferenceObjectBindingBo} to its immutable counterpart, {@link ReferenceObjectBinding}.
189      * @param referenceObjectBindingBo the mutable business object.
190      * @return a {@link ReferenceObjectBinding} the immutable object.
191      * 
192      */
193     public static ReferenceObjectBinding to(ReferenceObjectBindingBo referenceObjectBindingBo) {
194         if (referenceObjectBindingBo == null) { return null; }
195         return ReferenceObjectBinding.Builder.create(referenceObjectBindingBo).build();
196     }
197 
198     /**
199      * Converts a immutable {@link ReferenceObjectBinding} to its mutable {@link ReferenceObjectBindingBo} counterpart.
200      * @param referenceObjectBinding the immutable object.
201      * @return a {@link ReferenceObjectBindingBo} the mutable ReferenceObjectBindingBo.
202      * 
203      */
204     public static org.kuali.rice.krms.impl.repository.ReferenceObjectBindingBo from(ReferenceObjectBinding referenceObjectBinding) {
205         if (referenceObjectBinding == null) return null;
206         ReferenceObjectBindingBo referenceObjectBindingBo = new ReferenceObjectBindingBo();
207         referenceObjectBindingBo.setCollectionName(referenceObjectBinding.getCollectionName());
208         referenceObjectBindingBo.setKrmsDiscriminatorType(referenceObjectBinding.getKrmsDiscriminatorType());
209         referenceObjectBindingBo.setKrmsObjectId(referenceObjectBinding.getKrmsObjectId());
210         referenceObjectBindingBo.setNamespace(referenceObjectBinding.getNamespace());
211         referenceObjectBindingBo.setReferenceDiscriminatorType(referenceObjectBinding.getReferenceDiscriminatorType());
212         referenceObjectBindingBo.setReferenceObjectId(referenceObjectBinding.getReferenceObjectId());
213         referenceObjectBindingBo.setId(referenceObjectBinding.getId());
214         referenceObjectBindingBo.setActive(referenceObjectBinding.isActive());
215         referenceObjectBindingBo.setVersionNumber(referenceObjectBinding.getVersionNumber());
216         // TODO collections, etc.
217         return referenceObjectBindingBo;
218     }
219 
220     /**
221      * Returns the next available id for the given table and class.
222      * @return String the next available id for the given table and class.
223      * 
224      */
225     private String getNewId(String table, Class clazz) {
226         if (sequenceAccessorService == null) {
227             sequenceAccessorService = KRADServiceLocator.getSequenceAccessorService();
228         }
229         Long id = sequenceAccessorService.getNextAvailableSequenceNumber(table, clazz);
230         return id.toString();
231     }
232 
233     /**
234      * Set the SequenceAccessorService, useful for testing.
235      * @param sas SequenceAccessorService to use for getNewId.
236      * 
237      */
238     public void setSequenceAccessorService(SequenceAccessorService sas) {
239         sequenceAccessorService = sas;
240     }
241 
242     public SequenceAccessorService getSequenceAccessorService() {
243         return sequenceAccessorService;
244     }
245 
246 }