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