01: /*
02: * Copyright 2005-2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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: /*
17: * Created on Oct 12, 2005
18: *
19: */
20: package org.kuali.module.gl.batch.poster.impl;
21:
22: import java.util.Date;
23:
24: import org.apache.ojb.broker.metadata.MetadataManager;
25: import org.kuali.module.gl.GLConstants;
26: import org.kuali.module.gl.batch.poster.PostTransaction;
27: import org.kuali.module.gl.bo.Reversal;
28: import org.kuali.module.gl.bo.Transaction;
29: import org.kuali.module.gl.dao.ReversalDao;
30: import org.springframework.transaction.annotation.Transactional;
31:
32: /**
33: * An implementation of PostTransaction which posts any reversals that need to be created for the transaction
34: */
35: @Transactional
36: public class PostReversal implements PostTransaction {
37: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
38: .getLogger(PostReversal.class);
39:
40: private ReversalDao reversalDao;
41:
42: public void setReversalDao(ReversalDao red) {
43: reversalDao = red;
44: }
45:
46: /**
47: * Constructs a PostReversal instance
48: */
49: public PostReversal() {
50: super ();
51: }
52:
53: /**
54: * If the transaction has a reversal date, saves a new reversal based on the transaction
55: *
56: * @param t the transaction which is being posted
57: * @param mode the mode the poster is currently running in
58: * @param postDate the date this transaction should post to
59: * @return the accomplished post type
60: * @see org.kuali.module.gl.batch.poster.PostTransaction#post(org.kuali.module.gl.bo.Transaction, int, java.util.Date)
61: */
62: public String post(Transaction t, int mode, Date postDate) {
63: LOG.debug("post() started");
64:
65: if (t.getFinancialDocumentReversalDate() == null) {
66: // No need to post this
67: return GLConstants.EMPTY_CODE;
68: }
69:
70: Reversal re = new Reversal(t);
71:
72: // Make sure the row will be unique when adding to the reversal table by
73: // adjusting the transaction sequence id
74: int maxSequenceId = reversalDao.getMaxSequenceNumber(t);
75: re.setTransactionLedgerEntrySequenceNumber(new Integer(
76: maxSequenceId + 1));
77:
78: reversalDao.save(re);
79:
80: return GLConstants.INSERT_CODE;
81: }
82:
83: /**
84: * @see org.kuali.module.gl.batch.poster.PostTransaction#getDestinationName()
85: */
86: public String getDestinationName() {
87: return MetadataManager.getInstance().getGlobalRepository()
88: .getDescriptorFor(Reversal.class).getFullTableName();
89: }
90: }
|