List of usage examples for org.springframework.util MultiValueMap keySet
Set<K> keySet();
From source file:fi.helsinki.moodi.integration.moodle.MoodleClient.java
private static String paramsToString(final MultiValueMap<String, String> params) { final StringBuilder sb = new StringBuilder(); for (final String name : params.keySet()) { sb.append(name).append(": ").append(params.get(name)); }/* w w w. j ava2 s .com*/ return sb.toString(); }
From source file:org.broadleafcommerce.core.web.api.endpoint.order.CartEndpoint.java
protected HashMap<String, String> getOptions(MultiValueMap<String, String> requestParams) { HashMap<String, String> productOptions = new HashMap<String, String>(); //Fill up a map of key values that will represent product options Set<String> keySet = requestParams.keySet(); for (String key : keySet) { if (requestParams.getFirst(key) != null) { //Product options should be returned with "productOption." as a prefix. We'll look for those, and //remove the prefix. if (key.startsWith("productOption.")) { productOptions.put(StringUtils.removeStart(key, "productOption."), requestParams.getFirst(key)); }/*w w w.j ava 2 s . c o m*/ } } return productOptions; }
From source file:org.kuali.rice.kew.doctype.service.impl.DocumentSecurityServiceImpl.java
protected void processDocumentRequiringExtensionProcessing(List<Document> documentsRequiringExtensionProcessing, SecuritySession securitySession, Set<String> authorizations) { if (CollectionUtils.isNotEmpty(documentsRequiringExtensionProcessing)) { LOG.info("Beginning processing of documents requiring extension processing (total: " + documentsRequiringExtensionProcessing.size() + " documents)"); long start = System.currentTimeMillis(); MultiValueMap<PartitionKey, Document> partitions = partitionDocumentsForSecurity( documentsRequiringExtensionProcessing, securitySession); MultiValueMap<String, DocumentSecurityDirective> applicationSecurityDirectives = new LinkedMultiValueMap<String, DocumentSecurityDirective>(); for (PartitionKey partitionKey : partitions.keySet()) { DocumentSecurityDirective directive = DocumentSecurityDirective .create(partitionKey.getDocumentSecurityAttributeNameList(), partitions.get(partitionKey)); applicationSecurityDirectives.add(partitionKey.applicationId, directive); }/* ww w .j a v a 2s. c o m*/ for (String applicationId : applicationSecurityDirectives.keySet()) { List<DocumentSecurityDirective> documentSecurityDirectives = applicationSecurityDirectives .get(applicationId); DocumentSecurityHandlerService securityHandler = loadSecurityHandler(applicationId); List<String> authorizedDocumentIds = securityHandler .getAuthorizedDocumentIds(securitySession.getPrincipalId(), documentSecurityDirectives); if (CollectionUtils.isNotEmpty(authorizedDocumentIds)) { authorizations.addAll(authorizedDocumentIds); } } long end = System.currentTimeMillis(); LOG.info("Finished processing of documents requiring extension processing (total time: " + (start - end) + ")"); } }
From source file:org.kuali.rice.kew.doctype.service.impl.DocumentSecurityServiceImpl.java
protected MultiValueMap<PartitionKey, Document> partitionDocumentsForSecurity(List<Document> documents, SecuritySession securitySession) { MultiValueMap<PartitionKey, Document> partitions = new LinkedMultiValueMap<PartitionKey, Document>(); for (Document document : documents) { DocumentTypeSecurity security = getDocumentTypeSecurity(document.getDocumentTypeName(), securitySession);//www .j a va 2 s. c om MultiValueMap<String, ExtensionDefinition> securityAttributeExtensionDefinitions = loadExtensionDefinitions( security, securitySession); for (String applicationId : securityAttributeExtensionDefinitions.keySet()) { List<ExtensionDefinition> extensionDefinitions = securityAttributeExtensionDefinitions .get(applicationId); PartitionKey key = new PartitionKey(applicationId, extensionDefinitions); partitions.add(key, document); } } return partitions; }
From source file:org.springframework.cloud.netflix.zuul.filters.ProxyRequestHelper.java
public Map<String, Object> debug(String verb, String uri, MultiValueMap<String, String> headers, MultiValueMap<String, String> params, InputStream requestEntity) throws IOException { Map<String, Object> info = new LinkedHashMap<String, Object>(); if (traces != null) { RequestContext context = RequestContext.getCurrentContext(); info.put("remote", true); info.put("serviceId", context.get("serviceId")); Map<String, Object> trace = new LinkedHashMap<String, Object>(); Map<String, Object> input = new LinkedHashMap<String, Object>(); trace.put("request", input); info.put("headers", trace); for (Entry<String, List<String>> entry : headers.entrySet()) { Collection<String> collection = entry.getValue(); Object value = collection; if (collection.size() < 2) { value = collection.isEmpty() ? "" : collection.iterator().next(); }/*from w ww. ja v a 2s.c o m*/ input.put(entry.getKey(), value); } StringBuilder query = new StringBuilder(); for (String param : params.keySet()) { for (String value : params.get(param)) { query.append(param); query.append("="); query.append(value); query.append("&"); } } info.put("method", verb); info.put("uri", uri); info.put("query", query.toString()); RequestContext ctx = RequestContext.getCurrentContext(); if (!ctx.isChunkedRequestBody()) { if (requestEntity != null) { debugRequestEntity(info, ctx.getRequest().getInputStream()); } } traces.add(info); return info; } return info; }
From source file:org.springframework.cloud.stream.app.jdbc.sink.JdbcSinkConfiguration.java
@Bean @ServiceActivator(autoStartup = "false", inputChannel = Sink.INPUT) public JdbcMessageHandler jdbcMessageHandler(DataSource dataSource) { final MultiValueMap<String, Expression> columnExpressionVariations = new LinkedMultiValueMap<>(); for (Map.Entry<String, String> entry : properties.getColumns().entrySet()) { String value = entry.getValue(); columnExpressionVariations.add(entry.getKey(), spelExpressionParser.parseExpression(value)); if (!value.startsWith("payload")) { columnExpressionVariations.add(entry.getKey(), spelExpressionParser.parseExpression("payload." + value)); }//w w w.j a v a 2s. c o m } JdbcMessageHandler jdbcMessageHandler = new JdbcMessageHandler(dataSource, generateSql(properties.getTableName(), columnExpressionVariations.keySet())); jdbcMessageHandler.setSqlParameterSourceFactory(new SqlParameterSourceFactory() { @Override public SqlParameterSource createParameterSource(Object o) { if (!(o instanceof Message)) { throw new IllegalArgumentException("Unable to handle type " + o.getClass().getName()); } Message<?> message = (Message<?>) o; MapSqlParameterSource parameterSource = new MapSqlParameterSource(); for (String key : columnExpressionVariations.keySet()) { List<Expression> spels = columnExpressionVariations.get(key); Object value = NOT_SET; EvaluationException lastException = null; for (Expression spel : spels) { try { value = spel.getValue(evaluationContext, message); break; } catch (EvaluationException e) { lastException = e; } } if (value == NOT_SET) { if (lastException != null) { logger.info( "Could not find value for column '" + key + "': " + lastException.getMessage()); } parameterSource.addValue(key, null); } else { if (value instanceof JsonPropertyAccessor.ToStringFriendlyJsonNode) { // Need to do some reflection until we have a getter for the Node DirectFieldAccessor dfa = new DirectFieldAccessor(value); JsonNode node = (JsonNode) dfa.getPropertyValue("node"); Object valueToUse; if (node == null || node.isNull()) { valueToUse = null; } else if (node.isNumber()) { valueToUse = node.numberValue(); } else if (node.isBoolean()) { valueToUse = node.booleanValue(); } else { valueToUse = node.textValue(); } parameterSource.addValue(key, valueToUse); } else { parameterSource.addValue(key, value); } } } return parameterSource; } }); return jdbcMessageHandler; }
From source file:org.springframework.http.converter.FormHttpMessageConverter.java
private boolean isMultipart(MultiValueMap<String, ?> map, @Nullable MediaType contentType) { if (contentType != null) { return MediaType.MULTIPART_FORM_DATA.includes(contentType); }/*from w ww. j a v a 2s . c o m*/ for (String name : map.keySet()) { for (Object value : map.get(name)) { if (value != null && !(value instanceof String)) { return true; } } } return false; }
From source file:org.springframework.http.converter.FormHttpMessageConverter.java
private void writeForm(MultiValueMap<String, String> form, @Nullable MediaType contentType, HttpOutputMessage outputMessage) throws IOException { Charset charset;/*w w w. j a v a 2s.com*/ if (contentType != null) { outputMessage.getHeaders().setContentType(contentType); charset = (contentType.getCharset() != null ? contentType.getCharset() : this.charset); } else { outputMessage.getHeaders().setContentType(MediaType.APPLICATION_FORM_URLENCODED); charset = this.charset; } StringBuilder builder = new StringBuilder(); for (Iterator<String> nameIterator = form.keySet().iterator(); nameIterator.hasNext();) { String name = nameIterator.next(); for (Iterator<String> valueIterator = form.get(name).iterator(); valueIterator.hasNext();) { String value = valueIterator.next(); builder.append(URLEncoder.encode(name, charset.name())); if (value != null) { builder.append('='); builder.append(URLEncoder.encode(value, charset.name())); if (valueIterator.hasNext()) { builder.append('&'); } } } if (nameIterator.hasNext()) { builder.append('&'); } } final byte[] bytes = builder.toString().getBytes(charset); outputMessage.getHeaders().setContentLength(bytes.length); if (outputMessage instanceof StreamingHttpOutputMessage) { StreamingHttpOutputMessage streamingOutputMessage = (StreamingHttpOutputMessage) outputMessage; streamingOutputMessage.setBody(new StreamingHttpOutputMessage.Body() { @Override public void writeTo(OutputStream outputStream) throws IOException { StreamUtils.copy(bytes, outputStream); } }); } else { StreamUtils.copy(bytes, outputMessage.getBody()); } }
From source file:org.springframework.messaging.simp.handler.SimpleBrokerMessageHandler.java
protected void sendMessageToSubscribers(String destination, Message<?> message) { MultiValueMap<String, String> subscriptions = this.subscriptionRegistry.findSubscriptions(message); for (String sessionId : subscriptions.keySet()) { for (String subscriptionId : subscriptions.get(sessionId)) { SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.wrap(message); headers.setSessionId(sessionId); headers.setSubscriptionId(subscriptionId); Object payload = message.getPayload(); Message<?> clientMessage = MessageBuilder.withPayloadAndHeaders(payload, headers).build(); try { this.messageChannel.send(clientMessage); } catch (Throwable ex) { logger.error("Failed to send message to destination=" + destination + ", sessionId=" + sessionId + ", subscriptionId=" + subscriptionId, ex); }//w ww. j a v a 2s. c o m } } }
From source file:org.springframework.social.linkedin.api.impl.ProfileTemplate.java
private URI expand(String url, SearchParameters parameters) { URIBuilder uriBuilder = URIBuilder.fromUri(url); if (parameters.getKeywords() != null) { uriBuilder.queryParam("keywords", parameters.getKeywords()); }// ww w. j a v a2 s . co m if (parameters.getFirstName() != null) { uriBuilder.queryParam("first-name", parameters.getFirstName()); } if (parameters.getLastName() != null) { uriBuilder.queryParam("last-name", parameters.getLastName()); } if (parameters.getCompanyName() != null) { uriBuilder.queryParam("company-name", parameters.getCompanyName()); } if (parameters.getCurrentCompany() != null) { uriBuilder.queryParam("current-company", parameters.getCurrentCompany().toString()); } if (parameters.getTitle() != null) { uriBuilder.queryParam("title", parameters.getTitle()); } if (parameters.getCurrentTitle() != null) { uriBuilder.queryParam("current-title", parameters.getCurrentTitle().toString()); } if (parameters.getSchoolName() != null) { uriBuilder.queryParam("school-name", parameters.getSchoolName()); } if (parameters.getCurrentSchool() != null) { uriBuilder.queryParam("current-school", parameters.getCurrentSchool().toString()); } if (parameters.getCountryCode() != null) { uriBuilder.queryParam("country-code", parameters.getCountryCode()); } if (parameters.getPostalCode() != null) { uriBuilder.queryParam("postal-code", parameters.getPostalCode()); } if (parameters.getDistance() != null) { uriBuilder.queryParam("distance", parameters.getDistance().toString()); } uriBuilder.queryParam("start", String.valueOf(parameters.getStart())); uriBuilder.queryParam("count", String.valueOf(parameters.getCount())); if (parameters.getSort() != null) { uriBuilder.queryParam("sort", parameters.getSort().toString()); } // Processing facets MultiValueMap<SearchParameters.FacetType, String> facets = parameters.getFacets(); for (SearchParameters.FacetType ft : facets.keySet()) { StringBuilder facetString = new StringBuilder(ft.toString()); for (String value : facets.get(ft)) { facetString.append(","); facetString.append(value); } uriBuilder.queryParam("facet", facetString.toString()); } return uriBuilder.build(); }