use of eu.bcvsolutions.idm.core.api.repository.filter.FilterKey in project CzechIdMng by bcvsolutions.
the class DefaultFilterManager method getRegisteredFilters.
private Map<FilterKey, FilterBuilderDto> getRegisteredFilters(Class<? extends BaseEntity> entityClass, Class<? extends BaseFilter> filterClass) {
Assert.notNull(entityClass, "Entity class is required to resolve registered filters.");
Assert.notNull(filterClass, "Filter class is required to resolve filter properties.");
//
Map<FilterKey, FilterBuilderDto> registeredServiceFilters = new HashMap<>();
Class<?> processFilterClass = filterClass;
while (!processFilterClass.equals(Object.class)) {
Stream.of(processFilterClass.getDeclaredFields(), // both static and private field from interfaces and super classes
processFilterClass.getFields()).flatMap(Stream::of).forEach(declaredField -> {
String propertyName = declaredField.getName();
if (Modifier.isStatic(declaredField.getModifiers())) {
try {
Object propertyValue = declaredField.get(null);
if (propertyValue instanceof String) {
propertyName = (String) propertyValue;
} else {
LOG.trace("Value of static property [{}] for class [{}] is not string, skip to resolve available filter criteria.", propertyName, filterClass);
return;
}
} catch (IllegalArgumentException | IllegalAccessException e) {
LOG.warn("Get value of static property [{}] for class [{}] failed, skip to resolve available filter criteria.", propertyName, filterClass);
return;
}
}
if (ignoredFilterProperties.contains(propertyName)) {
LOG.trace("Pageable or internal property [{}] will be ignored by filters.", propertyName);
return;
}
FilterKey filterKey = new FilterKey(entityClass, propertyName);
if (registeredServiceFilters.containsKey(filterKey)) {
// already resolved e.g. by interface
return;
}
//
FilterBuilderDto dto = new FilterBuilderDto();
dto.setName(propertyName);
dto.setDescription("Internal service implementation (toPredicates).");
dto.setEntityClass(entityClass);
dto.setFilterClass(filterClass);
// service is always effective filter
dto.setDisabled(false);
//
registeredServiceFilters.put(filterKey, dto);
});
//
processFilterClass = processFilterClass.getSuperclass();
}
//
return registeredServiceFilters;
}
use of eu.bcvsolutions.idm.core.api.repository.filter.FilterKey in project CzechIdMng by bcvsolutions.
the class DefaultFilterManagerUnitTest method testCheckFilterSizeExceeded.
@Test(expected = FilterSizeExceededException.class)
public void testCheckFilterSizeExceeded() {
Mockito.when(configurationService.getIntegerValue(FilterManager.PROPERTY_CHECK_FILTER_SIZE_MAXIMUM, FilterManager.DEFAULT_CHECK_FILTER_SIZE_MAXIMUM)).thenReturn(10);
//
List<UUID> values = Stream.generate(UUID::randomUUID).limit(11).collect(Collectors.toList());
//
Assert.assertEquals(values.size(), manager.checkFilterSizeExceeded(new FilterKey(IdmIdentity.class, "mockProperty"), values).size());
}
use of eu.bcvsolutions.idm.core.api.repository.filter.FilterKey in project CzechIdMng by bcvsolutions.
the class DefaultFilterManagerUnitTest method testCheckFilterSize.
@Test
public void testCheckFilterSize() {
Mockito.when(configurationService.getIntegerValue(FilterManager.PROPERTY_CHECK_FILTER_SIZE_MAXIMUM, FilterManager.DEFAULT_CHECK_FILTER_SIZE_MAXIMUM)).thenReturn(10);
//
List<UUID> values = Stream.generate(UUID::randomUUID).limit(10).collect(Collectors.toList());
//
Assert.assertEquals(values.size(), manager.checkFilterSizeExceeded(new FilterKey(IdmIdentity.class, "mockProperty"), values).size());
//
values = Stream.generate(UUID::randomUUID).limit(9).collect(Collectors.toList());
//
Assert.assertEquals(values.size(), manager.checkFilterSizeExceeded(new FilterKey(IdmIdentity.class, "mockProperty"), values).size());
}
Aggregations