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.bc.document.dataaccess.impl; 017 018 import java.math.BigDecimal; 019 import java.util.Iterator; 020 021 import org.apache.ojb.broker.query.Criteria; 022 import org.apache.ojb.broker.query.QueryFactory; 023 import org.apache.ojb.broker.query.ReportQueryByCriteria; 024 import org.kuali.kfs.module.bc.BCConstants; 025 import org.kuali.kfs.module.bc.BCPropertyConstants; 026 import org.kuali.kfs.module.bc.businessobject.BudgetConstructionPayRateHolding; 027 import org.kuali.kfs.module.bc.businessobject.BudgetConstructionPosition; 028 import org.kuali.kfs.module.bc.businessobject.PendingBudgetConstructionAppointmentFunding; 029 import org.kuali.kfs.module.bc.document.dataaccess.PayrateExportDao; 030 import org.kuali.kfs.sys.KFSPropertyConstants; 031 import org.kuali.rice.kns.dao.impl.PlatformAwareDaoBaseOjb; 032 033 public class PayrateExportDaoOjb extends PlatformAwareDaoBaseOjb implements PayrateExportDao { 034 035 036 /** 037 * 038 * @see org.kuali.kfs.module.bc.document.dataaccess.PayrateExportDao#isValidPositionUnionCode(java.lang.String) 039 */ 040 public boolean isValidPositionUnionCode(String positionUnionCode) { 041 Criteria criteria = new Criteria(); 042 043 criteria.addEqualTo(BCPropertyConstants.POSITION_UNION_CODE, positionUnionCode); 044 045 if (getPersistenceBrokerTemplate().getCollectionByQuery(QueryFactory.newQuery(BudgetConstructionPosition.class, criteria)).size() == 0) return false; 046 047 return true; 048 } 049 050 /** 051 * 052 * @see org.kuali.kfs.module.bc.document.dataaccess.PayrateExportDao#buildPayRateHoldingRows(java.lang.Integer, java.lang.String, java.lang.String) 053 */ 054 public Integer buildPayRateHoldingRows(Integer budgetYear, String positionUnionCode, String principalId) { 055 Integer rowsSaved = 0; 056 057 Iterator<Object[]> payRateRows = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(queryForPayrateHoldingRecords(budgetYear, positionUnionCode)); 058 while (payRateRows.hasNext()) 059 { 060 Object[] payRateRow = payRateRows.next(); 061 BudgetConstructionPayRateHolding payRateHolder = new BudgetConstructionPayRateHolding(); 062 payRateHolder.setAppointmentRequestedPayRate(new BigDecimal(0)); 063 payRateHolder.setEmplid((String) payRateRow[0]); 064 payRateHolder.setPositionNumber((String) payRateRow[1]); 065 payRateHolder.setName((String) payRateRow[2]); 066 payRateHolder.setSetidSalary((String) payRateRow[3]); 067 payRateHolder.setSalaryAdministrationPlan((String) payRateRow[4]); 068 payRateHolder.setGrade((String) payRateRow[5]); 069 payRateHolder.setUnionCode((String) payRateRow[6]); 070 payRateHolder.setPrincipalId(principalId); 071 072 getPersistenceBrokerTemplate().store(payRateHolder); 073 rowsSaved = rowsSaved+1; 074 } 075 return rowsSaved; 076 } 077 078 /** 079 * Selects the unique list of PendingBudgetConstructionAppointmentFunding to populate the payrate holding table for export 080 * This method... 081 * @param budgetYear 082 * @param positionUnionCode 083 * @return 084 */ 085 protected ReportQueryByCriteria queryForPayrateHoldingRecords(Integer budgetYear, String positionUnionCode) { 086 Criteria criteria = new Criteria(); 087 088 criteria.addEqualTo(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, budgetYear); 089 criteria.addNotEqualTo(KFSPropertyConstants.EMPLID, BCConstants.VACANT_EMPLID); 090 criteria.addEqualTo(KFSPropertyConstants.ACTIVE, "Y"); 091 criteria.addEqualTo(BCPropertyConstants.BUDGET_CONSTRUCTION_POSITION + "." + BCPropertyConstants.POSITION_UNION_CODE, positionUnionCode); 092 criteria.addEqualTo(BCPropertyConstants.BUDGET_CONSTRUCTION_POSITION + "." + BCPropertyConstants.CONFIDENTIAL_POSITION, "N"); 093 094 095 ReportQueryByCriteria queryId = new ReportQueryByCriteria(PendingBudgetConstructionAppointmentFunding.class, criteria, true); 096 097 String[] selectList = new String[7]; 098 selectList[0] = KFSPropertyConstants.EMPLID; 099 selectList[1] = KFSPropertyConstants.POSITION_NUMBER; 100 selectList[2] = BCPropertyConstants.BUDGET_CONSTRUCTION_INTENDED_INCUMBENT + "." + KFSPropertyConstants.PERSON_NAME; 101 selectList[3] = BCPropertyConstants.BUDGET_CONSTRUCTION_POSITION + "." + BCPropertyConstants.SET_SALARY_ID; 102 selectList[4] = BCPropertyConstants.BUDGET_CONSTRUCTION_POSITION + "." + BCPropertyConstants.POSITION_SALARY_PLAN_DEFAULT; 103 selectList[5] = BCPropertyConstants.BUDGET_CONSTRUCTION_POSITION + "." + BCPropertyConstants.POSITION_GRADE_DEFAULT; 104 selectList[6] = BCPropertyConstants.BUDGET_CONSTRUCTION_POSITION + "." + BCPropertyConstants.POSITION_UNION_CODE; 105 106 queryId.setAttributes(selectList); 107 108 return queryId; 109 } 110 } 111