use of org.olat.course.certificate.model.CertificateInfos in project OpenOLAT by OpenOLAT.
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 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.model.CertificateInfos in project OpenOLAT by OpenOLAT.
the class CertificatesSelectionOverviewController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
FlexiTableColumnModel columnsModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
;
int colPos = 0;
if (isAdministrativeUser) {
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel("table.header.name", CertificatesSelectionDataModel.USERNAME_COL));
}
List<UserPropertyHandler> userPropertyHandlers = userManager.getUserPropertyHandlersFor(AssessedIdentitiesTableDataModel.usageIdentifyer, isAdministrativeUser);
List<UserPropertyHandler> resultingPropertyHandlers = new ArrayList<UserPropertyHandler>();
// followed by the users fields
for (int i = 0; i < userPropertyHandlers.size(); i++) {
UserPropertyHandler userPropertyHandler = userPropertyHandlers.get(i);
boolean visible = userManager.isMandatoryUserProperty(AssessedIdentitiesTableDataModel.usageIdentifyer, userPropertyHandler);
if (visible) {
resultingPropertyHandlers.add(userPropertyHandler);
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(userPropertyHandler.i18nColumnDescriptorLabelKey(), colPos++));
}
}
if (hasAssessableNodes) {
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel("table.header.passed", CertificatesSelectionDataModel.PASSED_COL, new PassedCellRenderer()));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel("table.header.score", CertificatesSelectionDataModel.SCORE_COL));
}
tableModel = new CertificatesSelectionDataModel(columnsModel, resultingPropertyHandlers);
@SuppressWarnings("unchecked") List<CertificateInfos> selectedInfos = (List<CertificateInfos>) getFromRunContext("infos");
tableModel.setObjects(selectedInfos);
uifactory.addTableElement(getWindowControl(), "selection", tableModel, getTranslator(), formLayout);
}
use of org.olat.course.certificate.model.CertificateInfos 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.model.CertificateInfos 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);
}
Aggregations