001/** 002 * Copyright 2004-2015 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 */ 016package org.kuali.kpme.core.groupkey; 017 018import java.util.ArrayList; 019import java.util.Collections; 020import java.util.List; 021 022import org.apache.commons.lang.StringUtils; 023import org.joda.time.LocalDate; 024import org.kuali.kpme.core.api.groupkey.HrGroupKey; 025import org.kuali.kpme.core.api.groupkey.HrGroupKeyService; 026import org.kuali.kpme.core.api.institution.Institution; 027import org.kuali.kpme.core.api.institution.service.InstitutionService; 028import org.kuali.kpme.core.api.location.Location; 029import org.kuali.kpme.core.api.location.service.LocationService; 030import org.kuali.kpme.core.groupkey.dao.HrGroupKeyDao; 031import org.kuali.rice.core.api.mo.ModelObjectUtils; 032import org.kuali.rice.krad.service.BusinessObjectService; 033import org.kuali.rice.location.api.campus.Campus; 034import org.kuali.rice.location.api.campus.CampusService; 035 036 037public class HrGroupKeyServiceImpl implements HrGroupKeyService { 038 private HrGroupKeyDao hrGroupKeyDao; 039 private LocationService locationService; 040 private InstitutionService institutionService; 041 private CampusService campusService; 042 private BusinessObjectService boService; 043 044 @Override 045 public HrGroupKey getHrGroupKeyById(String id) { 046 return HrGroupKeyBo.to(boService.findByPrimaryKey(HrGroupKeyBo.class, Collections.singletonMap("id", id))); 047 } 048 049 @Override 050 public HrGroupKey getHrGroupKey(String groupKeyCode, LocalDate asOfDate) { 051 return HrGroupKeyBo.to(hrGroupKeyDao.getHrGroupKey(groupKeyCode, asOfDate)); 052 } 053 054 @Override 055 public HrGroupKey populateSubObjects(HrGroupKey groupKey, LocalDate asOfDate) { 056 HrGroupKey.Builder builder = HrGroupKey.Builder.create(groupKey); 057 058 if (asOfDate == null) { 059 asOfDate = groupKey.getEffectiveLocalDate(); 060 } 061 if (StringUtils.isNotEmpty(builder.getLocationId())) { 062 builder.setLocation(Location.Builder.create(locationService.getLocation(builder.getLocationId(), asOfDate))); 063 } 064 if (StringUtils.isNotEmpty(builder.getInstitutionCode())) { 065 builder.setInstitution(Institution.Builder.create(institutionService.getInstitution(builder.getInstitutionCode(), asOfDate))); 066 } 067 if (StringUtils.isNotEmpty(builder.getCampusCode())) { 068 builder.setCampus(Campus.Builder.create(campusService.getCampus(builder.getCampusCode()))); 069 } 070 return builder.build(); 071 } 072 073 @Override 074 public List<HrGroupKey> getAllActiveHrGroupKeys(LocalDate asOfDate) { 075 if (asOfDate == null) { 076 asOfDate = LocalDate.now(); 077 } 078 079 return ModelObjectUtils.transform(hrGroupKeyDao.getAllActiveHrGroupKeys(asOfDate), HrGroupKeyBo.toImmutable); 080 } 081 082 083 public void setHrGroupKeyDao(HrGroupKeyDao hrGroupKeyDao) { 084 this.hrGroupKeyDao = hrGroupKeyDao; 085 } 086 087 public void setBoService(BusinessObjectService boService) { 088 this.boService = boService; 089 } 090 091 public void setLocationService(LocationService locationService) { 092 this.locationService = locationService; 093 } 094 095 public void setCampusService(CampusService campusService) { 096 this.campusService = campusService; 097 } 098 099 public void setInstitutionService(InstitutionService institutionService) { 100 this.institutionService = institutionService; 101 } 102 103 @Override 104 public List<HrGroupKey> getHrGroupKeysWithInstitution(String institutionCode, LocalDate asOfDate) { 105 if (asOfDate == null) { 106 asOfDate = LocalDate.now(); 107 } 108 109 return ModelObjectUtils.transform(hrGroupKeyDao.getHrGroupKeysWithInstitution(institutionCode, asOfDate), HrGroupKeyBo.toImmutable); 110 } 111 112 @Override 113 public List<HrGroupKey> getHrGroupKeysWithLocation(String locationId, LocalDate asOfDate) { 114 if (asOfDate == null) { 115 asOfDate = LocalDate.now(); 116 } 117 118 return ModelObjectUtils.transform(hrGroupKeyDao.getHrGroupKeysWithLocation(locationId, asOfDate), HrGroupKeyBo.toImmutable); 119 } 120 121 @Override 122 public List<HrGroupKey> getHrGroupKeysForLocations(List<String> locations, LocalDate asOfDate) { 123 if (asOfDate == null) { 124 asOfDate = LocalDate.now(); 125 } 126 127 return ModelObjectUtils.transform(hrGroupKeyDao.getHrGroupKeysWithLocations(locations, asOfDate), HrGroupKeyBo.toImmutable); 128 } 129}