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.util.Collection;
019: import java.util.HashMap;
020: import java.util.Map;
021:
022: import org.kuali.core.bo.user.KualiGroup;
023: import org.kuali.core.exceptions.GroupNotFoundException;
024: import org.kuali.core.service.BusinessObjectService;
025: import org.kuali.core.service.KualiGroupService;
026: import org.kuali.kfs.context.SpringContext;
027: import org.kuali.module.cg.bo.Award;
028: import org.kuali.module.cg.bo.AwardAccount;
029: import org.kuali.module.cg.dao.AwardDao;
030: import org.kuali.module.cg.service.AwardService;
031: import org.springframework.transaction.annotation.Transactional;
032:
033: /**
034: * This class exposes operations on Awards.
035: */
036: @Transactional
037: public class AwardServiceImpl implements AwardService {
038:
039: private AwardDao awardDao;
040: private KualiGroupService kualiGroupService;
041:
042: public void deleteAll() {
043: awardDao.deleteAll();
044: }
045:
046: public void setAwardDao(AwardDao awardDao) {
047: this .awardDao = awardDao;
048: }
049:
050: /**
051: * @see org.kuali.module.cg.service.AwardService#getKualiGroup(java.lang.String)
052: */
053: public KualiGroup getKualiGroup(String groupId) {
054: KualiGroup group = null;
055:
056: if (kualiGroupService.groupExists(groupId)) {
057: try {
058: group = kualiGroupService.getByGroupName(groupId);
059: } catch (GroupNotFoundException gnfe) {
060: group = null;
061: }
062: }
063:
064: return group;
065: }
066:
067: /**
068: * @return
069: */
070: public KualiGroupService getKualiGroupService() {
071: return kualiGroupService;
072: }
073:
074: /**
075: * @param kualiGroupService
076: */
077: public void setKualiGroupService(KualiGroupService kualiGroupService) {
078: this .kualiGroupService = kualiGroupService;
079: }
080:
081: /**
082: * @see org.kuali.module.cg.service.AwardService#save(org.kuali.module.cg.bo.Award)
083: */
084: public void save(Award award) {
085: awardDao.save(award);
086: }
087:
088: /**
089: * @see org.kuali.module.cg.service.AwardService#getAwardWorkgroupForAccount(java.lang.String, java.lang.String)
090: */
091: public String getAwardWorkgroupForAccount(String chart,
092: String account) {
093: BusinessObjectService boService = SpringContext
094: .getBean(BusinessObjectService.class);
095: Long maxProposalNumber;
096: Map awardAccountMap = new HashMap();
097: Map awardMap = new HashMap();
098: awardAccountMap.put("chartOfAccountsCode", chart);
099: awardAccountMap.put("accountNumber", account);
100: Collection proposals = boService.findMatchingOrderBy(
101: AwardAccount.class, awardAccountMap, "proposalNumber",
102: false);
103: if (proposals != null && !proposals.isEmpty()) {
104: maxProposalNumber = ((AwardAccount) proposals.iterator()
105: .next()).getProposalNumber();
106: awardMap.put("proposalNumber", maxProposalNumber);
107: return ((Award) boService.findByPrimaryKey(Award.class,
108: awardMap)).getWorkgroupName();
109: } else {
110: return null;
111: }
112:
113: }
114:
115: }
|