Search in sources :

Example 1 with TaskDefinitionList

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

the class GTAManagerImpl method getTaskDefinitions.

@Override
public List<TaskDefinition> getTaskDefinitions(CourseEnvironment courseEnv, GTACourseNode cNode) {
    Path taskDefinitionsPath = Paths.get(FolderConfig.getCanonicalRoot(), courseEnv.getCourseBaseContainer().getRelPath(), "gtasks", cNode.getIdent(), TASKS_DEFINITIONS);
    List<TaskDefinition> taskDefinitions = new ArrayList<>();
    if (Files.exists(taskDefinitionsPath)) {
        TaskDefinitionList taskDefinitionsList = (TaskDefinitionList) taskDefinitionsXstream.fromXML(taskDefinitionsPath.toFile());
        if (taskDefinitionsList != null && taskDefinitionsList.getTasks() != null) {
            taskDefinitions.addAll(taskDefinitionsList.getTasks());
        }
    } else {
        syncWithTaskList(courseEnv, cNode, new TaskListSynched() {

            @Override
            public void sync() {
                ModuleConfiguration config = cNode.getModuleConfiguration();
                TaskDefinitionList tasks = (TaskDefinitionList) config.get(GTACourseNode.GTASK_TASKS);
                if (tasks != null) {
                    taskDefinitions.addAll(tasks.getTasks());
                }
                storeTaskDefinitions(taskDefinitions, courseEnv, cNode);
            }
        });
    }
    return taskDefinitions;
}
Also used : Path(java.nio.file.Path) TaskDefinition(org.olat.course.nodes.gta.model.TaskDefinition) ModuleConfiguration(org.olat.modules.ModuleConfiguration) ArrayList(java.util.ArrayList) TaskDefinitionList(org.olat.course.nodes.gta.model.TaskDefinitionList)

Example 2 with TaskDefinitionList

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

the class GTAManagerImpl method storeTaskDefinitions.

private void storeTaskDefinitions(List<TaskDefinition> taskDefinitions, CourseEnvironment courseEnv, GTACourseNode cNode) {
    TaskDefinitionList list = new TaskDefinitionList();
    list.setTasks(taskDefinitions);
    Path taskDefinitionsPath = Paths.get(FolderConfig.getCanonicalRoot(), courseEnv.getCourseBaseContainer().getRelPath(), "gtasks", cNode.getIdent(), TASKS_DEFINITIONS);
    XStreamHelper.writeObject(taskDefinitionsXstream, taskDefinitionsPath.toFile(), list);
}
Also used : Path(java.nio.file.Path) TaskDefinitionList(org.olat.course.nodes.gta.model.TaskDefinitionList)

Example 3 with TaskDefinitionList

use of org.olat.course.nodes.gta.model.TaskDefinitionList in project OpenOLAT by OpenOLAT.

the class GTAManagerImpl method getTaskDefinitions.

@Override
public List<TaskDefinition> getTaskDefinitions(CourseEnvironment courseEnv, GTACourseNode cNode) {
    Path taskDefinitionsPath = Paths.get(FolderConfig.getCanonicalRoot(), courseEnv.getCourseBaseContainer().getRelPath(), "gtasks", cNode.getIdent(), TASKS_DEFINITIONS);
    List<TaskDefinition> taskDefinitions = new ArrayList<>();
    if (Files.exists(taskDefinitionsPath)) {
        TaskDefinitionList taskDefinitionsList = (TaskDefinitionList) taskDefinitionsXstream.fromXML(taskDefinitionsPath.toFile());
        if (taskDefinitionsList != null && taskDefinitionsList.getTasks() != null) {
            taskDefinitions.addAll(taskDefinitionsList.getTasks());
        }
    } else {
        syncWithTaskList(courseEnv, cNode, new TaskListSynched() {

            @Override
            public void sync() {
                ModuleConfiguration config = cNode.getModuleConfiguration();
                TaskDefinitionList tasks = (TaskDefinitionList) config.get(GTACourseNode.GTASK_TASKS);
                if (tasks != null) {
                    taskDefinitions.addAll(tasks.getTasks());
                }
                storeTaskDefinitions(taskDefinitions, courseEnv, cNode);
            }
        });
    }
    return taskDefinitions;
}
Also used : Path(java.nio.file.Path) TaskDefinition(org.olat.course.nodes.gta.model.TaskDefinition) ModuleConfiguration(org.olat.modules.ModuleConfiguration) ArrayList(java.util.ArrayList) TaskDefinitionList(org.olat.course.nodes.gta.model.TaskDefinitionList)

Example 4 with TaskDefinitionList

use of org.olat.course.nodes.gta.model.TaskDefinitionList in project OpenOLAT by OpenOLAT.

the class GTAManagerImpl method storeTaskDefinitions.

private void storeTaskDefinitions(List<TaskDefinition> taskDefinitions, CourseEnvironment courseEnv, GTACourseNode cNode) {
    TaskDefinitionList list = new TaskDefinitionList();
    list.setTasks(taskDefinitions);
    Path taskDefinitionsPath = Paths.get(FolderConfig.getCanonicalRoot(), courseEnv.getCourseBaseContainer().getRelPath(), "gtasks", cNode.getIdent(), TASKS_DEFINITIONS);
    XStreamHelper.writeObject(taskDefinitionsXstream, taskDefinitionsPath.toFile(), list);
}
Also used : Path(java.nio.file.Path) TaskDefinitionList(org.olat.course.nodes.gta.model.TaskDefinitionList)

Example 5 with TaskDefinitionList

use of org.olat.course.nodes.gta.model.TaskDefinitionList in project OpenOLAT by OpenOLAT.

the class ConvertToGTACourseNode method convertTasks.

private void convertTasks(TaskList taskList, TACourseNode sourceNode, GTACourseNode gtaNode, ICourse course) {
    File taskFolder = new File(FolderConfig.getCanonicalRoot(), TACourseNode.getTaskFolderPathRelToFolderRoot(course, sourceNode));
    OlatRootFolderImpl taskContainer = new OlatRootFolderImpl(TACourseNode.getTaskFolderPathRelToFolderRoot(course, sourceNode), null);
    CourseEnvironment courseEnv = course.getCourseEnvironment();
    File gtaskDirectory = gtaManager.getTasksDirectory(courseEnv, gtaNode);
    VFSContainer gtaskContainer = gtaManager.getTasksContainer(courseEnv, gtaNode);
    // make the task
    TaskDefinitionList taskDefs = new TaskDefinitionList();
    for (File task : taskFolder.listFiles(SystemFileFilter.FILES_ONLY)) {
        TaskDefinition taskDef = new TaskDefinition();
        taskDef.setDescription("");
        taskDef.setFilename(task.getName());
        taskDef.setTitle(task.getName());
        taskDefs.getTasks().add(taskDef);
        try {
            File target = new File(gtaskDirectory, task.getName());
            Files.copy(task.toPath(), target.toPath(), StandardCopyOption.REPLACE_EXISTING);
            convertMetada(taskContainer, gtaskContainer, task.getName(), taskDef, null);
        } catch (Exception ex) {
            log.error("", ex);
        }
        List<Property> samples = courseEnv.getCoursePropertyManager().listCourseNodeProperties(sourceNode, null, null, TaskController.PROP_ASSIGNED);
        for (Property sample : samples) {
            File taskFile = new File(gtaskDirectory, sample.getStringValue());
            Identity id = securityManager.loadIdentityByKey(sample.getIdentity().getKey());
            gtaManager.selectTask(id, taskList, gtaNode, taskFile);
        }
    }
    gtaNode.getModuleConfiguration().set(GTACourseNode.GTASK_TASKS, taskDefs);
}
Also used : TaskDefinition(org.olat.course.nodes.gta.model.TaskDefinition) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) VFSContainer(org.olat.core.util.vfs.VFSContainer) TaskDefinitionList(org.olat.course.nodes.gta.model.TaskDefinitionList) Identity(org.olat.core.id.Identity) File(java.io.File) Property(org.olat.properties.Property)

Aggregations

TaskDefinitionList (org.olat.course.nodes.gta.model.TaskDefinitionList)6 Path (java.nio.file.Path)4 TaskDefinition (org.olat.course.nodes.gta.model.TaskDefinition)4 File (java.io.File)2 ArrayList (java.util.ArrayList)2 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)2 Identity (org.olat.core.id.Identity)2 VFSContainer (org.olat.core.util.vfs.VFSContainer)2 CourseEnvironment (org.olat.course.run.environment.CourseEnvironment)2 UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)2 ModuleConfiguration (org.olat.modules.ModuleConfiguration)2 Property (org.olat.properties.Property)2