use of java.beans.MethodDescriptor in project CzechIdMng by bcvsolutions.
the class DefaultRequestManager method findPotencialParents.
/**
* Find potential parents. Invokes all method with UUID return type and without
* input parameters.
*
* @param filter
* @return
*/
private List<RequestPredicate> findPotencialParents(BaseFilter filter) {
Assert.notNull(filter, "Filter is mandatory!");
List<MethodDescriptor> descriptors;
try {
descriptors = //
Lists.newArrayList(Introspector.getBeanInfo(filter.getClass()).getMethodDescriptors()).stream().filter(//
methodDescriptor -> UUID.class.equals(methodDescriptor.getMethod().getReturnType())).filter(methodDescriptor -> methodDescriptor.getMethod().getParameterTypes() == null || //
methodDescriptor.getMethod().getParameterTypes().length == 0).collect(Collectors.toList());
} catch (IntrospectionException e) {
throw new CoreException(e);
}
//
List<RequestPredicate> results = new ArrayList<>();
descriptors.stream().forEach(descriptor -> {
try {
Object value = descriptor.getMethod().invoke(filter, new Object[] {});
if (value == null) {
return;
}
RequestFilterPredicate filterPredicate = descriptor.getMethod().getAnnotation(RequestFilterPredicate.class);
results.add(new RequestPredicate((UUID) value, filterPredicate != null ? filterPredicate.field() : null));
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new CoreException(e);
}
});
return results;
}
Aggregations