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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations