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.cxf.common.util.StringUtils;
19 import org.apache.log4j.Logger;
20 import org.kuali.rice.kim.api.permission.Permission;
21 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
22 import org.kuali.rice.kim.impl.permission.GenericPermissionBo;
23 import org.kuali.rice.kim.impl.permission.PermissionBo;
24 import org.kuali.rice.kim.impl.permission.PermissionTemplateBo;
25 import org.kuali.rice.kim.impl.responsibility.ReviewResponsibilityBo;
26 import org.kuali.rice.kns.maintenance.KualiMaintainableImpl;
27 import org.kuali.rice.krad.bo.BusinessObject;
28 import org.kuali.rice.krad.bo.PersistableBusinessObject;
29 import org.kuali.rice.krad.util.KRADConstants;
30
31 import java.util.HashMap;
32
33
34
35
36
37
38
39 public class GenericPermissionMaintainable extends KualiMaintainableImpl {
40
41 private static final Logger LOG = Logger.getLogger( GenericPermissionMaintainable.class );
42 private static final long serialVersionUID = -8102504656976243468L;
43
44
45
46
47
48
49 @Override
50 public void saveDataObject() {
51 if (getDataObject() instanceof PersistableBusinessObject) {
52 GenericPermissionBo genericPermissionBo = (GenericPermissionBo)getDataObject();
53 boolean permissionExists = false;
54 if (genericPermissionBo.getId() != null) {
55 permissionExists = KimApiServiceLocator.getPermissionService().getPermission(genericPermissionBo.getId()) != null;
56 }
57
58 if (genericPermissionBo.getTemplateId() != null) {
59 genericPermissionBo.setTemplate(
60 PermissionTemplateBo.from(
61 KimApiServiceLocator.getPermissionService().getPermissionTemplate(genericPermissionBo.getTemplateId())));
62 }
63 PermissionBo perm = GenericPermissionBo.toPermissionBo(genericPermissionBo);
64 if (permissionExists) {
65 KimApiServiceLocator.getPermissionService().updatePermission(PermissionBo.to(perm));
66 } else {
67 KimApiServiceLocator.getPermissionService().createPermission(PermissionBo.to(perm));
68 }
69 } else {
70 throw new RuntimeException(
71 "Cannot save object of type: " + getDataObjectClass() + " with permission service");
72 }
73 }
74
75
76
77
78
79
80 @Override
81 public Class<? extends PersistableBusinessObject> getBoClass() {
82 return GenericPermissionBo.class;
83 }
84
85
86
87
88
89
90 @Override
91 public boolean isExternalBusinessObject() {
92 return true;
93 }
94
95
96
97
98
99
100 @Override
101 public void prepareBusinessObject(BusinessObject businessObject) {
102 try {
103 if ( businessObject == null ) {
104 throw new RuntimeException( "Configuration ERROR: GenericPermissionMaintainable.prepareBusinessObject passed a null object." );
105 }
106 if ( businessObject instanceof PermissionBo ) {
107 PermissionBo perm = getBusinessObjectService().findBySinglePrimaryKey(PermissionBo.class, ((PermissionBo)businessObject).getId() );
108 businessObject = new GenericPermissionBo(perm);
109 } else if ( businessObject instanceof GenericPermissionBo ) {
110
111 PermissionBo perm = getBusinessObjectService().findBySinglePrimaryKey(PermissionBo.class, ((GenericPermissionBo)businessObject).getId() );
112 ((GenericPermissionBo)businessObject).loadFromPermission(perm);
113 } else {
114 throw new RuntimeException( "Configuration ERROR: GenericPermissionMaintainable passed an unsupported object type: " + businessObject.getClass() );
115 }
116 if ( businessObject instanceof PersistableBusinessObject ) {
117 setBusinessObject( (PersistableBusinessObject)businessObject );
118 }
119 super.prepareBusinessObject(businessObject);
120 } catch ( RuntimeException ex ) {
121 LOG.error( "Exception in prepareBusinessObject()", ex );
122 throw ex;
123 }
124 }
125
126 }