use of org.olat.restapi.support.vo.KeyValuePair in project OpenOLAT by OpenOLAT.
the class CourseDBTest method getUsedCategories.
@Test
public void getUsedCategories() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login(auth.getName(), JunitTestHelper.PWD));
String category = createRndCategory();
KeyValuePair keyValuePair = new KeyValuePair();
keyValuePair.setKey("catKey");
keyValuePair.setValue("category value");
UriBuilder uri = getUriBuilder(course.getResourceableId(), category).path("values");
HttpPut put = conn.createPut(uri.build(), MediaType.APPLICATION_JSON, true);
conn.addJsonEntity(put, keyValuePair);
HttpResponse response = conn.execute(put);
assertEquals(200, response.getStatusLine().getStatusCode());
EntityUtils.consume(response.getEntity());
conn.shutdown();
List<String> categories = courseDbManager.getUsedCategories(course);
Assert.assertNotNull(categories);
Assert.assertTrue(categories.contains(category));
}
use of org.olat.restapi.support.vo.KeyValuePair in project OpenOLAT by OpenOLAT.
the class CourseDbWebService method getValue.
/**
* Retrieve a value of an authenticated user.
* @response.representation.200.qname {http://www.example.com}keyValuePair
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The value in the course
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_KEYVALUEVO}
* @response.representation.404.doc The entry cannot be found
* @param courseId The course resourceable's id
* @param category The name of the database
* @parma name The name of the key value pair
* @param request The HTTP request
* @return
*/
@GET
@Path("values/{name}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getValue(@PathParam("courseId") Long courseId, @PathParam("category") String category, @PathParam("name") String name, @Context HttpServletRequest request) {
ICourse course = loadCourse(courseId);
UserRequest ureq = RestSecurityHelper.getUserRequest(request);
CourseDBEntry entry = CoreSpringFactory.getImpl(CourseDBManager.class).getValue(course, ureq.getIdentity(), category, name);
if (entry == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
Object value = entry.getValue();
KeyValuePair pair = new KeyValuePair(name, value == null ? "" : value.toString());
return Response.ok(pair).build();
}
use of org.olat.restapi.support.vo.KeyValuePair in project openolat by klemens.
the class CourseDBTest method createEntry_putJsonEntity.
@Test
public void createEntry_putJsonEntity() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login(auth.getName(), JunitTestHelper.PWD));
String category = createRndCategory();
KeyValuePair keyValuePair = new KeyValuePair();
keyValuePair.setKey("firstKey");
keyValuePair.setValue("first value");
UriBuilder uri = getUriBuilder(course.getResourceableId(), category).path("values");
HttpPut put = conn.createPut(uri.build(), MediaType.APPLICATION_JSON, true);
conn.addJsonEntity(put, keyValuePair);
HttpResponse response = conn.execute(put);
assertEquals(200, response.getStatusLine().getStatusCode());
EntityUtils.consume(response.getEntity());
conn.shutdown();
}
use of org.olat.restapi.support.vo.KeyValuePair in project openolat by klemens.
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.restapi.support.vo.KeyValuePair in project openolat by klemens.
the class CourseDbWebService method getValue.
/**
* Retrieve a value of an authenticated user.
* @response.representation.200.qname {http://www.example.com}keyValuePair
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The value in the course
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_KEYVALUEVO}
* @response.representation.404.doc The entry cannot be found
* @param courseId The course resourceable's id
* @param category The name of the database
* @parma name The name of the key value pair
* @param request The HTTP request
* @return
*/
@GET
@Path("values/{name}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getValue(@PathParam("courseId") Long courseId, @PathParam("category") String category, @PathParam("name") String name, @Context HttpServletRequest request) {
ICourse course = loadCourse(courseId);
UserRequest ureq = RestSecurityHelper.getUserRequest(request);
CourseDBEntry entry = CoreSpringFactory.getImpl(CourseDBManager.class).getValue(course, ureq.getIdentity(), category, name);
if (entry == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
Object value = entry.getValue();
KeyValuePair pair = new KeyValuePair(name, value == null ? "" : value.toString());
return Response.ok(pair).build();
}
Aggregations