use of eu.bcvsolutions.idm.core.api.dto.OperationResultDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleRequestService method toEntity.
@Override
protected IdmAutomaticRoleRequest toEntity(IdmAutomaticRoleRequestDto dto, IdmAutomaticRoleRequest entity) {
if (this.isNew(dto)) {
dto.setResult(new OperationResultDto(OperationState.CREATED));
dto.setState(RequestState.CONCEPT);
if (dto.getRequestType() == null) {
dto.setRequestType(AutomaticRoleRequestType.ATTRIBUTE);
}
}
IdmAutomaticRoleRequest requestEntity = super.toEntity(dto, entity);
// Convert type of automatic role
if (dto != null) {
UUID automaticRoleId = dto.getAutomaticRole();
if (automaticRoleId != null && AutomaticRoleRequestType.ATTRIBUTE == dto.getRequestType()) {
requestEntity.setAutomaticRole((IdmAutomaticRoleAttribute) lookupService.lookupEntity(IdmAutomaticRoleAttribute.class, automaticRoleId));
}
if (automaticRoleId != null && AutomaticRoleRequestType.TREE == dto.getRequestType()) {
requestEntity.setAutomaticRole((IdmRoleTreeNode) lookupService.lookupEntity(IdmRoleTreeNode.class, automaticRoleId));
}
}
if (requestEntity != null && requestEntity.getAutomaticRole() != null) {
requestEntity.setRole(requestEntity.getAutomaticRole().getRole());
if (Strings.isNullOrEmpty(requestEntity.getName())) {
requestEntity.setName(requestEntity.getAutomaticRole().getName());
}
}
return requestEntity;
}
use of eu.bcvsolutions.idm.core.api.dto.OperationResultDto in project CzechIdMng by bcvsolutions.
the class IdmAutomaticRoleRequestController method post.
@Override
@ResponseBody
@RequestMapping(method = RequestMethod.POST)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.AUTOMATIC_ROLE_REQUEST_CREATE + "')" + " or hasAuthority('" + CoreGroupPermission.AUTOMATIC_ROLE_REQUEST_UPDATE + "')")
@ApiOperation(value = "Create / update role request", nickname = "postRoleRequest", response = IdmAutomaticRoleRequestDto.class, tags = { IdmAutomaticRoleRequestController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.AUTOMATIC_ROLE_REQUEST_CREATE, description = ""), @AuthorizationScope(scope = CoreGroupPermission.AUTOMATIC_ROLE_REQUEST_UPDATE, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.AUTOMATIC_ROLE_REQUEST_CREATE, description = ""), @AuthorizationScope(scope = CoreGroupPermission.AUTOMATIC_ROLE_REQUEST_UPDATE, description = "") }) })
public ResponseEntity<?> post(@RequestBody @NotNull IdmAutomaticRoleRequestDto request) {
if (getService().isNew(request)) {
request.setResult(new OperationResultDto(OperationState.CREATED));
request.setState(RequestState.CONCEPT);
if (request.getRequestType() == null) {
request.setRequestType(AutomaticRoleRequestType.ATTRIBUTE);
}
}
return super.post(request);
}
Aggregations