Search in sources :

Example 26 with TaskDefinition

use of org.olat.course.nodes.gta.model.TaskDefinition in project openolat by klemens.

the class NewTaskController method getTaskDefinition.

public TaskDefinition getTaskDefinition() {
    TaskDefinition taskDef = new TaskDefinition();
    taskDef.setTitle(titleEl.getValue());
    taskDef.setFilename(getFilename());
    taskDef.setDescription(descriptionEl.getValue());
    return taskDef;
}
Also used : TaskDefinition(org.olat.course.nodes.gta.model.TaskDefinition)

Example 27 with TaskDefinition

use of org.olat.course.nodes.gta.model.TaskDefinition in project openolat by klemens.

the class GTACourseNode method validateInternalConfiguration.

private List<StatusDescription> validateInternalConfiguration(CourseEditorEnv cev) {
    List<StatusDescription> sdList = new ArrayList<>(5);
    ModuleConfiguration config = getModuleConfiguration();
    boolean hasScoring = config.getBooleanSafe(GTASK_GRADING);
    if (hasScoring) {
        if (!config.getBooleanSafe(MSCourseNode.CONFIG_KEY_HAS_SCORE_FIELD) && !config.getBooleanSafe(MSCourseNode.CONFIG_KEY_HAS_PASSED_FIELD) && !config.getBooleanSafe(MSCourseNode.CONFIG_KEY_HAS_COMMENT_FIELD)) {
            addStatusErrorDescription("error.missing.score.config", GTAEditController.PANE_TAB_GRADING, sdList);
        }
    }
    if (GTAType.group.name().equals(config.getStringValue(GTACourseNode.GTASK_TYPE))) {
        List<Long> groupKeys = config.getList(GTACourseNode.GTASK_GROUPS, Long.class);
        List<Long> areaKeys = config.getList(GTACourseNode.GTASK_AREAS, Long.class);
        if (groupKeys.isEmpty() && areaKeys.isEmpty()) {
            addStatusErrorDescription("error.missing.group", GTAEditController.PANE_TAB_GRADING, sdList);
        }
    }
    // at least one step
    if (!config.getBooleanSafe(GTACourseNode.GTASK_ASSIGNMENT) && !config.getBooleanSafe(GTACourseNode.GTASK_SUBMIT) && !config.getBooleanSafe(GTACourseNode.GTASK_REVIEW_AND_CORRECTION) && !config.getBooleanSafe(GTACourseNode.GTASK_REVISION_PERIOD) && !config.getBooleanSafe(GTACourseNode.GTASK_SAMPLE_SOLUTION) && !config.getBooleanSafe(GTACourseNode.GTASK_GRADING)) {
        addStatusErrorDescription("error.select.atleastonestep", GTAEditController.PANE_TAB_WORKLOW, sdList);
    }
    if (cev != null) {
        // check assignment
        GTAManager gtaManager = CoreSpringFactory.getImpl(GTAManager.class);
        RepositoryEntry courseRe = cev.getCourseGroupManager().getCourseEntry();
        ICourse course = CourseFactory.loadCourse(courseRe);
        if (config.getBooleanSafe(GTACourseNode.GTASK_ASSIGNMENT)) {
            File taskDirectory = gtaManager.getTasksDirectory(course.getCourseEnvironment(), this);
            if (!TaskHelper.hasDocuments(taskDirectory)) {
                if (config.getBooleanSafe(GTACourseNode.GTASK_COACH_ALLOWED_UPLOAD_TASKS, false)) {
                    addStatusWarningDescription("error.missing.tasks", GTAEditController.PANE_TAB_ASSIGNMENT, sdList);
                } else {
                    addStatusErrorDescription("error.missing.tasks", GTAEditController.PANE_TAB_ASSIGNMENT, sdList);
                }
            } else {
                List<TaskDefinition> taskList = gtaManager.getTaskDefinitions(course.getCourseEnvironment(), this);
                if (taskList == null || taskList.isEmpty()) {
                    if (config.getBooleanSafe(GTACourseNode.GTASK_COACH_ALLOWED_UPLOAD_TASKS, false)) {
                        addStatusWarningDescription("error.missing.tasks", GTAEditController.PANE_TAB_ASSIGNMENT, sdList);
                    } else {
                        addStatusErrorDescription("error.missing.tasks", GTAEditController.PANE_TAB_ASSIGNMENT, sdList);
                    }
                } else {
                    String[] filenames = taskDirectory.list();
                    for (TaskDefinition taskDef : taskList) {
                        boolean found = false;
                        for (String filename : filenames) {
                            if (filename.equals(taskDef.getFilename())) {
                                found = true;
                                break;
                            }
                        }
                        if (!found) {
                            addStatusWarningDescription("error.missing.file", GTAEditController.PANE_TAB_ASSIGNMENT, sdList);
                        }
                    }
                }
            }
        }
        // check solutions
        if (config.getBooleanSafe(GTACourseNode.GTASK_SAMPLE_SOLUTION)) {
            File solutionDirectory = gtaManager.getSolutionsDirectory(course.getCourseEnvironment(), this);
            if (!TaskHelper.hasDocuments(solutionDirectory)) {
                if (config.getBooleanSafe(GTACourseNode.GTASK_COACH_ALLOWED_UPLOAD_TASKS, false)) {
                    addStatusWarningDescription("error.missing.solutions", GTAEditController.PANE_TAB_SOLUTIONS, sdList);
                } else {
                    addStatusErrorDescription("error.missing.solutions", GTAEditController.PANE_TAB_SOLUTIONS, sdList);
                }
            }
        }
        List<IdentityRef> participants = gtaManager.getDuplicatedMemberships(this);
        if (participants.size() > 0) {
            UserManager um = CoreSpringFactory.getImpl(UserManager.class);
            StringBuilder sb = new StringBuilder();
            for (IdentityRef participant : participants) {
                String fullname = um.getUserDisplayName(participant.getKey());
                if (sb.length() > 0)
                    sb.append(", ");
                sb.append(fullname);
            }
            String[] params = new String[] { getShortTitle(), sb.toString() };
            StatusDescription sd = new StatusDescription(StatusDescription.WARNING, "error.duplicate.memberships", "error.duplicate.memberships", params, PACKAGE_GTA);
            sd.setDescriptionForUnit(getIdent());
            sd.setActivateableViewIdentifier(GTAEditController.PANE_TAB_WORKLOW);
            sdList.add(sd);
        }
    }
    return sdList;
}
Also used : ModuleConfiguration(org.olat.modules.ModuleConfiguration) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) TaskDefinition(org.olat.course.nodes.gta.model.TaskDefinition) StatusDescription(org.olat.course.editor.StatusDescription) UserManager(org.olat.user.UserManager) IdentityRef(org.olat.basesecurity.IdentityRef) GTAManager(org.olat.course.nodes.gta.GTAManager) File(java.io.File)

Example 28 with TaskDefinition

use of org.olat.course.nodes.gta.model.TaskDefinition in project openolat by klemens.

the class GTACoachController method getTaskDefinition.

private TaskDefinition getTaskDefinition(Task task) {
    if (task == null)
        return null;
    TaskDefinition taskDef = null;
    List<TaskDefinition> availableTasks = gtaManager.getTaskDefinitions(courseEnv, gtaNode);
    for (TaskDefinition availableTask : availableTasks) {
        if (availableTask.getFilename() != null && availableTask.getFilename().equals(task.getTaskName())) {
            taskDef = availableTask;
            break;
        }
    }
    return taskDef;
}
Also used : TaskDefinition(org.olat.course.nodes.gta.model.TaskDefinition)

Example 29 with TaskDefinition

use of org.olat.course.nodes.gta.model.TaskDefinition in project openolat by klemens.

the class EditTaskController method validateFormLogic.

@Override
protected boolean validateFormLogic(UserRequest ureq) {
    boolean allOk = true;
    titleEl.clearError();
    if (!StringHelper.containsNonWhitespace(titleEl.getValue())) {
        titleEl.setErrorKey("form.mandatory.hover", null);
        allOk &= false;
    }
    fileEl.clearError();
    if (fileEl.getInitialFile() == null && fileEl.getUploadFile() == null) {
        fileEl.setErrorKey("form.mandatory.hover", null);
        allOk &= false;
    } else if (!FileUtils.validateFilename(fileEl.getUploadFileName())) {
        fileEl.setErrorKey("error.file.invalid", null);
        allOk = false;
    } else if (!replaceFile && fileEl.getUploadFile() != null) {
        String filename = fileEl.getUploadFileName();
        File target = new File(taskContainer, filename);
        if (target.exists()) {
            fileEl.setErrorKey("error.file.exists", new String[] { filename });
            allOk &= false;
        }
    } else if (replaceFile && fileEl.getUploadFile() != null) {
        String filename = fileEl.getUploadFileName();
        if (currentDefinitions != null) {
            for (TaskDefinition definition : currentDefinitions) {
                if (filename.equals(definition.getFilename()) && !task.getTitle().equals(definition.getTitle())) {
                    fileEl.setErrorKey("error.file.exists", new String[] { filename });
                    allOk &= false;
                }
            }
        }
    }
    return allOk & super.validateFormLogic(ureq);
}
Also used : TaskDefinition(org.olat.course.nodes.gta.model.TaskDefinition) File(java.io.File)

Example 30 with TaskDefinition

use of org.olat.course.nodes.gta.model.TaskDefinition in project openolat by klemens.

the class EditTaskController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    task.setTitle(titleEl.getValue());
    task.setDescription(descriptionEl.getValue());
    if (fileEl.getUploadFile() != null) {
        if (replaceFile && StringHelper.containsNonWhitespace(task.getFilename())) {
            int usage = 0;
            if (currentDefinitions != null) {
                for (TaskDefinition definition : currentDefinitions) {
                    if (task.getFilename().equals(definition.getFilename())) {
                        usage++;
                    }
                }
            }
            if (usage == 1) {
                File currentFile = new File(taskContainer, task.getFilename());
                if (currentFile.exists()) {
                    currentFile.delete();
                }
            }
        }
        String filename = fileEl.getUploadFileName();
        task.setFilename(filename);
        try {
            Path upload = fileEl.getUploadFile().toPath();
            File target = new File(taskContainer, filename);
            Files.move(upload, target.toPath(), StandardCopyOption.REPLACE_EXISTING);
        } catch (Exception ex) {
            logError("", ex);
        }
    }
    fireEvent(ureq, Event.DONE_EVENT);
}
Also used : Path(java.nio.file.Path) TaskDefinition(org.olat.course.nodes.gta.model.TaskDefinition) File(java.io.File)

Aggregations

TaskDefinition (org.olat.course.nodes.gta.model.TaskDefinition)32 File (java.io.File)10 ArrayList (java.util.ArrayList)8 Path (java.nio.file.Path)4 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)4 TaskDefinitionList (org.olat.course.nodes.gta.model.TaskDefinitionList)4 ModuleConfiguration (org.olat.modules.ModuleConfiguration)4 IdentityRef (org.olat.basesecurity.IdentityRef)2 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)2 FormItem (org.olat.core.gui.components.form.flexible.FormItem)2 DownloadLink (org.olat.core.gui.components.form.flexible.elements.DownloadLink)2 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)2 Identity (org.olat.core.id.Identity)2 VFSContainer (org.olat.core.util.vfs.VFSContainer)2 VFSItem (org.olat.core.util.vfs.VFSItem)2 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)2 ICourse (org.olat.course.ICourse)2 StatusDescription (org.olat.course.editor.StatusDescription)2 GTAManager (org.olat.course.nodes.gta.GTAManager)2 CourseEnvironment (org.olat.course.run.environment.CourseEnvironment)2