View Javadoc

1   /*
2    * Copyright 2007-2009 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.bo.impl.GenericPermission;
20  import org.kuali.rice.kim.bo.impl.PermissionImpl;
21  import org.kuali.rice.kim.bo.role.impl.KimPermissionImpl;
22  import org.kuali.rice.kim.service.KIMServiceLocator;
23  import org.kuali.rice.kns.bo.BusinessObject;
24  import org.kuali.rice.kns.bo.PersistableBusinessObject;
25  import org.kuali.rice.kns.maintenance.KualiMaintainableImpl;
26  
27  /**
28   * This is a description of what this class does - jonathan don't forget to fill this in. 
29   * 
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   *
32   */
33  public class GenericPermissionMaintainable extends KualiMaintainableImpl {
34  
35  	private static final Logger LOG = Logger.getLogger( GenericPermissionMaintainable.class );	
36  	private static final long serialVersionUID = -8102504656976243468L;
37  
38  	/**
39  	 * Saves the responsibility via the responsibility update service
40  	 * 
41  	 * @see org.kuali.rice.kns.maintenance.KualiMaintainableImpl#saveBusinessObject()
42  	 */
43  	@Override
44  	public void saveBusinessObject() {
45  		try {
46  			if ( LOG.isInfoEnabled() ) {
47  				LOG.info( "Attempting to save GenericPermission BO via PermissionUpdateService: " + getBusinessObject() );
48  			}
49  			GenericPermission perm = (GenericPermission)getBusinessObject();
50  			
51  			KIMServiceLocator.getPermissionUpdateService().savePermission( perm.getPermissionId(), 
52  					perm.getTemplateId(),
53  					perm.getNamespaceCode(), 
54  					perm.getName(), 
55  					perm.getDescription(), 
56  					perm.isActive(), 
57  					perm.getDetails() );
58  		} catch ( RuntimeException ex ) {
59  			LOG.error( "Exception in saveBusinessObject()", ex );
60  			throw ex;
61  		}
62  	}
63  	
64  	/**
65  	 * This overridden method ...
66  	 * 
67  	 * @see org.kuali.rice.kns.maintenance.KualiMaintainableImpl#getBoClass()
68  	 */
69  	@Override
70  	public Class<? extends BusinessObject> getBoClass() {
71  		return GenericPermission.class;
72  	}
73  	
74  	/**
75  	 * This overridden method ...
76  	 * 
77  	 * @see org.kuali.rice.kns.maintenance.KualiMaintainableImpl#isExternalBusinessObject()
78  	 */
79  	@Override
80  	public boolean isExternalBusinessObject() {
81  		return true;
82  	}
83  	
84  	/**
85  	 * This overridden method ...
86  	 * 
87  	 * @see org.kuali.rice.kns.maintenance.KualiMaintainableImpl#prepareBusinessObject(org.kuali.rice.kns.bo.BusinessObject)
88  	 */
89  	@Override
90  	public void prepareBusinessObject(BusinessObject businessObject) {
91  		try {
92  			if ( businessObject == null ) {
93  				throw new RuntimeException( "Configuration ERROR: GenericPermissionMaintainable.prepareBusinessObject passed a null object." );
94  			}
95  			if ( businessObject instanceof PermissionImpl ) {
96  				KimPermissionImpl perm = getBusinessObjectService().findBySinglePrimaryKey(KimPermissionImpl.class, ((PermissionImpl)businessObject).getPermissionId() );
97  				businessObject = new GenericPermission( perm );
98  			} else if ( businessObject instanceof GenericPermission ) {
99  				// lookup the KimResponsibilityImpl and convert to a ReviewResponsibility
100 				KimPermissionImpl perm = getBusinessObjectService().findBySinglePrimaryKey(KimPermissionImpl.class, ((GenericPermission)businessObject).getPermissionId() );		
101 				((GenericPermission)businessObject).loadFromKimPermission(perm);
102 			} else {
103 				throw new RuntimeException( "Configuration ERROR: GenericPermissionMaintainable passed an unsupported object type: " + businessObject.getClass() );
104 			}
105 			if ( businessObject instanceof PersistableBusinessObject ) {
106 				setBusinessObject( (PersistableBusinessObject)businessObject );
107 			}
108 			super.prepareBusinessObject(businessObject);
109 		} catch ( RuntimeException ex ) {
110 			LOG.error( "Exception in prepareBusinessObject()", ex );
111 			throw ex;
112 		}
113 	}
114 	
115 }