use of eu.bcvsolutions.idm.core.api.exception.AcceptedException in project CzechIdMng by bcvsolutions.
the class TreeNodeDeleteProcessor method process.
@Override
public EventResult<IdmTreeNodeDto> process(EntityEvent<IdmTreeNodeDto> event) {
IdmTreeNodeDto treeNode = event.getContent();
//
if (identityContractRepository.countByWorkPosition_Id(treeNode.getId()) > 0) {
throw new TreeNodeException(CoreResultCode.TREE_NODE_DELETE_FAILED_HAS_CONTRACTS, ImmutableMap.of("treeNode", treeNode.getName()));
}
// remove related automatic roles
IdmRoleTreeNodeFilter filter = new IdmRoleTreeNodeFilter();
filter.setTreeNodeId(treeNode.getId());
roleTreeNodeService.find(filter, null).forEach(roleTreeNode -> {
try {
roleTreeNodeService.delete(roleTreeNode);
} catch (AcceptedException ex) {
throw new TreeNodeException(CoreResultCode.TREE_NODE_DELETE_FAILED_HAS_ROLE, ImmutableMap.of("treeNode", treeNode.getName(), "roleTreeNode", roleTreeNode.getId()));
}
});
//
service.deleteInternal(treeNode);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.exception.AcceptedException in project CzechIdMng by bcvsolutions.
the class DefaultAutomaticRoleManager method createAutomaticRoleByTree.
@Override
public IdmRoleTreeNodeDto createAutomaticRoleByTree(IdmRoleTreeNodeDto automaticRole, boolean executeImmediately) {
IdmAutomaticRoleRequestDto request = new IdmAutomaticRoleRequestDto();
request.setOperation(RequestOperationType.ADD);
request.setRequestType(AutomaticRoleRequestType.TREE);
request.setExecuteImmediately(executeImmediately);
request.setName(automaticRole.getName());
request.setRole(automaticRole.getRole());
request.setTreeNode(automaticRole.getTreeNode());
request = roleRequestService.save(request);
request = roleRequestService.startRequest(request.getId(), true);
if (RequestState.EXECUTED == request.getState()) {
UUID createdAutomaticRoleId = request.getAutomaticRole();
Assert.notNull(createdAutomaticRoleId);
return roleTreeNodeService.get(request.getAutomaticRole());
}
if (RequestState.IN_PROGRESS == request.getState()) {
throw new AcceptedException(request.getId().toString());
}
if (RequestState.EXCEPTION == request.getState()) {
throw new CoreException(request.getResult().getCause());
}
return null;
}
use of eu.bcvsolutions.idm.core.api.exception.AcceptedException in project CzechIdMng by bcvsolutions.
the class DefaultAutomaticRoleManager method createAutomaticRoleByAttribute.
@Override
public IdmAutomaticRoleAttributeDto createAutomaticRoleByAttribute(IdmAutomaticRoleAttributeDto automaticRole, boolean executeImmediately, IdmAutomaticRoleAttributeRuleDto... rules) {
IdmAutomaticRoleRequestDto request = new IdmAutomaticRoleRequestDto();
request.setOperation(RequestOperationType.ADD);
request.setRequestType(AutomaticRoleRequestType.ATTRIBUTE);
request.setExecuteImmediately(executeImmediately);
request.setName(automaticRole.getName());
request.setRole(automaticRole.getRole());
request = roleRequestService.save(request);
if (rules != null) {
for (IdmAutomaticRoleAttributeRuleDto rule : rules) {
IdmAutomaticRoleAttributeRuleRequestDto ruleRequest = new IdmAutomaticRoleAttributeRuleRequestDto();
ruleRequest.setRequest(request.getId());
ruleRequest.setOperation(RequestOperationType.ADD);
ruleRequest.setAttributeName(rule.getAttributeName());
ruleRequest.setComparison(rule.getComparison());
ruleRequest.setType(rule.getType());
ruleRequest.setFormAttribute(rule.getFormAttribute());
ruleRequest.setValue(rule.getValue());
ruleRequest.setRule(rule.getId());
ruleRequest = ruleRequestService.save(ruleRequest);
}
}
request = roleRequestService.startRequest(request.getId(), true);
if (RequestState.EXECUTED == request.getState()) {
UUID createdAutomaticRoleId = request.getAutomaticRole();
Assert.notNull(createdAutomaticRoleId);
return automaticRoleAttributeService.get(request.getAutomaticRole());
}
if (RequestState.IN_PROGRESS == request.getState()) {
throw new AcceptedException(request.getId().toString());
}
if (RequestState.EXCEPTION == request.getState()) {
throw new CoreException(request.getResult().getCause());
}
return null;
}
use of eu.bcvsolutions.idm.core.api.exception.AcceptedException in project CzechIdMng by bcvsolutions.
the class DefaultAutomaticRoleManager method deleteAutomaticRole.
@Override
public void deleteAutomaticRole(AbstractIdmAutomaticRoleDto automaticRole, boolean executeImmediately) {
Assert.notNull(automaticRole);
Assert.notNull(automaticRole.getId(), "Automatic role must exists!");
IdmAutomaticRoleRequestDto request = new IdmAutomaticRoleRequestDto();
if (automaticRole instanceof IdmRoleTreeNodeDto) {
request.setRequestType(AutomaticRoleRequestType.TREE);
request.setTreeNode(((IdmRoleTreeNodeDto) automaticRole).getTreeNode());
} else {
request.setRequestType(AutomaticRoleRequestType.ATTRIBUTE);
}
request.setOperation(RequestOperationType.REMOVE);
request.setExecuteImmediately(executeImmediately);
request.setAutomaticRole(automaticRole.getId());
request.setName(automaticRole.getName());
request.setRole(automaticRole.getRole());
request = roleRequestService.save(request);
request = roleRequestService.startRequest(request.getId(), true);
if (RequestState.EXECUTED == request.getState()) {
return;
}
if (RequestState.IN_PROGRESS == request.getState()) {
throw new AcceptedException(request.getId().toString());
}
if (RequestState.EXCEPTION == request.getState()) {
throw new CoreException(request.getResult().getCause());
}
}
use of eu.bcvsolutions.idm.core.api.exception.AcceptedException 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");
}
Aggregations