Search in sources :

Example 1 with RoleTreeNodeEvent

use of eu.bcvsolutions.idm.core.model.event.RoleTreeNodeEvent in project CzechIdMng by bcvsolutions.

the class DefaultIdmRoleTreeNodeService method save.

/**
 * Publish {@link RoleTreeNodeEvent} only.
 *
 * @see {@link RoleTreeNodeSaveProcessor}
 */
@Override
@Transactional(noRollbackFor = AcceptedException.class)
public IdmRoleTreeNodeDto save(IdmRoleTreeNodeDto roleTreeNode, BasePermission... permission) {
    Assert.notNull(roleTreeNode);
    checkAccess(toEntity(roleTreeNode, null), permission);
    // 
    LOG.debug("Saving automatic role [{}] - [{}] - [{}]", roleTreeNode.getRole(), roleTreeNode.getTreeNode(), roleTreeNode.getRecursionType());
    // 
    if (isNew(roleTreeNode)) {
        // create
        // check if exists same entity for roleId, treeNodeId and recursion type
        IdmRoleTreeNodeFilter filter = new IdmRoleTreeNodeFilter();
        filter.setRoleId(roleTreeNode.getRole());
        filter.setTreeNodeId(roleTreeNode.getTreeNode());
        filter.setRecursionType(roleTreeNode.getRecursionType());
        List<IdmRoleTreeNodeDto> content = this.find(filter, null).getContent();
        if (!content.isEmpty()) {
            throw new ResultCodeException(CoreResultCode.ROLE_TREE_NODE_TYPE_EXISTS, ImmutableMap.of("roleId", roleTreeNode.getRole(), "treeNodeId", roleTreeNode.getTreeNode(), "recursionType", roleTreeNode.getRecursionType()));
        }
        // 
        EventContext<IdmRoleTreeNodeDto> context = entityEventManager.process(new RoleTreeNodeEvent(RoleTreeNodeEventType.CREATE, roleTreeNode));
        if (context.isSuspended()) {
            throw new AcceptedException();
        }
        return context.getContent();
    }
    throw new ResultCodeException(CoreResultCode.METHOD_NOT_ALLOWED, "Automatic role update is not supported");
}
Also used : IdmRoleTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleTreeNodeFilter) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) RoleTreeNodeEvent(eu.bcvsolutions.idm.core.model.event.RoleTreeNodeEvent) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with RoleTreeNodeEvent

use of eu.bcvsolutions.idm.core.model.event.RoleTreeNodeEvent in project CzechIdMng by bcvsolutions.

the class DefaultIdmRoleTreeNodeService method delete.

/**
 * Publish {@link RoleTreeNodeEvent} only.
 *
 * @see {@link RoleTreeNodeDeleteProcessor}
 */
@Override
@Transactional(noRollbackFor = AcceptedException.class)
public void delete(IdmRoleTreeNodeDto roleTreeNode, BasePermission... permission) {
    Assert.notNull(roleTreeNode);
    checkAccess(this.getEntity(roleTreeNode.getId()), permission);
    // 
    LOG.debug("Deleting automatic role [{}] - [{}] - [{}]", roleTreeNode.getRole(), roleTreeNode.getTreeNode(), roleTreeNode.getRecursionType());
    // 
    EventContext<IdmRoleTreeNodeDto> context = entityEventManager.process(new RoleTreeNodeEvent(RoleTreeNodeEventType.DELETE, roleTreeNode));
    // 
    if (context.isSuspended()) {
        throw new AcceptedException();
    }
}
Also used : IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) RoleTreeNodeEvent(eu.bcvsolutions.idm.core.model.event.RoleTreeNodeEvent) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdmRoleTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto)2 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)2 RoleTreeNodeEvent (eu.bcvsolutions.idm.core.model.event.RoleTreeNodeEvent)2 Transactional (org.springframework.transaction.annotation.Transactional)2 IdmRoleTreeNodeFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleTreeNodeFilter)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1