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.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 | |
|
33 | |
|
34 | |
|
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 | |
|
44 | |
|
45 | |
|
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 | |
|
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 | |
|
91 | 0 | } else { |
92 | 0 | throw new RuntimeException( |
93 | |
"Cannot save object of type: " + getDataObjectClass() + " with permission service"); |
94 | |
} |
95 | 0 | } |
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
@Override |
103 | |
public Class<? extends PersistableBusinessObject> getBoClass() { |
104 | 0 | return GenericPermissionBo.class; |
105 | |
} |
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
@Override |
113 | |
public boolean isExternalBusinessObject() { |
114 | 0 | return true; |
115 | |
} |
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
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 | |
|
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 | |
} |