View Javadoc
1   /**
2    * Copyright 2004-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
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.kpme.core.role;
17  
18  import java.sql.Timestamp;
19  import java.util.Date;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.kuali.kpme.core.api.namespace.KPMENamespace;
23  import org.kuali.kpme.core.api.role.KPMERoleMemberBoContract;
24  import org.kuali.kpme.core.util.HrConstants;
25  import org.kuali.rice.kim.api.role.Role;
26  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
27  import org.kuali.rice.kim.impl.role.RoleMemberBo;
28  
29  @SuppressWarnings("unchecked")
30  public abstract class KPMERoleMemberBo extends RoleMemberBo implements KPMERoleMemberBoContract {
31      public static final String CACHE_NAME = HrConstants.CacheNamespace.NAMESPACE_PREFIX + "KPMERoleMember";
32  	private static final long serialVersionUID = 3137509859347223332L;
33  
34  	public Date getEffectiveDate() {
35  		Date effectiveDate = null;
36  		
37  		if (getActiveFromDate() != null) {
38  			effectiveDate = getActiveFromDate().toDate();
39  		}
40  		
41  		return effectiveDate;
42  	}
43  	
44  	public void setEffectiveDate(Date effectiveDate) {
45  		if (effectiveDate != null) {
46  			setActiveFromDateValue(new Timestamp(effectiveDate.getTime()));
47  		}
48  	}
49  	
50  	public Date getExpirationDate() {
51  		Date expirationDate = null;
52  		
53  		if (getActiveToDate() != null) {
54  			expirationDate = getActiveToDate().toDate();
55  		}
56  		
57  		return expirationDate;
58  	}
59  	
60  	public void setExpirationDate(Date expirationDate) {
61  		if (expirationDate != null) {
62  			setActiveToDateValue(new Timestamp(expirationDate.getTime()));
63  		}
64  	}
65  	
66  	public String getRoleName() {
67  		String roleName = StringUtils.EMPTY;
68  		
69  		if (getRoleId() != null) {
70  			Role role = KimApiServiceLocator.getRoleService().getRole(getRoleId());
71  			
72  			if (role != null) {
73  				roleName = role.getName();
74  			}
75  		}
76  		
77  		return roleName;
78  	}
79  	
80  	public void setRoleName(String roleName) {
81  		if (StringUtils.isNotBlank(roleName)) {
82  			setRoleId(KimApiServiceLocator.getRoleService().getRoleIdByNamespaceCodeAndName(KPMENamespace.KPME_HR.getNamespaceCode(), roleName));
83  			if (StringUtils.isBlank(getRoleId())) {
84  				setRoleId(KimApiServiceLocator.getRoleService().getRoleIdByNamespaceCodeAndName(KPMENamespace.KPME_TK.getNamespaceCode(), roleName));
85  				if (StringUtils.isBlank(getRoleId())) {
86  					setRoleId(KimApiServiceLocator.getRoleService().getRoleIdByNamespaceCodeAndName(KPMENamespace.KPME_LM.getNamespaceCode(), roleName));
87  				}
88  			}
89  		}
90  	}
91  
92  }