Example usage for org.springframework.util LinkedMultiValueMap add

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

Introduction

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

Prototype

@Override
    public void add(K key, @Nullable V value) 

Source Link

Usage

From source file:com.goldengekko.meetr.itest.AuthITest.java

public static LinkedMultiValueMap<String, String> getOAuth2Request() {

    LinkedMultiValueMap<String, String> request = new LinkedMultiValueMap<String, String>();

    request.add("access_token", TOKEN);
    request.add("providerId", OAuth2Service.PROVIDER_ID_ITEST);
    request.add("providerUserId", ITestTemplate.ITEST_PROVIDER_USER_ID);
    request.add("expires_in", "60");
    request.add("appArg0", "appArg0");
    return request;
}

From source file:eu.falcon.semantic.client.DenaClient.java

public static String publishOntology(String fileClassPath, String format, String dataset) {

    RestTemplate restTemplate = new RestTemplate();
    LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
    final String uri = "http://localhost:8090/api/v1/ontology/publish";
    //final String uri = "http://falconsemanticmanager.euprojects.net/api/v1/ontology/publish";

    map.add("file", new ClassPathResource(fileClassPath));
    map.add("format", format);
    map.add("dataset", dataset);
    HttpHeaders headers = new HttpHeaders();

    headers.setContentType(MediaType.MULTIPART_FORM_DATA);

    HttpEntity<LinkedMultiValueMap<String, Object>> entity = new HttpEntity<LinkedMultiValueMap<String, Object>>(
            map, headers);/*from  w ww  .j a va  2 s .c om*/

    String result = restTemplate.postForObject(uri, entity, String.class);

    return result;

}

From source file:eu.falcon.semantic.client.DenaClient.java

public static String addInstances(String fileClassPath, String format) {

    RestTemplate restTemplate = new RestTemplate();
    LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
    //final String uri = "http://localhost:8090/api/v1/ontology/instances/publish";
    final String uri = "http://falconsemanticmanager.euprojects.net/api/v1/ontology/instances/publish";

    map.add("file", new ClassPathResource(fileClassPath));
    map.add("format", format);
    HttpHeaders headers = new HttpHeaders();

    headers.setContentType(MediaType.MULTIPART_FORM_DATA);

    HttpEntity<LinkedMultiValueMap<String, Object>> entity = new HttpEntity<LinkedMultiValueMap<String, Object>>(
            map, headers);// w  w  w  . ja v  a 2  s.  co  m

    String result = restTemplate.postForObject(uri, entity, String.class);

    return result;

}

From source file:org.pad.pgsql.loadmovies.LoadFiles.java

/**
 * Read tags and load them in a multivalue map.
 *
 * @return MultivalueMap with key movieId and values all tags.
 * @throws Exception it is only a demo.//from w  ww  . j  a va  2 s  .  c o m
 */
private static LinkedMultiValueMap<Integer, Tag> readTags() throws Exception {
    TagDao tagDao = new TagDao(DS);
    LinkedMultiValueMap<Integer, Tag> tags = new LinkedMultiValueMap();
    final Reader reader = new FileReader("C:\\PRIVE\\SRC\\ml-20m\\tags.csv");
    CSVParser parser = new CSVParser(reader, CSVFormat.EXCEL.withHeader());
    for (CSVRecord record : parser) {

        Integer movieId = Integer.parseInt(record.get("movieId"));
        Integer userId = Integer.parseInt(record.get("userId"));
        if (keepId(movieId) && keepId(userId)) {
            //CSV Header : userId,movieId,tag,timestamp
            Tag newTag = new Tag();
            newTag.setUserId(userId);
            newTag.setMovieId(movieId);
            newTag.setTag(record.get("tag"));
            newTag.setDate(new Date(Long.parseLong(record.get("timestamp")) * 1000));
            //Adding to map for json loading
            tags.add(newTag.getMovieId(), newTag);
            //Saving in tag table
            //tagDao.save(newTag);
        }
    }
    return tags;
}

From source file:org.pad.pgsql.loadmovies.LoadFiles.java

/**
 * Load ratings and enrich movies with tags informations before updating the related movie.
 *
 * @throws Exception/*from w ww  . j a v  a2s .  com*/
 */
private static void loadRatings() throws Exception {
    //MultivalueMap with key movieId and values all tags
    LinkedMultiValueMap<Integer, Tag> tags = readTags();

    //MultivalueMap with key movieId and values all ratings
    LinkedMultiValueMap<Integer, Rating> ratings = new LinkedMultiValueMap();

    //"userId,movieId,rating,timestamp
    final Reader reader = new FileReader("C:\\PRIVE\\SRC\\ml-20m\\ratings.csv");
    CSVParser parser = new CSVParser(reader, CSVFormat.EXCEL.withHeader());
    RatingDao ratingDao = new RatingDao(DS);
    for (CSVRecord record : parser) {
        Integer movieId = Integer.parseInt(record.get("movieId"));
        Integer userId = Integer.parseInt(record.get("userId"));
        if (keepId(movieId) && keepId(userId)) {
            //Building a rating object.
            Rating rating = new Rating();
            rating.setUserId(userId);
            rating.setMovieId(movieId);
            rating.setRating(Float.parseFloat(record.get("rating")));
            rating.setDate(new Date(Long.parseLong(record.get("timestamp")) * 1000));
            //Add for json saving
            ratings.add(rating.getMovieId(), rating);
            //traditional saving
            //ratingDao.save(rating);
        }
    }
    MovieDaoJSON movieDaoJSON = new MovieDaoJSON(DS);
    ratings.entrySet().stream().forEach((integerListEntry -> {
        //Building other information objects
        OtherInformations otherInformations = new OtherInformations();
        List ratingList = integerListEntry.getValue();
        otherInformations.setRatings(ratingList.subList(0, Math.min(10, ratingList.size())));
        otherInformations.computeMean();
        //Retrieve tags from the movieId
        otherInformations.setTags(tags.get(integerListEntry.getKey()));
        try {
            movieDaoJSON.addOtherInformationsToMovie(integerListEntry.getKey(), otherInformations);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
    }));

}

From source file:org.cloudfoundry.identity.statsd.integration.UaaMetricsEmitterIT.java

@Test
public void testStatsDClientEmitsMetricsCollectedFromUAA() throws InterruptedException, IOException {
    RestTemplate template = new RestTemplate();

    HttpHeaders headers = new HttpHeaders();
    headers.set(headers.ACCEPT, MediaType.TEXT_HTML_VALUE);
    ResponseEntity<String> loginResponse = template.exchange(UAA_BASE_URL + "/login", HttpMethod.GET,
            new HttpEntity<>(null, headers), String.class);

    if (loginResponse.getHeaders().containsKey("Set-Cookie")) {
        for (String cookie : loginResponse.getHeaders().get("Set-Cookie")) {
            headers.add("Cookie", cookie);
        }//w  w w .  ja v a  2 s . com
    }
    String csrf = IntegrationTestUtils.extractCookieCsrf(loginResponse.getBody());

    LinkedMultiValueMap<String, String> body = new LinkedMultiValueMap<>();
    body.add("username", TEST_USERNAME);
    body.add("password", TEST_PASSWORD);
    body.add(CookieBasedCsrfTokenRepository.DEFAULT_CSRF_COOKIE_NAME, csrf);
    loginResponse = template.exchange(UAA_BASE_URL + "/login.do", HttpMethod.POST,
            new HttpEntity<>(body, headers), String.class);
    assertEquals(HttpStatus.FOUND, loginResponse.getStatusCode());
    assertNotNull(getMessage("uaa.audit_service.user_authentication_count:1", 5000));
}

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

@Test
public void testRedirectAfterFailedLogin() throws Exception {
    RestTemplate template = new RestTemplate();
    LinkedMultiValueMap<String, String> body = new LinkedMultiValueMap<>();
    body.add("username", testAccounts.getUserName());
    body.add("password", "invalidpassword");
    ResponseEntity<Void> loginResponse = template.exchange(baseUrl + "/login.do", HttpMethod.POST,
            new HttpEntity<>(body, null), Void.class);
    assertEquals(HttpStatus.FOUND, loginResponse.getStatusCode());
}

From source file:com.embedler.moon.graphql.boot.sample.test.GenericTodoSchemaParserTest.java

@Test
public void restUploadFileUrlEncodedTest() throws IOException {

    LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
    map.add("query",
            "mutation AddTodoMutationMutation{addTodoMutation(input: {clientMutationId:\"m-123\", addTodoInput:{text: \"text\"}}){ clientMutationId, todoEdge {cursor, node {text, complete}} }}");
    map.add("variables", "{}");
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    HttpEntity<LinkedMultiValueMap<String, Object>> requestEntity = new HttpEntity<>(map, headers);

    ResponseEntity<GraphQLServerResult> responseEntity = restTemplate.exchange(
            "http://localhost:" + port + "/graphql", HttpMethod.POST, requestEntity, GraphQLServerResult.class);

    GraphQLServerResult result = responseEntity.getBody();
    Assert.assertTrue(CollectionUtils.isEmpty(result.getErrors()));
    Assert.assertFalse(CollectionUtils.isEmpty(result.getData()));
    LOGGER.info(objectMapper.writeValueAsString(result.getData()));
}

From source file:com.embedler.moon.graphql.boot.sample.test.GenericTodoSchemaParserTest.java

@Test
public void restUploadFileTest() throws IOException {

    LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
    map.add("file", new ClassPathResource("application.yml"));
    String qlQuery = "mutation UploadFileMutation{uploadFile(input: {clientMutationId:\"m-123\"}){ filename }}";
    map.add("query", qlQuery);
    map.add("variables", "{}");

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.MULTIPART_FORM_DATA);
    HttpEntity<LinkedMultiValueMap<String, Object>> requestEntity = new HttpEntity<>(map, headers);

    ResponseEntity<GraphQLServerResult> responseEntity = restTemplate.exchange(
            "http://localhost:" + port + "/graphql", HttpMethod.POST, requestEntity, GraphQLServerResult.class);

    GraphQLServerResult result = responseEntity.getBody();
    Assert.assertTrue(CollectionUtils.isEmpty(result.getErrors()));
    Assert.assertFalse(CollectionUtils.isEmpty(result.getData()));
    LOGGER.info(objectMapper.writeValueAsString(result.getData()));
}

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(//  w ww  .ja v  a2 s.com
            "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());
}