Search in sources :

Example 11 with DataFilter

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

the class DefaultFilterManagerIntegrationTest method testFilterNotSupported.

@Test(expected = FilterNotSupportedException.class)
public void testFilterNotSupported() {
    try {
        configurationService.setBooleanValue(FilterManager.PROPERTY_CHECK_SUPPORTED_FILTER_ENABLED, true);
        DataFilter filter = new DataFilter(IdmConfigurationDto.class);
        filter.set("wrong", "mock");
        configurationService.find(filter, null);
    } finally {
        configurationService.setBooleanValue(FilterManager.PROPERTY_CHECK_SUPPORTED_FILTER_ENABLED, FilterManager.DEFAULT_CHECK_SUPPORTED_FILTER_ENABLED);
    }
}
Also used : DataFilter(eu.bcvsolutions.idm.core.api.dto.filter.DataFilter) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 12 with DataFilter

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

the class DefaultFilterManagerIntegrationTest method testFilterSupportedByFilterInstance.

@Test
public void testFilterSupportedByFilterInstance() {
    try {
        configurationService.setBooleanValue(FilterManager.PROPERTY_CHECK_SUPPORTED_FILTER_ENABLED, true);
        DataFilter filter = new DataFilter(IdmConfigurationDto.class) {

            @SuppressWarnings("unused")
            private String wrong;
        };
        filter.set("wrong", "mock");
        Page<IdmConfigurationDto> configurations = configurationService.find(filter, null);
        // 
        Assert.assertNotNull(configurations);
    } finally {
        configurationService.setBooleanValue(FilterManager.PROPERTY_CHECK_SUPPORTED_FILTER_ENABLED, FilterManager.DEFAULT_CHECK_SUPPORTED_FILTER_ENABLED);
    }
}
Also used : DataFilter(eu.bcvsolutions.idm.core.api.dto.filter.DataFilter) IdmConfigurationDto(eu.bcvsolutions.idm.core.api.dto.IdmConfigurationDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 13 with DataFilter

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

the class AbstractReadWriteDtoControllerRestTest method testDuplicateExternalId.

@Test
public void testDuplicateExternalId() throws Exception {
    if (!DataFilter.class.isAssignableFrom(getController().getFilterClass())) {
        LOG.warn("Controller [{}] doesn't support DataFilter. Find by external id will not be tested.", getController().getClass());
        return;
    }
    // 
    DTO dto = prepareDto();
    if (!(dto instanceof ExternalIdentifiable)) {
        // ignore test
        return;
    }
    // 
    ExternalIdentifiable externalIdentifiableDto = (ExternalIdentifiable) dto;
    String name = getHelper().createName();
    externalIdentifiableDto.setExternalId(name);
    // 
    DTO original = createDto(dto);
    DTO duplicate = prepareDto();
    ((ExternalIdentifiable) duplicate).setExternalId(name);
    // 
    if (!supportsPost()) {
        try {
            createDto(duplicate);
            Assert.fail();
        } catch (DuplicateExternalIdException ex) {
            Assert.assertEquals(original.getId(), ex.getDuplicateId());
        }
    } else {
        getMockMvc().perform(post(getBaseUrl()).with(authentication(getAdminAuthentication())).content(getMapper().writeValueAsString(duplicate)).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().isConflict());
    }
}
Also used : DataFilter(eu.bcvsolutions.idm.core.api.dto.filter.DataFilter) ExternalIdentifiable(eu.bcvsolutions.idm.core.api.domain.ExternalIdentifiable) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) DuplicateExternalIdException(eu.bcvsolutions.idm.core.api.exception.DuplicateExternalIdException) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test)

Example 14 with DataFilter

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

the class AbstractReadWriteDtoControllerRestTest method testDuplicateExternalCode.

@Test
public void testDuplicateExternalCode() throws Exception {
    if (!DataFilter.class.isAssignableFrom(getController().getFilterClass())) {
        LOG.warn("Controller [{}] doesn't support DataFilter. Find by external id will not be tested.", getController().getClass());
        return;
    }
    // 
    DTO dto = prepareDto();
    if (!(dto instanceof ExternalCodeable)) {
        // ignore test
        return;
    }
    // 
    ExternalCodeable externalIdentifiableDto = (ExternalCodeable) dto;
    String name = getHelper().createName();
    externalIdentifiableDto.setExternalCode(name);
    // 
    createDto(dto);
    // 
    getMockMvc().perform(post(getBaseUrl()).with(authentication(getAdminAuthentication())).content(getMapper().writeValueAsString(dto)).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().isConflict());
}
Also used : DataFilter(eu.bcvsolutions.idm.core.api.dto.filter.DataFilter) ExternalCodeable(eu.bcvsolutions.idm.core.api.domain.ExternalCodeable) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test)

Example 15 with DataFilter

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

the class IdmAuditController method loadEmbeddedEntity.

/**
 * Fills referenced entity to dto - prevent to load entity for each row.
 *
 * @param dto
 */
private void loadEmbeddedEntity(Map<UUID, BaseDto> loadedDtos, IdmAuditDto dto) {
    UUID entityId = dto.getEntityId();
    if (entityId == null || StringUtils.isEmpty(dto.getType())) {
        // just for sure - IdmAudit entity doesn't specify it as required (but it should be)
        return;
    }
    // set context - add additional common props
    DataFilter context = new DataFilter(null);
    context.set(IdmFormValueFilter.PARAMETER_ADD_OWNER_DTO, Boolean.TRUE);
    BaseDto revision = null;
    if (loadedDtos.containsKey(entityId)) {
        revision = loadedDtos.get(entityId);
    } else {
        try {
            BaseEntity revisionEntity = getLookupService().lookupEntity(dto.getType(), entityId);
            if (revisionEntity != null) {
                revision = getLookupService().toDto(revisionEntity, null, context);
            }
            loadedDtos.put(entityId, revision);
        } catch (IllegalArgumentException ex) {
            LOG.debug("Class [{}] not found on classpath (e.g. module was uninstalled)", dto.getType(), ex);
        } catch (Exception ex) {
            LOG.debug("Type [{}] cannot be mapped to dto.", dto.getType(), ex);
        }
    }
    // nullable
    dto.getEmbedded().put(IdmAudit_.entityId.getName(), revision);
    // try to load last revision for deleted entity - main table only ~ subowner will not be solved
    if (revision == null) {
        dto.setDeleted(true);
        try {
            Object lastPersistedVersion = auditService.findLastPersistedVersion(Class.forName(dto.getType()), entityId);
            if (lastPersistedVersion != null) {
                dto.getEmbedded().put(IdmAudit_.entityId.getName(), getLookupService().toDto((BaseEntity) lastPersistedVersion, null, context));
            }
        } catch (IllegalArgumentException | ClassNotFoundException ex) {
            LOG.debug("Class [{}] not found on classpath (e.g. module was uninstalled)", dto.getType(), ex);
        } catch (Exception ex) {
            LOG.debug("Type [{}] cannot be mapped to dto.", dto.getType(), ex);
        }
    }
    // For subowner, some entities doesn't support owner and subowner.
    if (dto.getSubOwnerId() != null) {
        try {
            UUID subOwnerId = UUID.fromString(dto.getSubOwnerId());
            if (!loadedDtos.containsKey(subOwnerId)) {
                loadedDtos.put(subOwnerId, getLookupService().lookupDto(dto.getSubOwnerType(), subOwnerId));
            }
            dto.getEmbedded().put(IdmAudit_.subOwnerId.getName(), loadedDtos.get(subOwnerId));
        } catch (IllegalArgumentException ex) {
            LOG.debug("Class [{}] not found on classpath (e.g. module was uninstalled)", dto.getSubOwnerType(), ex);
        } catch (Exception ex) {
            LOG.debug("Type [{}] cannot be mapped to dto.", dto.getSubOwnerId(), ex);
        }
    }
    // For owner, some entities doesn't support owner and subowner.
    if (dto.getOwnerId() != null) {
        try {
            UUID ownerId = UUID.fromString(dto.getOwnerId());
            if (!loadedDtos.containsKey(ownerId)) {
                loadedDtos.put(ownerId, getLookupService().lookupDto(dto.getOwnerType(), ownerId));
            }
            dto.getEmbedded().put(IdmAudit_.ownerId.getName(), loadedDtos.get(ownerId));
        } catch (IllegalArgumentException ex) {
            LOG.debug("Class [{}] not found on classpath (e.g. module was uninstalled)", dto.getSubOwnerType(), ex);
        } catch (Exception ex) {
            LOG.debug("Entity [{}] cannot be mapped to dto.", dto.getOwnerId(), ex);
        }
    }
    // Fill embedded contract for FE agenda (prevent to load contract for each row).
    if ((dto instanceof IdmAuditEntityDto) && dto.getType().equals(IdmIdentityRole.class.getCanonicalName())) {
        IdmAuditEntityDto auditEntity = (IdmAuditEntityDto) dto;
        if (auditEntity.getEntity().containsKey(IdmIdentityRoleDto.PROPERTY_IDENTITY_CONTRACT) && !auditEntity.getEmbedded().containsKey(IdmIdentityRoleDto.PROPERTY_IDENTITY_CONTRACT)) {
            UUID contractId = DtoUtils.toUuid(auditEntity.getEntity().get(IdmIdentityRoleDto.PROPERTY_IDENTITY_CONTRACT));
            if (contractId != null) {
                if (!loadedDtos.containsKey(contractId)) {
                    loadedDtos.put(contractId, getLookupService().lookupDto(IdmIdentityContractDto.class, contractId));
                }
                auditEntity.getEmbedded().put(IdmIdentityRoleDto.PROPERTY_IDENTITY_CONTRACT, loadedDtos.get(contractId));
            }
        }
    }
}
Also used : DataFilter(eu.bcvsolutions.idm.core.api.dto.filter.DataFilter) IdmAuditEntityDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditEntityDto) BaseEntity(eu.bcvsolutions.idm.core.api.entity.BaseEntity) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) UUID(java.util.UUID) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException)

Aggregations

DataFilter (eu.bcvsolutions.idm.core.api.dto.filter.DataFilter)22 Test (org.junit.Test)17 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)12 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)7 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)7 IdmConfigurationDto (eu.bcvsolutions.idm.core.api.dto.IdmConfigurationDto)6 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)6 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)4 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)3 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)3 IdmIdentityFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter)3 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)3 IdmBulkActionDto (eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto)2 ExternalCodeable (eu.bcvsolutions.idm.core.api.domain.ExternalCodeable)2 FilterBuilder (eu.bcvsolutions.idm.core.api.repository.filter.FilterBuilder)2 IdmIdentityService (eu.bcvsolutions.idm.core.api.service.IdmIdentityService)2 AbstractRestTest (eu.bcvsolutions.idm.test.api.AbstractRestTest)2 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 Lists (com.google.common.collect.Lists)1