Search in sources :

Example 1 with IdmAutomaticRole

use of eu.bcvsolutions.idm.core.model.entity.IdmAutomaticRole in project CzechIdMng by bcvsolutions.

the class DefaultIdmConceptRoleRequestService method toDto.

@Override
protected IdmConceptRoleRequestDto toDto(IdmConceptRoleRequest entity, IdmConceptRoleRequestDto dto) {
    dto = super.toDto(entity, dto);
    if (dto == null) {
        return null;
    }
    // Contract from identity role has higher priority then contract ID in concept role
    if (entity != null && entity.getIdentityRole() != null) {
        dto.setIdentityContract(entity.getIdentityRole().getIdentityContract().getId());
    }
    // we must set automatic role to role tree node
    if (entity != null && entity.getAutomaticRole() != null) {
        dto.setAutomaticRole(entity.getAutomaticRole().getId());
        IdmAutomaticRole automaticRole = entity.getAutomaticRole();
        Map<String, BaseDto> embedded = dto.getEmbedded();
        // 
        BaseDto baseDto = null;
        if (automaticRole instanceof IdmAutomaticRoleAttribute) {
            baseDto = lookupService.getDtoService(IdmAutomaticRoleAttributeDto.class).get(automaticRole.getId());
        } else {
            baseDto = lookupService.getDtoService(IdmRoleTreeNodeDto.class).get(automaticRole.getId());
        }
        // roleTreeNode must be placed there as string, in meta model isn't any attribute like this
        embedded.put("roleTreeNode", baseDto);
        dto.setEmbedded(embedded);
    }
    return dto;
}
Also used : IdmAutomaticRole(eu.bcvsolutions.idm.core.model.entity.IdmAutomaticRole) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) IdmAutomaticRoleAttribute(eu.bcvsolutions.idm.core.model.entity.IdmAutomaticRoleAttribute)

Example 2 with IdmAutomaticRole

use of eu.bcvsolutions.idm.core.model.entity.IdmAutomaticRole in project CzechIdMng by bcvsolutions.

the class DefaultIdmIdentityRoleService method toEntity.

@Override
protected IdmIdentityRole toEntity(IdmIdentityRoleDto dto, IdmIdentityRole entity) {
    IdmIdentityRole resultEntity = super.toEntity(dto, entity);
    // set additional automatic role
    if (resultEntity != null && dto.getRoleTreeNode() != null) {
        // it isn't possible use lookupService entity lookup
        IdmAutomaticRole automaticRole = automaticRoleRepository.findOne(dto.getRoleTreeNode());
        resultEntity.setAutomaticRole(automaticRole);
    }
    return resultEntity;
}
Also used : IdmIdentityRole(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole) IdmAutomaticRole(eu.bcvsolutions.idm.core.model.entity.IdmAutomaticRole)

Example 3 with IdmAutomaticRole

use of eu.bcvsolutions.idm.core.model.entity.IdmAutomaticRole in project CzechIdMng by bcvsolutions.

the class DefaultIdmConceptRoleRequestService method toEntity.

@Override
@Transactional(readOnly = true)
public IdmConceptRoleRequest toEntity(IdmConceptRoleRequestDto dto, IdmConceptRoleRequest entity) {
    if (dto == null) {
        return null;
    }
    // TODO: Create converter for skip fields mark as read only
    if (dto.getId() != null) {
        IdmConceptRoleRequestDto dtoPersisited = this.get(dto.getId());
        if (dto.getState() == null) {
            dto.setState(dtoPersisited.getState());
        }
        if (dto.getLog() == null) {
            dto.setLog(dtoPersisited.getLog());
        }
        if (dto.getWfProcessId() == null) {
            dto.setWfProcessId(dtoPersisited.getWfProcessId());
        }
    } else {
        dto.setState(RoleRequestState.CONCEPT);
    }
    // 
    // field automatic role exists in entity but not in dto
    TypeMap<IdmConceptRoleRequestDto, IdmConceptRoleRequest> typeMap = modelMapper.getTypeMap(getDtoClass(), getEntityClass());
    if (typeMap == null) {
        modelMapper.createTypeMap(getDtoClass(), getEntityClass());
        typeMap = modelMapper.getTypeMap(getDtoClass(), getEntityClass());
        typeMap.addMappings(new PropertyMap<IdmConceptRoleRequestDto, IdmConceptRoleRequest>() {

            @Override
            protected void configure() {
                this.skip().setAutomaticRole(null);
            }
        });
    }
    // 
    if (entity != null) {
        modelMapper.map(dto, entity);
    } else {
        entity = modelMapper.map(dto, getEntityClass(dto));
    }
    // set additional automatic role
    if (entity != null) {
        if (dto.getAutomaticRole() != null) {
            // it isn't possible use lookupService entity lookup
            IdmAutomaticRole automaticRole = automaticRoleRepository.findOne(dto.getAutomaticRole());
            entity.setAutomaticRole(automaticRole);
        } else {
            // relation was removed
            entity.setAutomaticRole(null);
        }
    }
    return entity;
}
Also used : IdmConceptRoleRequest(eu.bcvsolutions.idm.core.model.entity.IdmConceptRoleRequest) IdmAutomaticRole(eu.bcvsolutions.idm.core.model.entity.IdmAutomaticRole) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with IdmAutomaticRole

use of eu.bcvsolutions.idm.core.model.entity.IdmAutomaticRole in project CzechIdMng by bcvsolutions.

the class DefaultIdmIdentityRoleService method toDto.

@Override
protected IdmIdentityRoleDto toDto(IdmIdentityRole entity, IdmIdentityRoleDto dto) {
    dto = super.toDto(entity, dto);
    if (dto == null) {
        return null;
    }
    // 
    IdmAutomaticRole automaticRole = entity.getAutomaticRole();
    if (automaticRole != null) {
        dto.setRoleTreeNode(automaticRole.getId());
        dto.setAutomaticRole(true);
        BaseDto baseDto = null;
        Map<String, BaseDto> embedded = dto.getEmbedded();
        if (automaticRole instanceof IdmAutomaticRoleAttribute) {
            baseDto = lookupService.getDtoService(IdmAutomaticRoleAttributeDto.class).get(automaticRole.getId());
        } else {
            baseDto = lookupService.getDtoService(IdmRoleTreeNodeDto.class).get(automaticRole.getId());
        }
        embedded.put(IdmAutomaticRoleAttributeService.ROLE_TREE_NODE_ATTRIBUTE_NAME, baseDto);
        dto.setEmbedded(embedded);
    }
    // 
    return dto;
}
Also used : IdmAutomaticRole(eu.bcvsolutions.idm.core.model.entity.IdmAutomaticRole) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) IdmAutomaticRoleAttribute(eu.bcvsolutions.idm.core.model.entity.IdmAutomaticRoleAttribute)

Aggregations

IdmAutomaticRole (eu.bcvsolutions.idm.core.model.entity.IdmAutomaticRole)4 BaseDto (eu.bcvsolutions.idm.core.api.dto.BaseDto)2 IdmAutomaticRoleAttribute (eu.bcvsolutions.idm.core.model.entity.IdmAutomaticRoleAttribute)2 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)1 IdmConceptRoleRequest (eu.bcvsolutions.idm.core.model.entity.IdmConceptRoleRequest)1 IdmIdentityRole (eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole)1 Transactional (org.springframework.transaction.annotation.Transactional)1