Example usage for org.springframework.util LinkedMultiValueMap LinkedMultiValueMap

List of usage examples for org.springframework.util LinkedMultiValueMap LinkedMultiValueMap

Introduction

In this page you can find the example usage for org.springframework.util LinkedMultiValueMap LinkedMultiValueMap.

Prototype

public LinkedMultiValueMap() 

Source Link

Document

Create a new LinkedMultiValueMap that wraps a LinkedHashMap .

Usage

From source file:de.tudarmstadt.ukp.clarin.webanno.crowdflower.CrowdJob.java

/**
 * Create job arguments that are used by CrowdClient to build a POST request for a new job on Crowdflower
 *//*from  w w  w. ja v a  2 s . c o  m*/
void createArgumentMaps() {
    argumentMap = new LinkedMultiValueMap<String, String>();
    includedCountries = new Vector<String>();
    excludedCountries = new Vector<String>();

    Iterator<Map.Entry<String, JsonNode>> jsonRootIt = template.fields();

    for (Map.Entry<String, JsonNode> elt; jsonRootIt.hasNext();) {
        elt = jsonRootIt.next();

        JsonNode currentNode = elt.getValue();
        String currentKey = elt.getKey();

        if (currentNode.isContainerNode()) {
            //special processing for these arrays:
            if (currentKey.equals(includedCountriesKey) || currentKey.equals(excludedCountriesKey)) {
                Iterator<JsonNode> jsonSubNodeIt = currentNode.elements();
                for (JsonNode subElt; jsonSubNodeIt.hasNext();) {
                    subElt = jsonSubNodeIt.next();
                    (currentKey.equals(includedCountriesKey) ? includedCountries : excludedCountries)
                            .addElement(subElt.path(countryCodeKey).asText());
                }

            }
        } else if (!currentNode.isNull() && argumentFilterSet.contains(currentKey)) {
            argumentMap.add(jobKey + "[" + currentKey + "]", currentNode.asText());
        }
        if (currentKey == idKey) {
            this.id = currentNode.asText();
        }
    }
}

From source file:com.naver.template.social.connect.DaoConnectionRepository.java

public MultiValueMap<String, Connection<?>> findConnectionsToUsers(
        MultiValueMap<String, String> providerUsers) {
    if (providerUsers == null || providerUsers.isEmpty()) {
        throw new IllegalArgumentException("Unable to execute find: no providerUsers provided");
    }// w  ww . j  a v  a2s. c  om
    //      StringBuilder providerUsersCriteriaSql = new StringBuilder();
    //      MapSqlParameterSource parameters = new MapSqlParameterSource();
    //      parameters.addValue("userId", userId);
    //      for (Iterator<Entry<String, List<String>>> it = providerUsers.entrySet().iterator(); it.hasNext();) {
    //         Entry<String, List<String>> entry = it.next();
    //         String providerId = entry.getKey();
    //         providerUsersCriteriaSql.append("providerId = :providerId_").append(providerId).append(" and providerUserId in (:providerUserIds_").append(providerId).append(")");
    //         parameters.addValue("providerId_" + providerId, providerId);
    //         parameters.addValue("providerUserIds_" + providerId, entry.getValue());
    //         if (it.hasNext()) {
    //            providerUsersCriteriaSql.append(" or " );
    //         }
    //      }
    //List<Connection<?>> resultList = new NamedParameterJdbcTemplate(jdbcTemplate).query(selectFromUserConnection() + " where userId = :userId and " + providerUsersCriteriaSql + " order by providerId, rank", parameters, connectionMapper);
    List<Connection<?>> resultList = userConnectionDAO.selectConnections(userId, providerUsers);
    MultiValueMap<String, Connection<?>> connectionsForUsers = new LinkedMultiValueMap<String, Connection<?>>();
    for (Connection<?> connection : resultList) {
        String providerId = connection.getKey().getProviderId();
        List<String> userIds = providerUsers.get(providerId);
        List<Connection<?>> connections = connectionsForUsers.get(providerId);
        if (connections == null) {
            connections = new ArrayList<Connection<?>>(userIds.size());
            for (int i = 0; i < userIds.size(); i++) {
                connections.add(null);
            }
            connectionsForUsers.put(providerId, connections);
        }
        String providerUserId = connection.getKey().getProviderUserId();
        int connectionIndex = userIds.indexOf(providerUserId);
        connections.set(connectionIndex, connection);
    }
    return connectionsForUsers;
}

From source file:de.zib.vold.client.VolDClient.java

/**
 * Insert a set of keys./*from w  ww.j av a  2 s .  c o m*/
 */
public void insert(String source, Map<Key, Set<String>> map, final long timeStamp) {
    // guard
    {
        log.trace("Insert: " + map.toString());

        // nothing to do here?
        if (0 == map.size())
            return;

        checkState();

        if (null == map) {
            throw new IllegalArgumentException("null is no valid argument!");
        }
    }

    // build greatest common scope
    String commonscope;
    {
        List<String> scopes = new ArrayList<String>(map.size());

        for (Key k : map.keySet()) {
            scopes.add(k.get_scope());
        }

        commonscope = getGreatestCommonPrefix(scopes);
    }

    // build variable map
    String url;
    {
        url = buildURL(commonscope, null);
        log.debug("INSERT URL: " + url);
    }

    // build request body
    MultiValueMap<String, String> request = new LinkedMultiValueMap<String, String>();
    {
        for (Map.Entry<Key, Set<String>> entry : map.entrySet()) {
            // remove common prefix from scope
            String scope = entry.getKey().get_scope().substring(commonscope.length());
            String type = entry.getKey().get_type();
            String keyname = entry.getKey().get_keyname();

            URIKey key = new URIKey(source, scope, type, keyname, false, false, enc);
            String urikey = key.toURIString();

            for (String value : entry.getValue()) {
                request.add(urikey, value);
            }
        }
    }

    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.add("TIMESTAMP", String.valueOf(timeStamp));
    HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>(
            request, requestHeaders);
    final ResponseEntity<HashMap> responseEntity = rest.exchange(url, HttpMethod.PUT, requestEntity,
            HashMap.class);
    //rest.put( url, request );
}

From source file:com.aestheticsw.jobkeywords.service.termextractor.impl.fivefilters.FiveFiltersClient.java

public String[][] executeFiveFiltersPost(String content) {
    String query = "http://termextract.fivefilters.org/extract.php";

    MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
    params.add("text", content);
    params.add("output", "json");
    params.add("max", "300");

    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
    HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>(
            params, requestHeaders);/*  w  ww  .ja v a2s. c  om*/

    ResponseEntity<String[][]> stringArrayEntty = restTemplate.exchange(query, HttpMethod.POST, requestEntity,
            String[][].class);

    String[][] stringArray = stringArrayEntty.getBody();

    return stringArray;
}

From source file:com.seajas.search.codex.social.connection.InMemoryConnectionRepository.java

@Override
public MultiValueMap<String, Connection<?>> findConnectionsToUsers(
        final MultiValueMap<String, String> providerUsers) {
    if (providerUsers == null || providerUsers.isEmpty()) {
        throw new IllegalArgumentException("Unable to execute find: no providerUsers provided");
    }/*from   www .  j  ava 2  s .c o m*/

    Map<String, List<String>> providerUserIdsByProviderId = new HashMap<String, List<String>>();
    for (Entry<String, List<String>> entry : providerUsers.entrySet()) {
        String providerId = entry.getKey();
        providerUserIdsByProviderId.put(providerId, entry.getValue());
    }

    List<ConnectionData> connectionDatas = new ArrayList<ConnectionData>();
    for (Map.Entry<String, List<String>> entry : providerUserIdsByProviderId.entrySet()) {
        connectionDatas.addAll(getInMemoryProviderConnectionRepository(entry.getKey())
                .findByProviderUserIdsOrderByProviderIdAndRank(entry.getValue()));
    }

    List<Connection<?>> resultList = createConnections(connectionDatas);
    MultiValueMap<String, Connection<?>> connectionsForUsers = new LinkedMultiValueMap<String, Connection<?>>();
    for (Connection<?> connection : resultList) {
        String providerId = connection.getKey().getProviderId();
        List<String> userIds = providerUsers.get(providerId);
        List<Connection<?>> connections = connectionsForUsers.get(providerId);
        if (connections == null) {
            connections = new ArrayList<Connection<?>>(userIds.size());
            for (int i = 0; i < userIds.size(); i++) {
                connections.add(null);
            }
            connectionsForUsers.put(providerId, connections);
        }
        String providerUserId = connection.getKey().getProviderUserId();
        int connectionIndex = userIds.indexOf(providerUserId);
        connections.set(connectionIndex, connection);
    }
    return connectionsForUsers;
}

From source file:com.weibo.api.Statuses.java

/**
 * http://open.weibo.com/wiki/2/statuses/upload_url_text
 * @deprecated TODO: need to added testcase.
 * @param status//from  w w  w  .  j  a  v  a  2 s  .co  m
 * @param visible
 * @param listId
 * @param url
 * @param accessToken
 * @return
 */
public Status uploadUrlText(String status, Visible visible, String listId, String url, String accessToken) {
    MultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>();
    map.add("status", status);
    if (visible != null) {
        map.add("visible", visible.getCode());
        if (visible == Visible.GROUP) {
            map.add("list_id", listId);
        }
    }
    map.add("url", url);
    map.add("access_token", accessToken);
    return weiboHttpClient.postForm(STATUSES_UPLOAD_URL_TEXT_URL, map, Status.class);
}

From source file:fr.littlereddot.pocket.site.controller.account.ConnectAccountController.java

/**
 * Process a connect form submission by commencing the process of establishing a connection to the provider on behalf of the member.
 * For OAuth1, fetches a new request token from the provider, temporarily stores it in the session, then redirects the member to the provider's site for authorization.
 * For OAuth2, redirects the user to the provider's site for authorization.
 *//*  ww w  .ja v a 2  s .com*/
@RequestMapping(value = "/{providerId}", method = RequestMethod.POST)
public RedirectView connect(@PathVariable String providerId, NativeWebRequest request) {
    ConnectionFactory<?> connectionFactory = connectionFactoryLocator.getConnectionFactory(providerId);
    MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
    try {
        return new RedirectView(connectSupport.buildOAuthUrl(connectionFactory, request, parameters));
    } catch (Exception e) {
        sessionStrategy.setAttribute(request, PROVIDER_ERROR_ATTRIBUTE, e);
        return connectionStatusRedirect(providerId, request);
    }
}

From source file:org.cloudfoundry.identity.uaa.login.SamlRemoteUaaController.java

@RequestMapping(value = "/oauth/token", method = RequestMethod.POST, params = "grant_type=password")
@ResponseBody//from   www  . j  a v a 2s . co  m
public ResponseEntity<byte[]> tokenEndpoint(HttpServletRequest request, HttpEntity<byte[]> entity,
        @RequestParam Map<String, String> parameters, Map<String, Object> model, Principal principal)
        throws Exception {

    // Request has a password. Owner password grant with a UAA password
    if (null != request.getParameter("password")) {
        return passthru(request, entity, model);
    } else {
        //
        MultiValueMap<String, String> requestHeadersForClientInfo = new LinkedMultiValueMap<String, String>();
        requestHeadersForClientInfo.add(AUTHORIZATION, request.getHeader(AUTHORIZATION));

        ResponseEntity<byte[]> clientInfoResponse = getDefaultTemplate().exchange(
                getUaaBaseUrl() + "/clientinfo", HttpMethod.POST,
                new HttpEntity<MultiValueMap<String, String>>(null, requestHeadersForClientInfo), byte[].class);

        if (clientInfoResponse.getStatusCode() == HttpStatus.OK) {
            String path = extractPath(request);

            MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
            map.setAll(parameters);
            if (principal != null) {
                map.set("source", "login");
                map.set("client_id", getClientId(clientInfoResponse.getBody()));
                map.setAll(getLoginCredentials(principal));
                map.remove("credentials"); // legacy vmc might break otherwise
            } else {
                throw new BadCredentialsException("No principal found in authorize endpoint");
            }

            HttpHeaders requestHeaders = new HttpHeaders();
            requestHeaders.putAll(getRequestHeaders(requestHeaders));
            requestHeaders.remove(AUTHORIZATION.toLowerCase());
            requestHeaders.remove(ACCEPT.toLowerCase());
            requestHeaders.remove(CONTENT_TYPE.toLowerCase());
            requestHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
            requestHeaders.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
            requestHeaders.remove(COOKIE);
            requestHeaders.remove(COOKIE.toLowerCase());

            ResponseEntity<byte[]> response = getAuthorizationTemplate().exchange(getUaaBaseUrl() + "/" + path,
                    HttpMethod.POST, new HttpEntity<MultiValueMap<String, String>>(map, requestHeaders),
                    byte[].class);

            saveCookie(response.getHeaders(), model);

            byte[] body = response.getBody();
            if (body != null) {
                HttpHeaders outgoingHeaders = getResponseHeaders(response.getHeaders());
                return new ResponseEntity<byte[]>(response.getBody(), outgoingHeaders,
                        response.getStatusCode());
            }

            throw new IllegalStateException("Neither a redirect nor a user approval");
        } else {
            throw new BadCredentialsException(new String(clientInfoResponse.getBody()));
        }
    }
}

From source file:org.apigw.util.OAuthTestHelper.java

private String loginAndGrabCookie() {

    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));

    MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>();
    formData.add("j_username", username);
    formData.add("j_password", password);

    // Should be redirected to the original URL, but now authenticated
    ResponseEntity<Void> result = serverRunning.postForStatus("/apigw-auth-server-web/login.do", headers,
            formData);/*  w  ww  . jav  a 2  s.co m*/

    assertEquals(HttpStatus.FOUND, result.getStatusCode());

    assertTrue(result.getHeaders().containsKey("Set-Cookie"));

    return result.getHeaders().getFirst("Set-Cookie");

}

From source file:org.cloudfoundry.identity.uaa.login.feature.ImplicitGrantIT.java

@Test
public void testInvalidScopes() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));

    LinkedMultiValueMap<String, String> postBody = new LinkedMultiValueMap<>();
    postBody.add("client_id", "cf");
    postBody.add("redirect_uri", "https://uaa.cloudfoundry.com/redirect/cf");
    postBody.add("response_type", "token");
    postBody.add("source", "credentials");
    postBody.add("username", testAccounts.getUserName());
    postBody.add("password", testAccounts.getPassword());
    postBody.add("scope", "read");

    ResponseEntity<Void> responseEntity = restOperations.exchange(baseUrl + "/oauth/authorize", HttpMethod.POST,
            new HttpEntity<>(postBody, headers), Void.class);

    Assert.assertEquals(HttpStatus.FOUND, responseEntity.getStatusCode());

    System.out.println(//from  www  .ja  v  a  2  s .  c  om
            "responseEntity.getHeaders().getLocation() = " + responseEntity.getHeaders().getLocation());

    UriComponents locationComponents = UriComponentsBuilder.fromUri(responseEntity.getHeaders().getLocation())
            .build();
    Assert.assertEquals("uaa.cloudfoundry.com", locationComponents.getHost());
    Assert.assertEquals("/redirect/cf", locationComponents.getPath());

    MultiValueMap<String, String> params = parseFragmentParams(locationComponents);

    Assert.assertThat(params.getFirst("error"), is("invalid_scope"));
    Assert.assertThat(params.getFirst("access_token"), isEmptyOrNullString());
    Assert.assertThat(params.getFirst("credentials"), isEmptyOrNullString());
}