Search in sources :

Example 6 with CoffeeNetApp

use of coffee.synyx.autoconfigure.discovery.service.CoffeeNetApp in project coffeenet-starter by coffeenet.

the class CoffeeNetWebServiceImplTest method getNoProfileApp.

@Test
public void getNoProfileApp() {
    Optional<CoffeeNetWebUser> coffeeNetWebUser = Optional.of(new CoffeeNetWebUser("username", "email"));
    when(coffeeNetWebExtractorMock.extractUser()).thenReturn(coffeeNetWebUser);
    Map<String, List<CoffeeNetApp>> apps = new HashMap<>();
    CoffeeNetApp coffeeNetApp = new CoffeeNetApp("Coffee App", "coffeeapp.coffeenet", emptySet());
    apps.put("apps", singletonList(coffeeNetApp));
    when(coffeeNetWebExtractorMock.extractApps()).thenReturn(Optional.of(apps));
    when(coffeeNetWebExtractorMock.extractLogoutPath()).thenReturn("/logout");
    CoffeeNetWeb coffeeNetWeb = sut.get();
    assertThat(coffeeNetWeb.getLogoutPath()).isEqualTo("/logout");
    assertThat(coffeeNetWeb.getCoffeeNetWebUser().getUsername()).isSameAs("username");
    assertThat(coffeeNetWeb.getCoffeeNetWebUser().getEmail()).isSameAs("email");
    assertThat(coffeeNetWeb.getProfileApp()).isNull();
    assertThat(coffeeNetWeb.getCoffeeNetApps()).hasSize(1);
    assertThat(coffeeNetWeb.getCoffeeNetApps().get(0)).isSameAs(coffeeNetApp);
}
Also used : HashMap(java.util.HashMap) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) CoffeeNetApp(coffee.synyx.autoconfigure.discovery.service.CoffeeNetApp) Test(org.junit.Test)

Example 7 with CoffeeNetApp

use of coffee.synyx.autoconfigure.discovery.service.CoffeeNetApp in project coffeenet-starter by coffeenet.

the class CoffeeNetWebServiceImplTest method get.

@Test
public void get() {
    Optional<CoffeeNetWebUser> coffeeNetWebUser = Optional.of(new CoffeeNetWebUser("username", "email"));
    when(coffeeNetWebExtractorMock.extractUser()).thenReturn(coffeeNetWebUser);
    Map<String, List<CoffeeNetApp>> apps = new HashMap<>();
    CoffeeNetApp coffeeNetApp = new CoffeeNetApp("Coffee App", "coffeeapp.coffeenet", emptySet());
    apps.put("apps", singletonList(coffeeNetApp));
    CoffeeNetApp profileApp = new CoffeeNetApp("Profile", "profile.coffeenet", emptySet());
    apps.put("profile", singletonList(profileApp));
    when(coffeeNetWebExtractorMock.extractApps()).thenReturn(Optional.of(apps));
    when(coffeeNetWebExtractorMock.extractLogoutPath()).thenReturn("/logout");
    CoffeeNetWeb coffeeNetWeb = sut.get();
    assertThat(coffeeNetWeb.getLogoutPath()).isEqualTo("/logout");
    assertThat(coffeeNetWeb.getCoffeeNetWebUser().getUsername()).isSameAs("username");
    assertThat(coffeeNetWeb.getCoffeeNetWebUser().getEmail()).isSameAs("email");
    assertThat(coffeeNetWeb.getProfileApp()).isSameAs(profileApp);
    assertThat(coffeeNetWeb.getCoffeeNetApps()).hasSize(1);
    assertThat(coffeeNetWeb.getCoffeeNetApps().get(0)).isSameAs(coffeeNetApp);
}
Also used : HashMap(java.util.HashMap) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) CoffeeNetApp(coffee.synyx.autoconfigure.discovery.service.CoffeeNetApp) Test(org.junit.Test)

Example 8 with CoffeeNetApp

use of coffee.synyx.autoconfigure.discovery.service.CoffeeNetApp in project coffeenet-starter by coffeenet.

the class CoffeeNetWebServiceImplTest method getNoUser.

@Test
public void getNoUser() {
    when(coffeeNetWebExtractorMock.extractUser()).thenReturn(Optional.empty());
    Map<String, List<CoffeeNetApp>> apps = new HashMap<>();
    CoffeeNetApp coffeeNetApp = new CoffeeNetApp("Coffee App", "coffeeapp.coffeenet", emptySet());
    apps.put("apps", singletonList(coffeeNetApp));
    CoffeeNetApp profileApp = new CoffeeNetApp("Profile", "profile.coffeenet", emptySet());
    apps.put("profile", singletonList(profileApp));
    when(coffeeNetWebExtractorMock.extractApps()).thenReturn(Optional.of(apps));
    when(coffeeNetWebExtractorMock.extractLogoutPath()).thenReturn("/logout");
    CoffeeNetWeb coffeeNetWeb = sut.get();
    assertThat(coffeeNetWeb.getLogoutPath()).isEqualTo("/logout");
    assertThat(coffeeNetWeb.getCoffeeNetWebUser()).isNull();
    assertThat(coffeeNetWeb.getProfileApp()).isSameAs(profileApp);
    assertThat(coffeeNetWeb.getCoffeeNetApps()).hasSize(1);
    assertThat(coffeeNetWeb.getCoffeeNetApps().get(0)).isSameAs(coffeeNetApp);
}
Also used : HashMap(java.util.HashMap) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) CoffeeNetApp(coffee.synyx.autoconfigure.discovery.service.CoffeeNetApp) Test(org.junit.Test)

Example 9 with CoffeeNetApp

use of coffee.synyx.autoconfigure.discovery.service.CoffeeNetApp 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)

Example 10 with CoffeeNetApp

use of coffee.synyx.autoconfigure.discovery.service.CoffeeNetApp in project coffeenet-starter by coffeenet.

the class CoffeeNetWebServiceImpl method get.

@Override
public CoffeeNetWeb get() {
    CoffeeNetWebUser coffeeNetWebUser = coffeeNetWebExtractor.extractUser().orElse(null);
    Map<String, List<CoffeeNetApp>> apps = coffeeNetWebExtractor.extractApps().orElseGet(Collections::emptyMap);
    String logoutPath = coffeeNetWebExtractor.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 CoffeeNetWeb(coffeeNetWebUser, coffeeNetApps, profileApp, logoutPath);
}
Also used : List(java.util.List) CoffeeNetApp(coffee.synyx.autoconfigure.discovery.service.CoffeeNetApp) Collections(java.util.Collections)

Aggregations

CoffeeNetApp (coffee.synyx.autoconfigure.discovery.service.CoffeeNetApp)10 List (java.util.List)9 Collections.singletonList (java.util.Collections.singletonList)8 HashMap (java.util.HashMap)8 Test (org.junit.Test)8 Map (java.util.Map)5 Collections.emptyList (java.util.Collections.emptyList)4 CoffeeNetUserDetails (coffee.synyx.autoconfigure.security.service.CoffeeNetUserDetails)3 HumanCoffeeNetUser (coffee.synyx.autoconfigure.security.service.HumanCoffeeNetUser)2 GrantedAuthority (org.springframework.security.core.GrantedAuthority)2 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)2 AppQuery (coffee.synyx.autoconfigure.discovery.service.AppQuery)1 Builder (coffee.synyx.autoconfigure.discovery.service.AppQuery.Builder)1 CoffeeNetAppService (coffee.synyx.autoconfigure.discovery.service.CoffeeNetAppService)1 CoffeeNetCurrentUserService (coffee.synyx.autoconfigure.security.service.CoffeeNetCurrentUserService)1 APP_SERVICE (coffee.synyx.autoconfigure.web.CoffeeNetWebExtractor.CoffeeNetServices.APP_SERVICE)1 USER_SERVICE (coffee.synyx.autoconfigure.web.CoffeeNetWebExtractor.CoffeeNetServices.USER_SERVICE)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 EnumMap (java.util.EnumMap)1