Search in sources :

Example 1 with CoffeeNetCurrentUserService

use of coffee.synyx.autoconfigure.security.service.CoffeeNetCurrentUserService in project coffeenet-starter by coffeenet.

the class CoffeeNetWebExtractor method extractApps.

/**
     * Extracts a map of bundled {@link CoffeeNetApp}s by their category. At this time there are only 'apps' and
     * 'profile' as keys
     *
     * @return  map of {@link CoffeeNetApp}s
     */
Optional<Map<String, List<CoffeeNetApp>>> extractApps() {
    Optional<CoffeeNetAppService> coffeeNetAppService = getCoffeeNetAppService();
    if (!coffeeNetAppService.isPresent()) {
        return Optional.empty();
    }
    Map<String, List<CoffeeNetApp>> preparedCoffeeNetApps = new HashMap<>();
    Optional<CoffeeNetCurrentUserService> userService = getCoffeeNetCurrentUserService();
    // create to retrieve CoffeeNet apps
    Builder queryBuilder = AppQuery.builder();
    // add user roles to query if there is a CoffeeNet user
    userService.ifPresent(coffeeNetCurrentUserService -> coffeeNetCurrentUserService.get().ifPresent(userDetails -> queryBuilder.withRoles(userDetails.getAuthoritiesAsString())));
    Map<String, List<CoffeeNetApp>> filteredCoffeeNetApps = coffeeNetAppService.get().getApps(queryBuilder.build());
    // extract profile application
    String profileServiceName = coffeeNetWebProperties.getProfileServiceName();
    List<CoffeeNetApp> profileApps = filteredCoffeeNetApps.get(profileServiceName);
    if (profileApps != null) {
        CoffeeNetApp profileApp = profileApps.get(0);
        filteredCoffeeNetApps.remove(profileServiceName);
        preparedCoffeeNetApps.put("profile", singletonList(profileApp));
    }
    // retrieve all CoffeeNetApps
    List<CoffeeNetApp> firstCoffeeNetApps = filteredCoffeeNetApps.entrySet().stream().map(entry -> entry.getValue().get(0)).sorted(Comparator.comparing(CoffeeNetApp::getName)).collect(toList());
    preparedCoffeeNetApps.put("apps", firstCoffeeNetApps);
    return Optional.of(preparedCoffeeNetApps);
}
Also used : CoffeeNetUserDetails(coffee.synyx.autoconfigure.security.service.CoffeeNetUserDetails) USER_SERVICE(coffee.synyx.autoconfigure.web.CoffeeNetWebExtractor.CoffeeNetServices.USER_SERVICE) Builder(coffee.synyx.autoconfigure.discovery.service.AppQuery.Builder) EnumMap(java.util.EnumMap) CoffeeNetApp(coffee.synyx.autoconfigure.discovery.service.CoffeeNetApp) HashMap(java.util.HashMap) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) AppQuery(coffee.synyx.autoconfigure.discovery.service.AppQuery) CoffeeNetCurrentUserService(coffee.synyx.autoconfigure.security.service.CoffeeNetCurrentUserService) Map(java.util.Map) Optional(java.util.Optional) Comparator(java.util.Comparator) CoffeeNetAppService(coffee.synyx.autoconfigure.discovery.service.CoffeeNetAppService) APP_SERVICE(coffee.synyx.autoconfigure.web.CoffeeNetWebExtractor.CoffeeNetServices.APP_SERVICE) CoffeeNetCurrentUserService(coffee.synyx.autoconfigure.security.service.CoffeeNetCurrentUserService) CoffeeNetAppService(coffee.synyx.autoconfigure.discovery.service.CoffeeNetAppService) HashMap(java.util.HashMap) Builder(coffee.synyx.autoconfigure.discovery.service.AppQuery.Builder) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) CoffeeNetApp(coffee.synyx.autoconfigure.discovery.service.CoffeeNetApp)

Aggregations

AppQuery (coffee.synyx.autoconfigure.discovery.service.AppQuery)1 Builder (coffee.synyx.autoconfigure.discovery.service.AppQuery.Builder)1 CoffeeNetApp (coffee.synyx.autoconfigure.discovery.service.CoffeeNetApp)1 CoffeeNetAppService (coffee.synyx.autoconfigure.discovery.service.CoffeeNetAppService)1 CoffeeNetCurrentUserService (coffee.synyx.autoconfigure.security.service.CoffeeNetCurrentUserService)1 CoffeeNetUserDetails (coffee.synyx.autoconfigure.security.service.CoffeeNetUserDetails)1 APP_SERVICE (coffee.synyx.autoconfigure.web.CoffeeNetWebExtractor.CoffeeNetServices.APP_SERVICE)1 USER_SERVICE (coffee.synyx.autoconfigure.web.CoffeeNetWebExtractor.CoffeeNetServices.USER_SERVICE)1 Collections.singletonList (java.util.Collections.singletonList)1 Comparator (java.util.Comparator)1 EnumMap (java.util.EnumMap)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors.toList (java.util.stream.Collectors.toList)1