Search in sources :

Example 16 with GTAManager

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

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 17 with GTAManager

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

the class BulkAssessmentTask method updateTasksState.

private void updateTasksState(GTACourseNode courseNode, UserCourseEnvironment uce, TaskProcess status) {
    final GTAManager gtaManager = CoreSpringFactory.getImpl(GTAManager.class);
    Identity identity = uce.getIdentityEnvironment().getIdentity();
    RepositoryEntry entry = uce.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    org.olat.course.nodes.gta.Task gtaTask;
    TaskList taskList = gtaManager.getTaskList(entry, courseNode);
    if (taskList == null) {
        taskList = gtaManager.createIfNotExists(entry, courseNode);
        gtaTask = gtaManager.createTask(null, taskList, status, null, identity, courseNode);
    } else {
        gtaTask = gtaManager.getTask(identity, taskList);
        if (gtaTask == null) {
            gtaManager.createTask(null, taskList, status, null, identity, courseNode);
        }
    }
    gtaManager.nextStep(status, courseNode);
}
Also used : TaskList(org.olat.course.nodes.gta.TaskList) GTAManager(org.olat.course.nodes.gta.GTAManager) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity)

Example 18 with GTAManager

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

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)

Example 19 with GTAManager

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

the class GTACourseNode method archiveNodeData.

private void archiveNodeData(ICourse course, Identity assessedIdentity, TaskList taskList, String dirName, ZipOutputStream exportStream) {
    ModuleConfiguration config = getModuleConfiguration();
    GTAManager gtaManager = CoreSpringFactory.getImpl(GTAManager.class);
    String name = assessedIdentity.getUser().getLastName() + "_" + assessedIdentity.getUser().getFirstName() + "_" + assessedIdentity.getName();
    // for beautiful ordering
    int flow = 0;
    String userDirName = dirName + "/" + StringHelper.transformDisplayNameToFileSystemName(name);
    Task task = gtaManager.getTask(assessedIdentity, 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 = userDirName + "/" + (++flow) + "_task/" + taskFile.getName();
            ZipUtil.addFileToZip(path, taskFile, exportStream);
        }
    }
    if (config.getBooleanSafe(GTASK_SUBMIT)) {
        File submitDirectory = gtaManager.getSubmitDirectory(course.getCourseEnvironment(), this, assessedIdentity);
        String submissionDirName = userDirName + "/" + (++flow) + "_submissions";
        ZipUtil.addDirectoryToZip(submitDirectory.toPath(), submissionDirName, exportStream);
    }
    if (config.getBooleanSafe(GTACourseNode.GTASK_REVIEW_AND_CORRECTION)) {
        File correctionsDir = gtaManager.getCorrectionDirectory(course.getCourseEnvironment(), this, assessedIdentity);
        String correctionDirName = userDirName + "/" + (++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, assessedIdentity);
            String revisionDirName = userDirName + "/" + (++flow) + "_revisions_" + i;
            ZipUtil.addDirectoryToZip(revisionDirectory.toPath(), revisionDirName, exportStream);
            File correctionDirectory = gtaManager.getRevisedDocumentsCorrectionsDirectory(course.getCourseEnvironment(), this, i, assessedIdentity);
            String correctionDirName = userDirName + "/" + (++flow) + "_corrections_" + i;
            ZipUtil.addDirectoryToZip(correctionDirectory.toPath(), correctionDirName, exportStream);
        }
    }
    // assessment documents
    if (config.getBooleanSafe(MSCourseNode.CONFIG_KEY_HAS_INDIVIDUAL_ASSESSMENT_DOCS, false)) {
        List<File> assessmentDocuments = course.getCourseEnvironment().getAssessmentManager().getIndividualAssessmentDocuments(this, assessedIdentity);
        if (assessmentDocuments != null && !assessmentDocuments.isEmpty()) {
            String assessmentDir = userDirName + "/" + (++flow) + "_assessment/";
            for (File document : assessmentDocuments) {
                String path = assessmentDir + document.getName();
                ZipUtil.addFileToZip(path, document, exportStream);
            }
        }
    }
}
Also used : Task(org.olat.course.nodes.gta.Task) ModuleConfiguration(org.olat.modules.ModuleConfiguration) GTAManager(org.olat.course.nodes.gta.GTAManager) File(java.io.File)

Example 20 with GTAManager

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

the class GTACourseNode method archiveNodeData.

@Override
public boolean archiveNodeData(Locale locale, ICourse course, ArchiveOptions options, ZipOutputStream exportStream, String charset) {
    final GTAManager gtaManager = CoreSpringFactory.getImpl(GTAManager.class);
    final ModuleConfiguration config = getModuleConfiguration();
    String prefix;
    if (GTAType.group.name().equals(config.getStringValue(GTACourseNode.GTASK_TYPE))) {
        prefix = "grouptask_";
    } else {
        prefix = "ita_";
    }
    String dirName = prefix + StringHelper.transformDisplayNameToFileSystemName(getShortName()) + "_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis()));
    TaskList taskList = gtaManager.getTaskList(course.getCourseEnvironment().getCourseGroupManager().getCourseEntry(), this);
    // save assessment datas
    List<Identity> users = null;
    if (config.getBooleanSafe(GTASK_GRADING)) {
        users = ScoreAccountingHelper.loadUsers(course.getCourseEnvironment(), options);
        String courseTitle = course.getCourseTitle();
        String fileName = ExportUtil.createFileNameWithTimeStamp(courseTitle, "xlsx");
        List<AssessableCourseNode> nodes = Collections.<AssessableCourseNode>singletonList(this);
        try (OutputStream out = new ShieldOutputStream(exportStream)) {
            exportStream.putNextEntry(new ZipEntry(dirName + "/" + fileName));
            ScoreAccountingHelper.createCourseResultsOverviewXMLTable(users, nodes, course, locale, out);
            exportStream.closeEntry();
        } catch (Exception e) {
            log.error("", e);
        }
    }
    // copy tasks
    if (taskList != null) {
        if (GTAType.group.name().equals(config.getStringValue(GTACourseNode.GTASK_TYPE))) {
            List<BusinessGroup> selectedGroups;
            if (options != null && options.getGroup() != null) {
                selectedGroups = Collections.singletonList(options.getGroup());
            } else {
                selectedGroups = gtaManager.getBusinessGroups(this);
            }
            for (BusinessGroup businessGroup : selectedGroups) {
                archiveNodeData(course, businessGroup, taskList, dirName, exportStream);
            }
        } else {
            if (users == null) {
                users = ScoreAccountingHelper.loadUsers(course.getCourseEnvironment(), options);
            }
            Set<Identity> uniqueUsers = new HashSet<>(users);
            for (Identity user : uniqueUsers) {
                archiveNodeData(course, user, taskList, dirName, exportStream);
            }
        }
    }
    // copy solutions
    if (config.getBooleanSafe(GTACourseNode.GTASK_SAMPLE_SOLUTION)) {
        VFSContainer solutions = gtaManager.getSolutionsContainer(course.getCourseEnvironment(), this);
        if (solutions.exists()) {
            String solutionDirName = dirName + "/solutions";
            for (VFSItem solution : solutions.getItems(new SystemItemFilter())) {
                ZipUtil.addToZip(solution, solutionDirName, exportStream);
            }
        }
    }
    return true;
}
Also used : ModuleConfiguration(org.olat.modules.ModuleConfiguration) BusinessGroup(org.olat.group.BusinessGroup) TaskList(org.olat.course.nodes.gta.TaskList) ShieldOutputStream(org.olat.core.util.io.ShieldOutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) OutputStream(java.io.OutputStream) ZipEntry(java.util.zip.ZipEntry) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) SystemItemFilter(org.olat.core.util.vfs.filters.SystemItemFilter) Date(java.util.Date) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) ShieldOutputStream(org.olat.core.util.io.ShieldOutputStream) GTAManager(org.olat.course.nodes.gta.GTAManager) Identity(org.olat.core.id.Identity) HashSet(java.util.HashSet)

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