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