Search in sources :

Example 11 with BulkAssessmentRow

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);
}
Also used : BulkAssessmentDatas(org.olat.course.assessment.model.BulkAssessmentDatas) ArrayList(java.util.ArrayList) BulkAssessmentRow(org.olat.course.assessment.model.BulkAssessmentRow)

Example 12 with BulkAssessmentRow

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();
}
Also used : ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) BulkAssessmentRow(org.olat.course.assessment.model.BulkAssessmentRow)

Example 13 with BulkAssessmentRow

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);
        }
    }
}
Also used : Path(java.nio.file.Path) ZipInputStream(java.util.zip.ZipInputStream) HashMap(java.util.HashMap) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) BulkAssessmentRow(org.olat.course.assessment.model.BulkAssessmentRow) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 14 with BulkAssessmentRow

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);
        }
    }
}
Also used : BulkAssessmentRow(org.olat.course.assessment.model.BulkAssessmentRow)

Aggregations

BulkAssessmentRow (org.olat.course.assessment.model.BulkAssessmentRow)14 ArrayList (java.util.ArrayList)6 BulkAssessmentDatas (org.olat.course.assessment.model.BulkAssessmentDatas)6 File (java.io.File)4 FileNotFoundException (java.io.FileNotFoundException)4 HashMap (java.util.HashMap)4 Identity (org.olat.core.id.Identity)4 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Path (java.nio.file.Path)2 ZipEntry (java.util.zip.ZipEntry)2 ZipInputStream (java.util.zip.ZipInputStream)2 BaseSecurity (org.olat.basesecurity.BaseSecurity)2 OlatRootFileImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFileImpl)2 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)2 DB (org.olat.core.commons.persistence.DB)2 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)2 Roles (org.olat.core.id.Roles)2 ICourse (org.olat.course.ICourse)2