Search in sources :

Example 1 with CASE_INSENSITIVE_ORDER

use of java.lang.String.CASE_INSENSITIVE_ORDER 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)

Example 2 with CASE_INSENSITIVE_ORDER

use of java.lang.String.CASE_INSENSITIVE_ORDER in project presto by prestodb.

the class AwsRequestSigner method process.

@Override
public void process(final HttpRequest request, final HttpContext context) throws IOException {
    String method = request.getRequestLine().getMethod();
    URI uri = URI.create(request.getRequestLine().getUri());
    URIBuilder uriBuilder = new URIBuilder(uri);
    Map<String, List<String>> parameters = new TreeMap<>(CASE_INSENSITIVE_ORDER);
    for (NameValuePair parameter : uriBuilder.getQueryParams()) {
        parameters.computeIfAbsent(parameter.getName(), key -> new ArrayList<>()).add(parameter.getValue());
    }
    Map<String, String> headers = Arrays.stream(request.getAllHeaders()).collect(toImmutableMap(Header::getName, Header::getValue));
    InputStream content = null;
    if (request instanceof HttpEntityEnclosingRequest) {
        HttpEntityEnclosingRequest enclosingRequest = (HttpEntityEnclosingRequest) request;
        if (enclosingRequest.getEntity() != null) {
            content = enclosingRequest.getEntity().getContent();
        }
    }
    DefaultRequest<?> awsRequest = new DefaultRequest<>(SERVICE_NAME);
    HttpHost host = (HttpHost) context.getAttribute(HTTP_TARGET_HOST);
    if (host != null) {
        awsRequest.setEndpoint(URI.create(host.toURI()));
    }
    awsRequest.setHttpMethod(HttpMethodName.fromValue(method));
    awsRequest.setResourcePath(uri.getRawPath());
    awsRequest.setContent(content);
    awsRequest.setParameters(parameters);
    awsRequest.setHeaders(headers);
    signer.sign(awsRequest, credentialsProvider.getCredentials());
    Header[] newHeaders = awsRequest.getHeaders().entrySet().stream().map(entry -> new BasicHeader(entry.getKey(), entry.getValue())).toArray(Header[]::new);
    request.setHeaders(newHeaders);
    InputStream newContent = awsRequest.getContent();
    checkState(newContent == null || request instanceof HttpEntityEnclosingRequest);
    if (newContent != null) {
        BasicHttpEntity entity = new BasicHttpEntity();
        entity.setContent(newContent);
        ((HttpEntityEnclosingRequest) request).setEntity(entity);
    }
}
Also used : Arrays(java.util.Arrays) DefaultRequest(com.amazonaws.DefaultRequest) CASE_INSENSITIVE_ORDER(java.lang.String.CASE_INSENSITIVE_ORDER) HTTP_TARGET_HOST(org.apache.http.protocol.HttpCoreContext.HTTP_TARGET_HOST) Header(org.apache.http.Header) ArrayList(java.util.ArrayList) Map(java.util.Map) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) AWS4Signer(com.amazonaws.auth.AWS4Signer) URI(java.net.URI) HttpRequestInterceptor(org.apache.http.HttpRequestInterceptor) HttpEntityEnclosingRequest(org.apache.http.HttpEntityEnclosingRequest) URIBuilder(org.apache.http.client.utils.URIBuilder) IOException(java.io.IOException) HttpMethodName(com.amazonaws.http.HttpMethodName) HttpRequest(org.apache.http.HttpRequest) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) TreeMap(java.util.TreeMap) BasicHttpEntity(org.apache.http.entity.BasicHttpEntity) HttpContext(org.apache.http.protocol.HttpContext) BasicHeader(org.apache.http.message.BasicHeader) NameValuePair(org.apache.http.NameValuePair) HttpHost(org.apache.http.HttpHost) InputStream(java.io.InputStream) NameValuePair(org.apache.http.NameValuePair) DefaultRequest(com.amazonaws.DefaultRequest) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) BasicHttpEntity(org.apache.http.entity.BasicHttpEntity) TreeMap(java.util.TreeMap) URI(java.net.URI) URIBuilder(org.apache.http.client.utils.URIBuilder) Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) HttpHost(org.apache.http.HttpHost) HttpEntityEnclosingRequest(org.apache.http.HttpEntityEnclosingRequest) ArrayList(java.util.ArrayList) List(java.util.List) BasicHeader(org.apache.http.message.BasicHeader)

Aggregations

CASE_INSENSITIVE_ORDER (java.lang.String.CASE_INSENSITIVE_ORDER)2 List (java.util.List)2 Map (java.util.Map)2 DefaultRequest (com.amazonaws.DefaultRequest)1 AWS4Signer (com.amazonaws.auth.AWS4Signer)1 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)1 HttpMethodName (com.amazonaws.http.HttpMethodName)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections.singletonList (java.util.Collections.singletonList)1 Comparator (java.util.Comparator)1 EnumMap (java.util.EnumMap)1 HashMap (java.util.HashMap)1 Optional (java.util.Optional)1 TreeMap (java.util.TreeMap)1