use of org.olat.course.nodes.cl.model.DBCheck in project OpenOLAT by OpenOLAT.
the class CheckboxManagerTest method loadCheck.
@Test
public void loadCheck() {
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("check-2");
OLATResourceable ores = OresHelper.createOLATResourceableInstance("checkbox-6", 2350l);
String resSubPath = UUID.randomUUID().toString();
String checkboxId = UUID.randomUUID().toString();
DBCheckbox checkbox = checkboxManager.createDBCheckbox(checkboxId, ores, resSubPath);
// create a check
DBCheck check = checkboxManager.createCheck(checkbox, id, new Float(1.0), Boolean.TRUE);
dbInstance.commitAndCloseSession();
// load the check
DBCheck loadedCheck = checkboxManager.loadCheck(checkbox, id);
// paranoia check
Assert.assertNotNull(loadedCheck);
Assert.assertEquals(check, loadedCheck);
Assert.assertEquals(id, loadedCheck.getIdentity());
Assert.assertEquals(checkbox, loadedCheck.getCheckbox());
Assert.assertEquals(Boolean.TRUE, loadedCheck.getChecked());
Assert.assertEquals(1.0f, loadedCheck.getScore().floatValue(), 0.00001);
}
use of org.olat.course.nodes.cl.model.DBCheck in project OpenOLAT by OpenOLAT.
the class CheckListAssessmentController method getAssessmentDataViews.
private List<CheckListAssessmentRow> getAssessmentDataViews(List<AssessmentData> datas, List<Checkbox> checkbox) {
List<CheckListAssessmentRow> dataViews = new ArrayList<>();
int numOfcheckbox = checkbox.size();
Map<String, Integer> indexed = new HashMap<>();
for (int i = numOfcheckbox; i-- > 0; ) {
indexed.put(checkbox.get(i).getCheckboxId(), new Integer(i));
}
for (AssessmentData data : datas) {
Float[] scores = new Float[numOfcheckbox];
Boolean[] checkBool = new Boolean[numOfcheckbox];
float totalPoints = 0.0f;
for (DBCheck check : data.getChecks()) {
Float score = check.getScore();
if (score != null) {
totalPoints += score.floatValue();
}
if (check.getChecked() == null)
continue;
check.getCheckbox();
Integer index = indexed.get(check.getCheckbox().getCheckboxId());
if (index != null) {
int i = index.intValue();
if (i >= 0 && i < numOfcheckbox) {
scores[i] = score;
checkBool[i] = check.getChecked();
}
}
}
if (maxScore != null && maxScore.floatValue() > 0f && totalPoints > maxScore.floatValue()) {
totalPoints = maxScore.floatValue();
}
CheckListAssessmentRow row = new CheckListAssessmentRow(data.getIdentity(), checkBool, scores, totalPoints, userPropertyHandlers, getLocale());
dataViews.add(row);
}
return dataViews;
}
use of org.olat.course.nodes.cl.model.DBCheck in project OpenOLAT by OpenOLAT.
the class CheckListRunController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
boolean readOnly = isReadOnly();
if (formLayout instanceof FormLayoutContainer) {
FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
layoutCont.contextPut("readOnly", Boolean.valueOf(readOnly));
if (dueDate != null) {
layoutCont.contextPut("dueDate", dueDate);
layoutCont.contextPut("in-due-date", isPanelOpen(ureq, "due-date", true));
if (dueDate.compareTo(new Date()) < 0) {
layoutCont.contextPut("afterDueDate", Boolean.TRUE);
}
}
layoutCont.contextPut("withScore", new Boolean(withScore));
if (courseNode.getModuleConfiguration().getBooleanSafe(MSCourseNode.CONFIG_KEY_HAS_SCORE_FIELD, false)) {
HighScoreRunController highScoreCtr = new HighScoreRunController(ureq, getWindowControl(), userCourseEnv, courseNode, this.mainForm);
if (highScoreCtr.isViewHighscore()) {
Component highScoreComponent = highScoreCtr.getInitialComponent();
layoutCont.put("highScore", highScoreComponent);
}
}
List<DBCheck> checks = checkboxManager.loadCheck(getIdentity(), courseOres, courseNode.getIdent());
Map<String, DBCheck> uuidToCheckMap = new HashMap<>();
for (DBCheck check : checks) {
uuidToCheckMap.put(check.getCheckbox().getCheckboxId(), check);
}
List<Checkbox> list = checkboxList.getList();
List<CheckboxWrapper> wrappers = new ArrayList<>(list.size());
for (Checkbox checkbox : list) {
DBCheck check = uuidToCheckMap.get(checkbox.getCheckboxId());
CheckboxWrapper wrapper = forgeCheckboxWrapper(checkbox, check, readOnly, formLayout);
layoutCont.add(wrapper.getCheckboxEl());
wrappers.add(wrapper);
}
layoutCont.contextPut("checkboxList", wrappers);
if (withScore || withPassed) {
layoutCont.contextPut("enableScoreInfo", Boolean.TRUE);
exposeConfigToVC(ureq, layoutCont);
exposeUserDataToVC(ureq, layoutCont);
} else {
layoutCont.contextPut("enableScoreInfo", Boolean.FALSE);
}
}
}
use of org.olat.course.nodes.cl.model.DBCheck in project OpenOLAT by OpenOLAT.
the class AssessedIdentityCheckListController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
if (formLayout instanceof FormLayoutContainer) {
FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
List<DBCheck> checks = checkboxManager.loadCheck(assessedIdentity, courseOres, courseNode.getIdent());
Map<String, DBCheck> uuidToCheckMap = new HashMap<>();
for (DBCheck check : checks) {
uuidToCheckMap.put(check.getCheckbox().getCheckboxId(), check);
}
List<Checkbox> list = checkboxList.getList();
wrappers = new ArrayList<>(list.size());
for (Checkbox checkbox : list) {
DBCheck check = uuidToCheckMap.get(checkbox.getCheckboxId());
boolean readOnly = false;
CheckboxWrapper wrapper = forgeCheckboxWrapper(checkbox, check, readOnly, formLayout);
wrappers.add(wrapper);
}
layoutCont.contextPut("checkboxList", wrappers);
}
FormLayoutContainer buttonCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
formLayout.add(buttonCont);
FormSubmit saveButton = uifactory.addFormSubmitButton("save", "save", buttonCont);
saveButton.setEnabled(checkboxList.getNumOfCheckbox() > 0);
saveButton.setVisible(!coachCourseEnv.isCourseReadOnly());
saveAndCloseLink = uifactory.addFormLink("save.close", buttonCont, Link.BUTTON);
saveAndCloseLink.setEnabled(checkboxList.getNumOfCheckbox() > 0);
saveAndCloseLink.setVisible(saveAndClose && !coachCourseEnv.isCourseReadOnly());
if (cancel) {
uifactory.addFormCancelButton("cancel", buttonCont, ureq, getWindowControl());
}
}
use of org.olat.course.nodes.cl.model.DBCheck in project OpenOLAT by OpenOLAT.
the class CheckboxManagerImpl method check.
@Override
public void check(OLATResourceable ores, String resSubPath, List<AssessmentBatch> batch) {
Collections.sort(batch, new BatchComparator());
EntityManager em = dbInstance.getCurrentEntityManager();
Set<String> dbBoxUuids = new HashSet<>();
for (AssessmentBatch row : batch) {
dbBoxUuids.add(row.getCheckboxId());
}
List<DBCheckbox> boxes = loadCheckbox(ores, resSubPath, dbBoxUuids);
Map<String, DBCheckbox> uuidToBox = new HashMap<>();
for (DBCheckbox box : boxes) {
uuidToBox.put(box.getCheckboxId(), box);
}
Identity currentIdentity = null;
for (AssessmentBatch row : batch) {
Long identityKey = row.getIdentityKey();
if (currentIdentity == null || !identityKey.equals(currentIdentity.getKey())) {
currentIdentity = em.getReference(IdentityImpl.class, identityKey);
}
boolean check = row.getCheck();
DBCheckbox checkbox = uuidToBox.get(row.getCheckboxId());
DBCheck currentCheck = loadCheck(checkbox, currentIdentity);
if (check) {
if (currentCheck == null) {
DBCheckbox lockedCheckbox = loadForUpdate(checkbox);
if (lockedCheckbox != null) {
// locked -> reload to make sure nobody create it
DBCheck reloaedCheck = loadCheck(checkbox, currentIdentity);
if (reloaedCheck == null) {
createCheck(lockedCheckbox, currentIdentity, row.getScore(), new Boolean(check));
} else {
currentCheck = reloaedCheck;
}
}
dbInstance.commit();
}
if (currentCheck != null) {
currentCheck.setScore(row.getScore());
currentCheck.setChecked(new Boolean(check));
em.merge(currentCheck);
}
// save check
} else if (currentCheck != null) {
currentCheck.setChecked(Boolean.FALSE);
currentCheck.setScore(new Float(0f));
em.merge(currentCheck);
}
}
}
Aggregations