001    /*
002     * Copyright 2011 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     */
016    package org.kuali.kfs.module.endow.businessobject.defaultvalue;
017    
018    import org.kuali.kfs.module.endow.EndowConstants;
019    import org.kuali.kfs.module.endow.EndowParameterKeyConstants;
020    import org.kuali.kfs.module.endow.businessobject.KEMID;
021    import org.kuali.kfs.sys.KFSConstants;
022    import org.kuali.kfs.sys.context.SpringContext;
023    import org.kuali.rice.kns.lookup.valueFinder.ValueFinder;
024    import org.kuali.rice.kns.service.ParameterService;
025    import org.kuali.rice.kns.service.SequenceAccessorService;
026    
027    public class NextKEMIDFinder implements ValueFinder {
028    
029        /**
030         * @see org.kuali.rice.kns.lookup.valueFinder.ValueFinder#getValue()
031         */
032        public String getValue() {
033            ParameterService parameterService = SpringContext.getBean(ParameterService.class);
034            String kemidValueSystemParam = parameterService.getParameterValue(KEMID.class, EndowParameterKeyConstants.KEMID_VALUE);
035    
036            if (EndowConstants.KemidValueOptions.AUTOMATIC.equals(kemidValueSystemParam)) {
037                return getLongValue().toString();
038            }
039            else
040                return KFSConstants.EMPTY_STRING;
041        }
042    
043        /**
044         * Gets the next sequence number as a long.
045         * 
046         * @return next sequence number as a long
047         */
048        public static Long getLongValue() {
049    
050            SequenceAccessorService sequenceAccessorService = SpringContext.getBean(SequenceAccessorService.class);
051            return sequenceAccessorService.getNextAvailableSequenceNumber(EndowConstants.Sequences.END_KEMID_SEQ, KEMID.class);
052        }
053    
054    }