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