1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.document; |
17 | |
|
18 | |
import org.apache.log4j.Logger; |
19 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
20 | |
import org.kuali.rice.kim.bo.impl.GenericPermission; |
21 | |
import org.kuali.rice.kim.impl.permission.PermissionBo; |
22 | |
import org.kuali.rice.kns.maintenance.KualiMaintainableImpl; |
23 | |
import org.kuali.rice.krad.bo.BusinessObject; |
24 | |
import org.kuali.rice.krad.bo.PersistableBusinessObject; |
25 | |
|
26 | |
import java.util.HashMap; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | 0 | public class GenericPermissionMaintainable extends KualiMaintainableImpl { |
35 | |
|
36 | 0 | private static final Logger LOG = Logger.getLogger( GenericPermissionMaintainable.class ); |
37 | |
private static final long serialVersionUID = -8102504656976243468L; |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
@Override |
45 | |
public void saveBusinessObject() { |
46 | |
try { |
47 | 0 | if ( LOG.isInfoEnabled() ) { |
48 | 0 | LOG.info( "Attempting to save GenericPermission BO via PermissionUpdateService: " + getBusinessObject() ); |
49 | |
} |
50 | 0 | GenericPermission perm = (GenericPermission)getBusinessObject(); |
51 | |
|
52 | 0 | KimApiServiceLocator.getPermissionUpdateService().savePermission( perm.getPermissionId(), |
53 | |
perm.getTemplateId(), |
54 | |
perm.getNamespaceCode(), |
55 | |
perm.getName(), |
56 | |
perm.getDescription(), |
57 | |
perm.isActive(), |
58 | |
new HashMap<String, String>(perm.getDetails()) ); |
59 | 0 | } catch ( RuntimeException ex ) { |
60 | 0 | LOG.error( "Exception in saveBusinessObject()", ex ); |
61 | 0 | throw ex; |
62 | 0 | } |
63 | 0 | } |
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
@Override |
71 | |
public Class<? extends PersistableBusinessObject> getBoClass() { |
72 | 0 | return GenericPermission.class; |
73 | |
} |
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
@Override |
81 | |
public boolean isExternalBusinessObject() { |
82 | 0 | return true; |
83 | |
} |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
@Override |
91 | |
public void prepareBusinessObject(BusinessObject businessObject) { |
92 | |
try { |
93 | 0 | if ( businessObject == null ) { |
94 | 0 | throw new RuntimeException( "Configuration ERROR: GenericPermissionMaintainable.prepareBusinessObject passed a null object." ); |
95 | |
} |
96 | 0 | if ( businessObject instanceof PermissionBo ) { |
97 | 0 | PermissionBo perm = getBusinessObjectService().findBySinglePrimaryKey(PermissionBo.class, ((PermissionBo)businessObject).getId() ); |
98 | 0 | businessObject = new GenericPermission( perm ); |
99 | 0 | } else if ( businessObject instanceof GenericPermission ) { |
100 | |
|
101 | 0 | PermissionBo perm = getBusinessObjectService().findBySinglePrimaryKey(PermissionBo.class, ((GenericPermission)businessObject).getPermissionId() ); |
102 | 0 | ((GenericPermission)businessObject).loadFromKimPermission(perm); |
103 | 0 | } else { |
104 | 0 | throw new RuntimeException( "Configuration ERROR: GenericPermissionMaintainable passed an unsupported object type: " + businessObject.getClass() ); |
105 | |
} |
106 | 0 | if ( businessObject instanceof PersistableBusinessObject ) { |
107 | 0 | setBusinessObject( (PersistableBusinessObject)businessObject ); |
108 | |
} |
109 | 0 | super.prepareBusinessObject(businessObject); |
110 | 0 | } catch ( RuntimeException ex ) { |
111 | 0 | LOG.error( "Exception in prepareBusinessObject()", ex ); |
112 | 0 | throw ex; |
113 | 0 | } |
114 | 0 | } |
115 | |
|
116 | |
} |