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;
}
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);
}
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());
}
}
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));
}
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));
}
Aggregations