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.principal.web;
17  
18  import java.util.Map;
19  
20  import org.apache.commons.lang.StringUtils;
21  import org.kuali.kpme.core.bo.HrBusinessObject;
22  import org.kuali.kpme.core.bo.HrBusinessObjectMaintainableImpl;
23  import org.kuali.kpme.core.cache.CacheUtils;
24  import org.kuali.kpme.core.principal.PrincipalHRAttributes;
25  import org.kuali.kpme.core.service.HrServiceLocator;
26  import org.kuali.kpme.core.util.HrConstants;
27  import org.kuali.rice.kim.api.identity.principal.EntityNamePrincipalName;
28  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
29  import org.kuali.rice.kns.document.MaintenanceDocument;
30  
31  public class PrincipalHRAttributesMaintainableImpl extends HrBusinessObjectMaintainableImpl {
32  	private static final long serialVersionUID = 1L;
33  
34  	@SuppressWarnings("rawtypes")
35  	@Override
36  	public Map populateBusinessObject(Map<String, String> fieldValues,
37  			MaintenanceDocument maintenanceDocument, String methodToCall) {
38  		if (fieldValues.containsKey("principalId")
39  				&& StringUtils.isNotEmpty(fieldValues.get("principalId"))) {
40  			EntityNamePrincipalName p = KimApiServiceLocator.getIdentityService().getDefaultNamesForPrincipalId(fieldValues.get("principalId"));
41  			if (p != null
42                      && p.getDefaultName() != null) {
43  				fieldValues.put("name", p.getDefaultName().getCompositeName());
44  			}else{
45  				fieldValues.put("name", "");
46  			}
47  		}
48  		return super.populateBusinessObject(fieldValues, maintenanceDocument,
49  				methodToCall);
50  	}
51  
52  	@Override
53  	public void processAfterCopy(MaintenanceDocument document,
54  			Map<String, String[]> parameters) {
55  		super.processAfterCopy(document, parameters);
56  		PrincipalHRAttributes principalHRAttributes = (PrincipalHRAttributes) document.getNewMaintainableObject().getBusinessObject();
57  		principalHRAttributes.setPrincipalId(null);
58  	}
59  
60  	@Override
61  	public void saveBusinessObject() {
62  		super.saveBusinessObject();
63  		CacheUtils.flushCache(PrincipalHRAttributes.CACHE_NAME);
64  		CacheUtils.flushCache(HrConstants.CacheNamespace.KPME_GLOBAL_CACHE_NAME);
65  	}
66  
67  	@Override
68  	public HrBusinessObject getObjectById(String id) {
69  		return HrServiceLocator.getPrincipalHRAttributeService().getPrincipalHRAttributes(id);
70  	}
71  	
72  	
73  }