use of org.olat.course.certificate.CertificateTemplate 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.CertificateTemplate in project OpenOLAT by OpenOLAT.
the class CertificatesManagerTest method createTemplate.
@Test
public void createTemplate() throws URISyntaxException {
URL templateUrl = CertificatesManagerTest.class.getResource("template.pdf");
Assert.assertNotNull(templateUrl);
File templateFile = new File(templateUrl.toURI());
String certificateName = UUID.randomUUID() + ".pdf";
CertificateTemplate template = certificatesManager.addTemplate(certificateName, templateFile, null, null, true);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(template);
Assert.assertNotNull(template.getKey());
Assert.assertNotNull(template.getCreationDate());
Assert.assertNotNull(template.getLastModified());
Assert.assertEquals(certificateName, template.getName());
Assert.assertTrue(template.isPublicTemplate());
}
use of org.olat.course.certificate.CertificateTemplate in project OpenOLAT by OpenOLAT.
the class CertificationWebService method putCertificate.
/**
* Generate a new certificate.
*
* @response.representation.200.doc If the certificate was created
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The identity or the resource cannot be found
* @response.representation.500.doc An unexpected error happened during the creation of the certificate
* @param identityKey The owner of the certificate
* @param resourceKey The primary key of the resource of the repository entry of the course.
* @param score The score which appears in the certificate
* @param passed The passed/failed which appears in the certificate (true/false)
* @param creationDate The date of the certification
* @param request The request
* @return Nothing special
*/
@PUT
@Path("{identityKey}")
public Response putCertificate(@PathParam("identityKey") Long identityKey, @PathParam("resourceKey") Long resourceKey, @QueryParam("score") Float score, @QueryParam("passed") Boolean passed, @QueryParam("creationDate") String creationDate, @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();
}
OLATResourceManager resourceManager = CoreSpringFactory.getImpl(OLATResourceManager.class);
OLATResource resource = resourceManager.findResourceById(resourceKey);
if (resource == null) {
resource = resourceManager.findResourceable(resourceKey, "CourseModule");
}
if (resource == null) {
return Response.serverError().status(Response.Status.NOT_FOUND).build();
} else {
CertificatesManager certificatesManager = CoreSpringFactory.getImpl(CertificatesManager.class);
ICourse course = CourseFactory.loadCourse(resource);
RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
CertificateTemplate template = null;
Long templateId = course.getCourseConfig().getCertificateTemplate();
if (templateId != null) {
template = certificatesManager.getTemplateById(templateId);
}
CertificateInfos certificateInfos = new CertificateInfos(assessedIdentity, score, passed);
if (StringHelper.containsNonWhitespace(creationDate)) {
Date date = ObjectFactory.parseDate(creationDate);
certificateInfos.setCreationDate(date);
}
Certificate certificate = certificatesManager.generateCertificate(certificateInfos, entry, template, false);
if (certificate != null) {
return Response.ok().build();
}
return Response.serverError().status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}
use of org.olat.course.certificate.CertificateTemplate in project OpenOLAT by OpenOLAT.
the class IdentityCertificatesController method doGenerateCertificate.
private void doGenerateCertificate(UserRequest ureq) {
ICourse course = CourseFactory.loadCourse(courseEntry);
CourseNode rootNode = course.getRunStructure().getRootNode();
Roles roles = securityManager.getRoles(assessedIdentity);
IdentityEnvironment identityEnv = new IdentityEnvironment(assessedIdentity, roles);
UserCourseEnvironment assessedUserCourseEnv = new UserCourseEnvironmentImpl(identityEnv, course.getCourseEnvironment());
ScoreAccounting scoreAccounting = assessedUserCourseEnv.getScoreAccounting();
scoreAccounting.evaluateAll();
ScoreEvaluation scoreEval = scoreAccounting.evalCourseNode((AssessableCourseNode) rootNode);
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.CertificateTemplate in project openolat by klemens.
the class CertificatesManagerTest method createTemplate.
@Test
public void createTemplate() throws URISyntaxException {
URL templateUrl = CertificatesManagerTest.class.getResource("template.pdf");
Assert.assertNotNull(templateUrl);
File templateFile = new File(templateUrl.toURI());
String certificateName = UUID.randomUUID() + ".pdf";
CertificateTemplate template = certificatesManager.addTemplate(certificateName, templateFile, null, null, true);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(template);
Assert.assertNotNull(template.getKey());
Assert.assertNotNull(template.getCreationDate());
Assert.assertNotNull(template.getLastModified());
Assert.assertEquals(certificateName, template.getName());
Assert.assertTrue(template.isPublicTemplate());
}
Aggregations