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