Example usage for org.springframework.context.annotation ConditionContext getEnvironment

List of usage examples for org.springframework.context.annotation ConditionContext getEnvironment

Introduction

In this page you can find the example usage for org.springframework.context.annotation ConditionContext getEnvironment.

Prototype

Environment getEnvironment();

Source Link

Document

Return the Environment for which the current application is running.

Usage

From source file:com.hp.autonomy.frontend.find.core.beanconfiguration.AbstractEnumCondition.java

private T getProperty(final ConditionContext context) {
    return Enum.valueOf(typeToken, context.getEnvironment().getProperty(systemProperty, defaultValue.name()));
}

From source file:org.apereo.openlrs.conditions.RedisEnabledCondition.java

@Override
public boolean matches(ConditionContext ctx, AnnotatedTypeMetadata atm) {
    String redis = ctx.getEnvironment().getProperty("xapi.statements.repository.twotier.write");
    return (redis != null && StringUtils.containsIgnoreCase(redis, "redis"));
}

From source file:io.gravitee.reporter.elastic.spring.conditional.AbstractElasticClientCondition.java

@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
    String sProtocol = context.getEnvironment().getProperty(PROTOCOL_CONFIG_KEY, Protocol.TRANSPORT.name());
    Protocol protocol = Protocol.getByName(sProtocol);

    return clientProtocol().equals(protocol);
}

From source file:me.j360.trace.autoconfiguration.collector.kafka.KafkaZooKeeperSetCondition.java

@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata a) {
    String kafkaZookeeper = context.getEnvironment().getProperty(PROPERTY_NAME);
    return kafkaZookeeper == null || kafkaZookeeper.isEmpty()
            ? ConditionOutcome.noMatch(PROPERTY_NAME + " isn't set")
            : ConditionOutcome.match();/*from   w w w .ja va 2 s  . c o  m*/
}

From source file:natalia.dymnikova.util.NotDevelopment.java

@Override
public boolean matches(final ConditionContext context, final AnnotatedTypeMetadata metadata) {
    return !stream(context.getEnvironment().getActiveProfiles()).filter("development"::equals).findAny()
            .isPresent();/* ww  w .j  a v  a2  s. c  om*/
}

From source file:org.bonitasoft.web.designer.config.DesignerConfigConditional.java

@Override
public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
    String edition = conditionContext.getEnvironment().getProperty("designer.edition", "Community");
    logger.info(String.format("Conf loaded :  %s edition", edition));
    return edition.equals("Community");
}

From source file:com.zxy.commons.hystrix.HystrixAutoConfigureCondition.java

@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
    String enabled = context.getEnvironment().getProperty("hystrix.enabled");
    if (StringUtils.isNotBlank(enabled) && "false".equalsIgnoreCase(enabled)) {
        return false;
    }/*from ww  w.  j a  v a 2s.c o  m*/
    try {
        // ?jar?, ?, ??
        context.getClassLoader().loadClass(Hystrix.class.getName());
        return true;
    } catch (Exception ex) {
        return false;
    }
}

From source file:com.zxy.commons.apidocs.conf.SwaggerConfiguareCondition.java

@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
    String enabled = context.getEnvironment().getProperty("apidocs.enabled");
    if (!StringUtils.isEmpty(enabled) && "false".equalsIgnoreCase(enabled)) {
        return false;
    }//w w w.j ava  2 s  .c o  m
    //        String xmlEnabled = context.getEnvironment().getProperty("apidocs.use.xml.enabled");
    //        if(!StringUtils.isEmpty(xmlEnabled) && "true".equalsIgnoreCase(xmlEnabled)) {
    //            return false;
    //        }
    try {
        // ?jar?, ?, ??
        context.getClassLoader().loadClass(Docket.class.getName());
        return true;
    } catch (Exception ex) {
        return false;
    }
}

From source file:com.github.kpavlov.commons.spring.annotations.BooleanValueCondition.java

@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
    final Environment environment = context.getEnvironment();
    if (environment != null) {
        Map<String, Object> attributes = metadata.getAnnotationAttributes(Enabled.class.getName());
        if (attributes != null) {
            String expression = (String) attributes.get("value");
            final String value = environment.resolvePlaceholders(expression);
            return (Boolean.parseBoolean(value));
        }//from   w  ww  .  ja va 2  s . c o  m
    }
    return true;
}

From source file:de.codecentric.boot.admin.config.SpringBootAdminClientEnabledCondition.java

@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata annotatedTypeMetadata) {

    if (!isEnabled(context.getEnvironment())) {
        return ConditionOutcome.noMatch(
                "Spring Boot Client is disabled, because 'spring.boot.admin.client.enabled' is false.");
    }/*from   w w w . j  a v  a 2 s .  c o m*/

    if (isUrlEmpty(context.getEnvironment())) {
        return ConditionOutcome
                .noMatch("Spring Boot Client is disabled, because 'spring.boot.admin.url' is empty.");
    }

    return ConditionOutcome.match();
}