use of org.olat.course.nodes.cl.model.DBCheckbox 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);
}
}
}
use of org.olat.course.nodes.cl.model.DBCheckbox in project openolat by klemens.
the class CheckListRunController method doCheck.
private boolean doCheck(UserRequest ureq, CheckboxWrapper wrapper, boolean checked) {
DBCheckbox theOne;
if (wrapper.getDbCheckbox() == null) {
String uuid = wrapper.getCheckbox().getCheckboxId();
theOne = checkboxManager.loadCheckbox(courseOres, courseNode.getIdent(), uuid);
} else {
theOne = wrapper.getDbCheckbox();
}
if (theOne == null) {
// only warning because this happen in course preview
logWarn("A checkbox is missing: " + courseOres + " / " + courseNode.getIdent(), null);
} else {
Float score;
if (checked) {
score = wrapper.getCheckbox().getPoints();
} else {
score = 0f;
}
checkboxManager.check(theOne, getIdentity(), score, Boolean.valueOf(checked));
// make sure all results is on the database before calculating some scores
// manager commit already
courseNode.updateScoreEvaluation(getIdentity(), userCourseEnv, getIdentity(), Role.user);
Checkbox checkbox = wrapper.getCheckbox();
logUpdateCheck(checkbox.getCheckboxId(), checkbox.getTitle());
}
exposeUserDataToVC(ureq, flc);
return courseNode.hasScoreConfigured() || courseNode.hasPassedConfigured();
}
use of org.olat.course.nodes.cl.model.DBCheckbox in project openolat by klemens.
the class CheckboxManagerImpl method syncCheckbox.
@Override
public void syncCheckbox(CheckboxList checkboxList, OLATResourceable ores, String resSubPath) {
List<DBCheckbox> dbCheckboxList = loadCheckbox(ores, resSubPath);
Map<String, DBCheckbox> uuids = new HashMap<String, DBCheckbox>();
for (DBCheckbox dbCheckbox : dbCheckboxList) {
uuids.put(dbCheckbox.getCheckboxId(), dbCheckbox);
}
if (checkboxList != null && checkboxList.getList() != null) {
List<Checkbox> resCheckboxList = checkboxList.getList();
for (Checkbox resCheckbox : resCheckboxList) {
String resUuid = resCheckbox.getCheckboxId();
if (uuids.containsKey(resUuid)) {
// already synched
uuids.remove(resUuid);
} else {
createDBCheckbox(resUuid, ores, resSubPath);
}
}
}
for (DBCheckbox dbCheckbox : uuids.values()) {
System.out.println("Remove them??? " + dbCheckbox.getCheckboxId());
}
}
use of org.olat.course.nodes.cl.model.DBCheckbox in project openolat by klemens.
the class CheckboxManagerImpl method check.
@Override
public void check(DBCheckbox checkbox, Identity owner, Float score, Boolean checked) {
DBCheck currentCheck = loadCheck(checkbox, owner);
if (currentCheck == null) {
DBCheckbox lockedCheckbox = loadForUpdate(checkbox);
if (lockedCheckbox != null) {
// locked -> reload to make sure nobody create it
DBCheck reloadedCheck = loadCheck(checkbox, owner);
if (reloadedCheck == null) {
createCheck(lockedCheckbox, owner, score, checked);
} else {
currentCheck = reloadedCheck;
}
}
}
if (currentCheck != null) {
currentCheck.setScore(score);
currentCheck.setChecked(checked);
}
dbInstance.commit();
}
use of org.olat.course.nodes.cl.model.DBCheckbox in project openolat by klemens.
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