Example usage for java.util.stream Collectors toSet

List of usage examples for java.util.stream Collectors toSet

Introduction

In this page you can find the example usage for java.util.stream Collectors toSet.

Prototype

public static <T> Collector<T, ?, Set<T>> toSet() 

Source Link

Document

Returns a Collector that accumulates the input elements into a new Set .

Usage

From source file:io.gravitee.management.security.listener.AuthenticationSuccessListener.java

@Override
public void onApplicationEvent(AuthenticationSuccessEvent event) {
    final Authentication authentication = event.getAuthentication();
    try {/*www . j av  a2  s.  c  o m*/
        userService.findByName(authentication.getName());
    } catch (UserNotFoundException unfe) {
        final NewUserEntity newUser = new NewUserEntity();
        newUser.setUsername(authentication.getName());
        final Set<String> roles = authentication.getAuthorities().stream().map(GrantedAuthority::getAuthority)
                .collect(Collectors.toSet());
        newUser.setRoles(roles);
        userService.create(newUser);
    }
}

From source file:io.gravitee.repository.redis.management.internal.impl.UserRedisRepositoryImpl.java

@Override
public Set<RedisUser> findAll() {
    Map<Object, Object> users = redisTemplate.opsForHash().entries(REDIS_KEY);

    return users.values().stream().map(object -> convert(object, RedisUser.class)).collect(Collectors.toSet());
}

From source file:io.gravitee.gateway.policy.impl.processor.spring.SpringPolicyContextProviderFactory.java

public PolicyContextProvider create(PolicyContext policyContext) {
    Import importAnnotation = policyContext.getClass().getAnnotation(Import.class);

    List<Class<?>> importClasses = Arrays.asList(importAnnotation.value());

    LOGGER.info("Initializing a Spring context provider from @Import annotation: {}",
            String.join(",", importClasses.stream().map(Class::getName).collect(Collectors.toSet())));

    AnnotationConfigApplicationContext policyApplicationContext = new AnnotationConfigApplicationContext();
    policyApplicationContext.setClassLoader(policyContext.getClass().getClassLoader());
    importClasses.forEach(policyApplicationContext::register);

    // TODO: set the parent application context ?
    // pluginContext.setEnvironment(applicationContextParent.getEnvironment());
    // pluginContext.setParent(applicationContextParent);

    policyApplicationContext.refresh();//from   w w w. j a  va2  s.co  m
    return new SpringPolicyContextProvider(policyApplicationContext);
}

From source file:io.gravitee.repository.redis.management.internal.impl.SubscriptionRedisRepositoryImpl.java

@Override
public Set<RedisSubscription> findByApplication(String application) {
    Set<Object> keys = redisTemplate.opsForSet().members(REDIS_KEY + ":application:" + application);
    List<Object> pageObjects = redisTemplate.opsForHash().multiGet(REDIS_KEY, keys);

    return pageObjects.stream().map(event -> convert(event, RedisSubscription.class))
            .collect(Collectors.toSet());
}

From source file:com.ejisto.core.classloading.ClassTransformerImpl.java

private static Collection<String> loadAllRegisteredClassNames(String contextPath,
        MockedFieldsRepository mockedFieldsRepository) {
    Collection<MockedField> fields = mockedFieldsRepository.load(requestAllClasses(contextPath));
    Set<String> classes = fields.stream().map(MockedField::getClassName).collect(Collectors.toSet());
    trace(format("filtered classes for %s: %s of %s", contextPath, classes, fields));
    return classes;
}

From source file:com.netflix.spinnaker.fiat.providers.BaseProvider.java

@Override
@SuppressWarnings("unchecked")
public Set<R> getAllRestricted(@NonNull Set<Role> roles) throws ProviderException {
    return (Set<R>) getAll().stream().filter(resource -> resource instanceof Resource.AccessControlled)
            .map(resource -> (Resource.AccessControlled) resource)
            .filter(resource -> resource.getPermissions().isRestricted())
            .filter(resource -> resource.getPermissions().isAuthorized(roles)).collect(Collectors.toSet());
}

From source file:io.gravitee.management.rest.enhancer.ApplicationEnhancer.java

public Function<ApplicationEntity, ApplicationEntity> enhance(String currentUser) {
    return application -> {
        // Add primary owner
        Collection<MemberEntity> members = applicationService.getMembers(application.getId(), null);
        Collection<MemberEntity> primaryOwnerMembers = members.stream()
                .filter(m -> MembershipType.PRIMARY_OWNER.equals(m.getType())).collect(Collectors.toSet());
        if (!primaryOwnerMembers.isEmpty()) {
            MemberEntity primaryOwner = primaryOwnerMembers.iterator().next();
            UserEntity user = userService.findByName(primaryOwner.getUser());

            PrimaryOwnerEntity owner = new PrimaryOwnerEntity();
            owner.setUsername(user.getUsername());
            owner.setEmail(user.getEmail());
            owner.setFirstname(user.getFirstname());
            owner.setLastname(user.getLastname());
            application.setPrimaryOwner(owner);
        }/*  w  ww. j  a  v a2s  .c  o  m*/

        // Add Members size
        application.setMembersSize(members.size());

        // Add permission for current user (if authenticated)
        if (currentUser != null) {
            MemberEntity member = applicationService.getMember(application.getId(), currentUser);
            if (member != null) {
                application.setPermission(member.getType());
            }
        }

        // Add APIs size
        application.setApisSize(apiService.countByApplication(application.getId()));

        return application;
    };
}

From source file:io.gravitee.repository.redis.management.RedisApplicationRepository.java

@Override
public Set<Application> findByIds(List<String> ids) throws TechnicalException {
    return applicationRedisRepository.find(ids).stream().map(this::convert).collect(Collectors.toSet());
}

From source file:com.vsct.dt.strowgr.admin.gui.mapping.json.EntryPointMappingJson.java

public EntryPointMappingJson(EntryPoint c) {
    this(c.getHaproxy(), c.getHapUser(), c.getHapVersion(), c.getBindingId(),
            c.getFrontends().stream().map(EntryPointFrontendMappingJson::new).collect(Collectors.toSet()),
            c.getBackends().stream().map(EntryPointBackendMappingJson::new).collect(Collectors.toSet()),
            c.getContext());/*w w  w.j  av a 2 s  .  c  o m*/
}

From source file:io.gravitee.repository.redis.management.RedisSubscriptionRepository.java

@Override
public Set<Subscription> findByApplication(String application) throws TechnicalException {
    return subscriptionRedisRepository.findByApplication(application).stream().map(this::convert)
            .collect(Collectors.toSet());
}