use of org.apereo.cas.configuration.support.RequiresModule in project cas by apereo.
the class ConfigurationMetadataGenerator method processHints.
private static Set<ConfigurationMetadataHint> processHints(final Collection<ConfigurationMetadataProperty> props, final Collection<ConfigurationMetadataProperty> groups) {
var hints = new LinkedHashSet<ConfigurationMetadataHint>(0);
val allValidProps = props.stream().filter(p -> p.getDeprecation() == null || !Deprecation.Level.ERROR.equals(p.getDeprecation().getLevel())).collect(Collectors.toList());
for (val entry : allValidProps) {
try {
val propName = StringUtils.substringAfterLast(entry.getName(), ".");
val groupName = StringUtils.substringBeforeLast(entry.getName(), ".");
val grp = groups.stream().filter(g -> g.getName().equalsIgnoreCase(groupName)).findFirst().orElseThrow(() -> new IllegalArgumentException("Cant locate group " + groupName));
val matcher = PATTERN_GENERICS.matcher(grp.getType());
val className = matcher.find() ? matcher.group(1) : grp.getType();
val clazz = ClassUtils.getClass(className);
val hint = new ConfigurationMetadataHint();
hint.setName(entry.getName());
val annotation = Arrays.stream(clazz.getAnnotations()).filter(a -> a.annotationType().equals(RequiresModule.class)).findFirst().map(RequiresModule.class::cast).orElseThrow(() -> new RuntimeException(clazz.getCanonicalName() + " is missing @RequiresModule"));
val valueHint = new ValueHint();
valueHint.setValue(toJson(Map.of("module", annotation.name(), "automated", annotation.automated())));
valueHint.setDescription(RequiresModule.class.getName());
hint.getValues().add(valueHint);
val grpHint = new ValueHint();
grpHint.setValue(toJson(Map.of("owner", clazz.getCanonicalName())));
grpHint.setDescription(PropertyOwner.class.getName());
hint.getValues().add(grpHint);
val names = RelaxedPropertyNames.forCamelCase(propName);
names.getValues().forEach(Unchecked.consumer(name -> {
val f = ReflectionUtils.findField(clazz, name);
if (f != null && f.isAnnotationPresent(RequiredProperty.class)) {
val propertyHint = new ValueHint();
propertyHint.setValue(toJson(Map.of("owner", clazz.getName())));
propertyHint.setDescription(RequiredProperty.class.getName());
hint.getValues().add(propertyHint);
}
if (f != null && f.isAnnotationPresent(DurationCapable.class)) {
val propertyHint = new ValueHint();
propertyHint.setDescription(DurationCapable.class.getName());
propertyHint.setValue(toJson(List.of(DurationCapable.class.getName())));
hint.getValues().add(propertyHint);
}
if (f != null && f.isAnnotationPresent(ExpressionLanguageCapable.class)) {
val propertyHint = new ValueHint();
propertyHint.setDescription(ExpressionLanguageCapable.class.getName());
propertyHint.setValue(toJson(List.of(ExpressionLanguageCapable.class.getName())));
hint.getValues().add(propertyHint);
}
}));
if (!hint.getValues().isEmpty()) {
hints.add(hint);
}
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
}
return hints;
}
Aggregations