use of eu.bcvsolutions.idm.core.api.dto.FilterBuilderDto in project CzechIdMng by bcvsolutions.
the class FilterBuilderControllerRestTest method testFindByName.
@Test
public void testFindByName() {
FilterBuilderFilter filter = new FilterBuilderFilter();
filter.setName(defaultManagersFilter.getName());
filter.setEntityClass(IdmIdentity.class.getCanonicalName());
List<FilterBuilderDto> results = find(filter);
//
Assert.assertFalse(results.isEmpty());
Assert.assertTrue(results.stream().anyMatch(f -> f.getFilterBuilderClass().equals(AutowireHelper.getTargetClass(defaultManagersFilter))));
Assert.assertTrue(results.stream().anyMatch(f -> f.getFilterBuilderClass().equals(AutowireHelper.getTargetClass(guaranteeManagersFilter))));
Assert.assertTrue(results.stream().allMatch(f -> f.getEntityClass().equals(IdmIdentity.class)));
Assert.assertTrue(results.stream().allMatch(f -> f.getName().equals(defaultManagersFilter.getName())));
//
// not-exists
filter.setName(getHelper().createName());
filter.setEntityClass(IdmIdentity.class.getCanonicalName());
results = find(filter);
Assert.assertTrue(results.isEmpty());
}
use of eu.bcvsolutions.idm.core.api.dto.FilterBuilderDto in project CzechIdMng by bcvsolutions.
the class DefaultFilterManager method getRegisteredServiceFilters.
/**
* Returns filters processed directly by service predicates.
*
* @return
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
private Map<FilterKey, FilterBuilderDto> getRegisteredServiceFilters() {
if (registeredServiceFilters == null) {
registeredServiceFilters = new HashMap<>();
// find field by recursion from registered services and filter dtos
Map<String, ReadDtoService> services = context.getBeansOfType(ReadDtoService.class);
services.forEach((beanName, service) -> {
Class<? extends BaseEntity> entityClass = service.getEntityClass();
Class<? extends BaseFilter> filterClass = service.getFilterClass();
if (entityClass == null || filterClass == null) {
LOG.trace("Service [{}], [{}] does not define controlled entity [{}] or filter[{}], skip to resolve available filter criteria.", beanName, service.getClass(), entityClass, filterClass);
} else {
registeredServiceFilters.putAll(getRegisteredFilters(entityClass, filterClass).entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), e -> {
FilterBuilderDto dto = e.getValue();
// service and property is unique combination
dto.setId(String.format("%s-%s", beanName, dto.getName()));
// service - can be overriden - https://wiki.czechidm.com/tutorial/dev/override_service
dto.setModule(EntityUtils.getModule(service.getClass()));
//
if (service instanceof AbstractFormValueService<?, ?>) {
// eav value services are constructed dynamically (prevent to show cglib class)
dto.setFilterBuilderClass(AbstractFormValueService.class);
} else {
dto.setFilterBuilderClass(AutowireHelper.getTargetClass(service));
}
return dto;
})));
}
});
}
//
return registeredServiceFilters;
}
use of eu.bcvsolutions.idm.core.api.dto.FilterBuilderDto 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.dto.FilterBuilderDto in project CzechIdMng by bcvsolutions.
the class DefaultFilterManager method toDto.
/**
* Convert filterBuilder to dto.
*
* @param key
* @param filterBuilder
* @return
*/
private FilterBuilderDto toDto(FilterBuilder<? extends BaseEntity, ? extends DataFilter> filterBuilder) {
FilterBuilderDto dto = new FilterBuilderDto();
dto.setId(filterBuilder.getId());
dto.setName(filterBuilder.getName());
dto.setModule(filterBuilder.getModule());
dto.setDisabled(filterBuilder.isDisabled());
dto.setDescription(filterBuilder.getDescription());
dto.setEntityClass(filterBuilder.getEntityClass());
dto.setFilterClass(filterBuilder.getFilterClass());
dto.setFilterBuilderClass(AutowireHelper.getTargetClass(filterBuilder));
return dto;
}
use of eu.bcvsolutions.idm.core.api.dto.FilterBuilderDto in project CzechIdMng by bcvsolutions.
the class DefaultFilterManagerUnitTest method testFindByDescription.
@Test
public void testFindByDescription() {
FilterBuilderDto dto = new FilterBuilderDto();
dto.setDescription("tesT-x");
dto.setEntityClass(IdmIdentity.class);
//
FilterBuilderFilter filter = new FilterBuilderFilter();
filter.setDescription("Test-x");
Assert.assertTrue(manager.passFilter(dto, filter));
filter.setDescription("test-");
Assert.assertTrue(manager.passFilter(dto, filter));
filter.setDescription("tee");
Assert.assertFalse(manager.passFilter(dto, filter));
dto.setDescription(null);
Assert.assertFalse(manager.passFilter(dto, filter));
}
Aggregations