Coverage Report - org.kuali.rice.kim.document.GenericPermissionMaintainable
 
Classes in this File Line Coverage Branch Coverage Complexity
GenericPermissionMaintainable
0%
0/48
0%
0/26
4.8
 
 1  
 /**
 2  
  * Copyright 2005-2011 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.document;
 17  
 
 18  
 import org.apache.log4j.Logger;
 19  
 import org.kuali.rice.kim.api.permission.Permission;
 20  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 21  
 import org.kuali.rice.kim.impl.permission.GenericPermissionBo;
 22  
 import org.kuali.rice.kim.impl.permission.PermissionBo;
 23  
 import org.kuali.rice.kim.impl.permission.PermissionTemplateBo;
 24  
 import org.kuali.rice.kim.impl.responsibility.ReviewResponsibilityBo;
 25  
 import org.kuali.rice.kns.maintenance.KualiMaintainableImpl;
 26  
 import org.kuali.rice.krad.bo.BusinessObject;
 27  
 import org.kuali.rice.krad.bo.PersistableBusinessObject;
 28  
 
 29  
 import java.util.HashMap;
 30  
 
 31  
 /**
 32  
  * This is a description of what this class does - jonathan don't forget to fill this in. 
 33  
  * 
 34  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 35  
  *
 36  
  */
 37  0
 public class GenericPermissionMaintainable extends KualiMaintainableImpl {
 38  
 
 39  0
         private static final Logger LOG = Logger.getLogger( GenericPermissionMaintainable.class );        
 40  
         private static final long serialVersionUID = -8102504656976243468L;
 41  
 
 42  
         /**
 43  
          * Saves the responsibility via the responsibility update service
 44  
          * 
 45  
          * @see org.kuali.rice.krad.maintenance.KualiMaintainableImpl#saveBusinessObject()
 46  
          */
 47  
         @Override
 48  
         public void saveBusinessObject() {
 49  
                 try {
 50  0
                         if ( LOG.isInfoEnabled() ) {
 51  0
                                 LOG.info( "Attempting to save Permission BO via PermissionService: " + getBusinessObject() );
 52  
                         }
 53  0
             GenericPermissionBo genericPermissionBo = (GenericPermissionBo)getBusinessObject();
 54  0
             if (genericPermissionBo.getTemplateId() != null && genericPermissionBo.getTemplate() == null) {
 55  0
                 genericPermissionBo.setTemplate(
 56  
                         PermissionTemplateBo.from(
 57  
                                 KimApiServiceLocator.getPermissionService().getPermissionTemplate(genericPermissionBo.getTemplateId())));
 58  
             }
 59  0
                         PermissionBo perm = GenericPermissionBo.toPermissionBo(genericPermissionBo);
 60  
                         
 61  0
                         KimApiServiceLocator.getPermissionService().createPermission(PermissionBo.to(perm));
 62  0
                 } catch ( RuntimeException ex ) {
 63  0
                         LOG.error( "Exception in saveBusinessObject()", ex );
 64  0
                         throw ex;
 65  0
                 }
 66  0
         }
 67  
 
 68  
     /**
 69  
      * @see org.kuali.rice.krad.maintenance.Maintainable#saveDataObject
 70  
      */
 71  
     @Override
 72  
     public void saveDataObject() {
 73  0
         if (getDataObject() instanceof PersistableBusinessObject) {
 74  0
             GenericPermissionBo genericPermissionBo = (GenericPermissionBo)getDataObject();
 75  0
             boolean permissionExists = false;
 76  0
             if (genericPermissionBo.getId() != null) {
 77  0
                 permissionExists = KimApiServiceLocator.getPermissionService().getPermission(genericPermissionBo.getId()) != null;
 78  
             }
 79  0
             if (genericPermissionBo.getTemplateId() != null && genericPermissionBo.getTemplate() == null) {
 80  0
                 genericPermissionBo.setTemplate(
 81  
                         PermissionTemplateBo.from(
 82  
                                 KimApiServiceLocator.getPermissionService().getPermissionTemplate(genericPermissionBo.getTemplateId())));
 83  
             }
 84  0
             PermissionBo perm = GenericPermissionBo.toPermissionBo(genericPermissionBo);
 85  0
             if (permissionExists) {
 86  0
                 KimApiServiceLocator.getPermissionService().updatePermission(PermissionBo.to(perm));
 87  
             } else {
 88  0
                 KimApiServiceLocator.getPermissionService().createPermission(PermissionBo.to(perm));
 89  
             }
 90  
             //getBusinessObjectService().linkAndSave((PersistableBusinessObject) dataObject);
 91  0
         } else {
 92  0
             throw new RuntimeException(
 93  
                     "Cannot save object of type: " + getDataObjectClass() + " with permission service");
 94  
         }
 95  0
     }
 96  
         
 97  
         /**
 98  
          * This overridden method ...
 99  
          * 
 100  
          * @see org.kuali.rice.krad.maintenance.KualiMaintainableImpl#getBoClass()
 101  
          */
 102  
         @Override
 103  
         public Class<? extends PersistableBusinessObject> getBoClass() {
 104  0
                 return GenericPermissionBo.class;
 105  
         }
 106  
         
 107  
         /**
 108  
          * This overridden method ...
 109  
          * 
 110  
          * @see org.kuali.rice.krad.maintenance.KualiMaintainableImpl#isExternalBusinessObject()
 111  
          */
 112  
         @Override
 113  
         public boolean isExternalBusinessObject() {
 114  0
                 return true;
 115  
         }
 116  
         
 117  
         /**
 118  
          * This overridden method ...
 119  
          * 
 120  
          * @see org.kuali.rice.krad.maintenance.KualiMaintainableImpl#prepareBusinessObject(org.kuali.rice.krad.bo.BusinessObject)
 121  
          */
 122  
         @Override
 123  
         public void prepareBusinessObject(BusinessObject businessObject) {
 124  
                 try {
 125  0
                         if ( businessObject == null ) {
 126  0
                                 throw new RuntimeException( "Configuration ERROR: GenericPermissionMaintainable.prepareBusinessObject passed a null object." );
 127  
                         }
 128  0
                         if ( businessObject instanceof PermissionBo ) {
 129  0
                                 PermissionBo perm = getBusinessObjectService().findBySinglePrimaryKey(PermissionBo.class, ((PermissionBo)businessObject).getId() );
 130  0
                                 businessObject = new GenericPermissionBo(perm);
 131  0
                         } else if ( businessObject instanceof GenericPermissionBo ) {
 132  
                                 // lookup the PermissionBo and convert to a GenericPermissionBo
 133  0
                                 PermissionBo perm = getBusinessObjectService().findBySinglePrimaryKey(PermissionBo.class, ((GenericPermissionBo)businessObject).getId() );
 134  0
                                 ((GenericPermissionBo)businessObject).loadFromPermission(perm);
 135  0
                         } else {
 136  0
                                 throw new RuntimeException( "Configuration ERROR: GenericPermissionMaintainable passed an unsupported object type: " + businessObject.getClass() );
 137  
                         }
 138  0
                         if ( businessObject instanceof PersistableBusinessObject ) {
 139  0
                                 setBusinessObject( (PersistableBusinessObject)businessObject );
 140  
                         }
 141  0
                         super.prepareBusinessObject(businessObject);
 142  0
                 } catch ( RuntimeException ex ) {
 143  0
                         LOG.error( "Exception in prepareBusinessObject()", ex );
 144  0
                         throw ex;
 145  0
                 }
 146  0
         }
 147  
         
 148  
 }