Search in sources :

Example 1 with CoffeeNetAppService

use of rocks.coffeenet.autoconfigure.discovery.service.CoffeeNetAppService in project coffeenet-starter by coffeenet.

the class CoffeeNetNavigationDataExtractor 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 = coffeeNetNavigationProperties.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, CASE_INSENSITIVE_ORDER)).collect(toList());
    preparedCoffeeNetApps.put("apps", firstCoffeeNetApps);
    return Optional.of(preparedCoffeeNetApps);
}
Also used : AppQuery(rocks.coffeenet.autoconfigure.discovery.service.AppQuery) CoffeeNetApp(rocks.coffeenet.autoconfigure.discovery.service.CoffeeNetApp) EnumMap(java.util.EnumMap) CASE_INSENSITIVE_ORDER(java.lang.String.CASE_INSENSITIVE_ORDER) BuildProperties(org.springframework.boot.info.BuildProperties) HashMap(java.util.HashMap) CoffeeNetCurrentUserService(rocks.coffeenet.autoconfigure.security.service.CoffeeNetCurrentUserService) BUILD_PROPERTIES(rocks.coffeenet.autoconfigure.navigation.CoffeeNetNavigationDataExtractor.CoffeeNetServices.BUILD_PROPERTIES) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) USER_SERVICE(rocks.coffeenet.autoconfigure.navigation.CoffeeNetNavigationDataExtractor.CoffeeNetServices.USER_SERVICE) CoffeeNetAppService(rocks.coffeenet.autoconfigure.discovery.service.CoffeeNetAppService) CoffeeNetUserDetails(rocks.coffeenet.autoconfigure.security.service.CoffeeNetUserDetails) Map(java.util.Map) Builder(rocks.coffeenet.autoconfigure.discovery.service.AppQuery.Builder) APP_SERVICE(rocks.coffeenet.autoconfigure.navigation.CoffeeNetNavigationDataExtractor.CoffeeNetServices.APP_SERVICE) Optional(java.util.Optional) Comparator(java.util.Comparator) CoffeeNetCurrentUserService(rocks.coffeenet.autoconfigure.security.service.CoffeeNetCurrentUserService) CoffeeNetAppService(rocks.coffeenet.autoconfigure.discovery.service.CoffeeNetAppService) HashMap(java.util.HashMap) Builder(rocks.coffeenet.autoconfigure.discovery.service.AppQuery.Builder) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) CoffeeNetApp(rocks.coffeenet.autoconfigure.discovery.service.CoffeeNetApp)

Aggregations

CASE_INSENSITIVE_ORDER (java.lang.String.CASE_INSENSITIVE_ORDER)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 BuildProperties (org.springframework.boot.info.BuildProperties)1 AppQuery (rocks.coffeenet.autoconfigure.discovery.service.AppQuery)1 Builder (rocks.coffeenet.autoconfigure.discovery.service.AppQuery.Builder)1 CoffeeNetApp (rocks.coffeenet.autoconfigure.discovery.service.CoffeeNetApp)1 CoffeeNetAppService (rocks.coffeenet.autoconfigure.discovery.service.CoffeeNetAppService)1 APP_SERVICE (rocks.coffeenet.autoconfigure.navigation.CoffeeNetNavigationDataExtractor.CoffeeNetServices.APP_SERVICE)1 BUILD_PROPERTIES (rocks.coffeenet.autoconfigure.navigation.CoffeeNetNavigationDataExtractor.CoffeeNetServices.BUILD_PROPERTIES)1 USER_SERVICE (rocks.coffeenet.autoconfigure.navigation.CoffeeNetNavigationDataExtractor.CoffeeNetServices.USER_SERVICE)1 CoffeeNetCurrentUserService (rocks.coffeenet.autoconfigure.security.service.CoffeeNetCurrentUserService)1 CoffeeNetUserDetails (rocks.coffeenet.autoconfigure.security.service.CoffeeNetUserDetails)1