Search in sources :

Example 6 with RestConnection

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

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 7 with RestConnection

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

the class RepositoryRestClient method deployCourse.

public CourseVO deployCourse(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/courses").build();
    HttpPost method = conn.createPost(request, MediaType.APPLICATION_JSON);
    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);
    CourseVO vo = conn.parse(response, CourseVO.class);
    assertNotNull(vo);
    assertNotNull(vo.getRepoEntryKey());
    assertNotNull(vo.getKey());
    return vo;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) CourseVO(org.olat.restapi.support.vo.CourseVO) RestConnection(org.olat.restapi.RestConnection) HttpEntity(org.apache.http.HttpEntity) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI)

Example 8 with RestConnection

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

the class RepositoryRestClient method deployCourse.

public CourseVO deployCourse(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/courses").build();
    HttpPost method = conn.createPost(request, MediaType.APPLICATION_JSON);
    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);
    CourseVO vo = conn.parse(response, CourseVO.class);
    assertNotNull(vo);
    assertNotNull(vo.getRepoEntryKey());
    assertNotNull(vo.getKey());
    return vo;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) CourseVO(org.olat.restapi.support.vo.CourseVO) RestConnection(org.olat.restapi.RestConnection) HttpEntity(org.apache.http.HttpEntity) HttpResponse(org.apache.http.HttpResponse) 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