use of org.olat.course.certificate.model.CertificateInfos in project OpenOLAT by OpenOLAT.
the class CertificatesManagerTest method createCertificate.
@Test
public void createCertificate() throws URISyntaxException {
Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("cer-1");
RepositoryEntry entry = JunitTestHelper.deployBasicCourse(identity);
dbInstance.commitAndCloseSession();
CertificateInfos certificateInfos = new CertificateInfos(identity, null, null);
Certificate certificate = certificatesManager.generateCertificate(certificateInfos, entry, null, false);
Assert.assertNotNull(certificate);
Assert.assertNotNull(certificate.getKey());
Assert.assertNotNull(certificate.getUuid());
Assert.assertEquals(entry.getOlatResource().getKey(), certificate.getArchivedResourceKey());
// check if the pdf exists / flush cache, reload the entry with the updated path
dbInstance.commitAndCloseSession();
waitCertificate(certificate.getKey());
Certificate reloadCertificate = certificatesManager.getCertificateById(certificate.getKey());
VFSLeaf certificateFile = certificatesManager.getCertificateLeaf(reloadCertificate);
Assert.assertNotNull(certificateFile);
Assert.assertTrue(certificateFile.exists());
}
use of org.olat.course.certificate.model.CertificateInfos in project OpenOLAT by OpenOLAT.
the class CertificatesManagerTest method certificateNotifications_courseCoachByGroups.
@Test
public void certificateNotifications_courseCoachByGroups() throws URISyntaxException {
Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("cer-5");
Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("cer-6");
Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("cer-7");
Identity participant2 = JunitTestHelper.createAndPersistIdentityAsRndUser("cer-8");
RepositoryEntry entry = JunitTestHelper.deployBasicCourse(owner);
BusinessGroup group = businessGroupService.createBusinessGroup(null, "certified-group", "Group with certification", null, null, false, false, entry);
businessGroupRelationDao.addRole(coach, group, GroupRoles.coach.name());
businessGroupRelationDao.addRole(participant1, group, GroupRoles.participant.name());
businessGroupRelationDao.addRole(participant2, group, GroupRoles.participant.name());
dbInstance.commitAndCloseSession();
// make a certificate
CertificateInfos certificateInfos1 = new CertificateInfos(participant1, null, null);
Certificate certificate1 = certificatesManager.generateCertificate(certificateInfos1, entry, null, false);
Assert.assertNotNull(certificate1);
CertificateInfos certificateInfos2 = new CertificateInfos(participant2, null, null);
Certificate certificate2 = certificatesManager.generateCertificate(certificateInfos2, entry, null, false);
Assert.assertNotNull(certificate2);
dbInstance.commitAndCloseSession();
waitCertificate(certificate1.getKey());
waitCertificate(certificate2.getKey());
dbInstance.commitAndCloseSession();
sleep(2000);
Calendar lastestNews = Calendar.getInstance();
lastestNews.add(Calendar.DATE, -1);
// check the notifications of the coach
List<Certificate> coachNotifications = certificatesManager.getCertificatesForNotifications(coach, entry, lastestNews.getTime());
Assert.assertNotNull(coachNotifications);
Assert.assertEquals(2, coachNotifications.size());
// check the notifications of the participant
List<Certificate> participantNotifications = certificatesManager.getCertificatesForNotifications(participant1, entry, lastestNews.getTime());
Assert.assertNotNull(participantNotifications);
Assert.assertEquals(1, participantNotifications.size());
Assert.assertTrue(participantNotifications.contains(certificate1));
}
use of org.olat.course.certificate.model.CertificateInfos in project OpenOLAT by OpenOLAT.
the class CertificationTest method getCertificate_head.
@Test
public void getCertificate_head() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login("administrator", "openolat"));
Identity assessedIdentity = JunitTestHelper.createAndPersistIdentityAsRndUser("cert-11");
Identity unassessedIdentity = JunitTestHelper.createAndPersistIdentityAsRndUser("cert-12");
Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("cert-2");
RepositoryEntry entry = JunitTestHelper.deployBasicCourse(author);
CertificateInfos certificateInfos = new CertificateInfos(assessedIdentity, 2.0f, true);
Certificate certificate = certificatesManager.generateCertificate(certificateInfos, entry, null, false);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(certificate);
sleep(1000);
URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("courses").path(entry.getOlatResource().getKey().toString()).path("certificates").path(assessedIdentity.getKey().toString()).build();
HttpHead method = conn.createHead(uri, "application/pdf", true);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
EntityUtils.consume(response.getEntity());
// check with a stupid number
URI nonExistentUri = UriBuilder.fromUri(getContextURI()).path("repo").path("courses").path(entry.getOlatResource().getKey().toString()).path("certificates").path(unassessedIdentity.getKey().toString()).build();
HttpHead nonExistentMethod = conn.createHead(nonExistentUri, "application/pdf", true);
HttpResponse nonExistentResponse = conn.execute(nonExistentMethod);
Assert.assertEquals(404, nonExistentResponse.getStatusLine().getStatusCode());
EntityUtils.consume(nonExistentResponse.getEntity());
conn.shutdown();
}
use of org.olat.course.certificate.model.CertificateInfos in project OpenOLAT by OpenOLAT.
the class CertificationTest method getCertificate_file.
@Test
public void getCertificate_file() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login("administrator", "openolat"));
Identity assessedIdentity = JunitTestHelper.createAndPersistIdentityAsRndUser("cert-1");
Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("cert-2");
RepositoryEntry entry = JunitTestHelper.deployBasicCourse(author);
CertificateInfos certificateInfos = new CertificateInfos(assessedIdentity, 2.0f, true);
Certificate certificate = certificatesManager.generateCertificate(certificateInfos, entry, null, false);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(certificate);
// wait until the certificate is created
waitForCondition(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
Certificate reloadedCertificate = certificatesManager.getCertificateById(certificate.getKey());
return CertificateStatus.ok.equals(reloadedCertificate.getStatus());
}
}, 30000);
URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("courses").path(entry.getOlatResource().getKey().toString()).path("certificates").path(assessedIdentity.getKey().toString()).build();
HttpGet method = conn.createGet(uri, "application/pdf", true);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
EntityUtils.consume(response.getEntity());
conn.shutdown();
}
use of org.olat.course.certificate.model.CertificateInfos in project OpenOLAT by OpenOLAT.
the class CertificatesSelectionDataModel method getValueAt.
@Override
public Object getValueAt(int row, int col) {
CertificateInfos infos = getObject(row);
Identity identity = infos.getAssessedIdentity();
if (col == USERNAME_COL) {
return identity.getName();
} else if (col == PASSED_COL) {
return infos.getPassed();
} else if (col == SCORE_COL) {
Float score = infos.getScore();
return AssessmentHelper.getRoundedScore(score);
} else if (col >= 0 && col < userPropertyHandlers.size()) {
UserPropertyHandler handler = userPropertyHandlers.get(col);
return handler.getUserProperty(identity.getUser(), null);
}
return null;
}
Aggregations