Search in sources :

Example 21 with CertificateInfos

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());
}
Also used : CertificateInfos(org.olat.course.certificate.model.CertificateInfos)

Example 22 with CertificateInfos

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();
    }
}
Also used : CertificateTemplate(org.olat.course.certificate.CertificateTemplate) CertificateInfos(org.olat.course.certificate.model.CertificateInfos) OLATResourceManager(org.olat.resource.OLATResourceManager) OLATResource(org.olat.resource.OLATResource) CertificatesManager(org.olat.course.certificate.CertificatesManager) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) Date(java.util.Date) BaseSecurity(org.olat.basesecurity.BaseSecurity) Certificate(org.olat.course.certificate.Certificate) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 23 with CertificateInfos

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);
}
Also used : CertificateInfos(org.olat.course.certificate.model.CertificateInfos) ArrayList(java.util.ArrayList) FlexiTableColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel) ArrayList(java.util.ArrayList) List(java.util.List) PassedCellRenderer(org.olat.course.assessment.bulk.PassedCellRenderer) DefaultFlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 24 with CertificateInfos

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);
}
Also used : ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) CertificateTemplate(org.olat.course.certificate.CertificateTemplate) CertificateInfos(org.olat.course.certificate.model.CertificateInfos) ICourse(org.olat.course.ICourse) Roles(org.olat.core.id.Roles) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) ScoreAccounting(org.olat.course.run.scoring.ScoreAccounting) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) CourseNode(org.olat.course.nodes.CourseNode) IdentityEnvironment(org.olat.core.id.IdentityEnvironment)

Example 25 with CertificateInfos

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);
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) HttpDelete(org.apache.http.client.methods.HttpDelete) CertificateInfos(org.olat.course.certificate.model.CertificateInfos) HttpResponse(org.apache.http.HttpResponse) RepositoryEntry(org.olat.repository.RepositoryEntry) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Identity(org.olat.core.id.Identity) Certificate(org.olat.course.certificate.Certificate) Test(org.junit.Test)

Aggregations

CertificateInfos (org.olat.course.certificate.model.CertificateInfos)34 Identity (org.olat.core.id.Identity)24 RepositoryEntry (org.olat.repository.RepositoryEntry)24 Certificate (org.olat.course.certificate.Certificate)18 Test (org.junit.Test)16 ICourse (org.olat.course.ICourse)12 CertificateTemplate (org.olat.course.certificate.CertificateTemplate)10 CourseNode (org.olat.course.nodes.CourseNode)8 ScoreEvaluation (org.olat.course.run.scoring.ScoreEvaluation)8 URI (java.net.URI)6 ArrayList (java.util.ArrayList)6 HttpResponse (org.apache.http.HttpResponse)6 AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)6 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)6 IOException (java.io.IOException)4 URISyntaxException (java.net.URISyntaxException)4 Calendar (java.util.Calendar)4 Date (java.util.Date)4 DefaultFlexiColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel)4 FlexiTableColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel)4