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