use of eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleRequestService in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleRequestService method startRequest.
@Override
@Transactional
public IdmAutomaticRoleRequestDto startRequest(UUID requestId, boolean checkRight) {
IdmAutomaticRoleRequestDto request = get(requestId);
Assert.notNull(request, "Request is required!");
// Validation on exist some rule
if (AutomaticRoleRequestType.ATTRIBUTE == request.getRequestType() && RequestOperationType.REMOVE != request.getOperation()) {
IdmAutomaticRoleAttributeRuleRequestFilter ruleFilter = new IdmAutomaticRoleAttributeRuleRequestFilter();
ruleFilter.setRoleRequestId(requestId);
List<IdmAutomaticRoleAttributeRuleRequestDto> ruleConcepts = automaticRoleRuleRequestService.find(ruleFilter, null).getContent();
if (ruleConcepts.isEmpty()) {
throw new RoleRequestException(CoreResultCode.AUTOMATIC_ROLE_REQUEST_START_WITHOUT_RULE, ImmutableMap.of("request", request.getName()));
}
}
try {
IdmAutomaticRoleRequestService service = this.getIdmAutomaticRoleRequestService();
if (!(service instanceof DefaultIdmAutomaticRoleRequestService)) {
throw new CoreException("We expects instace of DefaultIdmAutomaticRoleRequestService!");
}
return ((DefaultIdmAutomaticRoleRequestService) service).startRequestNewTransactional(requestId, checkRight);
} catch (Exception ex) {
LOG.error(ex.getLocalizedMessage(), ex);
request = get(requestId);
Throwable exceptionToLog = resolveException(ex);
// TODO: I set only cause of exception, not code and properties. If are
// properties set, then request cannot be save!
request.setResult(new OperationResultDto.Builder(OperationState.EXCEPTION).setCause(exceptionToLog).build());
request.setState(RequestState.EXCEPTION);
return save(request);
}
}
use of eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleRequestService in project CzechIdMng by bcvsolutions.
the class IdmAutomaticRoleRequestController method delete.
@Override
@ResponseBody
@RequestMapping(value = "/{backendId}", method = RequestMethod.DELETE)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.AUTOMATIC_ROLE_REQUEST_DELETE + "')")
@ApiOperation(value = "Delete role request", nickname = "deleteRoleRequest", tags = { IdmAutomaticRoleRequestController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.AUTOMATIC_ROLE_REQUEST_DELETE, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.AUTOMATIC_ROLE_REQUEST_DELETE, description = "") }) })
public ResponseEntity<?> delete(@ApiParam(value = "Role request's uuid identifier.", required = true) @PathVariable @NotNull String backendId) {
IdmAutomaticRoleRequestService service = ((IdmAutomaticRoleRequestService) this.getService());
IdmAutomaticRoleRequestDto dto = service.get(backendId);
//
checkAccess(dto, IdmBasePermission.DELETE);
// Request in Executed state can not be delete or change
if (RequestState.EXECUTED == dto.getState()) {
throw new RoleRequestException(CoreResultCode.ROLE_REQUEST_EXECUTED_CANNOT_DELETE, ImmutableMap.of("request", dto));
}
// Only request in Concept state, can be deleted. In others states, will be request set to Canceled state and save.
if (RequestState.CONCEPT == dto.getState()) {
service.delete(dto);
} else {
service.cancel(dto);
}
return new ResponseEntity<Object>(HttpStatus.NO_CONTENT);
}
Aggregations