001    /**
002     * Copyright 2004-2012 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     */
016    package org.kuali.hr.time.principal.service;
017    
018    import java.util.Map;
019    
020    import org.apache.commons.lang.StringUtils;
021    import org.kuali.hr.core.cache.CacheUtils;
022    import org.kuali.hr.time.principal.PrincipalHRAttributes;
023    import org.kuali.rice.kim.api.identity.Person;
024    import org.kuali.rice.kim.api.services.KimApiServiceLocator;
025    import org.kuali.rice.kns.document.MaintenanceDocument;
026    import org.kuali.rice.kns.maintenance.KualiMaintainableImpl;
027    import org.kuali.rice.krad.service.KRADServiceLocator;
028    
029    public class PrincipalHRAttributesMaintainableImpl extends KualiMaintainableImpl {
030            private static final long serialVersionUID = 1L;
031    
032            @SuppressWarnings("rawtypes")
033            @Override
034            public Map populateBusinessObject(Map<String, String> fieldValues,
035                            MaintenanceDocument maintenanceDocument, String methodToCall) {
036                    if (fieldValues.containsKey("principalId")
037                                    && StringUtils.isNotEmpty(fieldValues.get("principalId"))) {
038                            Person p = KimApiServiceLocator.getPersonService().getPerson(
039                                            fieldValues.get("principalId"));
040                            if (p != null) {
041                                    fieldValues.put("name", p.getName());
042                            }else{
043                                    fieldValues.put("name", "");
044                            }
045                    }
046                    return super.populateBusinessObject(fieldValues, maintenanceDocument,
047                                    methodToCall);
048            }
049    
050            @Override
051            public void saveBusinessObject() {
052                    PrincipalHRAttributes principalHRAttr = (PrincipalHRAttributes) this.getBusinessObject();
053                    principalHRAttr.setTimestamp(null);
054                    KRADServiceLocator.getBusinessObjectService().save(principalHRAttr);
055            CacheUtils.flushCache(PrincipalHRAttributes.CACHE_NAME);
056            }
057            
058            
059    }