Search in sources :

Example 1 with RestConnection

use of org.olat.restapi.RestConnection in project OpenOLAT by OpenOLAT.

the class RepositoryRestClient method deployResource.

public RepositoryEntryVO deployResource(File archive, String resourcename, String displayname) throws URISyntaxException, IOException {
    RestConnection conn = new RestConnection(deploymentUrl);
    assertTrue(conn.login(username, password));
    URI request = UriBuilder.fromUri(deploymentUrl.toURI()).path("restapi").path("repo").path("entries").build();
    HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
    String softKey = UUID.randomUUID().toString();
    HttpEntity entity = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE).addBinaryBody("file", archive, ContentType.APPLICATION_OCTET_STREAM, archive.getName()).addTextBody("filename", archive.getName()).addTextBody("resourcename", resourcename).addTextBody("displayname", displayname).addTextBody("access", "3").addTextBody("softkey", softKey).build();
    method.setEntity(entity);
    HttpResponse response = conn.execute(method);
    assertTrue(response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 201);
    RepositoryEntryVO vo = conn.parse(response, RepositoryEntryVO.class);
    assertNotNull(vo);
    assertNotNull(vo.getDisplayname());
    assertNotNull(vo.getKey());
    return vo;
}
Also used : RestConnection(org.olat.restapi.RestConnection) RepositoryEntryVO(org.olat.restapi.support.vo.RepositoryEntryVO) HttpEntity(org.apache.http.HttpEntity) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut)

Example 2 with RestConnection

use of org.olat.restapi.RestConnection in project openolat by klemens.

the class RepositoryRestClient method deployResource.

public RepositoryEntryVO deployResource(File archive, String resourcename, String displayname) throws URISyntaxException, IOException {
    RestConnection conn = new RestConnection(deploymentUrl);
    assertTrue(conn.login(username, password));
    URI request = UriBuilder.fromUri(deploymentUrl.toURI()).path("restapi").path("repo").path("entries").build();
    HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
    String softKey = UUID.randomUUID().toString();
    HttpEntity entity = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE).addBinaryBody("file", archive, ContentType.APPLICATION_OCTET_STREAM, archive.getName()).addTextBody("filename", archive.getName()).addTextBody("resourcename", resourcename).addTextBody("displayname", displayname).addTextBody("access", "3").addTextBody("softkey", softKey).build();
    method.setEntity(entity);
    HttpResponse response = conn.execute(method);
    assertTrue(response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 201);
    RepositoryEntryVO vo = conn.parse(response, RepositoryEntryVO.class);
    assertNotNull(vo);
    assertNotNull(vo.getDisplayname());
    assertNotNull(vo.getKey());
    return vo;
}
Also used : RestConnection(org.olat.restapi.RestConnection) RepositoryEntryVO(org.olat.restapi.support.vo.RepositoryEntryVO) HttpEntity(org.apache.http.HttpEntity) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut)

Example 3 with RestConnection

use of org.olat.restapi.RestConnection in project openolat by klemens.

the class UserRestClient method createAuthor.

public UserVO createAuthor(String name) throws IOException, URISyntaxException {
    RestConnection restConnection = new RestConnection(deploymentUrl);
    assertTrue(restConnection.login(username, password));
    UserVO user = createUser(restConnection, name, "Auth");
    RolesVO roles = new RolesVO();
    roles.setAuthor(true);
    // update roles of author
    URI request = getUsersURIBuilder().path(user.getKey().toString()).path("roles").build();
    HttpPost method = restConnection.createPost(request, MediaType.APPLICATION_JSON);
    restConnection.addJsonEntity(method, roles);
    HttpResponse response = restConnection.execute(method);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    EntityUtils.consume(response.getEntity());
    restConnection.shutdown();
    return user;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) RestConnection(org.olat.restapi.RestConnection) UserVO(org.olat.user.restapi.UserVO) HttpResponse(org.apache.http.HttpResponse) RolesVO(org.olat.user.restapi.RolesVO) URI(java.net.URI)

Example 4 with RestConnection

use of org.olat.restapi.RestConnection in project openolat by klemens.

the class UserRestClient method createRandomUser.

public UserVO createRandomUser(String name) throws IOException, URISyntaxException {
    RestConnection restConnection = new RestConnection(deploymentUrl);
    assertTrue(restConnection.login(username, password));
    UserVO user = createUser(restConnection, name, "Rnd");
    restConnection.shutdown();
    return user;
}
Also used : RestConnection(org.olat.restapi.RestConnection) UserVO(org.olat.user.restapi.UserVO)

Example 5 with RestConnection

use of org.olat.restapi.RestConnection in project OpenOLAT by OpenOLAT.

the class UserRestClient method createAuthor.

public UserVO createAuthor(String name) throws IOException, URISyntaxException {
    RestConnection restConnection = new RestConnection(deploymentUrl);
    assertTrue(restConnection.login(username, password));
    UserVO user = createUser(restConnection, name, "Auth");
    RolesVO roles = new RolesVO();
    roles.setAuthor(true);
    // update roles of author
    URI request = getUsersURIBuilder().path(user.getKey().toString()).path("roles").build();
    HttpPost method = restConnection.createPost(request, MediaType.APPLICATION_JSON);
    restConnection.addJsonEntity(method, roles);
    HttpResponse response = restConnection.execute(method);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    EntityUtils.consume(response.getEntity());
    restConnection.shutdown();
    return user;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) RestConnection(org.olat.restapi.RestConnection) UserVO(org.olat.user.restapi.UserVO) HttpResponse(org.apache.http.HttpResponse) RolesVO(org.olat.user.restapi.RolesVO) URI(java.net.URI)

Aggregations

RestConnection (org.olat.restapi.RestConnection)8 URI (java.net.URI)6 HttpResponse (org.apache.http.HttpResponse)6 HttpEntity (org.apache.http.HttpEntity)4 HttpPost (org.apache.http.client.methods.HttpPost)4 UserVO (org.olat.user.restapi.UserVO)4 HttpPut (org.apache.http.client.methods.HttpPut)2 CourseVO (org.olat.restapi.support.vo.CourseVO)2 RepositoryEntryVO (org.olat.restapi.support.vo.RepositoryEntryVO)2 RolesVO (org.olat.user.restapi.RolesVO)2