Search in sources :

Example 1 with AnnotationMetadataReadingVisitor

use of org.springframework.core.type.classreading.AnnotationMetadataReadingVisitor in project incubator-atlas by apache.

the class OnAtlasPropertyCondition method matches.

@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
    boolean matches = false;
    String propertyName = (String) metadata.getAnnotationAttributes(ConditionalOnAtlasProperty.class.getName()).get("property");
    boolean isDefault = (Boolean) metadata.getAnnotationAttributes(ConditionalOnAtlasProperty.class.getName()).get("isDefault");
    String className = ((AnnotationMetadataReadingVisitor) metadata).getClassName();
    try {
        Configuration configuration = ApplicationProperties.get();
        String configuredProperty = configuration.getString(propertyName);
        if (StringUtils.isNotEmpty(configuredProperty)) {
            matches = configuredProperty.equals(className);
        } else if (isDefault)
            matches = true;
    } catch (AtlasException e) {
        LOG.error("Unable to load atlas properties. Dependent bean configuration may fail");
    }
    return matches;
}
Also used : ConditionalOnAtlasProperty(org.apache.atlas.annotation.ConditionalOnAtlasProperty) Configuration(org.apache.commons.configuration.Configuration) AnnotationMetadataReadingVisitor(org.springframework.core.type.classreading.AnnotationMetadataReadingVisitor) AtlasException(org.apache.atlas.AtlasException)

Aggregations

AtlasException (org.apache.atlas.AtlasException)1 ConditionalOnAtlasProperty (org.apache.atlas.annotation.ConditionalOnAtlasProperty)1 Configuration (org.apache.commons.configuration.Configuration)1 AnnotationMetadataReadingVisitor (org.springframework.core.type.classreading.AnnotationMetadataReadingVisitor)1