1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.service.impl; |
17 | |
|
18 | |
import java.util.Iterator; |
19 | |
import java.util.List; |
20 | |
|
21 | |
import javax.jws.WebService; |
22 | |
|
23 | |
import org.apache.commons.lang.StringUtils; |
24 | |
import org.apache.log4j.Logger; |
25 | |
import org.kuali.rice.kim.bo.role.impl.KimPermissionImpl; |
26 | |
import org.kuali.rice.kim.bo.role.impl.PermissionAttributeDataImpl; |
27 | |
import org.kuali.rice.kim.bo.types.dto.AttributeSet; |
28 | |
import org.kuali.rice.kim.bo.types.dto.KimTypeAttributeInfo; |
29 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
30 | |
import org.kuali.rice.kim.service.PermissionUpdateService; |
31 | |
import org.kuali.rice.kim.util.KIMWebServiceConstants; |
32 | |
import org.kuali.rice.kim.util.KimConstants; |
33 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
@WebService(endpointInterface = KIMWebServiceConstants.PermissionUpdateService.INTERFACE_CLASS, serviceName = KIMWebServiceConstants.PermissionUpdateService.WEB_SERVICE_NAME, portName = KIMWebServiceConstants.PermissionUpdateService.WEB_SERVICE_PORT, targetNamespace = KIMWebServiceConstants.MODULE_TARGET_NAMESPACE) |
41 | 0 | public class PermissionUpdateServiceImpl extends PermissionServiceBase implements PermissionUpdateService { |
42 | 0 | private static final Logger LOG = Logger.getLogger( PermissionUpdateServiceImpl.class ); |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
public void savePermission(String permissionId, String permissionTemplateId, |
49 | |
String namespaceCode, String name, String description, boolean active, |
50 | |
AttributeSet permissionDetails) { |
51 | |
|
52 | |
try { |
53 | 0 | KimPermissionImpl perm = getBusinessObjectService().findBySinglePrimaryKey(KimPermissionImpl.class, permissionId); |
54 | 0 | if ( perm == null ) { |
55 | 0 | perm = new KimPermissionImpl(); |
56 | 0 | perm.setPermissionId(permissionId); |
57 | |
} |
58 | 0 | perm.setTemplateId(permissionTemplateId); |
59 | 0 | perm.refreshReferenceObject( "template" ); |
60 | 0 | perm.setNamespaceCode(namespaceCode); |
61 | 0 | perm.setName(name); |
62 | 0 | perm.setDescription(description); |
63 | 0 | perm.setActive(active); |
64 | 0 | AttributeSet attributesToAdd = new AttributeSet( permissionDetails ); |
65 | 0 | List<PermissionAttributeDataImpl> details = perm.getDetailObjects(); |
66 | 0 | Iterator<PermissionAttributeDataImpl> detailIter = details.iterator(); |
67 | 0 | while ( detailIter.hasNext() ) { |
68 | 0 | PermissionAttributeDataImpl detail = detailIter.next(); |
69 | 0 | String attrName = detail.getKimAttribute().getAttributeName(); |
70 | 0 | String attrValue = attributesToAdd.get(attrName); |
71 | |
|
72 | 0 | if ( StringUtils.isBlank(attrValue) ) { |
73 | 0 | detailIter.remove(); |
74 | |
} else { |
75 | 0 | detail.setAttributeValue(attrValue); |
76 | |
} |
77 | |
|
78 | 0 | attributesToAdd.remove(attrName); |
79 | 0 | } |
80 | 0 | for ( String attrName : attributesToAdd.keySet() ) { |
81 | 0 | KimTypeAttributeInfo attr = perm.getTemplate().getKimType().getAttributeDefinitionByName(attrName); |
82 | 0 | if ( attr != null ) { |
83 | 0 | PermissionAttributeDataImpl newDetail = new PermissionAttributeDataImpl(); |
84 | 0 | newDetail.setAttributeDataId(getNewAttributeDataId()); |
85 | 0 | newDetail.setKimAttributeId(attr.getKimAttributeId()); |
86 | 0 | newDetail.setKimTypeId(perm.getTemplate().getKimTypeId()); |
87 | 0 | newDetail.setPermissionId(permissionId); |
88 | 0 | newDetail.setAttributeValue(attributesToAdd.get(attrName)); |
89 | 0 | details.add(newDetail); |
90 | 0 | } else { |
91 | 0 | LOG.error( "Unknown attribute name saving permission: '" + attrName + "'" ); |
92 | |
} |
93 | 0 | } |
94 | 0 | getBusinessObjectService().save(perm); |
95 | 0 | KIMServiceLocator.getIdentityManagementService().flushPermissionCaches(); |
96 | 0 | flushPermissionImplCache(); |
97 | 0 | } catch ( RuntimeException ex ) { |
98 | 0 | LOG.error( "Exception in savePermission: ", ex ); |
99 | 0 | throw ex; |
100 | 0 | } |
101 | 0 | } |
102 | |
|
103 | |
public String getNextAvailablePermissionId() throws UnsupportedOperationException { |
104 | 0 | Long nextSeq = KNSServiceLocator.getSequenceAccessorService().getNextAvailableSequenceNumber(KimConstants.SequenceNames.KRIM_PERM_ID_S, KimPermissionImpl.class); |
105 | |
|
106 | 0 | if (nextSeq == null) { |
107 | 0 | LOG.error("Unable to get new permission id from sequence " + KimConstants.SequenceNames.KRIM_PERM_ID_S); |
108 | 0 | throw new RuntimeException("Unable to get new permission id from sequence " + KimConstants.SequenceNames.KRIM_PERM_ID_S); |
109 | |
} |
110 | |
|
111 | 0 | return nextSeq.toString(); |
112 | |
} |
113 | |
|
114 | |
} |