Search in sources :

Example 21 with GTAManager

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

the class GTACourseNode method createInstanceForCopy.

@Override
public CourseNode createInstanceForCopy(boolean isNewTitle, ICourse course, Identity author) {
    GTACourseNode cNode = (GTACourseNode) super.createInstanceForCopy(isNewTitle, course, author);
    GTAManager gtaManager = CoreSpringFactory.getImpl(GTAManager.class);
    // copy tasks
    File taskDirectory = gtaManager.getTasksDirectory(course.getCourseEnvironment(), this);
    File copyTaskDirectory = gtaManager.getTasksDirectory(course.getCourseEnvironment(), cNode);
    FileUtils.copyDirContentsToDir(taskDirectory, copyTaskDirectory, false, "copy task course node");
    File taskDefinitions = new File(taskDirectory.getParentFile(), GTAManager.TASKS_DEFINITIONS);
    if (taskDefinitions.exists()) {
        File copyTaskDefinitions = new File(copyTaskDirectory.getParentFile(), GTAManager.TASKS_DEFINITIONS);
        FileUtils.copyFileToFile(taskDefinitions, copyTaskDefinitions, false);
    }
    // copy solutions
    File solutionsDirectory = gtaManager.getSolutionsDirectory(course.getCourseEnvironment(), this);
    File copySolutionsDirectory = gtaManager.getSolutionsDirectory(course.getCourseEnvironment(), cNode);
    FileUtils.copyDirContentsToDir(solutionsDirectory, copySolutionsDirectory, false, "copy task course node solutions");
    File solutionDefinitions = new File(solutionsDirectory.getParentFile(), GTAManager.SOLUTIONS_DEFINITIONS);
    if (solutionDefinitions.exists()) {
        File copySolutionDefinitions = new File(copySolutionsDirectory.getParentFile(), GTAManager.SOLUTIONS_DEFINITIONS);
        FileUtils.copyFileToFile(solutionDefinitions, copySolutionDefinitions, false);
    }
    return cNode;
}
Also used : GTAManager(org.olat.course.nodes.gta.GTAManager) File(java.io.File)

Example 22 with GTAManager

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

the class GTACourseNode method postCopy.

@Override
public void postCopy(CourseEnvironmentMapper envMapper, Processing processType, ICourse course, ICourse sourceCourse) {
    super.postCopy(envMapper, processType, course, sourceCourse);
    // change groups and areas mapping
    postImportCopy(envMapper);
    GTAManager gtaManager = CoreSpringFactory.getImpl(GTAManager.class);
    // copy tasks
    File sourceTaskDirectory = gtaManager.getTasksDirectory(sourceCourse.getCourseEnvironment(), this);
    File copyTaskDirectory = gtaManager.getTasksDirectory(course.getCourseEnvironment(), this);
    FileUtils.copyDirContentsToDir(sourceTaskDirectory, copyTaskDirectory, false, "copy task course node");
    File taskDefinitions = new File(sourceTaskDirectory.getParentFile(), GTAManager.TASKS_DEFINITIONS);
    if (taskDefinitions.exists()) {
        File copyTaskDefinitions = new File(copyTaskDirectory.getParentFile(), GTAManager.TASKS_DEFINITIONS);
        FileUtils.copyFileToFile(taskDefinitions, copyTaskDefinitions, false);
    }
    // copy solutions
    File sourceSolutionsDirectory = gtaManager.getSolutionsDirectory(sourceCourse.getCourseEnvironment(), this);
    File copySolutionsDirectory = gtaManager.getSolutionsDirectory(course.getCourseEnvironment(), this);
    FileUtils.copyDirContentsToDir(sourceSolutionsDirectory, copySolutionsDirectory, false, "copy task course node solutions");
    File solutionDefinitions = new File(sourceSolutionsDirectory.getParentFile(), GTAManager.SOLUTIONS_DEFINITIONS);
    if (solutionDefinitions.exists()) {
        File copySolutionDefinitions = new File(copySolutionsDirectory.getParentFile(), GTAManager.SOLUTIONS_DEFINITIONS);
        FileUtils.copyFileToFile(solutionDefinitions, copySolutionDefinitions, false);
    }
    RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    gtaManager.createIfNotExists(entry, this);
}
Also used : GTAManager(org.olat.course.nodes.gta.GTAManager) RepositoryEntry(org.olat.repository.RepositoryEntry) File(java.io.File)

Example 23 with GTAManager

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

the class GTACourseNode method importNode.

@Override
public void importNode(File importDirectory, ICourse course, Identity owner, Locale locale, boolean withReferences) {
    File fNodeImportDir = new File(importDirectory, getIdent());
    GTAManager gtaManager = CoreSpringFactory.getImpl(GTAManager.class);
    // import tasks
    File tasksImportDir = new File(fNodeImportDir, "tasks");
    File taskDirectory = gtaManager.getTasksDirectory(course.getCourseEnvironment(), this);
    FileUtils.copyDirContentsToDir(tasksImportDir, taskDirectory, false, "import task course node");
    File taskDefinitions = new File(tasksImportDir.getParentFile(), GTAManager.TASKS_DEFINITIONS);
    if (taskDefinitions.exists()) {
        File copyTaskDefinitions = new File(taskDirectory.getParentFile(), GTAManager.TASKS_DEFINITIONS);
        FileUtils.copyFileToFile(taskDefinitions, copyTaskDefinitions, false);
    }
    // import solutions
    File fSolImportDir = new File(fNodeImportDir, "solutions");
    File solutionsDirectory = gtaManager.getSolutionsDirectory(course.getCourseEnvironment(), this);
    FileUtils.copyDirContentsToDir(fSolImportDir, solutionsDirectory, false, "import task course node solutions");
    File solutionDefinitions = new File(fSolImportDir.getParentFile(), GTAManager.SOLUTIONS_DEFINITIONS);
    if (solutionDefinitions.exists()) {
        File copySolutionDefinitions = new File(solutionsDirectory.getParentFile(), GTAManager.SOLUTIONS_DEFINITIONS);
        FileUtils.copyFileToFile(solutionDefinitions, copySolutionDefinitions, false);
    }
    RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    gtaManager.createIfNotExists(entry, this);
}
Also used : GTAManager(org.olat.course.nodes.gta.GTAManager) RepositoryEntry(org.olat.repository.RepositoryEntry) File(java.io.File)

Example 24 with GTAManager

use of org.olat.course.nodes.gta.GTAManager 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)

Aggregations

GTAManager (org.olat.course.nodes.gta.GTAManager)24 File (java.io.File)16 RepositoryEntry (org.olat.repository.RepositoryEntry)10 Identity (org.olat.core.id.Identity)8 ModuleConfiguration (org.olat.modules.ModuleConfiguration)8 TaskList (org.olat.course.nodes.gta.TaskList)6 OutputStream (java.io.OutputStream)4 Date (java.util.Date)4 ZipEntry (java.util.zip.ZipEntry)4 ZipOutputStream (java.util.zip.ZipOutputStream)4 ShieldOutputStream (org.olat.core.util.io.ShieldOutputStream)4 VFSContainer (org.olat.core.util.vfs.VFSContainer)4 VFSItem (org.olat.core.util.vfs.VFSItem)4 ICourse (org.olat.course.ICourse)4 Task (org.olat.course.nodes.gta.Task)4 BusinessGroup (org.olat.group.BusinessGroup)4 BusinessGroupService (org.olat.group.BusinessGroupService)4 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 IdentityRef (org.olat.basesecurity.IdentityRef)2