use of org.olat.course.assessment.model.BulkAssessmentRow in project openolat by klemens.
the class ValidationStepForm method formOK.
@Override
protected void formOK(UserRequest ureq) {
if (validModel.getRowCount() == 0) {
// do not continue wizard without valid data
return;
}
BulkAssessmentDatas datas = (BulkAssessmentDatas) getFromRunContext("datas");
List<BulkAssessmentRow> rows = new ArrayList<>(validModel.getRowCount() + invalidModel.getRowCount());
for (int i = validModel.getRowCount(); i-- > 0; ) {
rows.add(validModel.getObject(i).getRow());
}
for (int i = invalidModel.getRowCount(); i-- > 0; ) {
rows.add(invalidModel.getObject(i).getRow());
}
datas.setRows(rows);
addToRunContext("datas", datas);
fireEvent(ureq, StepsEvent.ACTIVATE_NEXT);
}
use of org.olat.course.assessment.model.BulkAssessmentRow in project openolat by klemens.
the class ValidationStepForm method doValidateRows.
private void doValidateRows(BulkAssessmentDatas datas) {
List<BulkAssessmentRow> rows = datas.getRows();
List<String> assessedIdList = new ArrayList<String>(rows.size());
for (BulkAssessmentRow row : rows) {
assessedIdList.add(row.getAssessedId());
}
Map<String, Identity> idToIdentityMap = loadAssessedIdentities(assessedIdList);
List<UserData> validDatas = new ArrayList<UserData>(idToIdentityMap.size());
List<UserData> invalidDatas = new ArrayList<UserData>(rows.size() - idToIdentityMap.size());
for (BulkAssessmentRow row : datas.getRows()) {
Identity foundIdentity = idToIdentityMap.get(row.getAssessedId());
if (foundIdentity == null) {
invalidDatas.add(new UserData(row, null));
} else {
row.setIdentityKey(foundIdentity.getKey());
validDatas.add(new UserData(row, foundIdentity));
}
}
validModel.setObjects(validDatas);
invalidModel.setObjects(invalidDatas);
flc.contextPut("hasValidItems", Boolean.valueOf(validDatas.size() > 0));
flc.contextPut("hasInvalidItems", Boolean.valueOf(invalidDatas.size() > 0));
validTableEl.reset();
invalidTableEl.reset();
}
use of org.olat.course.assessment.model.BulkAssessmentRow in project openolat by klemens.
the class DataStepForm method processReturnFiles.
private void processReturnFiles(VFSLeaf target, List<BulkAssessmentRow> rows) {
Map<String, BulkAssessmentRow> assessedIdToRow = new HashMap<>();
for (BulkAssessmentRow row : rows) {
assessedIdToRow.put(row.getAssessedId(), row);
}
if (target.exists()) {
InputStream is = target.getInputStream();
File parentTarget = ((LocalImpl) target).getBasefile().getParentFile();
ZipInputStream zis = new ZipInputStream(is);
ZipEntry entry;
try {
byte[] b = new byte[FileUtils.BSIZE];
while ((entry = zis.getNextEntry()) != null) {
if (!entry.isDirectory()) {
while (zis.read(b) > 0) {
// continue
}
Path op = new File(parentTarget, entry.getName()).toPath();
if (!Files.isHidden(op) && !Files.isDirectory(op)) {
Path parentDir = op.getParent();
String assessedId = parentDir.getFileName().toString();
String filename = op.getFileName().toString();
BulkAssessmentRow row;
if (assessedIdToRow.containsKey(assessedId)) {
row = assessedIdToRow.get(assessedId);
} else {
row = new BulkAssessmentRow();
row.setAssessedId(assessedId);
assessedIdToRow.put(assessedId, row);
rows.add(row);
}
if (row.getReturnFiles() == null) {
row.setReturnFiles(new ArrayList<String>(2));
}
row.getReturnFiles().add(filename);
}
}
}
} catch (Exception e) {
logError("", e);
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(zis);
}
}
}
use of org.olat.course.assessment.model.BulkAssessmentRow in project openolat by klemens.
the class ChooseColumnsStepForm method createRow.
/**
* Create a row object from an array of strings. The array
* is assessed identity identifier, score, status, comment.
* @param values
* @return
*/
private void createRow(String[] values, BulkAssessmentColumnSettings settings, List<BulkAssessmentRow> rows, Map<String, BulkAssessmentRow> assessedIdToRow) {
int valuesLength = values.length;
if (valuesLength <= 0 || valuesLength <= settings.getUsernameColumn()) {
return;
}
String identifyer = values[settings.getUsernameColumn()];
identifyer.trim();
if (!StringHelper.containsNonWhitespace(identifyer)) {
identifyer = "-";
}
BulkAssessmentRow row;
if (assessedIdToRow.containsKey(identifyer)) {
row = assessedIdToRow.get(identifyer);
} else {
row = new BulkAssessmentRow();
row.setAssessedId(identifyer);
rows.add(row);
}
if (valuesLength > settings.getScoreColumn()) {
String scoreStr = values[settings.getScoreColumn()];
scoreStr = scoreStr.trim();
Float score;
if (StringHelper.containsNonWhitespace(scoreStr)) {
try {
// accept writing with , or .
score = Float.parseFloat(scoreStr.replace(',', '.'));
} catch (NumberFormatException e) {
score = null;
}
} else {
// only set new numbers, ignore everything else
score = null;
}
row.setScore(score);
}
if (valuesLength > settings.getPassedColumn()) {
String passedStr = values[settings.getPassedColumn()];
passedStr = passedStr.trim();
Boolean passed;
if ("y".equalsIgnoreCase(passedStr) || "yes".equalsIgnoreCase(passedStr) || "passed".equalsIgnoreCase(passedStr) || "true".equalsIgnoreCase(passedStr) || "1".equalsIgnoreCase(passedStr)) {
passed = Boolean.TRUE;
} else if ("n".equalsIgnoreCase(passedStr) || "no".equalsIgnoreCase(passedStr) || "false".equalsIgnoreCase(passedStr) || "failed".equalsIgnoreCase(passedStr) || "0".equalsIgnoreCase(passedStr)) {
passed = Boolean.FALSE;
} else {
// only set defined values, ignore everything else
passed = null;
}
row.setPassed(passed);
}
if (valuesLength > settings.getCommentColumn()) {
String commentStr = values[settings.getCommentColumn()];
commentStr = commentStr.trim();
if (commentStr.isEmpty()) {
// ignore empty values
row.setComment(null);
} else if ("\"\"".equals(commentStr) || "''".equals(commentStr)) {
row.setComment("");
} else {
row.setComment(commentStr);
}
}
}
Aggregations