01: /*
02: * Copyright 2006-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: package org.kuali.module.kra.budget.service.impl;
18:
19: import java.util.ArrayList;
20: import java.util.HashMap;
21: import java.util.Iterator;
22: import java.util.List;
23: import java.util.Map;
24:
25: import org.kuali.core.service.BusinessObjectService;
26: import org.kuali.kfs.KFSPropertyConstants;
27: import org.kuali.module.kra.budget.bo.BudgetTask;
28: import org.kuali.module.kra.budget.service.BudgetTaskService;
29: import org.springframework.transaction.annotation.Transactional;
30:
31: @Transactional
32: public class BudgetTaskServiceImpl implements BudgetTaskService {
33:
34: private BusinessObjectService businessObjectService;
35:
36: /**
37: * @return Returns the budgetTaskDao.
38: */
39:
40: /*
41: * (non-Javadoc)
42: *
43: * @see org.kuali.service.BudgetPeriodService#getBudgetPeriod(java.lang.Long, java.lang.Integer)
44: */
45: public BudgetTask getBudgetTask(String documentNumber,
46: Integer budgetTaskSequenceNumber) {
47: return (BudgetTask) businessObjectService
48: .retrieve(new BudgetTask(documentNumber,
49: budgetTaskSequenceNumber));
50: }
51:
52: public BudgetTask getFirstBudgetTask(String documentNumber) {
53: Map fieldValues = new HashMap();
54: fieldValues.put(KFSPropertyConstants.DOCUMENT_NUMBER,
55: documentNumber);
56: List budgetTasks = new ArrayList(
57: businessObjectService
58: .findMatchingOrderBy(
59: BudgetTask.class,
60: fieldValues,
61: KFSPropertyConstants.BUDGET_TASK_SEQUENCE_NUMBER,
62: true));
63:
64: // there should always be a budgetTask by the time we get to here, so we want an exception thrown if there's not
65: return (BudgetTask) budgetTasks.get(0);
66: }
67:
68: public int getTaskIndex(Integer budgetTaskSequenceNumber,
69: List budgetTaskList) {
70: int taskIndexNumber = -1;
71: Iterator budgetTaskListIter = budgetTaskList.iterator();
72:
73: for (int i = 0; budgetTaskListIter.hasNext(); i++) {
74: BudgetTask budgetTask = (BudgetTask) budgetTaskListIter
75: .next();
76:
77: if (budgetTask.getBudgetTaskSequenceNumber().equals(
78: budgetTaskSequenceNumber)) {
79: taskIndexNumber = i;
80: break;
81: }
82: }
83:
84: return taskIndexNumber;
85: }
86:
87: public void setBusinessObjectService(
88: BusinessObjectService businessObjectService) {
89: this.businessObjectService = businessObjectService;
90: }
91: }
|