no.finn.unleash.strategy.UserWithIdStrategy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of unleash-client-java Show documentation
Show all versions of unleash-client-java Show documentation
A client library for Unleash
package no.finn.unleash.strategy;
import java.util.Map;
import java.util.Optional;
import no.finn.unleash.UnleashContext;
import static java.util.Arrays.asList;
public final class UserWithIdStrategy implements Strategy {
protected static final String PARAM = "userIds";
private static final String STRATEGY_NAME = "userWithId";
@Override
public String getName() {
return STRATEGY_NAME;
}
@Override
public boolean isEnabled(Map parameters) {
return false;
}
@Override
public boolean isEnabled(Map parameters, UnleashContext unleashContext) {
return unleashContext.getUserId()
.map(currentUserId -> Optional.ofNullable(parameters.get(PARAM))
.map(userIdString -> asList(userIdString.split(",\\s?")))
.filter(f -> f.contains(currentUserId)).isPresent())
.orElse(false);
}
}