org.flips.condition.SpringProfileFlipCondition Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of flips-core Show documentation
Show all versions of flips-core Show documentation
Flips Core framework, provides all the flip annotations, conditions and different advices
package org.flips.condition;
import org.flips.model.FeatureContext;
import org.flips.model.FlipAnnotationAttributes;
import org.flips.utils.Utils;
import org.flips.utils.ValidationUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import static java.util.Arrays.asList;
@Component
public class SpringProfileFlipCondition implements FlipCondition {
private static final Logger logger = LoggerFactory.getLogger(SpringProfileFlipCondition.class);
@Override
public boolean evaluateCondition(FeatureContext featureContext, FlipAnnotationAttributes flipAnnotationAttributes) {
String[] expectedProfiles = flipAnnotationAttributes.getAttributeValue("activeProfiles", Utils.EMPTY_STRING_ARRAY);
String[] activeProfiles = featureContext.getActiveProfilesOrEmpty();
ValidationUtils.requireNonEmpty(expectedProfiles, "activeProfiles element can not be NULL or EMPTY when using @FlipOnProfiles");
return isAnyActiveProfileContainedInExpectedProfile(expectedProfiles, activeProfiles);
}
private boolean isAnyActiveProfileContainedInExpectedProfile(String[] expectedProfiles, String[] activeProfiles) {
logger.info("SpringProfileFlipCondition: Expected profile(s) {}, active profile(s) {}", expectedProfiles, activeProfiles);
return CollectionUtils.containsAny(asList(activeProfiles), asList(expectedProfiles));
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy