Search in sources :

Example 1 with DataFilter

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

the class IdentityFindPositionsTest method testFindManagers.

@Test
public void testFindManagers() {
    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 user = getHelper().createIdentity((GuardedString) null);
    IdmIdentityDto user2 = getHelper().createIdentity((GuardedString) null);
    IdmIdentityDto user3 = getHelper().createIdentity((GuardedString) null);
    IdmIdentityDto user4 = getHelper().createIdentity((GuardedString) null);
    IdmTreeTypeDto treeTypeFirst = getHelper().createTreeType();
    IdmTreeTypeDto treeTypeSecond = getHelper().createTreeType();
    // create root for second type
    getHelper().createTreeNode(treeTypeSecond, null);
    // create root for first type
    IdmTreeNodeDto nodeRoot = getHelper().createTreeNode(treeTypeFirst, null);
    // create one for first type
    IdmTreeNodeDto nodeOne = getHelper().createTreeNode(treeTypeFirst, nodeRoot);
    // create two for first type
    IdmTreeNodeDto nodeTwo = getHelper().createTreeNode(treeTypeFirst, nodeOne);
    createIdentityContract(user, null, nodeRoot);
    createIdentityContract(user2, null, nodeOne);
    createIdentityContract(user3, null, nodeOne);
    createIdentityContract(user4, null, nodeTwo);
    // createIdentityContract(user, manager3, null);
    List<IdmIdentityDto> managersList = identityService.findAllManagers(user3.getId(), treeTypeFirst.getId());
    assertEquals(1, managersList.size());
    IdmIdentityDto manager = managersList.get(0);
    assertEquals(user.getId(), manager.getId());
    managersList = identityService.findAllManagers(user4.getId(), treeTypeFirst.getId(), Boolean.TRUE);
    assertEquals(2, managersList.size());
    managersList = identityService.findAllManagers(user.getId(), treeTypeFirst.getId());
    assertEquals(1, managersList.size());
    createIdentityContract(user, null, nodeTwo);
    managersList = identityService.findAllManagers(user.getId(), treeTypeFirst.getId());
    assertEquals(2, managersList.size());
    List<IdmIdentityDto> managersListSec = identityService.findAllManagers(user.getId(), treeTypeSecond.getId());
    // user with superAdminRole
    assertEquals(1, managersListSec.size());
}
Also used : DataFilter(eu.bcvsolutions.idm.core.api.dto.filter.DataFilter) IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) 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 2 with DataFilter

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

the class DefaultFilterManager method getBuilder.

@SuppressWarnings("unchecked")
private <E extends BaseEntity> FilterBuilder<E, DataFilter> getBuilder(FilterKey key) {
    if (!builders.hasPluginFor(key)) {
        return null;
    }
    // 
    // default plugin by ordered definition
    FilterBuilder<E, DataFilter> builder = (FilterBuilder<E, DataFilter>) builders.getPluginFor(key);
    if (builder.isDisabled()) {
        return new DisabledFilterBuilder<E>(builder);
    }
    String implName = builder.getConfigurationValue(ConfigurationService.PROPERTY_IMPLEMENTATION);
    if (StringUtils.isEmpty(implName)) {
        // return default builder - configuration is empty
        return builder;
    }
    // 
    try {
        // returns bean by name from filter configuration
        return (FilterBuilder<E, DataFilter>) context.getBean(implName);
    } catch (Exception ex) {
        throw new ResultCodeException(CoreResultCode.FILTER_IMPLEMENTATION_NOT_FOUND, ImmutableMap.of("implementation", implName, "propertyName", key.getName(), "configurationProperty", builder.getConfigurationPropertyName(ConfigurationService.PROPERTY_IMPLEMENTATION)), ex);
    }
}
Also used : DataFilter(eu.bcvsolutions.idm.core.api.dto.filter.DataFilter) DisabledFilterBuilder(eu.bcvsolutions.idm.core.api.repository.filter.DisabledFilterBuilder) FilterBuilder(eu.bcvsolutions.idm.core.api.repository.filter.FilterBuilder) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) DisabledFilterBuilder(eu.bcvsolutions.idm.core.api.repository.filter.DisabledFilterBuilder) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) FilterNotSupportedException(eu.bcvsolutions.idm.core.api.exception.FilterNotSupportedException) FilterSizeExceededException(eu.bcvsolutions.idm.core.api.exception.FilterSizeExceededException)

Example 3 with DataFilter

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

the class ConfigurationDeleteBulkActionIntegrationTest method processBulkActionByFilter.

@Test
public void processBulkActionByFilter() {
    List<IdmConfigurationDto> configs = createConfigurationItems(testCount);
    DataFilter filter = new DataFilter(IdmConfigurationDto.class);
    filter.setText(commonNameRoot);
    List<IdmConfigurationDto> checkConfigs = configurationService.find(filter, null).getContent();
    assertEquals(testCount, checkConfigs.size());
    IdmBulkActionDto bulkAction = this.findBulkAction(IdmConfiguration.class, ConfigurationDeleteBulkAction.NAME);
    bulkAction.setTransformedFilter(filter);
    bulkAction.setFilter(toMap(filter));
    IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
    checkResultLrt(processAction, (long) testCount, null, null);
    for (IdmConfigurationDto config : configs) {
        IdmConfigurationDto dto = configurationService.get(config.getId());
        assertNull(dto);
    }
}
Also used : DataFilter(eu.bcvsolutions.idm.core.api.dto.filter.DataFilter) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) IdmConfigurationDto(eu.bcvsolutions.idm.core.api.dto.IdmConfigurationDto) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Example 4 with DataFilter

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

the class UuidFilterBuilderIntegrationTest method testFindIdentityByUuid.

@Test
public void testFindIdentityByUuid() {
    // prepare data
    IdmIdentityDto identityOne = getHelper().createIdentity((GuardedString) null);
    IdmIdentityDto identityTwo = getHelper().createIdentity((GuardedString) null);
    IdmRoleDto roleOne = getHelper().createRole();
    UuidFilter<IdmIdentity> identityFilter = new FindableUuidFilter<>(repository);
    // 
    DataFilter dataFilter = new DataFilter(IdmIdentityDto.class);
    dataFilter.setId(identityOne.getId());
    List<IdmIdentity> identities = identityFilter.find(dataFilter, null).getContent();
    // 
    assertEquals(1, identities.size());
    assertEquals(identityOne.getId(), identities.get(0).getId());
    // 
    dataFilter.setId(identityTwo.getId());
    identities = identityFilter.find(dataFilter, null).getContent();
    assertEquals(1, identities.size());
    assertEquals(identityTwo.getId(), identities.get(0).getId());
    // 
    dataFilter.setId(roleOne.getId());
    assertEquals(0, identityFilter.find(dataFilter, null).getTotalElements());
}
Also used : DataFilter(eu.bcvsolutions.idm.core.api.dto.filter.DataFilter) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) 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 5 with DataFilter

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

the class AbstractReadWriteDtoControllerRestTest method testFindByCodeable.

/**
 * Test search by external identifier, if DTO implements {@link ExternalIdentifiable}
 *
 * @throws Exception
 */
@Test
public void testFindByCodeable() {
    if (!DataFilter.class.isAssignableFrom(getController().getFilterClass())) {
        LOG.warn("Controller [{}] doesn't support DataFilter. Find by codeable will not be tested.", getController().getClass());
        return;
    }
    // 
    DTO dto = prepareDto();
    if (!(dto instanceof Codeable)) {
        // ignore test
        return;
    }
    Codeable codeable = (Codeable) dto;
    if (StringUtils.isEmpty(codeable.getCode())) {
        throw new CoreException("Code has to be set by #prepareDto method, its required by default");
    }
    // 
    DTO createdDto = createDto(dto);
    // mock dto
    createDto(prepareDto());
    // 
    MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
    parameters.set(DataFilter.PARAMETER_CODEABLE_IDENTIFIER, codeable.getCode());
    // 
    List<DTO> results = find(parameters);
    // 
    Assert.assertEquals(1, results.size());
    Assert.assertEquals(createdDto.getId(), results.get(0).getId());
    // 
    if (supportsAutocomplete()) {
        results = autocomplete(parameters);
        // 
        Assert.assertEquals(1, results.size());
        Assert.assertEquals(createdDto.getId(), results.get(0).getId());
    } else {
        LOG.info("Controller [{}] doesn't support autocomplete method. Method will not be tested.", getController().getClass());
    }
    // 
    Assert.assertEquals(1, count(parameters));
}
Also used : DataFilter(eu.bcvsolutions.idm.core.api.dto.filter.DataFilter) Codeable(eu.bcvsolutions.idm.core.api.domain.Codeable) ExternalCodeable(eu.bcvsolutions.idm.core.api.domain.ExternalCodeable) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test)

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