01: /*
02: * Copyright 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: package org.kuali.module.cg.service.impl;
17:
18: import java.util.HashMap;
19: import java.util.Map;
20:
21: import org.kuali.core.bo.user.UniversalUser;
22: import org.kuali.core.exceptions.UserNotFoundException;
23: import org.kuali.core.service.BusinessObjectService;
24: import org.kuali.core.service.UniversalUserService;
25: import org.kuali.core.util.spring.Cached;
26: import org.kuali.kfs.KFSPropertyConstants;
27: import org.kuali.module.cg.bo.ProjectDirector;
28: import org.kuali.module.cg.service.ProjectDirectorService;
29: import org.springframework.transaction.annotation.Transactional;
30:
31: /**
32: * Implementation of the ProjectDirector service.
33: */
34: @Transactional
35: public class ProjectDirectorServiceImpl implements
36: ProjectDirectorService {
37:
38: private UniversalUserService universalUserService;
39: private BusinessObjectService businessObjectService;
40:
41: /**
42: * @see org.kuali.module.cg.service.ProjectDirectorService#getByPersonUserIdentifier(String)
43: */
44: @Cached
45: public ProjectDirector getByPersonUserIdentifier(String username) {
46: try {
47: UniversalUser user = universalUserService
48: .getUniversalUserByAuthenticationUserId(username);
49: return getByPrimaryId(user.getPersonUniversalIdentifier());
50: } catch (UserNotFoundException ex) {
51: return null;
52: }
53: }
54:
55: /**
56: * @see org.kuali.module.cg.service.ProjectDirectorService#getByPrimaryId(String)
57: */
58: @Cached
59: public ProjectDirector getByPrimaryId(String universalIdentifier) {
60: return (ProjectDirector) businessObjectService
61: .findByPrimaryKey(ProjectDirector.class,
62: mapPrimaryKeys(universalIdentifier));
63: }
64:
65: /**
66: * @see org.kuali.module.cg.service.ProjectDirectorService#primaryIdExists(String)
67: */
68: @Cached
69: public boolean primaryIdExists(String universalIdentifier) {
70: return businessObjectService.countMatching(
71: ProjectDirector.class,
72: mapPrimaryKeys(universalIdentifier)) > 0;
73: }
74:
75: private Map<String, Object> mapPrimaryKeys(
76: String universalIdentifier) {
77: Map<String, Object> primaryKeys = new HashMap();
78: primaryKeys.put(
79: KFSPropertyConstants.PERSON_UNIVERSAL_IDENTIFIER,
80: universalIdentifier == null ? null
81: : universalIdentifier.trim());
82: return primaryKeys;
83: }
84:
85: public void setUniversalUserService(
86: UniversalUserService universalUserService) {
87: this .universalUserService = universalUserService;
88: }
89:
90: public void setBusinessObjectService(
91: BusinessObjectService businessObjectService) {
92: this.businessObjectService = businessObjectService;
93: }
94: }
|