use of org.olat.course.certificate.Certificate in project openolat by klemens.
the class CertificationTest method uploadCertificate.
@Test
public void uploadCertificate() 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);
dbInstance.commitAndCloseSession();
URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("courses").path(entry.getOlatResource().getKey().toString()).path("certificates").path(assessedIdentity.getKey().toString()).build();
URL certificateUrl = CertificationTest.class.getResource("certificate.pdf");
Assert.assertNotNull(certificateUrl);
File certificateFile = new File(certificateUrl.toURI());
HttpPost method = conn.createPost(uri, MediaType.APPLICATION_JSON);
Date creationDate = createDate(2014, 7, 1);
MultipartEntityBuilder builder = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE).addTextBody("filename", certificateFile.getName()).addBinaryBody("file", certificateFile, ContentType.APPLICATION_OCTET_STREAM, certificateFile.getName()).addTextBody("creationDate", ObjectFactory.formatDate(creationDate));
method.setEntity(builder.build());
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
EntityUtils.consume(response.getEntity());
// check certificate
Certificate certificate = certificatesManager.getLastCertificate(assessedIdentity, entry.getOlatResource().getKey());
Assert.assertNotNull(certificate);
Assert.assertEquals(creationDate, certificate.getCreationDate());
// check the certificate file
VFSLeaf certificateLeaf = certificatesManager.getCertificateLeaf(certificate);
Assert.assertNotNull(certificateLeaf);
Assert.assertEquals(certificateFile.length(), certificateLeaf.getSize());
}
use of org.olat.course.certificate.Certificate in project openolat by klemens.
the class CertificationTest method uploadCertificate_standalone.
@Test
public void uploadCertificate_standalone() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login("administrator", "openolat"));
Identity assessedIdentity = JunitTestHelper.createAndPersistIdentityAsRndUser("cert-1");
dbInstance.commitAndCloseSession();
Long resourceKey = 23687468l;
URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("courses").path(resourceKey.toString()).path("certificates").path(assessedIdentity.getKey().toString()).build();
URL certificateUrl = CertificationTest.class.getResource("certificate.pdf");
Assert.assertNotNull(certificateUrl);
File certificateFile = new File(certificateUrl.toURI());
HttpPost method = conn.createPost(uri, MediaType.APPLICATION_JSON);
Date creationDate = createDate(2014, 7, 1);
MultipartEntityBuilder builder = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE).addTextBody("filename", certificateFile.getName()).addBinaryBody("file", certificateFile, ContentType.APPLICATION_OCTET_STREAM, certificateFile.getName()).addTextBody("creationDate", ObjectFactory.formatDate(creationDate));
method.setEntity(builder.build());
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
EntityUtils.consume(response.getEntity());
// check certificate
Certificate certificate = certificatesManager.getLastCertificate(assessedIdentity, resourceKey);
Assert.assertNotNull(certificate);
Assert.assertEquals(creationDate, certificate.getCreationDate());
// check the certificate file
VFSLeaf certificateLeaf = certificatesManager.getCertificateLeaf(certificate);
Assert.assertNotNull(certificateLeaf);
Assert.assertEquals(certificateFile.length(), certificateLeaf.getSize());
}
use of org.olat.course.certificate.Certificate in project openolat by klemens.
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.Certificate in project openolat by klemens.
the class OLATUpgrade_11_0_6 method processCourse.
private void processCourse(RepositoryEntry entry) {
List<Certificate> certificates = certificatesManager.getCertificates(entry.getOlatResource());
for (Certificate certificate : certificates) {
if (certificate.getNextRecertificationDate() != null)
continue;
Date nextCertification = certificatesManager.getDateNextRecertification(certificate, entry);
if (nextCertification != null) {
certificate.setNextRecertificationDate(nextCertification);
dbInstance.getCurrentEntityManager().merge(certificate);
}
}
}
use of org.olat.course.certificate.Certificate in project openolat by klemens.
the class CertificatesManagerTest method uploadCertificate.
@Test
public void uploadCertificate() throws URISyntaxException {
Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("cer-1");
RepositoryEntry entry = JunitTestHelper.deployBasicCourse(identity);
dbInstance.commitAndCloseSession();
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
cal.set(Calendar.YEAR, 2012);
Date creationDate = cal.getTime();
URL certificateUrl = CertificatesManagerTest.class.getResource("template.pdf");
Assert.assertNotNull(certificateUrl);
File certificateFile = new File(certificateUrl.toURI());
Certificate certificate = certificatesManager.uploadCertificate(identity, creationDate, entry.getOlatResource(), certificateFile);
Assert.assertNotNull(certificate);
Assert.assertNotNull(certificate.getKey());
Assert.assertNotNull(certificate.getUuid());
Assert.assertEquals(entry.getDisplayname(), certificate.getCourseTitle());
Assert.assertEquals(identity, certificate.getIdentity());
dbInstance.commitAndCloseSession();
// double check
Certificate reloadedCertificate = certificatesManager.getCertificateById(certificate.getKey());
Assert.assertNotNull(reloadedCertificate);
Assert.assertNotNull(reloadedCertificate.getUuid());
Assert.assertEquals(entry.getDisplayname(), reloadedCertificate.getCourseTitle());
Assert.assertEquals(identity, reloadedCertificate.getIdentity());
Assert.assertEquals(entry.getOlatResource().getKey(), reloadedCertificate.getArchivedResourceKey());
Assert.assertEquals(creationDate, reloadedCertificate.getCreationDate());
// the file
VFSLeaf savedCertificateFile = certificatesManager.getCertificateLeaf(reloadedCertificate);
Assert.assertNotNull(savedCertificateFile);
Assert.assertTrue(savedCertificateFile.exists());
// load last
Certificate lastCertificate = certificatesManager.getLastCertificate(identity, entry.getOlatResource().getKey());
Assert.assertNotNull(lastCertificate);
Assert.assertEquals(certificate, lastCertificate);
}
Aggregations