use of org.olat.course.certificate.model.CertificateInfos in project openolat by klemens.
the class CertificatesManagerTest method loadCertificate.
@Test
public void loadCertificate() {
Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("cer-1");
RepositoryEntry entry = JunitTestHelper.deployBasicCourse(identity);
dbInstance.commitAndCloseSession();
CertificateInfos certificateInfos = new CertificateInfos(identity, 5.0f, Boolean.TRUE);
Certificate certificate = certificatesManager.generateCertificate(certificateInfos, entry, null, false);
Assert.assertNotNull(certificate);
dbInstance.commitAndCloseSession();
// full
Certificate reloadedCertificate = certificatesManager.getCertificateById(certificate.getKey());
Assert.assertNotNull(reloadedCertificate);
Assert.assertEquals(certificate, reloadedCertificate);
Assert.assertNotNull(reloadedCertificate.getUuid());
Assert.assertEquals(certificate.getUuid(), reloadedCertificate.getUuid());
Assert.assertEquals(entry.getDisplayname(), reloadedCertificate.getCourseTitle());
Assert.assertEquals(identity, reloadedCertificate.getIdentity());
// light
CertificateLight reloadedLight = certificatesManager.getCertificateLightById(certificate.getKey());
Assert.assertNotNull(reloadedLight);
Assert.assertEquals(certificate.getKey(), reloadedLight.getKey());
Assert.assertEquals(entry.getDisplayname(), reloadedLight.getCourseTitle());
Assert.assertEquals(identity.getKey(), reloadedLight.getIdentityKey());
Assert.assertEquals(entry.getOlatResource().getKey(), reloadedLight.getOlatResourceKey());
// uuid
Certificate reloadedUuid = certificatesManager.getCertificateByUuid(certificate.getUuid());
Assert.assertNotNull(reloadedUuid);
Assert.assertEquals(certificate, reloadedUuid);
Assert.assertEquals(entry.getDisplayname(), reloadedUuid.getCourseTitle());
Assert.assertEquals(identity, reloadedUuid.getIdentity());
// boolean
boolean has = certificatesManager.hasCertificate(identity, entry.getOlatResource().getKey());
Assert.assertTrue(has);
}
use of org.olat.course.certificate.model.CertificateInfos in project openolat by klemens.
the class CertificatesManagerImpl method generateCertificates.
@Override
public void generateCertificates(List<CertificateInfos> certificateInfos, RepositoryEntry entry, CertificateTemplate template, boolean sendMail) {
int count = 0;
for (CertificateInfos certificateInfo : certificateInfos) {
generateCertificate(certificateInfo, entry, template, sendMail);
if (++count % 10 == 0) {
dbInstance.commitAndCloseSession();
}
}
markPublisherNews(null, entry.getOlatResource());
}
use of org.olat.course.certificate.model.CertificateInfos in project openolat by klemens.
the class AssessedIdentityCertificatesController method doGenerateCertificate.
private void doGenerateCertificate(UserRequest ureq) {
ICourse course = CourseFactory.loadCourse(resource);
CourseNode rootNode = course.getRunStructure().getRootNode();
Identity assessedIdentity = assessedUserCourseEnv.getIdentityEnvironment().getIdentity();
ScoreEvaluation scoreEval = assessedUserCourseEnv.getScoreAccounting().getScoreEvaluation(rootNode);
RepositoryEntry courseEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
CertificateTemplate template = null;
Long templateKey = course.getCourseConfig().getCertificateTemplate();
if (templateKey != null) {
template = certificatesManager.getTemplateById(templateKey);
}
Float score = scoreEval == null ? null : scoreEval.getScore();
Boolean passed = scoreEval == null ? null : scoreEval.getPassed();
CertificateInfos certificateInfos = new CertificateInfos(assessedIdentity, score, passed);
certificatesManager.generateCertificate(certificateInfos, courseEntry, template, true);
loadList();
showInfo("msg.certificate.pending");
fireEvent(ureq, Event.CHANGED_EVENT);
}
use of org.olat.course.certificate.model.CertificateInfos in project OpenOLAT by OpenOLAT.
the class CertificationTest method deleteCertificate.
@Test
public void deleteCertificate() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login("administrator", "openolat"));
Identity assessedIdentity = JunitTestHelper.createAndPersistIdentityAsRndUser("cert-15");
Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("cert-5");
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 certificate is generated
waitForCondition(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
Certificate reloadedCertificate = certificatesManager.getCertificateById(certificate.getKey());
return CertificateStatus.ok.equals(reloadedCertificate.getStatus());
}
}, 30000);
// check that there is a real certificate with its file
Certificate reloadedCertificate = certificatesManager.getCertificateById(certificate.getKey());
VFSLeaf certificateFile = certificatesManager.getCertificateLeaf(reloadedCertificate);
Assert.assertNotNull(certificateFile);
Assert.assertTrue(certificateFile.exists());
// delete the certificate
URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("courses").path(entry.getOlatResource().getKey().toString()).path("certificates").path(assessedIdentity.getKey().toString()).build();
HttpDelete method = conn.createDelete(uri, MediaType.APPLICATION_JSON);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
EntityUtils.consume(response.getEntity());
conn.shutdown();
// check that the file and the database record are deleted
VFSLeaf deletedFile = certificatesManager.getCertificateLeaf(reloadedCertificate);
Assert.assertNull(deletedFile);
Certificate deletedCertificate = certificatesManager.getCertificateById(certificate.getKey());
Assert.assertNull(deletedCertificate);
}
use of org.olat.course.certificate.model.CertificateInfos in project OpenOLAT by OpenOLAT.
the class CertificatesManagerTest method certificateNotifications_courseCoach.
@Test
public void certificateNotifications_courseCoach() throws URISyntaxException {
Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("cer-2");
Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("cer-3");
Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("cer-4");
Identity participant2 = JunitTestHelper.createAndPersistIdentityAsRndUser("cer-4");
RepositoryEntry entry = JunitTestHelper.deployBasicCourse(owner);
repositoryEntryRelationDao.addRole(coach, entry, GroupRoles.coach.name());
repositoryEntryRelationDao.addRole(participant1, entry, GroupRoles.participant.name());
repositoryEntryRelationDao.addRole(participant2, entry, GroupRoles.participant.name());
dbInstance.commitAndCloseSession();
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();
Calendar lastestNews = Calendar.getInstance();
lastestNews.add(Calendar.HOUR_OF_DAY, -1);
// check the notifications of the author ( entry admin )
List<Certificate> authorNotifications = certificatesManager.getCertificatesForNotifications(owner, entry, lastestNews.getTime());
Assert.assertNotNull(authorNotifications);
Assert.assertEquals(2, authorNotifications.size());
// 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));
}
Aggregations