001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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.module.cg.service.impl;
017:
018: import java.sql.Date;
019: import java.util.Collection;
020:
021: import org.kuali.core.service.DateTimeService;
022: import org.kuali.module.cg.bo.Award;
023: import org.kuali.module.cg.bo.Close;
024: import org.kuali.module.cg.bo.Proposal;
025: import org.kuali.module.cg.dao.AwardDao;
026: import org.kuali.module.cg.dao.CloseDao;
027: import org.kuali.module.cg.dao.ProposalDao;
028: import org.kuali.module.cg.service.CloseService;
029: import org.springframework.transaction.annotation.Transactional;
030:
031: @Transactional
032: public class CloseServiceImpl implements CloseService {
033:
034: private AwardDao awardDao;
035: private ProposalDao proposalDao;
036: private CloseDao closeDao;
037: private DateTimeService dateTimeService;
038:
039: /**
040: * <ul>
041: * <li>Get the max proposal_close_number in cg_prpsl_close_t.</li>
042: * <li>Get the Close with that max_close_number.</li>
043: * <li>If todays date is the same as the user_initiate_date on that Close, continue. Else, break.</li>
044: * <li>Get all proposals with a null closing_date and a submission_date <= the last_closed_date of the Close with the
045: * max_proposal_close number.</li>
046: * <li>Save the number of proposals that come back.</li>
047: * <li>Update each of these proposals setting the close_date to todays date.</li>
048: * <li>Get all awards with a null closing_date, an entry_date <= the last_closed_date of the Close with the max_close number
049: * and a status_code not equal to 'U'.</li>
050: * <li>Save the number of awards that come back.</li>
051: * <li>Update each of these awards setting the close_date to todays date.</li>
052: * <li>Update the Close with that max_close_number setting the proposal_closed_count to the number of proposals brought back
053: * above and the award_closed_count to the number of awards brought back above.</li>
054: * <li>Save the Close.</li>
055: * </ul>
056: *
057: * @see org.kuali.module.cg.service.CloseService#close()
058: */
059: public void close() {
060:
061: Close max = closeDao.getMaxApprovedClose();
062: Date today = dateTimeService.getCurrentSqlDateMidnight();
063:
064: if (null == max) { // no closes at all. Gotta wait until we get an approved one.
065: return;
066: }
067:
068: if (!today.equals(max.getUserInitiatedCloseDate())) {
069: return;
070: }
071:
072: Collection<Proposal> proposals = proposalDao
073: .getProposalsToClose(max);
074: Long proposalCloseCount = new Long(proposals.size());
075: for (Proposal p : proposals) {
076: p.setProposalClosingDate(today);
077: proposalDao.save(p);
078: }
079:
080: Collection<Award> awards = awardDao.getAwardsToClose(max);
081: Long awardCloseCount = new Long(awards.size());
082: for (Award a : awards) {
083: a.setAwardClosingDate(today);
084: awardDao.save(a);
085: }
086:
087: max.setAwardClosedCount(awardCloseCount);
088: max.setProposalClosedCount(proposalCloseCount);
089:
090: closeDao.save(max);
091:
092: }
093:
094: public Close getMostRecentClose() {
095: return closeDao.getMaxApprovedClose();
096: }
097:
098: public void save(Close close) {
099: closeDao.save(close);
100: }
101:
102: public void setAwardDao(AwardDao awardDao) {
103: this .awardDao = awardDao;
104: }
105:
106: public void setDateTimeService(DateTimeService dateTimeService) {
107: this .dateTimeService = dateTimeService;
108: }
109:
110: public void setCloseDao(CloseDao closeDao) {
111: this .closeDao = closeDao;
112: }
113:
114: public void setProposalDao(ProposalDao proposalDao) {
115: this.proposalDao = proposalDao;
116: }
117:
118: }
|