001/**
002 * Copyright 2005-2016 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.krms.impl.repository;
017
018import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
019import org.kuali.rice.krad.service.KRADServiceLocator;
020import org.kuali.rice.krad.service.SequenceAccessorService;
021import org.kuali.rice.krms.api.repository.language.NaturalLanguageUsage;
022import org.kuali.rice.krms.api.repository.language.NaturalLanguageUsageContract;
023
024/**
025 * The mutable implementation of the @{link NaturalLanguageUsageContract} interface, the counterpart to the immutable implementation {@link NaturalLanguageUsage}.
026 * @author Kuali Rice Team (rice.collab@kuali.org)
027 * 
028 */
029public class NaturalLanguageUsageBo
030    extends PersistableBusinessObjectBase
031    implements NaturalLanguageUsageContract
032{
033
034    private String name;
035    private String description;
036    private String namespace;
037    private String id;
038    private boolean active;
039    private Long versionNumber;
040    private SequenceAccessorService sequenceAccessorService;
041
042    /**
043     * Default Constructor
044     * 
045     */
046    public NaturalLanguageUsageBo() {
047    }
048
049    @Override
050    public String getName() {
051        return this.name;
052    }
053
054    @Override
055    public String getDescription() {
056        return this.description;
057    }
058
059    @Override
060    public String getNamespace() {
061        return this.namespace;
062    }
063
064    @Override
065    public String getId() {
066        return this.id;
067    }
068
069    @Override
070    public boolean isActive() {
071        return this.active;
072    }
073
074    @Override
075    public Long getVersionNumber() {
076        return this.versionNumber;
077    }
078
079    /**
080     * Sets the value of name on this builder to the given value.
081     * 
082     * @param name the name value to set.
083     * 
084     */
085    public void setName(String name) {
086        this.name = name;
087    }
088
089    /**
090     * Sets the value of description on this builder to the given value.
091     * 
092     * @param description the description value to set.
093     * 
094     */
095    public void setDescription(String description) {
096        this.description = description;
097    }
098
099    /**
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}