Search in sources :

Example 51 with AbstractDto

use of eu.bcvsolutions.idm.core.api.dto.AbstractDto in project CzechIdMng by bcvsolutions.

the class IdmEntityEventController method toFilter.

@Override
protected IdmEntityEventFilter toFilter(MultiValueMap<String, Object> parameters) {
    IdmEntityEventFilter filter = new IdmEntityEventFilter(parameters, getParameterConverter());
    // owner decorator
    String ownerId = getParameterConverter().toString(parameters, IdmEntityEventFilter.PARAMETER_OWNER_ID);
    UUID ownerUuid = null;
    String ownerType = filter.getOwnerType();
    if (StringUtils.isNotEmpty(ownerType) && StringUtils.isNotEmpty(ownerId)) {
        // try to find entity owner by Codeable identifier
        AbstractDto owner = manager.findOwner(ownerType, ownerId);
        if (owner != null) {
            ownerUuid = owner.getId();
        } else {
            LOG.debug("Entity type [{}] with identifier [{}] does not found, raw ownerId will be used as uuid.", ownerType, ownerId);
            // Better exception for FE.
            try {
                DtoUtils.toUuid(ownerId);
            } catch (ClassCastException ex) {
                throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", ownerId), ex);
            }
        }
    }
    if (ownerUuid == null) {
        ownerUuid = getParameterConverter().toUuid(parameters, IdmEntityEventFilter.PARAMETER_OWNER_ID);
    }
    filter.setOwnerId(ownerUuid);
    // 
    // super owner decorator
    String superOwnerId = getParameterConverter().toString(parameters, IdmEntityEventFilter.PARAMETER_SUPER_OWNER_ID);
    UUID superOwnerUuid = null;
    String superOwnerType = getParameterConverter().toString(parameters, IdmEntityEventFilter.PARAMETER_SUPER_OWNER_TYPE);
    if (StringUtils.isNotEmpty(superOwnerType) && StringUtils.isNotEmpty(superOwnerId)) {
        // try to find entity owner by Codeable identifier
        AbstractDto owner = manager.findOwner(superOwnerType, superOwnerId);
        if (owner != null) {
            superOwnerUuid = owner.getId();
        } else {
            LOG.debug("Entity type [{}] with identifier [{}] does not found, raw ownerId will be used as uuid.", superOwnerType, superOwnerId);
            // Better exception for FE.
            try {
                DtoUtils.toUuid(ownerId);
            } catch (ClassCastException ex) {
                throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", ownerId), ex);
            }
        }
    }
    if (superOwnerUuid == null) {
        superOwnerUuid = getParameterConverter().toUuid(parameters, IdmEntityEventFilter.PARAMETER_SUPER_OWNER_ID);
    }
    filter.setSuperOwnerId(superOwnerUuid);
    // 
    return filter;
}
Also used : AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmEntityEventFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter) UUID(java.util.UUID)

Example 52 with AbstractDto

use of eu.bcvsolutions.idm.core.api.dto.AbstractDto in project CzechIdMng by bcvsolutions.

the class DefaultLookupServiceIntegrationTest method testLookupEmbeddedReflectionFailed.

@SuppressWarnings("unused")
@Test(expected = IllegalArgumentException.class)
public void testLookupEmbeddedReflectionFailed() {
    AbstractDto mockDto = new AbstractDto() {

        private static final long serialVersionUID = 1L;

        @Embedded(dtoClass = IdmIdentityRoleDto.class)
        private IdmIdentityRoleDto wrong;

        public IdmIdentityRoleDto getWrong() {
            throw new UnsupportedOperationException("mock");
        }

        public void setWrong(IdmIdentityRoleDto wrong) {
            this.wrong = wrong;
        }
    };
    // 
    lookupService.lookupEmbeddedDto(mockDto, "wrong");
}
Also used : AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 53 with AbstractDto

use of eu.bcvsolutions.idm.core.api.dto.AbstractDto in project CzechIdMng by bcvsolutions.

the class DefaultLookupServiceIntegrationTest method testLookupEmbeddedNotSerializable.

@SuppressWarnings("unused")
@Test(expected = IllegalArgumentException.class)
public void testLookupEmbeddedNotSerializable() {
    AbstractDto mockDto = new AbstractDto() {

        private static final long serialVersionUID = 1L;

        @Embedded(dtoClass = IdmIdentityRoleDto.class)
        private GuardedString wrong = new GuardedString("mock");

        public GuardedString getWrong() {
            return wrong;
        }

        public void setWrong(GuardedString wrong) {
            this.wrong = wrong;
        }
    };
    // 
    lookupService.lookupEmbeddedDto(mockDto, "wrong");
}
Also used : AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 54 with AbstractDto

use of eu.bcvsolutions.idm.core.api.dto.AbstractDto in project CzechIdMng by bcvsolutions.

the class AbstractSynchronizationExecutor method getDtoByAccount.

@Override
@SuppressWarnings("unchecked")
public DTO getDtoByAccount(UUID entityId, AccAccountDto account) {
    if (entityId == null && account != null) {
        Assert.notNull(account.getId(), "Account ID cannot be null!");
        EntityAccountFilter entityAccountFilter = createEntityAccountFilter();
        entityAccountFilter.setAccountId(account.getId());
        entityAccountFilter.setOwnership(Boolean.TRUE);
        List<EntityAccountDto> entityAccounts = // 
        this.getEntityAccountService().find(entityAccountFilter, // 
        PageRequest.of(0, 1)).getContent();
        if (!entityAccounts.isEmpty()) {
            // We assume that all identity accounts
            // (mark as
            // ownership) have same identity!
            EntityAccountDto entityAccountDto = entityAccounts.get(0);
            if (entityAccountDto instanceof AbstractDto && entityAccountDto.getEntity() != null) {
                UUID entityIdLocal = entityAccountDto.getEntity();
                AbstractDto entityAccount = (AbstractDto) entityAccountDto;
                // Try to find target entity in embedded by entityId.
                BaseDto targetDto = // 
                entityAccount.getEmbedded().values().stream().filter(// 
                dto -> entityIdLocal.equals(dto.getId())).findFirst().orElse(null);
                if (targetDto != null) {
                    return (DTO) targetDto;
                } else {
                    entityId = entityIdLocal;
                }
            }
        }
    }
    DTO entity = null;
    if (entityId != null) {
        entity = this.getService().get(entityId);
    }
    return entity;
}
Also used : EntityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.EntityAccountFilter) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) EntityAccountDto(eu.bcvsolutions.idm.acc.dto.EntityAccountDto) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) UUID(java.util.UUID)

Aggregations

AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)54 UUID (java.util.UUID)28 Test (org.junit.Test)16 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)15 BaseDto (eu.bcvsolutions.idm.core.api.dto.BaseDto)13 HashMap (java.util.HashMap)12 List (java.util.List)11 Autowired (org.springframework.beans.factory.annotation.Autowired)11 Transactional (org.springframework.transaction.annotation.Transactional)11 Assert (org.springframework.util.Assert)11 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)10 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)10 Map (java.util.Map)10 Service (org.springframework.stereotype.Service)10 Embedded (eu.bcvsolutions.idm.core.api.domain.Embedded)9 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)9 IntrospectionException (java.beans.IntrospectionException)9 Field (java.lang.reflect.Field)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 ImmutableMap (com.google.common.collect.ImmutableMap)8