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.service.impl;
017
018 import java.util.HashMap;
019 import java.util.Map;
020
021 import org.kuali.kfs.module.bc.businessobject.BudgetConstructionIntendedIncumbent;
022 import org.kuali.kfs.module.bc.businessobject.Incumbent;
023 import org.kuali.kfs.module.bc.exception.BudgetIncumbentAlreadyExistsException;
024 import org.kuali.kfs.module.bc.service.BudgetConstructionIntendedIncumbentService;
025 import org.kuali.kfs.module.bc.service.HumanResourcesPayrollService;
026 import org.kuali.kfs.sys.KFSPropertyConstants;
027 import org.kuali.rice.kns.service.BusinessObjectService;
028 import org.kuali.rice.kns.util.spring.Logged;
029
030 /**
031 * implements the service methods defined in BudgetConstructionIntendedIncumbentService
032 */
033 public class BudgetConstructionIntendedIncumbentServiceImpl implements BudgetConstructionIntendedIncumbentService {
034 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(BudgetConstructionIntendedIncumbentServiceImpl.class);
035
036 private BusinessObjectService businessObjectService;
037 private HumanResourcesPayrollService humanResourcesPayrollService;
038
039 /**
040 * @see org.kuali.kfs.module.bc.service.BudgetConstructionIntendedIncumbentService#pullNewIncumbentFromExternal(java.lang.String)
041 */
042 public synchronized void pullNewIncumbentFromExternal(String emplid) throws BudgetIncumbentAlreadyExistsException {
043 // call humanResourcesPayrollService service to pull record
044 Incumbent incumbent = humanResourcesPayrollService.getIncumbent(emplid);
045
046 // populate BudgetConstructionIntendedIncumbent
047 BudgetConstructionIntendedIncumbent bcIncumbent = new BudgetConstructionIntendedIncumbent();
048 bcIncumbent.setEmplid(incumbent.getEmplid());
049 bcIncumbent.setName(incumbent.getName());
050 bcIncumbent.setIuClassificationLevel("TL");
051 bcIncumbent.setSetidSalary("XXXXX");
052 bcIncumbent.setSalaryAdministrationPlan("XXX");
053 bcIncumbent.setGrade("YYY");
054
055 bcIncumbent.setActive(Boolean.TRUE);
056
057 // check if incumbent already exists in budget incumbent table, if not add incumbent
058 BudgetConstructionIntendedIncumbent retrievedIncumbent = getByPrimaryId(emplid);
059 if (retrievedIncumbent != null) {
060 throw new BudgetIncumbentAlreadyExistsException(emplid);
061 }
062
063 businessObjectService.save(bcIncumbent);
064 }
065
066 /**
067 * @see org.kuali.kfs.module.bc.service.BudgetConstructionIntendedIncumbentService#refreshIncumbentFromExternal(java.lang.String)
068 */
069 public void refreshIncumbentFromExternal(String emplid) {
070 // call humanResourcesPayrollService service to pull record
071 Incumbent incumbent = humanResourcesPayrollService.getIncumbent(emplid);
072
073 // populate BudgetConstructionIntendedIncumbent
074 BudgetConstructionIntendedIncumbent bcIncumbent = new BudgetConstructionIntendedIncumbent();
075 bcIncumbent.setEmplid(incumbent.getEmplid());
076 bcIncumbent.setName(incumbent.getName());
077
078 // update budget record
079 BudgetConstructionIntendedIncumbent retrievedIncumbent = getByPrimaryId(emplid);
080 bcIncumbent.setVersionNumber(retrievedIncumbent.getVersionNumber());
081 bcIncumbent.setIuClassificationLevel("TL");
082 bcIncumbent.setSetidSalary("XXXXX");
083 bcIncumbent.setSalaryAdministrationPlan("XXX");
084 bcIncumbent.setGrade("YYY");
085 bcIncumbent.setActive(retrievedIncumbent.isActive());
086
087 businessObjectService.save(bcIncumbent);
088 }
089
090 /**
091 * @see org.kuali.kfs.module.bc.service.BudgetConstructionIntendedIncumbentService#getByPrimaryId(java.lang.String)
092 */
093 public BudgetConstructionIntendedIncumbent getByPrimaryId(String emplid) {
094 Map<String, Object> primaryKeys = new HashMap<String, Object>();
095 primaryKeys.put(KFSPropertyConstants.EMPLID, emplid);
096
097 return (BudgetConstructionIntendedIncumbent) businessObjectService.findByPrimaryKey(BudgetConstructionIntendedIncumbent.class, primaryKeys);
098 }
099
100 /**
101 * Sets the businessObjectService attribute value.
102 *
103 * @param businessObjectService The businessObjectService to set.
104 */
105 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
106 this.businessObjectService = businessObjectService;
107 }
108
109 /**
110 * Sets the humanResourcesPayrollService attribute value.
111 *
112 * @param humanResourcesPayrollService The humanResourcesPayrollService to set.
113 */
114 public void setHumanResourcesPayrollService(HumanResourcesPayrollService humanResourcesPayrollService) {
115 this.humanResourcesPayrollService = humanResourcesPayrollService;
116 }
117 }
118