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);
}
Aggregations