Search in sources :

Example 1 with FilterBuilderDto

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

the class DefaultFilterManager method findFilters.

/**
 * Registered filters - by service and filter builders.
 *
 * @param filter search filters
 * @return registered filters by given key
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
protected Map<FilterKey, List<FilterBuilderDto>> findFilters(FilterBuilderFilter filter) {
    Map<FilterKey, List<FilterBuilderDto>> registeredFilters = new HashMap<>();
    // 
    // registered filter builders
    // TODO: not possible to cache now => cache has to be evicted, when module is enabled / disabled.
    Map<String, FilterBuilder> filterBuilders = context.getBeansOfType(FilterBuilder.class);
    filterBuilders.forEach((beanName, filterBuilder) -> {
        if (enabledEvaluator.isEnabled(filterBuilder)) {
            FilterBuilderDto dto = toDto(filterBuilder);
            if (passFilter(dto, filter)) {
                FilterKey filterKey = new FilterKey(dto.getEntityClass(), dto.getName());
                // evaluate effective filter
                if (getBuilder(filterKey) != filterBuilder) {
                    // check reference to instance
                    dto.setDisabled(true);
                }
                if (!registeredFilters.containsKey(filterKey)) {
                    registeredFilters.put(filterKey, new ArrayList<>());
                }
                registeredFilters.get(filterKey).add(dto);
            }
        }
    });
    // 
    // find field by recursion from registered services and filter dtos
    getRegisteredServiceFilters().forEach((filterKey, filterBuilder) -> {
        if (registeredFilters.containsKey(filterKey)) {
            LOG.trace("Property [{}] for class [{}] has their own filter builder implemented.", filterKey.getName(), filterKey.getEntityClass());
        } else if (passFilter(filterBuilder, filter)) {
            // just one => not registrable, not overridable
            registeredFilters.put(filterKey, Lists.newArrayList(filterBuilder));
        }
    });
    // 
    LOG.debug("Returning [{}] registered filterBuilders", registeredFilters.size());
    // 
    return registeredFilters;
}
Also used : HashMap(java.util.HashMap) DisabledFilterBuilder(eu.bcvsolutions.idm.core.api.repository.filter.DisabledFilterBuilder) FilterBuilder(eu.bcvsolutions.idm.core.api.repository.filter.FilterBuilder) FilterBuilderDto(eu.bcvsolutions.idm.core.api.dto.FilterBuilderDto) ArrayList(java.util.ArrayList) List(java.util.List) FilterKey(eu.bcvsolutions.idm.core.api.repository.filter.FilterKey)

Example 2 with FilterBuilderDto

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

the class FilterBuilderController method find.

@ResponseBody
@RequestMapping(method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.MODULE_READ + "')")
@ApiOperation(value = "Find all filter builders", nickname = "findAllFilterBuilders", tags = { FilterBuilderController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.MODULE_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.MODULE_READ, description = "") }) }, notes = "Returns all registered filter builders.")
@SuppressWarnings({ "unchecked", "rawtypes" })
public Resources<?> find(@RequestParam(required = false) MultiValueMap<String, Object> parameters) {
    List<FilterBuilderDto> filterBuilderDtos = filterManager.find(toFilter(parameters));
    PageImpl page = new PageImpl(filterBuilderDtos, PageRequest.of(0, filterBuilderDtos.size() == 0 ? 10 : filterBuilderDtos.size()), filterBuilderDtos.size());
    if (page.getContent().isEmpty()) {
        return pagedResourcesAssembler.toEmptyResource(page, FilterBuilderDto.class);
    }
    return pagedResourcesAssembler.toResource(page);
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) FilterBuilderDto(eu.bcvsolutions.idm.core.api.dto.FilterBuilderDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with FilterBuilderDto

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

the class FilterBuilderControllerRestTest method testEnable.

@Test
public void testEnable() throws Exception {
    try {
        getHelper().enableFilter(defaultManagersFilter.getClass());
        // 
        FilterBuilderFilter filter = new FilterBuilderFilter();
        filter.setFilterBuilderClass(AutowireHelper.getTargetType(defaultManagersFilter));
        List<FilterBuilderDto> results = find(filter);
        // 
        Assert.assertEquals(1, results.size());
        Assert.assertEquals(defaultManagersFilter.getName(), results.get(0).getName());
        Assert.assertEquals(defaultManagersFilter.getEntityClass(), results.get(0).getEntityClass());
        Assert.assertFalse(results.get(0).isDisabled());
        // 
        filter.setFilterBuilderClass(AutowireHelper.getTargetType(guaranteeManagersFilter));
        results = find(filter);
        Assert.assertEquals(1, results.size());
        Assert.assertEquals(guaranteeManagersFilter.getName(), results.get(0).getName());
        Assert.assertEquals(guaranteeManagersFilter.getEntityClass(), results.get(0).getEntityClass());
        Assert.assertTrue(results.get(0).isDisabled());
        // 
        getMockMvc().perform(put(BaseController.BASE_PATH + "/filter-builders/" + results.get(0).getId() + "/enable").with(authentication(getAdminAuthentication())).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().is2xxSuccessful());
        // 
        filter.setFilterBuilderClass(AutowireHelper.getTargetType(defaultManagersFilter));
        results = find(filter);
        Assert.assertEquals(1, results.size());
        Assert.assertEquals(defaultManagersFilter.getName(), results.get(0).getName());
        Assert.assertEquals(defaultManagersFilter.getEntityClass(), results.get(0).getEntityClass());
        Assert.assertTrue(results.get(0).isDisabled());
        // 
        filter.setFilterBuilderClass(AutowireHelper.getTargetType(guaranteeManagersFilter));
        results = find(filter);
        Assert.assertEquals(1, results.size());
        Assert.assertEquals(guaranteeManagersFilter.getName(), results.get(0).getName());
        Assert.assertEquals(guaranteeManagersFilter.getEntityClass(), results.get(0).getEntityClass());
        Assert.assertFalse(results.get(0).isDisabled());
    } finally {
        getHelper().enableFilter(defaultManagersFilter.getClass());
    }
}
Also used : FilterBuilderFilter(eu.bcvsolutions.idm.core.api.dto.filter.FilterBuilderFilter) FilterBuilderDto(eu.bcvsolutions.idm.core.api.dto.FilterBuilderDto) Test(org.junit.Test) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest)

Example 4 with FilterBuilderDto

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

the class DefaultFilterManagerUnitTest method testFindByFilterBuilderClass.

@Test
@SuppressWarnings("serial")
public void testFindByFilterBuilderClass() {
    FilterBuilderDto dto = new FilterBuilderDto();
    dto.setModule("test");
    dto.setEntityClass(IdmIdentity.class);
    dto.setFilterBuilderClass(IdmIdentityService.class);
    // 
    FilterBuilderFilter filter = new FilterBuilderFilter();
    filter.setFilterBuilderClass(IdmIdentityService.class.getCanonicalName());
    Assert.assertTrue(manager.passFilter(dto, filter));
    filter.setFilterBuilderClass(IdmIdentityService.class.getSimpleName());
    Assert.assertFalse(manager.passFilter(dto, filter));
    // inline classes with null cannonical name
    dto.setFilterBuilderClass((new IdmIdentity() {
    }).getClass());
    filter.setFilterBuilderClass(IdmIdentity.class.getCanonicalName());
    Assert.assertFalse(manager.passFilter(dto, filter));
}
Also used : FilterBuilderFilter(eu.bcvsolutions.idm.core.api.dto.filter.FilterBuilderFilter) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) FilterBuilderDto(eu.bcvsolutions.idm.core.api.dto.FilterBuilderDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 5 with FilterBuilderDto

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

the class DefaultFilterManagerUnitTest method testEmptyFilter.

@Test
public void testEmptyFilter() {
    Assert.assertTrue(manager.passFilter(new FilterBuilderDto(), null));
    FilterBuilderFilter filter = new FilterBuilderFilter();
    Assert.assertTrue(manager.passFilter(new FilterBuilderDto(), filter));
}
Also used : FilterBuilderFilter(eu.bcvsolutions.idm.core.api.dto.filter.FilterBuilderFilter) FilterBuilderDto(eu.bcvsolutions.idm.core.api.dto.FilterBuilderDto) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Aggregations

FilterBuilderDto (eu.bcvsolutions.idm.core.api.dto.FilterBuilderDto)16 Test (org.junit.Test)11 FilterBuilderFilter (eu.bcvsolutions.idm.core.api.dto.filter.FilterBuilderFilter)10 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)8 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)4 FilterBuilder (eu.bcvsolutions.idm.core.api.repository.filter.FilterBuilder)2 FilterKey (eu.bcvsolutions.idm.core.api.repository.filter.FilterKey)2 AbstractRestTest (eu.bcvsolutions.idm.test.api.AbstractRestTest)2 HashMap (java.util.HashMap)2 List (java.util.List)2 DataFilter (eu.bcvsolutions.idm.core.api.dto.filter.DataFilter)1 DisabledFilterBuilder (eu.bcvsolutions.idm.core.api.repository.filter.DisabledFilterBuilder)1 BaseController (eu.bcvsolutions.idm.core.api.rest.BaseController)1 IdmIdentityService (eu.bcvsolutions.idm.core.api.service.IdmIdentityService)1 ReadDtoService (eu.bcvsolutions.idm.core.api.service.ReadDtoService)1 AutowireHelper (eu.bcvsolutions.idm.core.api.utils.AutowireHelper)1 AbstractFormValueService (eu.bcvsolutions.idm.core.eav.service.impl.AbstractFormValueService)1 DefaultManagersFilter (eu.bcvsolutions.idm.core.model.repository.filter.DefaultManagersFilter)1 GuaranteeManagersFilter (eu.bcvsolutions.idm.core.model.repository.filter.GuaranteeManagersFilter)1 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)1