Search in sources :

Example 16 with CourseDBEntry

use of org.olat.course.db.CourseDBEntry in project openolat by klemens.

the class CourseDBTest method createEntry_putQuery.

@Test
public void createEntry_putQuery() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login(auth.getName(), JunitTestHelper.PWD));
    String category = createRndCategory();
    String key = "myKeyName";
    String value = "an interessant value";
    UriBuilder uri = getUriBuilder(course.getResourceableId(), 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());
}
Also used : HttpResponse(org.apache.http.HttpResponse) UriBuilder(javax.ws.rs.core.UriBuilder) HttpPut(org.apache.http.client.methods.HttpPut) CourseDBEntry(org.olat.course.db.CourseDBEntry) Test(org.junit.Test)

Example 17 with CourseDBEntry

use of org.olat.course.db.CourseDBEntry in project openolat by klemens.

the class CourseDbWebService method internPutValue.

private Response internPutValue(Long courseId, String category, String name, Object value, HttpServletRequest request) {
    ICourse course = loadCourse(courseId);
    UserRequest ureq = RestSecurityHelper.getUserRequest(request);
    CourseDBEntry entry = CoreSpringFactory.getImpl(CourseDBManager.class).setValue(course, ureq.getIdentity(), category, name, value);
    if (entry == null) {
        return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    }
    return Response.ok().build();
}
Also used : CourseDBManager(org.olat.course.db.CourseDBManager) ICourse(org.olat.course.ICourse) UserRequest(org.olat.core.gui.UserRequest) CourseDBEntry(org.olat.course.db.CourseDBEntry)

Example 18 with CourseDBEntry

use of org.olat.course.db.CourseDBEntry in project openolat by klemens.

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();
}
Also used : CourseDBManager(org.olat.course.db.CourseDBManager) KeyValuePair(org.olat.restapi.support.vo.KeyValuePair) ICourse(org.olat.course.ICourse) UserRequest(org.olat.core.gui.UserRequest) CourseDBEntry(org.olat.course.db.CourseDBEntry) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

CourseDBEntry (org.olat.course.db.CourseDBEntry)18 CourseDBManager (org.olat.course.db.CourseDBManager)10 UriBuilder (javax.ws.rs.core.UriBuilder)8 HttpResponse (org.apache.http.HttpResponse)8 Test (org.junit.Test)8 UserRequest (org.olat.core.gui.UserRequest)8 ICourse (org.olat.course.ICourse)8 GET (javax.ws.rs.GET)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 KeyValuePair (org.olat.restapi.support.vo.KeyValuePair)6 HttpPut (org.apache.http.client.methods.HttpPut)4 HttpGet (org.apache.http.client.methods.HttpGet)2 HttpPost (org.apache.http.client.methods.HttpPost)2 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)2 Identity (org.olat.core.id.Identity)2 OLATResourceable (org.olat.core.id.OLATResourceable)2 ArgumentParseException (org.olat.course.condition.interpreter.ArgumentParseException)2 CourseEditorEnv (org.olat.course.editor.CourseEditorEnv)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2