Search in sources :

Example 11 with GTAManager

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

the class GroupBulkDownloadResource method prepare.

@Override
public void prepare(HttpServletResponse hres) {
    try {
        hres.setCharacterEncoding(encoding);
    } catch (Exception e) {
        log.error("", e);
    }
    String label = StringHelper.transformDisplayNameToFileSystemName(courseNode.getShortName()) + "_" + Formatter.formatDatetimeWithMinutes(new Date()) + ".zip";
    String urlEncodedLabel = StringHelper.urlEncodeUTF8(label);
    hres.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + urlEncodedLabel);
    hres.setHeader("Content-Description", urlEncodedLabel);
    try (ZipOutputStream zout = new ZipOutputStream(hres.getOutputStream())) {
        zout.setLevel(9);
        ICourse course = CourseFactory.loadCourse(courseOres);
        GTAManager gtaManager = CoreSpringFactory.getImpl(GTAManager.class);
        if (courseNode.getModuleConfiguration().getBooleanSafe(GTACourseNode.GTASK_GRADING)) {
            List<Identity> assessableIdentities = CoreSpringFactory.getImpl(BusinessGroupService.class).getMembers(groups, GroupRoles.participant.name());
            String courseTitle = course.getCourseTitle();
            String fileName = ExportUtil.createFileNameWithTimeStamp(courseTitle, "xlsx");
            List<AssessableCourseNode> nodes = Collections.<AssessableCourseNode>singletonList(courseNode);
            try (OutputStream out = new ShieldOutputStream(zout)) {
                zout.putNextEntry(new ZipEntry(fileName));
                ScoreAccountingHelper.createCourseResultsOverviewXMLTable(assessableIdentities, nodes, course, locale, out);
                zout.closeEntry();
            } catch (Exception e) {
                log.error("", e);
            }
        }
        TaskList taskList = gtaManager.getTaskList(course.getCourseEnvironment().getCourseGroupManager().getCourseEntry(), courseNode);
        for (BusinessGroup businessGroup : groups) {
            courseNode.archiveNodeData(course, businessGroup, taskList, "", zout);
        }
    } catch (Exception e) {
        log.error("", e);
    }
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) ZipOutputStream(java.util.zip.ZipOutputStream) OutputStream(java.io.OutputStream) ShieldOutputStream(org.olat.core.util.io.ShieldOutputStream) ZipEntry(java.util.zip.ZipEntry) TaskList(org.olat.course.nodes.gta.TaskList) ICourse(org.olat.course.ICourse) Date(java.util.Date) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) ShieldOutputStream(org.olat.core.util.io.ShieldOutputStream) BusinessGroupService(org.olat.group.BusinessGroupService) ZipOutputStream(java.util.zip.ZipOutputStream) GTAManager(org.olat.course.nodes.gta.GTAManager) Identity(org.olat.core.id.Identity)

Example 12 with GTAManager

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

the class BulkAssessmentTask method getReturnBox.

/**
 * Return the target folder of the assessed identity. This is a factory method which take care
 * of the type of the course node.
 *
 * @param uce
 * @param courseNode
 * @param identity
 * @return
 */
private VFSContainer getReturnBox(UserCourseEnvironment uce, CourseNode courseNode, Identity identity) {
    VFSContainer returnContainer = null;
    if (courseNode instanceof GTACourseNode) {
        final GTAManager gtaManager = CoreSpringFactory.getImpl(GTAManager.class);
        CourseEnvironment courseEnv = uce.getCourseEnvironment();
        returnContainer = gtaManager.getCorrectionContainer(courseEnv, (GTACourseNode) courseNode, identity);
    } else {
        String returnPath = ReturnboxController.getReturnboxPathRelToFolderRoot(uce.getCourseEnvironment(), courseNode);
        OlatRootFolderImpl rootFolder = new OlatRootFolderImpl(returnPath, null);
        VFSItem assessedItem = rootFolder.resolve(identity.getName());
        if (assessedItem == null) {
            returnContainer = rootFolder.createChildContainer(identity.getName());
        } else if (assessedItem instanceof VFSContainer) {
            returnContainer = (VFSContainer) assessedItem;
        }
    }
    return returnContainer;
}
Also used : OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) VFSContainer(org.olat.core.util.vfs.VFSContainer) GTACourseNode(org.olat.course.nodes.GTACourseNode) GTAManager(org.olat.course.nodes.gta.GTAManager) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 13 with GTAManager

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

the class GTACourseNode method exportNode.

/**
 * The files are exported in export/{node ident}/tasks and export/{node ident}/solutions
 */
@Override
public void exportNode(File fExportDirectory, ICourse course) {
    File fNodeExportDir = new File(fExportDirectory, getIdent());
    GTAManager gtaManager = CoreSpringFactory.getImpl(GTAManager.class);
    // export the tasks
    File tasksExportDir = new File(fNodeExportDir, "tasks");
    File taskDirectory = gtaManager.getTasksDirectory(course.getCourseEnvironment(), this);
    fNodeExportDir.mkdirs();
    FileUtils.copyDirContentsToDir(taskDirectory, tasksExportDir, false, "export task course node");
    File taskDefinitions = new File(taskDirectory.getParentFile(), GTAManager.TASKS_DEFINITIONS);
    if (taskDefinitions.exists()) {
        File copyTaskDefinitions = new File(tasksExportDir.getParentFile(), GTAManager.TASKS_DEFINITIONS);
        FileUtils.copyFileToFile(taskDefinitions, copyTaskDefinitions, false);
    }
    // export the solutions
    File fSolExportDir = new File(fNodeExportDir, "solutions");
    File solutionsDirectory = gtaManager.getSolutionsDirectory(course.getCourseEnvironment(), this);
    fSolExportDir.mkdirs();
    FileUtils.copyDirContentsToDir(solutionsDirectory, fSolExportDir, false, "export task course node solutions");
    File solutionDefinitions = new File(solutionsDirectory.getParentFile(), GTAManager.SOLUTIONS_DEFINITIONS);
    if (solutionDefinitions.exists()) {
        File copySolutionDefinitions = new File(fSolExportDir.getParentFile(), GTAManager.SOLUTIONS_DEFINITIONS);
        FileUtils.copyFileToFile(solutionDefinitions, copySolutionDefinitions, false);
    }
}
Also used : GTAManager(org.olat.course.nodes.gta.GTAManager) File(java.io.File)

Example 14 with GTAManager

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

the class GTACourseNode method cleanupOnDelete.

@Override
public void cleanupOnDelete(ICourse course) {
    super.cleanupOnDelete(course);
    GTAManager gtaManager = CoreSpringFactory.getImpl(GTAManager.class);
    // tasks
    File taskDirectory = gtaManager.getTasksDirectory(course.getCourseEnvironment(), this);
    FileUtils.deleteDirsAndFiles(taskDirectory, true, true);
    // solutions
    File solutionsDirectory = gtaManager.getSolutionsDirectory(course.getCourseEnvironment(), this);
    FileUtils.deleteDirsAndFiles(solutionsDirectory, true, true);
    // clean up database
    RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    gtaManager.deleteTaskList(entry, this);
    // clean subscription
    SubscriptionContext subscriptionContext = gtaManager.getSubscriptionContext(course.getCourseEnvironment(), this);
    NotificationsManager.getInstance().delete(subscriptionContext);
}
Also used : GTAManager(org.olat.course.nodes.gta.GTAManager) RepositoryEntry(org.olat.repository.RepositoryEntry) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) File(java.io.File)

Example 15 with GTAManager

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

the class GTACourseNode method archiveNodeData.

public void archiveNodeData(ICourse course, BusinessGroup businessGroup, TaskList taskList, String dirName, ZipOutputStream exportStream) {
    ModuleConfiguration config = getModuleConfiguration();
    GTAManager gtaManager = CoreSpringFactory.getImpl(GTAManager.class);
    // for beautiful ordering
    int flow = 0;
    String groupDirName = dirName + "/" + StringHelper.transformDisplayNameToFileSystemName(businessGroup.getName()) + "_" + businessGroup.getKey();
    Task task = gtaManager.getTask(businessGroup, taskList);
    if (task != null && task.getTaskName() != null && config.getBooleanSafe(GTASK_ASSIGNMENT)) {
        File taskDirectory = gtaManager.getTasksDirectory(course.getCourseEnvironment(), this);
        File taskFile = new File(taskDirectory, task.getTaskName());
        if (taskFile.exists()) {
            String path = groupDirName + "/" + (++flow) + "_task/" + taskFile.getName();
            ZipUtil.addFileToZip(path, taskFile, exportStream);
        }
    }
    if (config.getBooleanSafe(GTASK_SUBMIT)) {
        File submitDirectory = gtaManager.getSubmitDirectory(course.getCourseEnvironment(), this, businessGroup);
        String submissionDirName = groupDirName + "/" + (++flow) + "_submissions";
        ZipUtil.addDirectoryToZip(submitDirectory.toPath(), submissionDirName, exportStream);
    }
    if (config.getBooleanSafe(GTACourseNode.GTASK_REVIEW_AND_CORRECTION)) {
        File correctionsDir = gtaManager.getCorrectionDirectory(course.getCourseEnvironment(), this, businessGroup);
        String correctionDirName = groupDirName + "/" + (++flow) + "_corrections";
        ZipUtil.addDirectoryToZip(correctionsDir.toPath(), correctionDirName, exportStream);
    }
    if (task != null && config.getBooleanSafe(GTACourseNode.GTASK_REVISION_PERIOD)) {
        int numOfIteration = task.getRevisionLoop();
        for (int i = 1; i <= numOfIteration; i++) {
            File revisionDirectory = gtaManager.getRevisedDocumentsDirectory(course.getCourseEnvironment(), this, i, businessGroup);
            String revisionDirName = groupDirName + "/" + (++flow) + "_revisions_" + i;
            ZipUtil.addDirectoryToZip(revisionDirectory.toPath(), revisionDirName, exportStream);
            File correctionDirectory = gtaManager.getRevisedDocumentsCorrectionsDirectory(course.getCourseEnvironment(), this, i, businessGroup);
            String correctionDirName = groupDirName + "/" + (++flow) + "_corrections_" + i;
            ZipUtil.addDirectoryToZip(correctionDirectory.toPath(), correctionDirName, exportStream);
        }
    }
    // assessment documents for all participants of the group
    if (config.getBooleanSafe(MSCourseNode.CONFIG_KEY_HAS_INDIVIDUAL_ASSESSMENT_DOCS, false)) {
        List<Identity> assessedIdentities = CoreSpringFactory.getImpl(BusinessGroupService.class).getMembers(businessGroup, GroupRoles.participant.name());
        String assessmentDirName = groupDirName + "/" + (++flow) + "_assessment";
        for (Identity assessedIdentity : assessedIdentities) {
            List<File> assessmentDocuments = course.getCourseEnvironment().getAssessmentManager().getIndividualAssessmentDocuments(this, assessedIdentity);
            if (assessmentDocuments != null && !assessmentDocuments.isEmpty()) {
                String name = assessedIdentity.getUser().getLastName() + "_" + assessedIdentity.getUser().getFirstName() + "_" + assessedIdentity.getName();
                String userDirName = assessmentDirName + "/" + StringHelper.transformDisplayNameToFileSystemName(name);
                for (File document : assessmentDocuments) {
                    String path = userDirName + "/" + document.getName();
                    ZipUtil.addFileToZip(path, document, exportStream);
                }
            }
        }
    }
}
Also used : Task(org.olat.course.nodes.gta.Task) ModuleConfiguration(org.olat.modules.ModuleConfiguration) BusinessGroupService(org.olat.group.BusinessGroupService) GTAManager(org.olat.course.nodes.gta.GTAManager) Identity(org.olat.core.id.Identity) 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