use of org.olat.course.certificate.Certificate in project OpenOLAT by OpenOLAT.
the class AssessedIdentityCertificatesController method loadList.
private void loadList() {
Identity assessedIdentity = assessedUserCourseEnv.getIdentityEnvironment().getIdentity();
List<Certificate> certificates = certificatesManager.getCertificates(assessedIdentity, resource);
List<Links> certificatesLink = new ArrayList<>(certificates.size());
int count = 0;
for (Certificate certificate : certificates) {
String displayName = formatter.formatDateAndTime(certificate.getCreationDate());
String url = DownloadCertificateCellRenderer.getUrl(certificate);
Links links = new Links(url, displayName, certificate.getStatus().name());
certificatesLink.add(links);
if (canDelete) {
Link deleteLink = LinkFactory.createLink("delete." + count++, "delete", getTranslator(), mainVC, this, Link.NONTRANSLATED);
deleteLink.setCustomDisplayText(" ");
deleteLink.setElementCssClass("o_sel_certificate_delete");
deleteLink.setIconLeftCSS("o_icon o_icon-lg o_icon_delete");
deleteLink.setUserObject(certificate);
links.setDelete(deleteLink);
}
}
mainVC.contextPut("certificates", certificatesLink);
}
use of org.olat.course.certificate.Certificate in project OpenOLAT by OpenOLAT.
the class CertificatesManagerImpl method getCertificatesForNotifications.
@Override
public List<Certificate> getCertificatesForNotifications(Identity identity, RepositoryEntry entry, Date lastNews) {
Roles roles = securityManager.getRoles(identity);
RepositoryEntrySecurity security = repositoryManager.isAllowed(identity, roles, entry);
if (!security.isEntryAdmin() && !security.isCourseCoach() && !security.isGroupCoach() && !security.isCourseParticipant() && !security.isGroupParticipant()) {
return Collections.emptyList();
}
StringBuilder sb = new StringBuilder();
sb.append("select cer from certificate cer").append(" inner join fetch cer.identity ident").append(" where cer.olatResource.key=:resourceKey and cer.last=true ");
// must be some kind of restrictions
boolean securityCheck = false;
List<Long> baseGroupKeys = null;
if (!security.isEntryAdmin()) {
sb.append(" and (");
boolean or = false;
if (security.isCourseCoach()) {
or = or(sb, or);
sb.append(" exists (select membership.identity.key from repoentrytogroup as rel, bgroup as reBaseGroup, bgroupmember membership ").append(" where ident.key=membership.identity.key and rel.entry.key=:repoKey and rel.group=reBaseGroup and membership.group=reBaseGroup and membership.role='").append(GroupRole.participant).append("'").append(" )");
securityCheck = true;
}
if (security.isGroupCoach()) {
SearchBusinessGroupParams params = new SearchBusinessGroupParams(identity, true, false);
List<BusinessGroup> groups = businessGroupService.findBusinessGroups(params, entry, 0, -1);
if (groups.size() > 0) {
or = or(sb, or);
sb.append(" exists (select membership.identity.key from bgroupmember membership ").append(" where ident.key=membership.identity.key and membership.group.key in (:groups) and membership.role='").append(GroupRole.participant).append("'").append(" )");
baseGroupKeys = new ArrayList<>(groups.size());
for (BusinessGroup group : groups) {
baseGroupKeys.add(group.getBaseGroup().getKey());
}
securityCheck = true;
}
}
if (security.isCourseParticipant() || security.isGroupParticipant()) {
or = or(sb, or);
sb.append(" ident.key=:identityKey");
securityCheck = true;
}
sb.append(")");
} else {
securityCheck = true;
}
if (!securityCheck) {
return Collections.emptyList();
}
sb.append(" order by cer.creationDate");
TypedQuery<Certificate> certificates = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Certificate.class).setParameter("resourceKey", entry.getOlatResource().getKey());
if (!security.isEntryAdmin()) {
if (security.isCourseCoach()) {
certificates.setParameter("repoKey", entry.getKey());
}
if (security.isCourseParticipant() || security.isGroupParticipant()) {
certificates.setParameter("identityKey", identity.getKey());
}
}
if (baseGroupKeys != null && !baseGroupKeys.isEmpty()) {
certificates.setParameter("groups", baseGroupKeys);
}
return certificates.getResultList();
}
use of org.olat.course.certificate.Certificate in project OpenOLAT by OpenOLAT.
the class CertificatesManagerImpl method isCertificationAllowed.
@Override
public boolean isCertificationAllowed(Identity identity, RepositoryEntry entry) {
boolean allowed = false;
try {
ICourse course = CourseFactory.loadCourse(entry);
CourseConfig config = course.getCourseEnvironment().getCourseConfig();
if (config.isRecertificationEnabled()) {
Certificate certificate = getLastCertificate(identity, entry.getOlatResource().getKey());
if (certificate == null) {
allowed = true;
} else {
Calendar cal = Calendar.getInstance();
Date now = cal.getTime();
Date nextCertificationDate = getDateNextRecertification(certificate, config);
allowed = (nextCertificationDate != null ? nextCertificationDate.before(now) : false);
}
} else {
allowed = !hasCertificate(identity, entry.getOlatResource().getKey());
}
} catch (CorruptedCourseException e) {
log.error("", e);
}
return allowed;
}
use of org.olat.course.certificate.Certificate in project OpenOLAT by OpenOLAT.
the class CertificationWebService method deleteCertificateInfo.
@DELETE
@Path("{identityKey}")
public Response deleteCertificateInfo(@PathParam("identityKey") Long identityKey, @PathParam("resourceKey") Long resourceKey, @Context HttpServletRequest request) {
if (!isAdmin(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
CertificatesManager certificatesManager = CoreSpringFactory.getImpl(CertificatesManager.class);
BaseSecurity baseSecurity = CoreSpringFactory.getImpl(BaseSecurity.class);
Identity identity = baseSecurity.loadIdentityByKey(identityKey);
if (identity == null) {
return Response.serverError().status(Response.Status.NOT_FOUND).build();
}
OLATResourceable courseOres = OresHelper.createOLATResourceableInstance("CourseModule", resourceKey);
OLATResourceManager resourceManager = CoreSpringFactory.getImpl(OLATResourceManager.class);
OLATResource resource = resourceManager.findResourceable(courseOres);
if (resource == null) {
resource = resourceManager.findResourceById(resourceKey);
}
if (resource == null) {
return Response.serverError().status(Response.Status.NOT_FOUND).build();
}
Certificate certificate = certificatesManager.getLastCertificate(identity, resource.getKey());
if (certificate == null) {
return Response.serverError().status(Response.Status.NOT_FOUND).build();
}
certificatesManager.deleteCertificate(certificate);
return Response.ok().build();
}
use of org.olat.course.certificate.Certificate in project OpenOLAT by OpenOLAT.
the class CertificationWebService method getCertificateInfo.
@HEAD
@Path("{identityKey}")
@Produces({ "application/pdf" })
public Response getCertificateInfo(@PathParam("identityKey") Long identityKey, @PathParam("resourceKey") Long resourceKey, @Context HttpServletRequest request) {
if (!isAdmin(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
CertificatesManager certificatesManager = CoreSpringFactory.getImpl(CertificatesManager.class);
BaseSecurity baseSecurity = CoreSpringFactory.getImpl(BaseSecurity.class);
Identity identity = baseSecurity.loadIdentityByKey(identityKey);
if (identity == null) {
return Response.serverError().status(Response.Status.NOT_FOUND).build();
}
OLATResourceable courseOres = OresHelper.createOLATResourceableInstance("CourseModule", resourceKey);
OLATResourceManager resourceManager = CoreSpringFactory.getImpl(OLATResourceManager.class);
OLATResource resource = resourceManager.findResourceable(courseOres);
if (resource == null) {
resource = resourceManager.findResourceById(resourceKey);
}
if (resource == null) {
return Response.serverError().status(Response.Status.NOT_FOUND).build();
}
Certificate certificate = certificatesManager.getLastCertificate(identity, resource.getKey());
if (certificate == null) {
return Response.serverError().status(Response.Status.NOT_FOUND).build();
}
VFSLeaf certificateFile = certificatesManager.getCertificateLeaf(certificate);
if (certificateFile == null || !certificateFile.exists()) {
return Response.serverError().status(Response.Status.NOT_FOUND).build();
}
return Response.ok().build();
}
Aggregations