use of org.olat.course.db.CourseDBEntry in project OpenOLAT by OpenOLAT.
the class CourseDBTest method createEntry_post.
@Test
public void createEntry_post() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login(auth.getName(), JunitTestHelper.PWD));
String category = createRndCategory();
String key = "postit";
String value = "create the value by POST";
UriBuilder uri = getUriBuilder(course.getResourceableId(), category).path("values").path(key);
HttpPost put = conn.createPost(uri.build(), MediaType.APPLICATION_JSON);
conn.addEntity(put, new BasicNameValuePair("val", value));
HttpResponse response = conn.execute(put);
assertEquals(200, response.getStatusLine().getStatusCode());
EntityUtils.consume(response.getEntity());
conn.shutdown();
CourseDBEntry entry = courseDbManager.getValue(course, auth, category, key);
Assert.assertNotNull(entry);
Assert.assertEquals(key, entry.getName());
Assert.assertEquals(value, entry.getValue());
Assert.assertEquals(category, entry.getCategory());
}
use of org.olat.course.db.CourseDBEntry in project OpenOLAT by OpenOLAT.
the class CourseDBTest method createEntry_get.
@Test
public void createEntry_get() throws IOException, URISyntaxException {
String category = createRndCategory();
String key = "getit";
String value = "get a value";
CourseDBEntry entry = courseDbManager.setValue(course, auth, category, key, value);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(entry);
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login(auth.getName(), JunitTestHelper.PWD));
UriBuilder uri = getUriBuilder(course.getResourceableId(), category).path("values").path(key);
HttpGet get = conn.createGet(uri.build(), MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(get);
assertEquals(200, response.getStatusLine().getStatusCode());
KeyValuePair savedEntry = conn.parse(response, KeyValuePair.class);
conn.shutdown();
Assert.assertNotNull(savedEntry);
Assert.assertEquals(key, savedEntry.getKey());
Assert.assertEquals(value, savedEntry.getValue());
}
use of org.olat.course.db.CourseDBEntry in project OpenOLAT by OpenOLAT.
the class CourseDBTest method createEntry_putQuery_repoKey.
@Test
public void createEntry_putQuery_repoKey() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login(auth.getName(), JunitTestHelper.PWD));
OLATResourceable courseOres = OresHelper.createOLATResourceableInstance("CourseModule", course.getResourceableId());
RepositoryEntry courseRe = repositoryManager.lookupRepositoryEntry(courseOres, true);
String category = createRndCategory();
String key = "myKeyName";
String value = "an interessant value";
UriBuilder uri = getUriBuilder(courseRe.getKey(), category).path("values").path(key).queryParam("value", value);
HttpPut put = conn.createPut(uri.build(), MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(put);
assertEquals(200, response.getStatusLine().getStatusCode());
EntityUtils.consume(response.getEntity());
conn.shutdown();
CourseDBEntry entry = courseDbManager.getValue(course, auth, category, key);
Assert.assertNotNull(entry);
Assert.assertEquals(key, entry.getName());
Assert.assertEquals(value, entry.getValue());
Assert.assertEquals(category, entry.getCategory());
}
use of org.olat.course.db.CourseDBEntry in project OpenOLAT by OpenOLAT.
the class CourseDbWebService method getValues.
/**
* Retrieve all values of the authenticated user
* @response.representation.200.qname {http://www.example.com}keyValuePair
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc All the values in the course
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_KEYVALUEVOes}
* @param courseId The course resourceable's id
* @param category The name of the database
* @param request The HTTP request
* @return
*/
@GET
@Path("values")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getValues(@PathParam("courseId") Long courseId, @PathParam("category") String category, @Context HttpServletRequest request) {
ICourse course = loadCourse(courseId);
UserRequest ureq = RestSecurityHelper.getUserRequest(request);
List<CourseDBEntry> entries = CoreSpringFactory.getImpl(CourseDBManager.class).getValues(course, ureq.getIdentity(), category, null);
KeyValuePair[] pairs = new KeyValuePair[entries.size()];
int count = 0;
for (CourseDBEntry entry : entries) {
Object value = entry.getValue();
pairs[count++] = new KeyValuePair(entry.getName(), value == null ? "" : value.toString());
}
return Response.ok(pairs).build();
}
use of org.olat.course.db.CourseDBEntry in project openolat by klemens.
the class CourseDBTest method createEntry_putQuery_repoKey.
@Test
public void createEntry_putQuery_repoKey() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login(auth.getName(), JunitTestHelper.PWD));
OLATResourceable courseOres = OresHelper.createOLATResourceableInstance("CourseModule", course.getResourceableId());
RepositoryEntry courseRe = repositoryManager.lookupRepositoryEntry(courseOres, true);
String category = createRndCategory();
String key = "myKeyName";
String value = "an interessant value";
UriBuilder uri = getUriBuilder(courseRe.getKey(), category).path("values").path(key).queryParam("value", value);
HttpPut put = conn.createPut(uri.build(), MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(put);
assertEquals(200, response.getStatusLine().getStatusCode());
EntityUtils.consume(response.getEntity());
conn.shutdown();
CourseDBEntry entry = courseDbManager.getValue(course, auth, category, key);
Assert.assertNotNull(entry);
Assert.assertEquals(key, entry.getName());
Assert.assertEquals(value, entry.getValue());
Assert.assertEquals(category, entry.getCategory());
}
Aggregations