Search in sources :

Example 1 with IdmAutomaticRoleRequest

use of eu.bcvsolutions.idm.core.model.entity.IdmAutomaticRoleRequest 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)

Aggregations

OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)1 IdmAutomaticRoleRequest (eu.bcvsolutions.idm.core.model.entity.IdmAutomaticRoleRequest)1 UUID (java.util.UUID)1