Search in sources :

Example 16 with DataFilter

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

the class IdentityFilterTest method testManagersForFilter.

@Test
public void testManagersForFilter() {
    FilterBuilder<IdmIdentity, DataFilter> filterBuilderSubordinates = filterManager.getBuilder(IdmIdentity.class, IdmIdentityFilter.PARAMETER_SUBORDINATES_FOR);
    FilterBuilder<IdmIdentity, DataFilter> filterBuilderManagers = filterManager.getBuilder(IdmIdentity.class, IdmIdentityFilter.PARAMETER_MANAGERS_FOR);
    FilterBuilder<IdmIdentityContract, DataFilter> filterBuilderContractByManager = filterManager.getBuilder(IdmIdentityContract.class, IdmIdentityContractFilter.PARAMETER_SUBORDINATES_FOR);
    Assert.assertEquals(DefaultManagersFilter.FILTER_NAME, filterBuilderManagers.getId());
    Assert.assertEquals(DefaultSubordinatesFilter.FILTER_NAME, filterBuilderSubordinates.getId());
    Assert.assertEquals(DefaultContractByManagerFilter.FILTER_NAME, filterBuilderContractByManager.getId());
    Assert.assertFalse(filterBuilderSubordinates.isDisabled());
    Assert.assertFalse(filterBuilderManagers.isDisabled());
    Assert.assertFalse(filterBuilderContractByManager.isDisabled());
    // 
    IdmIdentityDto person = getIdmIdentity("ThisIsTestName009", "ThisIsTestName009", "ThisIsTestName009@gemail.eu", "000000009", false);
    IdmIdentityDto manager = getIdmIdentity("ThisIsTestName010", "ThisIsTestName010", "ThisIsTestName010@gemail.eu", "000000010", false);
    IdmTreeTypeDto type1 = getHelper().createTreeType();
    IdmTreeNodeDto node2 = getHelper().createTreeNode(type1, null);
    IdmTreeNodeDto node1 = getHelper().createTreeNode(type1, node2);
    getHelper().createContract(manager, node2);
    getHelper().createContract(person, node1);
    // 
    IdmIdentityFilter filter = new IdmIdentityFilter();
    filter.setIncludeGuarantees(false);
    filter.setManagersFor(person.getId());
    filter.setManagersByTreeType(type1.getId());
    List<IdmIdentityDto> results = identityService.find(filter, null).getContent();
    Assert.assertEquals(1, results.size());
    Assert.assertEquals(manager.getId(), results.get(0).getId());
}
Also used : DataFilter(eu.bcvsolutions.idm.core.api.dto.filter.DataFilter) IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 17 with DataFilter

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

the class ModelMapperChecker method verify.

/**
 * Check registered services and their conversions to dto provided by model mapper.
 * Throws Exception, if check does not pass.
 *
 * @throws ConfigurationDisabledException if check is disabled by configuration.
 * @throws ResultCodeException if service check failed (referential integrity is broken or other IdM exception occurs).
 * @throws ModelMapperServiceInitException if mapper is wrongly inited.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public void verify() {
    if (!configurationService.getBooleanValue(PROPERTY_ENABLED, DEFAULT_ENABLED)) {
        LOG.warn("Init: check registered IdM services is disabled.");
        // 
        throw new ConfigurationDisabledException(ModelMapperChecker.PROPERTY_ENABLED);
    }
    long start = System.currentTimeMillis();
    int modelMapperUsed = 0;
    Map<String, ReadDtoService> services = context.getBeansOfType(ReadDtoService.class);
    for (ReadDtoService service : services.values()) {
        if ((service instanceof DefaultWorkflowHistoricTaskInstanceService) || (service instanceof DefaultWorkflowHistoricProcessInstanceService)) {
            LOG.debug("Workflow history service [{}] will not be checked - find method with pagination is not fully supported and took long time.", service.getClass());
            continue;
        }
        // 
        LOG.trace("Service [{}] will be checked.", service.getClass());
        try {
            BaseFilter filter = null;
            if (service.getFilterClass() != null) {
                // some services could not define filter
                try {
                    if (service.getFilterClass().equals(DataFilter.class)) {
                        filter = new DataFilter(service.getDtoClass());
                    } else {
                        filter = (BaseFilter) mapper.convertValue(new HashMap(), service.getFilterClass());
                    }
                } catch (Exception ex) {
                    LOG.debug("Service [{}] filter [{}] cannot be constructed. Find method will be checked without filter.", service.getClass(), service.getFilterClass());
                }
            }
            if (!service.find(filter, PageRequest.of(0, 1)).getContent().isEmpty()) {
                modelMapperUsed++;
            }
        } catch (UnsupportedOperationException ex) {
            LOG.debug("Service [{}] does not support find method. Check will be skipped.", service.getClass());
        } catch (MappingException ex) {
            throw new ModelMapperServiceInitException(AutowireHelper.getTargetType(service), ex);
        } catch (EntityNotFoundException ex) {
            throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", String.valueOf(ex.getMessage())), ex);
        } catch (ResultCodeException ex) {
            throw ex;
        } catch (Exception ex) {
            if (ex.getCause() instanceof EntityNotFoundException) {
                throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", String.valueOf(ex.getCause().getMessage()), "service", service.getClass().getCanonicalName()), ex);
            }
            LOG.error("Service [{}] cannot be checked. Find method cannot be called.", service.getClass(), ex);
        }
        LOG.trace("Service [{}] was checked.", service.getClass());
    }
    LOG.info("Init: all registered IdM services [{}]. " + "Services usage were checked [{}] (agenda contains some records) [took: {}ms].", services.size(), modelMapperUsed, System.currentTimeMillis() - start);
}
Also used : DataFilter(eu.bcvsolutions.idm.core.api.dto.filter.DataFilter) HashMap(java.util.HashMap) ReadDtoService(eu.bcvsolutions.idm.core.api.service.ReadDtoService) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) EntityNotFoundException(javax.persistence.EntityNotFoundException) ConfigurationDisabledException(eu.bcvsolutions.idm.core.security.api.exception.ConfigurationDisabledException) BaseFilter(eu.bcvsolutions.idm.core.api.dto.filter.BaseFilter) ModelMapperServiceInitException(eu.bcvsolutions.idm.core.exception.ModelMapperServiceInitException) ConfigurationDisabledException(eu.bcvsolutions.idm.core.security.api.exception.ConfigurationDisabledException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) EntityNotFoundException(javax.persistence.EntityNotFoundException) MappingException(org.modelmapper.MappingException) ModelMapperServiceInitException(eu.bcvsolutions.idm.core.exception.ModelMapperServiceInitException) MappingException(org.modelmapper.MappingException) DefaultWorkflowHistoricTaskInstanceService(eu.bcvsolutions.idm.core.workflow.service.impl.DefaultWorkflowHistoricTaskInstanceService) DefaultWorkflowHistoricProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.impl.DefaultWorkflowHistoricProcessInstanceService)

Example 18 with DataFilter

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

the class IdmConfigurationController method toFilter.

@Override
protected DataFilter toFilter(MultiValueMap<String, Object> parameters) {
    DataFilter filter = new DataFilter(getDtoClass(), parameters, getParameterConverter());
    filter.setAddSecredProxyString(true);
    // 
    return filter;
}
Also used : DataFilter(eu.bcvsolutions.idm.core.api.dto.filter.DataFilter)

Example 19 with DataFilter

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

the class DefaultFilterManagerIntegrationTest method testDisableSubordinatesBuilder.

@Test
public void testDisableSubordinatesBuilder() {
    IdmIdentityDto subordinate = getHelper().createIdentity((GuardedString) null);
    IdmIdentityDto manager = getHelper().createIdentity((GuardedString) null);
    getHelper().createContractGuarantee(getHelper().getPrimeContract(subordinate.getId()).getId(), manager.getId());
    // 
    FilterBuilder<IdmIdentity, DataFilter> filter = filterManager.getBuilder(IdmIdentity.class, IdmIdentityFilter.PARAMETER_SUBORDINATES_FOR);
    String enabledPropertyName = filter.getConfigurationPropertyName(ConfigurationService.PROPERTY_ENABLED);
    String implProperty = filter.getConfigurationPropertyName(ConfigurationService.PROPERTY_IMPLEMENTATION);
    String currentFilterBeanName = filter.getConfigurationValue(ConfigurationService.PROPERTY_IMPLEMENTATION);
    // 
    Assert.assertNotNull(filter);
    Assert.assertFalse(filter.isDisabled());
    IdmIdentityFilter identityFilter = new IdmIdentityFilter();
    identityFilter.setSubordinatesFor(manager.getId());
    identityFilter.setIncludeGuarantees(true);
    List<IdmIdentityDto> subordinates = getHelper().getService(IdmIdentityService.class).find(identityFilter, null).getContent();
    Assert.assertEquals(1, subordinates.size());
    Assert.assertEquals(subordinate.getId(), subordinates.get(0).getId());
    // 
    try {
        configurationService.setBooleanValue(enabledPropertyName, false);
        // 
        filter = filterManager.getBuilder(IdmIdentity.class, IdmIdentityFilter.PARAMETER_SUBORDINATES_FOR);
        Assert.assertNotNull(filter);
        Assert.assertTrue(filter.isDisabled());
        // 
        subordinates = getHelper().getService(IdmIdentityService.class).find(identityFilter, null).getContent();
        Assert.assertTrue(subordinates.isEmpty());
        // 
        // configure different filter - should be disabled to
        configurationService.setValue(implProperty, GuaranteeSubordinatesFilter.BEAN_NAME);
        filter = filterManager.getBuilder(IdmIdentity.class, IdmIdentityFilter.PARAMETER_SUBORDINATES_FOR);
        // 
        Assert.assertNotNull(filter);
        Assert.assertTrue(filter.isDisabled());
        Assert.assertEquals(GuaranteeSubordinatesFilter.BEAN_NAME, filter.getConfigurationValue(ConfigurationService.PROPERTY_IMPLEMENTATION));
        // 
        subordinates = getHelper().getService(IdmIdentityService.class).find(identityFilter, null).getContent();
        Assert.assertTrue(subordinates.isEmpty());
    } finally {
        configurationService.setBooleanValue(enabledPropertyName, true);
        configurationService.setValue(implProperty, currentFilterBeanName);
    }
}
Also used : DataFilter(eu.bcvsolutions.idm.core.api.dto.filter.DataFilter) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 20 with DataFilter

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

the class DefaultFilterManagerIntegrationTest method testFilterNotSupportedWithoutValues.

@Test
public void testFilterNotSupportedWithoutValues() {
    DataFilter filter = new DataFilter(IdmConfigurationDto.class);
    filter.put("wrong", new ArrayList<>());
    // 
    Page<IdmConfigurationDto> configurations = configurationService.find(filter, PageRequest.of(0, 1));
    // 
    Assert.assertNotNull(configurations);
}
Also used : DataFilter(eu.bcvsolutions.idm.core.api.dto.filter.DataFilter) IdmConfigurationDto(eu.bcvsolutions.idm.core.api.dto.IdmConfigurationDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

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