use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto 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.dto.IdmAutomaticRoleRequestDto 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.dto.IdmAutomaticRoleRequestDto 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.dto.IdmAutomaticRoleRequestDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleRequestService method startApprovalProcess.
@Override
@Transactional
public boolean startApprovalProcess(IdmAutomaticRoleRequestDto request, boolean checkRight, EntityEvent<IdmAutomaticRoleRequestDto> event, String wfDefinition) {
// and do realization immediately (without start approval process)
if (request.isExecuteImmediately()) {
boolean haveRightExecuteImmediately = securityService.hasAnyAuthority(CoreGroupPermission.AUTOMATIC_ROLE_REQUEST_ADMIN);
if (checkRight && !haveRightExecuteImmediately) {
throw new RoleRequestException(CoreResultCode.ROLE_REQUEST_NO_EXECUTE_IMMEDIATELY_RIGHT, ImmutableMap.of("new", request));
}
// Execute request immediately
return true;
} else {
Map<String, Object> variables = new HashMap<>();
// Minimize size of DTO persisting to WF
IdmAutomaticRoleRequestDto eventRequest = event.getContent();
eventRequest.setEmbedded(null);
variables.put(EntityEvent.EVENT_PROPERTY, event);
variables.put("approvalForAutomaticRole", Boolean.TRUE);
ProcessInstance processInstance = workflowProcessInstanceService.startProcess(wfDefinition, IdmRoleDto.class.getSimpleName(), request.getCreator(), request.getCreatorId().toString(), variables);
// We have to refresh request (maybe was changed in wf process)
request = this.get(request.getId());
request.setWfProcessId(processInstance.getProcessInstanceId());
this.save(request);
}
return false;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleRequestService method deleteAutomaticRole.
@Override
public void deleteAutomaticRole(AbstractIdmAutomaticRoleDto automaticRole, AutomaticRoleRequestType type) {
Assert.notNull(automaticRole);
Assert.notNull(type);
IdmAutomaticRoleRequestDto request = new IdmAutomaticRoleRequestDto();
request.setAutomaticRole(automaticRole.getId());
request.setName(automaticRole.getName());
request.setRequestType(type);
request.setOperation(RequestOperationType.REMOVE);
request.setResult(new OperationResultDto.Builder(OperationState.CREATED).build());
request = this.save(request);
this.getIdmAutomaticRoleRequestService().startRequest(request.getId(), true);
}
Aggregations