Search in sources :

Example 16 with OperationResultDto

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;
}
Also used : OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) UUID(java.util.UUID) IdmAutomaticRoleRequest(eu.bcvsolutions.idm.core.model.entity.IdmAutomaticRoleRequest)

Example 17 with OperationResultDto

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);
}
Also used : OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)17 IdmEntityEventDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)13 Transactional (org.springframework.transaction.annotation.Transactional)12 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)11 Test (org.junit.Test)11 IdmEntityEventFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter)8 UUID (java.util.UUID)8 IdmEntityStateDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto)3 ArrayList (java.util.ArrayList)3 PageRequest (org.springframework.data.domain.PageRequest)3 Lists (com.google.common.collect.Lists)2 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)2 PriorityType (eu.bcvsolutions.idm.core.api.domain.PriorityType)2 Objects (com.google.common.base.Objects)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 CoreModuleDescriptor (eu.bcvsolutions.idm.core.CoreModuleDescriptor)1 EventConfiguration (eu.bcvsolutions.idm.core.api.config.domain.EventConfiguration)1 Auditable (eu.bcvsolutions.idm.core.api.domain.Auditable)1 ConfigurationMap (eu.bcvsolutions.idm.core.api.domain.ConfigurationMap)1 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)1