Search in sources :

Example 91 with Identity

use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.

the class ReturnboxFullAccessCallback method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
 */
@Override
public void event(UserRequest ureq, Controller source, Event event) {
    if (source == dropboxFolderRunController) {
        if (event instanceof FolderEvent) {
            FolderEvent folderEvent = (FolderEvent) event;
            if (folderEvent.getCommand().equals(FolderEvent.DELETE_EVENT)) {
                UserNodeAuditManager am = userCourseEnv.getCourseEnvironment().getAuditManager();
                // log entry for this file
                Identity coach = ureq.getIdentity();
                Identity student = userCourseEnv.getIdentityEnvironment().getIdentity();
                am.appendToUserNodeLog(node, coach, student, "FILE DELETED: " + folderEvent.getFilename());
            }
        }
    } else if (source == returnboxFolderRunController) {
        if (event instanceof FolderEvent) {
            FolderEvent folderEvent = (FolderEvent) event;
            if (folderEvent.getCommand().equals(FolderEvent.UPLOAD_EVENT) || folderEvent.getCommand().equals(FolderEvent.NEW_FILE_EVENT)) {
                UserNodeAuditManager am = userCourseEnv.getCourseEnvironment().getAuditManager();
                // log entry for this file
                Identity coach = ureq.getIdentity();
                Identity student = userCourseEnv.getIdentityEnvironment().getIdentity();
                if (node instanceof AssessableCourseNode) {
                    AssessableCourseNode acn = (AssessableCourseNode) node;
                    AssessmentEvaluation eval = acn.getUserScoreEvaluation(userCourseEnv);
                    if (eval.getAssessmentStatus() == null || eval.getAssessmentStatus() == AssessmentEntryStatus.notStarted) {
                        eval = new AssessmentEvaluation(eval, AssessmentEntryStatus.inProgress);
                        acn.updateUserScoreEvaluation(eval, userCourseEnv, coach, false, Role.coach);
                    }
                }
                am.appendToUserNodeLog(node, coach, student, "FILE UPLOADED: " + folderEvent.getFilename());
                String toMail = UserManager.getInstance().getUserDisplayEmail(student, ureq.getLocale());
                OLATResourceable ores = OresHelper.createOLATResourceableInstance(CourseNode.class, Long.valueOf(node.getIdent()));
                ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(ores);
                BusinessControl bc = BusinessControlFactory.getInstance().createBusinessControl(ce, getWindowControl().getBusinessControl());
                String link = BusinessControlFactory.getInstance().getAsURIString(bc, true);
                log.debug("DEBUG : Returnbox notification email with link=" + link);
                String subject = translate("returnbox.email.subject");
                String body = translate("returnbox.email.body", new String[] { userCourseEnv.getCourseEnvironment().getCourseTitle(), node.getShortTitle(), folderEvent.getFilename(), link });
                MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
                MailBundle bundle = new MailBundle();
                bundle.setContext(context);
                bundle.setToId(student);
                bundle.setContent(subject, body);
                MailerResult result = CoreSpringFactory.getImpl(MailManager.class).sendMessage(bundle);
                if (result.getReturnCode() > 0) {
                    am.appendToUserNodeLog(node, coach, student, "MAIL SEND FAILED TO:" + toMail + "; MailReturnCode: " + result.getReturnCode());
                    log.warn("Could not send email 'returnbox notification' to " + student + "with email=" + toMail);
                } else {
                    log.info("Send email 'returnbox notification' to " + student + "with email=" + toMail);
                }
            }
        } else if (FolderCommand.FOLDERCOMMAND_FINISHED == event) {
            if (node instanceof AssessableCourseNode) {
                AssessableCourseNode acn = (AssessableCourseNode) node;
                AssessmentEvaluation eval = acn.getUserScoreEvaluation(userCourseEnv);
                if (eval == null) {
                    eval = AssessmentEvaluation.EMPTY_EVAL;
                }
                if (eval.getAssessmentStatus() == null || eval.getAssessmentStatus() == AssessmentEntryStatus.notStarted) {
                    eval = new AssessmentEvaluation(eval, AssessmentEntryStatus.inProgress);
                    acn.updateUserScoreEvaluation(eval, userCourseEnv, getIdentity(), false, Role.coach);
                    fireEvent(ureq, Event.CHANGED_EVENT);
                }
            }
        }
    } else if (source == statusForm) {
        if (event == Event.DONE_EVENT) {
            // get identity not from request (this would be an author)
            StatusManager.getInstance().saveStatusFormData(statusForm, node, userCourseEnv);
        }
    } else if (source == dialogBoxController) {
        if (DialogBoxUIFactory.isYesEvent(event) && assignedTask != null) {
            // cancel task assignment, and show "no task assigned to user"
            removeAssignedTask(userCourseEnv, userCourseEnv.getIdentityEnvironment().getIdentity());
            // update UI
            myContent.contextPut("assignedtask", null);
        }
    }
}
Also used : MailContextImpl(org.olat.core.util.mail.MailContextImpl) AssessmentEvaluation(org.olat.course.run.scoring.AssessmentEvaluation) OLATResourceable(org.olat.core.id.OLATResourceable) MailContext(org.olat.core.util.mail.MailContext) MailerResult(org.olat.core.util.mail.MailerResult) BusinessControl(org.olat.core.id.context.BusinessControl) ContextEntry(org.olat.core.id.context.ContextEntry) UserNodeAuditManager(org.olat.course.auditing.UserNodeAuditManager) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) FolderEvent(org.olat.core.commons.modules.bc.FolderEvent) CourseNode(org.olat.course.nodes.CourseNode) TACourseNode(org.olat.course.nodes.TACourseNode) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle)

Example 92 with Identity

use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.

the class StatusManager method saveStatusFormData.

public void saveStatusFormData(StatusForm statusForm, CourseNode node, UserCourseEnvironment userCourseEnv) {
    Identity identity = userCourseEnv.getIdentityEnvironment().getIdentity();
    String selectedKey = statusForm.getSelectedStatus();
    CoursePropertyManager cpm = userCourseEnv.getCourseEnvironment().getCoursePropertyManager();
    Property statusProperty;
    statusProperty = cpm.findCourseNodeProperty(node, identity, null, PROPERTY_KEY_STATUS);
    if (statusProperty == null) {
        statusProperty = cpm.createCourseNodePropertyInstance(node, identity, null, PROPERTY_KEY_STATUS, null, null, selectedKey, null);
        cpm.saveProperty(statusProperty);
    } else {
        statusProperty.setStringValue(selectedKey);
        cpm.updateProperty(statusProperty);
    }
}
Also used : Identity(org.olat.core.id.Identity) Property(org.olat.properties.Property) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager)

Example 93 with Identity

use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.

the class AttemptsRuleSPI method filter.

@Override
public void filter(RepositoryEntry entry, List<Identity> identities, ReminderRule rule) {
    if (rule instanceof ReminderRuleImpl) {
        ReminderRuleImpl r = (ReminderRuleImpl) rule;
        String nodeIdent = r.getLeftOperand();
        String operator = r.getOperator();
        int value = Integer.parseInt(r.getRightOperand());
        ICourse course = CourseFactory.loadCourse(entry);
        CourseNode courseNode = course.getRunStructure().getNode(nodeIdent);
        if (courseNode == null) {
            identities.clear();
            log.error("Attempts rule in course " + entry.getKey() + " (" + entry.getDisplayname() + ") is missing a course element");
            return;
        }
        Map<Long, Integer> attempts = helperDao.getAttempts(entry, courseNode, identities);
        for (Iterator<Identity> identityIt = identities.iterator(); identityIt.hasNext(); ) {
            Identity identity = identityIt.next();
            Integer attempt = attempts.get(identity.getKey());
            if (attempt == null) {
                attempt = 0;
            }
            if (!evaluateAttempt(attempt.intValue(), operator, value)) {
                identityIt.remove();
            }
        }
    }
}
Also used : ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) ICourse(org.olat.course.ICourse) CourseNode(org.olat.course.nodes.CourseNode) Identity(org.olat.core.id.Identity)

Example 94 with Identity

use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.

the class BinderAssessmentController method loadModel.

private void loadModel() {
    List<AssessmentSection> aSections = portfolioService.getAssessmentSections(binder, null);
    Map<Section, AssessmentSection> aSectionsMap = new HashMap<>();
    for (AssessmentSection aSection : aSections) {
        aSectionsMap.put(aSection.getSection(), aSection);
    }
    // binder done only is an owner is present
    // and all owners have done the binder
    boolean binderDone = false;
    List<Identity> assessedIdentities = portfolioService.getMembers(binder, PortfolioRoles.owner.name());
    int countDone = 0;
    for (Identity assessedIdentity : assessedIdentities) {
        AssessmentEntryStatus status = portfolioService.getAssessmentStatus(assessedIdentity, binder);
        if (status == AssessmentEntryStatus.done) {
            countDone++;
        }
    }
    binderDone = (countDone > 0 && countDone == assessedIdentities.size());
    boolean allClosed = true;
    List<Section> sections = portfolioService.getSections(binder);
    List<AssessmentSectionWrapper> rows = new ArrayList<>();
    Map<Section, AssessmentSectionWrapper> sectionToRows = new HashMap<>();
    for (Section section : sections) {
        AssessmentSection assessmentSection = aSectionsMap.get(section);
        AssessmentSectionWrapper row = new AssessmentSectionWrapper(section, assessmentSection);
        sectionToRows.put(section, row);
        if (secCallback.canViewAssess(section) || secCallback.canAssess(section)) {
            rows.add(row);
        }
        allClosed &= section.getSectionStatus() == SectionStatus.closed;
    }
    List<Page> pages = portfolioService.getPages(binder, null);
    for (Page page : pages) {
        AssessmentSectionWrapper row = sectionToRows.get(page.getSection());
        if (row != null) {
            row.setNumOfPages(row.getNumOfPages() + 1);
        }
    }
    boolean allowedToAssess = false;
    boolean allowedToAssessBinder = secCallback.canAssess(binder);
    for (AssessmentSectionWrapper row : rows) {
        boolean canAssess = secCallback.canAssess(row.getSection());
        if (canAssess && !binderDone) {
            forgeAssessmentSection(row);
            allowedToAssess = true;
        }
    }
    reopenLink.setVisible(allowedToAssessBinder && binderDone);
    saveAndDoneLink.setVisible(allowedToAssessBinder && !binderDone && allClosed);
    saveButton.setVisible(allowedToAssess);
    cancelButton.setVisible(allowedToAssess);
    model.setObjects(rows);
    tableEl.reset();
    tableEl.reloadData();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Page(org.olat.modules.portfolio.Page) AssessmentSection(org.olat.modules.portfolio.AssessmentSection) Section(org.olat.modules.portfolio.Section) AssessmentEntryStatus(org.olat.modules.assessment.model.AssessmentEntryStatus) AssessmentSection(org.olat.modules.portfolio.AssessmentSection) Identity(org.olat.core.id.Identity)

Example 95 with Identity

use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.

the class BinderAssessmentController method commitChanges.

private void commitChanges() {
    List<AssessmentSectionWrapper> rows = model.getObjects();
    List<Identity> assessedIdentities = portfolioService.getMembers(binder, PortfolioRoles.owner.name());
    List<AssessmentSectionChange> changes = new ArrayList<>();
    for (AssessmentSectionWrapper row : rows) {
        Section section = row.getSection();
        if (secCallback.canAssess(section) && !SectionStatus.isClosed(section)) {
            BigDecimal score = null;
            if (withScore) {
                String value = row.getScoreEl().getValue();
                if (StringHelper.containsNonWhitespace(value)) {
                    score = new BigDecimal(value);
                }
            }
            Boolean passed = null;
            if (withPassed) {
                passed = row.getPassedEl().isSelected(0);
            }
            for (Identity assessedIdentity : assessedIdentities) {
                changes.add(new AssessmentSectionChange(assessedIdentity, row.getSection(), row.getAssessmentSection(), score, passed));
            }
        }
    }
    portfolioService.updateAssessmentSections(binder, changes, getIdentity());
}
Also used : AssessmentSectionChange(org.olat.modules.portfolio.model.AssessmentSectionChange) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) AssessmentSection(org.olat.modules.portfolio.AssessmentSection) Section(org.olat.modules.portfolio.Section) BigDecimal(java.math.BigDecimal)

Aggregations

Identity (org.olat.core.id.Identity)3749 Test (org.junit.Test)1956 RepositoryEntry (org.olat.repository.RepositoryEntry)898 BusinessGroup (org.olat.group.BusinessGroup)560 ArrayList (java.util.ArrayList)550 Date (java.util.Date)312 URI (java.net.URI)272 ICourse (org.olat.course.ICourse)266 HttpResponse (org.apache.http.HttpResponse)260 File (java.io.File)211 AssessmentManager (org.olat.course.assessment.AssessmentManager)210 Path (javax.ws.rs.Path)182 OLATResource (org.olat.resource.OLATResource)172 OLATResourceable (org.olat.core.id.OLATResourceable)156 Roles (org.olat.core.id.Roles)154 HashMap (java.util.HashMap)151 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)142 HashSet (java.util.HashSet)136 List (java.util.List)132 Produces (javax.ws.rs.Produces)130