Search in sources :

Example 6 with EfficiencyStatementVO

use of org.olat.course.assessment.model.EfficiencyStatementVO in project OpenOLAT by OpenOLAT.

the class EfficiencyStatementTest method putEfficiencyStatement_standalone_alt.

/**
 * Don't give the identity key in URL but in the JSON object
 *
 * @throws IOException
 * @throws URISyntaxException
 */
@Test
public void putEfficiencyStatement_standalone_alt() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    Identity assessedIdentity = JunitTestHelper.createAndPersistIdentityAsRndUser("cert-3");
    dbInstance.commitAndCloseSession();
    Long resourceKey = 3495783497l;
    URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("courses").path(resourceKey.toString()).path("statements").build();
    EfficiencyStatementVO statement = new EfficiencyStatementVO();
    statement.setIdentityKey(assessedIdentity.getKey());
    statement.setCreationDate(new Date());
    statement.setPassed(Boolean.TRUE);
    statement.setScore(8.5f);
    statement.setCourseTitle("Standalone");
    HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
    conn.addJsonEntity(method, statement);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    EntityUtils.consume(response.getEntity());
    // check the efficiency statement
    UserEfficiencyStatement efficiencyStatement = efficiencyStatementManager.getUserEfficiencyStatementFullByResourceKey(resourceKey, assessedIdentity);
    Assert.assertNotNull(efficiencyStatement);
    Assert.assertEquals(8.5f, efficiencyStatement.getScore(), 0.001);
    Assert.assertEquals(Boolean.TRUE, efficiencyStatement.getPassed());
    Assert.assertEquals("Standalone", efficiencyStatement.getShortTitle());
    Assert.assertEquals(assessedIdentity, efficiencyStatement.getIdentity());
}
Also used : EfficiencyStatementVO(org.olat.course.assessment.model.EfficiencyStatementVO) UserEfficiencyStatement(org.olat.course.assessment.UserEfficiencyStatement) HttpResponse(org.apache.http.HttpResponse) Identity(org.olat.core.id.Identity) URI(java.net.URI) Date(java.util.Date) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 7 with EfficiencyStatementVO

use of org.olat.course.assessment.model.EfficiencyStatementVO in project OpenOLAT by OpenOLAT.

the class EfficiencyStatementTest method getEfficiencyStatement.

@Test
public void getEfficiencyStatement() throws IOException, URISyntaxException {
    // create a standalone efficiency statement
    Identity admin = BaseSecurityManager.getInstance().findIdentityByName("administrator");
    Identity assessedIdentity = JunitTestHelper.createAndPersistIdentityAsRndUser("eff-1");
    ICourse course = CoursesWebService.createEmptyCourse(admin, "courses1", "courses1 long name", null, null, null, RepositoryEntry.ACC_OWNERS, false, null, null, null, null, null, null);
    dbInstance.commitAndCloseSession();
    OLATResource resource = course.getCourseEnvironment().getCourseGroupManager().getCourseResource();
    UserEfficiencyStatement statement = efficiencyStatementManager.createUserEfficiencyStatement(new Date(), 5.0f, true, assessedIdentity, resource);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(statement);
    // get the statement
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("courses").path(resource.getKey().toString()).path("statements").path(assessedIdentity.getKey().toString()).build();
    HttpGet getStatement = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(getStatement);
    assertEquals(200, response.getStatusLine().getStatusCode());
    EfficiencyStatementVO statementVO = conn.parse(response, EfficiencyStatementVO.class);
    Assert.assertNotNull(statementVO);
    Assert.assertEquals(5.0f, statementVO.getScore(), 0.0001);
    Assert.assertEquals(true, statementVO.getPassed());
    Assert.assertEquals(assessedIdentity.getKey(), statementVO.getIdentityKey());
}
Also used : EfficiencyStatementVO(org.olat.course.assessment.model.EfficiencyStatementVO) UserEfficiencyStatement(org.olat.course.assessment.UserEfficiencyStatement) HttpGet(org.apache.http.client.methods.HttpGet) OLATResource(org.olat.resource.OLATResource) HttpResponse(org.apache.http.HttpResponse) ICourse(org.olat.course.ICourse) Identity(org.olat.core.id.Identity) URI(java.net.URI) Date(java.util.Date) Test(org.junit.Test)

Example 8 with EfficiencyStatementVO

use of org.olat.course.assessment.model.EfficiencyStatementVO in project OpenOLAT by OpenOLAT.

the class EfficiencyStatementTest method putEfficiencyStatement_standalone.

@Test
public void putEfficiencyStatement_standalone() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    Identity assessedIdentity = JunitTestHelper.createAndPersistIdentityAsRndUser("cert-3");
    dbInstance.commitAndCloseSession();
    Long resourceKey = 3495783497l;
    URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("courses").path(resourceKey.toString()).path("statements").path(assessedIdentity.getKey().toString()).build();
    EfficiencyStatementVO statement = new EfficiencyStatementVO();
    statement.setCreationDate(new Date());
    statement.setPassed(Boolean.TRUE);
    statement.setScore(8.5f);
    statement.setCourseTitle("Standalone");
    HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
    conn.addJsonEntity(method, statement);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    EntityUtils.consume(response.getEntity());
    // check the efficiency statement
    UserEfficiencyStatement efficiencyStatement = efficiencyStatementManager.getUserEfficiencyStatementFullByResourceKey(resourceKey, assessedIdentity);
    Assert.assertNotNull(efficiencyStatement);
    Assert.assertEquals(8.5f, efficiencyStatement.getScore(), 0.001);
    Assert.assertEquals(Boolean.TRUE, efficiencyStatement.getPassed());
    Assert.assertEquals("Standalone", efficiencyStatement.getShortTitle());
    Assert.assertEquals(assessedIdentity, efficiencyStatement.getIdentity());
}
Also used : EfficiencyStatementVO(org.olat.course.assessment.model.EfficiencyStatementVO) UserEfficiencyStatement(org.olat.course.assessment.UserEfficiencyStatement) HttpResponse(org.apache.http.HttpResponse) Identity(org.olat.core.id.Identity) URI(java.net.URI) Date(java.util.Date) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 9 with EfficiencyStatementVO

use of org.olat.course.assessment.model.EfficiencyStatementVO in project openolat by klemens.

the class EfficiencyStatementTest method putEfficiencyStatement_standalone_alt.

/**
 * Don't give the identity key in URL but in the JSON object
 *
 * @throws IOException
 * @throws URISyntaxException
 */
@Test
public void putEfficiencyStatement_standalone_alt() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    Identity assessedIdentity = JunitTestHelper.createAndPersistIdentityAsRndUser("cert-3");
    dbInstance.commitAndCloseSession();
    Long resourceKey = 3495783497l;
    URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("courses").path(resourceKey.toString()).path("statements").build();
    EfficiencyStatementVO statement = new EfficiencyStatementVO();
    statement.setIdentityKey(assessedIdentity.getKey());
    statement.setCreationDate(new Date());
    statement.setPassed(Boolean.TRUE);
    statement.setScore(8.5f);
    statement.setCourseTitle("Standalone");
    HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
    conn.addJsonEntity(method, statement);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    EntityUtils.consume(response.getEntity());
    // check the efficiency statement
    UserEfficiencyStatement efficiencyStatement = efficiencyStatementManager.getUserEfficiencyStatementFullByResourceKey(resourceKey, assessedIdentity);
    Assert.assertNotNull(efficiencyStatement);
    Assert.assertEquals(8.5f, efficiencyStatement.getScore(), 0.001);
    Assert.assertEquals(Boolean.TRUE, efficiencyStatement.getPassed());
    Assert.assertEquals("Standalone", efficiencyStatement.getShortTitle());
    Assert.assertEquals(assessedIdentity, efficiencyStatement.getIdentity());
}
Also used : EfficiencyStatementVO(org.olat.course.assessment.model.EfficiencyStatementVO) UserEfficiencyStatement(org.olat.course.assessment.UserEfficiencyStatement) HttpResponse(org.apache.http.HttpResponse) Identity(org.olat.core.id.Identity) URI(java.net.URI) Date(java.util.Date) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 10 with EfficiencyStatementVO

use of org.olat.course.assessment.model.EfficiencyStatementVO in project openolat by klemens.

the class EfficiencyStatementWebService method getEfficiencyStatement.

@GET
@Path("{identityKey}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getEfficiencyStatement(@PathParam("identityKey") Long identityKey, @PathParam("resourceKey") Long resourceKey, @Context HttpServletRequest request) {
    if (!isAdmin(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    BaseSecurity baseSecurity = CoreSpringFactory.getImpl(BaseSecurity.class);
    Identity assessedIdentity = baseSecurity.loadIdentityByKey(identityKey);
    if (assessedIdentity == null) {
        return Response.serverError().status(Response.Status.NOT_FOUND).build();
    }
    UserEfficiencyStatement efficiencyStatement = CoreSpringFactory.getImpl(EfficiencyStatementManager.class).getUserEfficiencyStatementLightByResource(resourceKey, assessedIdentity);
    if (efficiencyStatement == null) {
        return Response.serverError().status(Response.Status.NOT_FOUND).build();
    }
    EfficiencyStatementVO statementVO = new EfficiencyStatementVO(efficiencyStatement);
    return Response.ok(statementVO).build();
}
Also used : EfficiencyStatementVO(org.olat.course.assessment.model.EfficiencyStatementVO) UserEfficiencyStatement(org.olat.course.assessment.UserEfficiencyStatement) EfficiencyStatementManager(org.olat.course.assessment.manager.EfficiencyStatementManager) Identity(org.olat.core.id.Identity) BaseSecurity(org.olat.basesecurity.BaseSecurity) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Identity (org.olat.core.id.Identity)10 UserEfficiencyStatement (org.olat.course.assessment.UserEfficiencyStatement)10 EfficiencyStatementVO (org.olat.course.assessment.model.EfficiencyStatementVO)10 URI (java.net.URI)8 Date (java.util.Date)8 HttpResponse (org.apache.http.HttpResponse)8 Test (org.junit.Test)8 HttpPut (org.apache.http.client.methods.HttpPut)6 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 HttpGet (org.apache.http.client.methods.HttpGet)2 BaseSecurity (org.olat.basesecurity.BaseSecurity)2 ICourse (org.olat.course.ICourse)2 EfficiencyStatementManager (org.olat.course.assessment.manager.EfficiencyStatementManager)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2 OLATResource (org.olat.resource.OLATResource)2