Search in sources :

Example 16 with AssessmentModeToArea

use of org.olat.course.assessment.AssessmentModeToArea in project openolat by klemens.

the class AssessmentModeEditController method save.

private void save(UserRequest ureq, boolean forceStatus) {
    if (assessmentMode.getKey() != null) {
        assessmentMode = assessmentModeMgr.getAssessmentModeById(assessmentMode.getKey());
    }
    assessmentMode.setName(nameEl.getValue());
    assessmentMode.setDescription(descriptionEl.getValue());
    assessmentMode.setBegin(beginEl.getDate());
    if (leadTimeEl.getIntValue() > 0) {
        assessmentMode.setLeadTime(leadTimeEl.getIntValue());
    } else {
        assessmentMode.setLeadTime(0);
    }
    assessmentMode.setEnd(endEl.getDate());
    if (followupTimeEl.getIntValue() > 0) {
        assessmentMode.setFollowupTime(followupTimeEl.getIntValue());
    } else {
        assessmentMode.setFollowupTime(0);
    }
    if (startModeEl.isOneSelected() && startModeEl.isSelected(1)) {
        assessmentMode.setManualBeginEnd(true);
    } else {
        assessmentMode.setManualBeginEnd(false);
    }
    String targetKey = targetEl.getSelectedKey();
    assessmentMode.setTargetAudience(AssessmentMode.Target.valueOf(targetKey));
    boolean elementRestrictions = courseElementsRestrictionEl.isAtLeastSelected(1);
    assessmentMode.setRestrictAccessElements(elementRestrictions);
    if (elementRestrictions) {
        StringBuilder sb = new StringBuilder();
        for (String elementKey : elementKeys) {
            if (sb.length() > 0)
                sb.append(",");
            sb.append(elementKey);
        }
        assessmentMode.setElementList(sb.toString());
    } else {
        assessmentMode.setElementList(null);
    }
    if (StringHelper.containsNonWhitespace(startElementKey)) {
        assessmentMode.setStartElement(startElementKey);
    } else {
        assessmentMode.setStartElement(null);
    }
    boolean ipRestriction = ipsEl.isAtLeastSelected(1);
    assessmentMode.setRestrictAccessIps(ipRestriction);
    if (ipRestriction) {
        assessmentMode.setIpList(ipListEl.getValue());
    } else {
        assessmentMode.setIpList(null);
    }
    boolean safeExamEnabled = safeExamBrowserEl.isAtLeastSelected(1);
    assessmentMode.setSafeExamBrowser(safeExamEnabled);
    if (safeExamEnabled) {
        assessmentMode.setSafeExamBrowserKey(safeExamBrowserKeyEl.getValue());
        assessmentMode.setSafeExamBrowserHint(safeExamBrowserHintEl.getValue());
    } else {
        assessmentMode.setSafeExamBrowserKey(null);
        assessmentMode.setSafeExamBrowserHint(null);
    }
    assessmentMode.setApplySettingsForCoach(forCoachEl.isAtLeastSelected(1));
    // mode need to be persisted for the following relations
    if (assessmentMode.getKey() == null) {
        assessmentMode = assessmentModeMgr.persist(assessmentMode);
    }
    // update groups
    if (groupKeys.isEmpty()) {
        if (!assessmentMode.getGroups().isEmpty()) {
            assessmentMode.getGroups().clear();
        }
    } else {
        Set<Long> currentKeys = new HashSet<>();
        for (Iterator<AssessmentModeToGroup> modeToGroupIt = assessmentMode.getGroups().iterator(); modeToGroupIt.hasNext(); ) {
            Long currentKey = modeToGroupIt.next().getBusinessGroup().getKey();
            if (!groupKeys.contains(currentKey)) {
                modeToGroupIt.remove();
            } else {
                currentKeys.add(currentKey);
            }
        }
        for (Long groupKey : groupKeys) {
            if (!currentKeys.contains(groupKey)) {
                BusinessGroup group = businessGroupService.loadBusinessGroup(groupKey);
                AssessmentModeToGroup modeToGroup = assessmentModeMgr.createAssessmentModeToGroup(assessmentMode, group);
                assessmentMode.getGroups().add(modeToGroup);
            }
        }
    }
    // update areas
    if (areaKeys.isEmpty()) {
        if (!assessmentMode.getAreas().isEmpty()) {
            assessmentMode.getAreas().clear();
        }
    } else {
        Set<Long> currentKeys = new HashSet<>();
        for (Iterator<AssessmentModeToArea> modeToAreaIt = assessmentMode.getAreas().iterator(); modeToAreaIt.hasNext(); ) {
            Long currentKey = modeToAreaIt.next().getArea().getKey();
            if (!areaKeys.contains(currentKey)) {
                modeToAreaIt.remove();
            } else {
                currentKeys.add(currentKey);
            }
        }
        for (Long areaKey : areaKeys) {
            if (!currentKeys.contains(areaKey)) {
                BGArea area = areaMgr.loadArea(areaKey);
                AssessmentModeToArea modeToArea = assessmentModeMgr.createAssessmentModeToArea(assessmentMode, area);
                assessmentMode.getAreas().add(modeToArea);
            }
        }
    }
    assessmentMode = assessmentModeMgr.merge(assessmentMode, forceStatus);
    fireEvent(ureq, Event.CHANGED_EVENT);
}
Also used : AssessmentModeToArea(org.olat.course.assessment.AssessmentModeToArea) BusinessGroup(org.olat.group.BusinessGroup) BGArea(org.olat.group.area.BGArea) AssessmentModeToGroup(org.olat.course.assessment.AssessmentModeToGroup) HashSet(java.util.HashSet)

Aggregations

AssessmentModeToArea (org.olat.course.assessment.AssessmentModeToArea)16 BusinessGroup (org.olat.group.BusinessGroup)16 BGArea (org.olat.group.area.BGArea)16 RepositoryEntry (org.olat.repository.RepositoryEntry)12 Test (org.junit.Test)10 Identity (org.olat.core.id.Identity)10 AssessmentMode (org.olat.course.assessment.AssessmentMode)10 AssessmentModeToGroup (org.olat.course.assessment.AssessmentModeToGroup)8 HashSet (java.util.HashSet)4 Target (org.olat.course.assessment.AssessmentMode.Target)4 ArrayList (java.util.ArrayList)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2 ICourse (org.olat.course.ICourse)2 Status (org.olat.course.assessment.AssessmentMode.Status)2 CourseNode (org.olat.course.nodes.CourseNode)2 CourseEditorTreeModel (org.olat.course.tree.CourseEditorTreeModel)2