Coverage Report - org.kuali.rice.kim.service.impl.ResponsibilityUpdateServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ResponsibilityUpdateServiceImpl
0%
0/43
0%
0/12
9
 
 1  
 /*
 2  
  * Copyright 2007-2010 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.rice.kim.service.impl;
 17  
 
 18  
 import java.util.Iterator;
 19  
 import java.util.List;
 20  
 import java.util.Map.Entry;
 21  
 
 22  
 import org.apache.commons.lang.StringUtils;
 23  
 import org.apache.log4j.Logger;
 24  
 import org.kuali.rice.kim.bo.role.impl.KimResponsibilityImpl;
 25  
 import org.kuali.rice.kim.bo.role.impl.ResponsibilityAttributeDataImpl;
 26  
 import org.kuali.rice.kim.bo.types.dto.AttributeSet;
 27  
 import org.kuali.rice.kim.bo.types.dto.KimTypeAttributeInfo;
 28  
 import org.kuali.rice.kim.service.KIMServiceLocator;
 29  
 import org.kuali.rice.kim.service.ResponsibilityUpdateService;
 30  
 
 31  
 /**
 32  
  * This is a description of what this class does - jjhanso don't forget to fill this in. 
 33  
  * 
 34  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 35  
  *
 36  
  */
 37  0
 public class ResponsibilityUpdateServiceImpl extends ResponsibilityServiceBase implements ResponsibilityUpdateService {
 38  0
         private static final Logger LOG = Logger.getLogger( ResponsibilityUpdateServiceImpl.class );
 39  
         // --------------------
 40  
     // ResponsibilityUpdateService methods
 41  
     // --------------------
 42  
 
 43  
     public void saveResponsibility(String responsibilityId,
 44  
                     String responsibilityTemplateId, String namespaceCode, String name,
 45  
                     String description, boolean active, AttributeSet responsibilityDetails ) {
 46  
             // look for an existing responsibility of the given type
 47  
             try {
 48  0
                     KimResponsibilityImpl resp = getBusinessObjectService().findBySinglePrimaryKey(KimResponsibilityImpl.class, responsibilityId);
 49  0
                     if ( resp == null ) {
 50  0
                             resp = new KimResponsibilityImpl();
 51  0
                             resp.setResponsibilityId(responsibilityId);
 52  
                     }
 53  0
                     resp.setTemplateId(responsibilityTemplateId);
 54  0
                     resp.refreshReferenceObject( "template" );
 55  0
                     resp.setNamespaceCode(namespaceCode);
 56  0
                     resp.setName(name);
 57  0
                     resp.setDescription(description);
 58  0
                     resp.setActive(active);
 59  0
                     AttributeSet attributesToAdd = new AttributeSet( responsibilityDetails );
 60  0
                     List<ResponsibilityAttributeDataImpl> details = resp.getDetailObjects();
 61  0
                     Iterator<ResponsibilityAttributeDataImpl> detailIter = details.iterator();
 62  0
                     while ( detailIter.hasNext() ) {
 63  0
                             ResponsibilityAttributeDataImpl detail = detailIter.next();
 64  0
                             String attrName = detail.getKimAttribute().getAttributeName();
 65  0
                             String attrValue = attributesToAdd.get(attrName);
 66  
                             // if not present in the list or is blank, remove from the list
 67  0
                             if ( StringUtils.isBlank(attrValue) ) {
 68  0
                                     detailIter.remove();
 69  
                             } else {
 70  0
                                     detail.setAttributeValue(attrValue);
 71  
                             }
 72  
                             // remove from detail map - used to add new ones later
 73  0
                             attributesToAdd.remove(attrName);
 74  0
                     }
 75  0
                     for ( Entry<String,String> attrEntry : attributesToAdd.entrySet() ) {
 76  0
                             KimTypeAttributeInfo attr = resp.getTemplate().getKimType().getAttributeDefinitionByName(attrEntry.getKey());
 77  0
                             if (attr != null && StringUtils.isNotBlank(attrEntry.getValue()) ) {
 78  0
                                     ResponsibilityAttributeDataImpl newDetail = new ResponsibilityAttributeDataImpl();
 79  0
                                     newDetail.setAttributeDataId(getNewAttributeDataId());
 80  0
                                     newDetail.setKimAttributeId(attr.getKimAttributeId());
 81  0
                                     newDetail.setKimTypeId(resp.getTemplate().getKimTypeId());
 82  0
                                     newDetail.setResponsibilityId(responsibilityId);
 83  0
                                     newDetail.setAttributeValue(attrEntry.getValue());
 84  0
                                     details.add(newDetail);
 85  
                             }
 86  0
                     }
 87  0
                     getBusinessObjectService().save(resp);
 88  
                     // flush the IdM service caches
 89  0
                     KIMServiceLocator.getIdentityManagementService().flushResponsibilityCaches();
 90  
                     // flush the local implementation class cache
 91  0
                     flushResponsibilityImplCache();
 92  0
             } catch ( RuntimeException ex ) {
 93  0
                     LOG.error( "Exception in saveResponsibility: ", ex );
 94  0
                     throw ex;
 95  0
             }
 96  0
     }
 97  
 
 98  
 }