All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.getunleash.strategy.UserWithIdStrategy Maven / Gradle / Ivy

There is a newer version: 9.2.4
Show newest version
package io.getunleash.strategy;

import static java.util.Arrays.asList;

import io.getunleash.UnleashContext;
import java.util.Map;
import java.util.Optional;

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);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy