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

no.finn.unleash.strategy.UserWithIdStrategy Maven / Gradle / Ivy

There is a newer version: 4.4.1
Show newest version
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);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy