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.ld.batch.service.impl;
017    
018    import java.sql.Date;
019    
020    import org.kuali.kfs.gl.batch.service.PostTransaction;
021    import org.kuali.kfs.gl.businessobject.Transaction;
022    import org.kuali.kfs.module.ld.LaborConstants;
023    import org.kuali.kfs.module.ld.batch.service.LaborAccountingCycleCachingService;
024    import org.kuali.kfs.module.ld.businessobject.LaborTransaction;
025    import org.kuali.kfs.module.ld.businessobject.LedgerEntry;
026    import org.kuali.kfs.module.ld.service.LaborLedgerEntryService;
027    import org.kuali.kfs.sys.KFSConstants;
028    import org.kuali.kfs.sys.service.ReportWriterService;
029    import org.springframework.transaction.annotation.Transactional;
030    
031    /**
032     * The class is used to post a transaction to labor ledger entry table
033     */
034    @Transactional
035    public class LaborLedgerEntryPoster implements PostTransaction {
036        private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(LaborLedgerEntryPoster.class);
037        private LaborAccountingCycleCachingService laborAccountingCycleCachingService;
038    
039        /**
040         * @see org.kuali.kfs.gl.batch.service.PostTransaction#post(org.kuali.kfs.gl.businessobject.Transaction, int, java.util.Date)
041         */
042        public String post(Transaction transaction, int mode, java.util.Date postDate, ReportWriterService posterReportWriterService) {
043            String operationType = KFSConstants.OperationType.INSERT;
044            LedgerEntry ledgerEntry = new LedgerEntry((LaborTransaction) transaction);
045            // ObjectUtil.buildObject(ledgerEntry, transaction);
046    
047            try {
048                ledgerEntry.setTransactionLedgerEntrySequenceNumber(getLaborAccountingCycleCachingService().getMaxLaborSequenceNumber(ledgerEntry) + 1);
049                ledgerEntry.setTransactionPostingDate(new Date(postDate.getTime()));
050                getLaborAccountingCycleCachingService().insertLedgerEntry(ledgerEntry);
051            }
052            catch (Exception e) {
053                throw new RuntimeException(e);
054            }
055            
056            return operationType;
057        }
058    
059        /**
060         * @see org.kuali.kfs.gl.batch.service.PostTransaction#getDestinationName()
061         */
062        public String getDestinationName() {
063            return LaborConstants.DestinationNames.LEDGER_ENRTY;
064        }
065    
066        /**
067         * Gets the laborAccountingCycleCachingService attribute. 
068         * @return Returns the laborAccountingCycleCachingService.
069         */
070        public LaborAccountingCycleCachingService getLaborAccountingCycleCachingService() {
071            return laborAccountingCycleCachingService;
072        }
073    
074        /**
075         * Sets the laborAccountingCycleCachingService attribute value.
076         * @param laborAccountingCycleCachingService The laborAccountingCycleCachingService to set.
077         */
078        public void setLaborAccountingCycleCachingService(LaborAccountingCycleCachingService laborAccountingCycleCachingService) {
079            this.laborAccountingCycleCachingService = laborAccountingCycleCachingService;
080        }
081    }