1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.core.groupkey;
17
18 import java.util.ArrayList;
19 import java.util.Collections;
20 import java.util.List;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.joda.time.LocalDate;
24 import org.kuali.kpme.core.api.groupkey.HrGroupKey;
25 import org.kuali.kpme.core.api.groupkey.HrGroupKeyService;
26 import org.kuali.kpme.core.api.institution.Institution;
27 import org.kuali.kpme.core.api.institution.service.InstitutionService;
28 import org.kuali.kpme.core.api.location.Location;
29 import org.kuali.kpme.core.api.location.service.LocationService;
30 import org.kuali.kpme.core.groupkey.dao.HrGroupKeyDao;
31 import org.kuali.rice.core.api.mo.ModelObjectUtils;
32 import org.kuali.rice.krad.service.BusinessObjectService;
33 import org.kuali.rice.location.api.campus.Campus;
34 import org.kuali.rice.location.api.campus.CampusService;
35
36
37 public class HrGroupKeyServiceImpl implements HrGroupKeyService {
38 private HrGroupKeyDao hrGroupKeyDao;
39 private LocationService locationService;
40 private InstitutionService institutionService;
41 private CampusService campusService;
42 private BusinessObjectService boService;
43
44 @Override
45 public HrGroupKey getHrGroupKeyById(String id) {
46 return HrGroupKeyBo.to(boService.findByPrimaryKey(HrGroupKeyBo.class, Collections.singletonMap("id", id)));
47 }
48
49 @Override
50 public HrGroupKey getHrGroupKey(String groupKeyCode, LocalDate asOfDate) {
51 return HrGroupKeyBo.to(hrGroupKeyDao.getHrGroupKey(groupKeyCode, asOfDate));
52 }
53
54 @Override
55 public HrGroupKey populateSubObjects(HrGroupKey groupKey, LocalDate asOfDate) {
56 HrGroupKey.Builder builder = HrGroupKey.Builder.create(groupKey);
57
58 if (asOfDate == null) {
59 asOfDate = groupKey.getEffectiveLocalDate();
60 }
61 if (StringUtils.isNotEmpty(builder.getLocationId())) {
62 builder.setLocation(Location.Builder.create(locationService.getLocation(builder.getLocationId(), asOfDate)));
63 }
64 if (StringUtils.isNotEmpty(builder.getInstitutionCode())) {
65 builder.setInstitution(Institution.Builder.create(institutionService.getInstitution(builder.getInstitutionCode(), asOfDate)));
66 }
67 if (StringUtils.isNotEmpty(builder.getCampusCode())) {
68 builder.setCampus(Campus.Builder.create(campusService.getCampus(builder.getCampusCode())));
69 }
70 return builder.build();
71 }
72
73 @Override
74 public List<HrGroupKey> getAllActiveHrGroupKeys(LocalDate asOfDate) {
75 if (asOfDate == null) {
76 asOfDate = LocalDate.now();
77 }
78
79 return ModelObjectUtils.transform(hrGroupKeyDao.getAllActiveHrGroupKeys(asOfDate), HrGroupKeyBo.toImmutable);
80 }
81
82
83 public void setHrGroupKeyDao(HrGroupKeyDao hrGroupKeyDao) {
84 this.hrGroupKeyDao = hrGroupKeyDao;
85 }
86
87 public void setBoService(BusinessObjectService boService) {
88 this.boService = boService;
89 }
90
91 public void setLocationService(LocationService locationService) {
92 this.locationService = locationService;
93 }
94
95 public void setCampusService(CampusService campusService) {
96 this.campusService = campusService;
97 }
98
99 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 }