use of rocks.coffeenet.autoconfigure.discovery.service.CoffeeNetApp in project coffeenet-starter by coffeenet.
the class CoffeeNetNavigationEndpointTest method invokeWithEmptyUserRoles.
@Test
public void invokeWithEmptyUserRoles() {
CurrentCoffeeNetUser currentCoffeeNetUser = new CurrentCoffeeNetUser("username", "email");
CoffeeNetApp coffeeNetApp = new CoffeeNetApp("NoRights", "urlNoRights", emptySet());
List<CoffeeNetApp> coffeeNetApps = singletonList(coffeeNetApp);
CoffeeNetNavigationAppInformation coffeeNetNavigationAppInformation = new CoffeeNetNavigationAppInformation("", "", "", "", "", "");
CoffeeNetNavigationInformation coffeeNetNavigationInformation = new CoffeeNetNavigationInformation(currentCoffeeNetUser, coffeeNetApps, coffeeNetApp, "path", coffeeNetNavigationAppInformation);
when(coffeeNetNavigationServiceMock.get()).thenReturn(coffeeNetNavigationInformation);
CoffeeNetNavigationEndpoint sut = new CoffeeNetNavigationEndpoint(coffeeNetNavigationServiceMock);
CoffeeNetNavigationInformation receivedCoffeeNetNavigationInformation = sut.invoke();
assertThat(receivedCoffeeNetNavigationInformation.getCoffeeNetApps(), is(coffeeNetApps));
assertThat(receivedCoffeeNetNavigationInformation.getCurrentCoffeeNetUser(), Is.is(currentCoffeeNetUser));
assertThat(receivedCoffeeNetNavigationInformation.getLogoutPath(), is("path"));
assertThat(receivedCoffeeNetNavigationInformation.getProfileApp(), is(coffeeNetApp));
}
use of rocks.coffeenet.autoconfigure.discovery.service.CoffeeNetApp 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);
}
use of rocks.coffeenet.autoconfigure.discovery.service.CoffeeNetApp in project coffeenet-starter by coffeenet.
the class CoffeeNetNavigationServiceImpl method get.
@Override
public CoffeeNetNavigationInformation get() {
CurrentCoffeeNetUser currentCoffeeNetUser = dataExtractor.extractUser().orElse(null);
CoffeeNetNavigationAppInformation appInformation = dataExtractor.extractAppInformation().orElse(null);
Map<String, List<CoffeeNetApp>> apps = dataExtractor.extractApps().orElseGet(Collections::emptyMap);
String logoutPath = dataExtractor.extractLogoutPath();
List<CoffeeNetApp> profileApps = apps.get("profile");
CoffeeNetApp profileApp = null;
if (profileApps != null && !profileApps.isEmpty()) {
profileApp = profileApps.get(0);
}
List<CoffeeNetApp> coffeeNetApps = apps.get("apps");
return new CoffeeNetNavigationInformation(currentCoffeeNetUser, coffeeNetApps, profileApp, logoutPath, appInformation);
}
use of rocks.coffeenet.autoconfigure.discovery.service.CoffeeNetApp in project coffeenet-starter by coffeenet.
the class CoffeeNetNavigationDataExtractorTest method extractNoUserService.
@Test
public void extractNoUserService() {
Map<String, List<CoffeeNetApp>> apps = new HashMap<>();
CoffeeNetApp coffeeNetApp = new CoffeeNetApp("Coffee App", "coffeeapp.coffeenet", emptySet());
apps.put("cna1", singletonList(coffeeNetApp));
CoffeeNetApp profileApp = new CoffeeNetApp("Profile", "profile.coffeenet", emptySet());
apps.put("profile", singletonList(profileApp));
sut.registerService(CoffeeNetNavigationDataExtractor.CoffeeNetServices.APP_SERVICE, coffeeNetAppServiceMock);
when(coffeeNetAppServiceMock.getApps(any())).thenReturn(apps);
Optional<Map<String, List<CoffeeNetApp>>> extractedApps = sut.extractApps();
Map<String, List<CoffeeNetApp>> coffeeNetApps = extractedApps.get();
assertThat(coffeeNetApps).hasSize(2);
assertThat(coffeeNetApps.get("apps")).hasSize(1);
assertThat(coffeeNetApps.get("apps").get(0)).isSameAs(coffeeNetApp);
assertThat(coffeeNetApps.get("profile")).hasSize(1);
assertThat(coffeeNetApps.get("profile").get(0)).isSameAs(profileApp);
}
use of rocks.coffeenet.autoconfigure.discovery.service.CoffeeNetApp in project coffeenet-starter by coffeenet.
the class CoffeeNetNavigationDataExtractorTest method extractAppsNoUser.
@Test
public void extractAppsNoUser() {
Map<String, List<CoffeeNetApp>> apps = new HashMap<>();
CoffeeNetApp coffeeNetApp = new CoffeeNetApp("Coffee App", "coffeeapp.coffeenet", emptySet());
CoffeeNetApp coffeeNetApp2 = new CoffeeNetApp("Coffee App2", "coffeeapp.coffeenet", new HashSet<>(singletonList("ROLE_COFFEENET-USER")));
apps.put("cna1", singletonList(coffeeNetApp));
apps.put("cna2", singletonList(coffeeNetApp2));
CoffeeNetApp profileApp = new CoffeeNetApp("Profile", "profile.coffeenet", emptySet());
apps.put("profile", singletonList(profileApp));
sut.registerService(CoffeeNetNavigationDataExtractor.CoffeeNetServices.APP_SERVICE, coffeeNetAppServiceMock);
when(coffeeNetAppServiceMock.getApps(any())).thenReturn(apps);
// user
sut.registerService(CoffeeNetNavigationDataExtractor.CoffeeNetServices.USER_SERVICE, coffeeNetCurrentUserServiceMock);
when(coffeeNetCurrentUserServiceMock.get()).thenReturn(Optional.empty());
Optional<Map<String, List<CoffeeNetApp>>> extractedApps = sut.extractApps();
Map<String, List<CoffeeNetApp>> coffeeNetApps = extractedApps.get();
assertThat(coffeeNetApps).hasSize(2);
assertThat(coffeeNetApps.get("apps")).hasSize(2);
assertThat(coffeeNetApps.get("apps").get(0)).isSameAs(coffeeNetApp);
assertThat(coffeeNetApps.get("apps").get(1)).isSameAs(coffeeNetApp2);
assertThat(coffeeNetApps.get("profile")).hasSize(1);
assertThat(coffeeNetApps.get("profile").get(0)).isSameAs(profileApp);
}
Aggregations