Search in sources :

Example 56 with CourseGroupManager

use of org.olat.course.groupsandrights.CourseGroupManager in project OpenOLAT by OpenOLAT.

the class ScoreAccountingHelper method loadUsers.

/**
 * Load all users from all known learning groups into a list
 *
 * @param courseEnv
 * @return The list of identities from this course
 */
public static List<Identity> loadUsers(CourseEnvironment courseEnv) {
    CourseGroupManager gm = courseEnv.getCourseGroupManager();
    List<BusinessGroup> groups = gm.getAllBusinessGroups();
    BusinessGroupService businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class);
    Set<Identity> userSet = new HashSet<>(businessGroupService.getMembers(groups, GroupRoles.participant.name()));
    RepositoryEntry re = gm.getCourseEntry();
    if (re != null) {
        RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
        userSet.addAll(repositoryService.getMembers(re, GroupRoles.participant.name()));
    }
    List<Identity> assessedList = courseEnv.getCoursePropertyManager().getAllIdentitiesWithCourseAssessmentData(userSet);
    if (!assessedList.isEmpty()) {
        userSet.addAll(assessedList);
    }
    return new ArrayList<>(userSet);
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) BusinessGroup(org.olat.group.BusinessGroup) BusinessGroupService(org.olat.group.BusinessGroupService) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) HashSet(java.util.HashSet) RepositoryService(org.olat.repository.RepositoryService)

Example 57 with CourseGroupManager

use of org.olat.course.groupsandrights.CourseGroupManager in project openolat by klemens.

the class RestSecurityHelper method isAuthorEditor.

public static boolean isAuthorEditor(ICourse course, HttpServletRequest request) {
    try {
        Roles roles = getRoles(request);
        if (roles.isOLATAdmin())
            return true;
        if (roles.isAuthor()) {
            UserRequest ureq = getUserRequest(request);
            Identity identity = ureq.getIdentity();
            CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager();
            return cgm.isIdentityCourseAdministrator(identity) || cgm.hasRight(identity, CourseRights.RIGHT_COURSEEDITOR);
        }
        return false;
    } catch (Exception e) {
        return false;
    }
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) Roles(org.olat.core.id.Roles) Identity(org.olat.core.id.Identity) UserRequest(org.olat.core.gui.UserRequest) ParseException(java.text.ParseException)

Example 58 with CourseGroupManager

use of org.olat.course.groupsandrights.CourseGroupManager in project openolat by klemens.

the class CourseHandler method importResource.

@Override
public RepositoryEntry importResource(Identity initialAuthor, String initialAuthorAlt, String displayname, String description, boolean withReferences, Locale locale, File file, String filename) {
    OLATResource newCourseResource = OLATResourceManager.getInstance().createOLATResourceInstance(CourseModule.class);
    ICourse course = CourseFactory.importCourseFromZip(newCourseResource, file);
    // cfc.release();
    if (course == null) {
        return null;
    }
    RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
    RepositoryEntry re = repositoryService.create(initialAuthor, null, "", displayname, description, newCourseResource, RepositoryEntry.ACC_OWNERS);
    DBFactory.getInstance().commit();
    // create empty run structure
    course = CourseFactory.openCourseEditSession(course.getResourceableId());
    Structure runStructure = course.getRunStructure();
    runStructure.getRootNode().removeAllChildren();
    CourseFactory.saveCourse(course.getResourceableId());
    // import references
    CourseEditorTreeNode rootNode = (CourseEditorTreeNode) course.getEditorTreeModel().getRootNode();
    importReferences(rootNode, course, initialAuthor, locale, withReferences);
    if (withReferences && course.getCourseConfig().hasCustomSharedFolder()) {
        importSharedFolder(course, initialAuthor);
    }
    if (withReferences && course.getCourseConfig().hasGlossary()) {
        importGlossary(course, initialAuthor);
    }
    // create group management / import groups
    CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager();
    File fImportBaseDirectory = course.getCourseExportDataDir().getBasefile();
    CourseEnvironmentMapper envMapper = cgm.importCourseBusinessGroups(fImportBaseDirectory);
    envMapper.setAuthor(initialAuthor);
    // upgrade course
    course = CourseFactory.loadCourse(cgm.getCourseResource());
    course.postImport(fImportBaseDirectory, envMapper);
    // rename root nodes, but only when user modified the course title
    boolean doUpdateTitle = true;
    File repoConfigXml = new File(fImportBaseDirectory, "repo.xml");
    if (repoConfigXml.exists()) {
        RepositoryEntryImport importConfig;
        try {
            importConfig = RepositoryEntryImportExport.getConfiguration(new FileInputStream(repoConfigXml));
            if (importConfig != null) {
                if (displayname.equals(importConfig.getDisplayname())) {
                    // do not update if title was not modified during import
                    // user does not expect to have an updated title and there is a chance
                    // the root node title is not the same as the course title
                    doUpdateTitle = false;
                }
            }
        } catch (FileNotFoundException e) {
        // ignore
        }
    }
    if (doUpdateTitle) {
        // do not use truncate!
        course.getRunStructure().getRootNode().setShortTitle(Formatter.truncateOnly(displayname, 25));
        course.getRunStructure().getRootNode().setLongTitle(displayname);
    }
    // course.saveRunStructure();
    CourseEditorTreeNode editorRootNode = ((CourseEditorTreeNode) course.getEditorTreeModel().getRootNode());
    // do not use truncate!
    editorRootNode.getCourseNode().setShortTitle(Formatter.truncateOnly(displayname, 25));
    editorRootNode.getCourseNode().setLongTitle(displayname);
    // mark entire structure as dirty/new so the user can re-publish
    markDirtyNewRecursively(editorRootNode);
    // root has already been created during export. Unmark it.
    editorRootNode.setNewnode(false);
    // save and close edit session
    CourseFactory.saveCourse(course.getResourceableId());
    CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
    RepositoryEntryImportExport imp = new RepositoryEntryImportExport(fImportBaseDirectory);
    if (imp.anyExportedPropertiesAvailable()) {
        re = imp.importContent(re, getMediaContainer(re));
    }
    // import reminders
    importReminders(re, fImportBaseDirectory, envMapper, initialAuthor);
    // clean up export folder
    cleanExportAfterImport(fImportBaseDirectory);
    return re;
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) PersistingCourseGroupManager(org.olat.course.groupsandrights.PersistingCourseGroupManager) RepositoryEntryImportExport(org.olat.repository.RepositoryEntryImportExport) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) FileNotFoundException(java.io.FileNotFoundException) OLATResource(org.olat.resource.OLATResource) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryEntryImport(org.olat.repository.RepositoryEntryImportExport.RepositoryEntryImport) FileInputStream(java.io.FileInputStream) Structure(org.olat.course.Structure) File(java.io.File) CourseEnvironmentMapper(org.olat.course.export.CourseEnvironmentMapper) RepositoryService(org.olat.repository.RepositoryService)

Example 59 with CourseGroupManager

use of org.olat.course.groupsandrights.CourseGroupManager in project openolat by klemens.

the class CourseHandler method copy.

@Override
public RepositoryEntry copy(Identity author, RepositoryEntry source, RepositoryEntry target) {
    final OLATResource sourceResource = source.getOlatResource();
    final OLATResource targetResource = target.getOlatResource();
    CourseFactory.copyCourse(sourceResource, targetResource);
    // transaction copied
    ICourse sourceCourse = CourseFactory.loadCourse(source);
    CourseGroupManager sourceCgm = sourceCourse.getCourseEnvironment().getCourseGroupManager();
    CourseEnvironmentMapper env = PersistingCourseGroupManager.getInstance(sourceResource).getBusinessGroupEnvironment();
    File fExportDir = new File(WebappHelper.getTmpDir(), UUID.randomUUID().toString());
    fExportDir.mkdirs();
    sourceCgm.exportCourseBusinessGroups(fExportDir, env, false, false);
    ICourse course = CourseFactory.loadCourse(target);
    CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager();
    // import groups
    CourseEnvironmentMapper envMapper = cgm.importCourseBusinessGroups(fExportDir);
    envMapper.setAuthor(author);
    // upgrade to the current version of the course
    course = CourseFactory.loadCourse(cgm.getCourseResource());
    course.postCopy(envMapper, sourceCourse);
    cloneReminders(author, envMapper, source, target);
    cloneLectureConfig(source, target);
    return target;
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) PersistingCourseGroupManager(org.olat.course.groupsandrights.PersistingCourseGroupManager) OLATResource(org.olat.resource.OLATResource) ICourse(org.olat.course.ICourse) File(java.io.File) CourseEnvironmentMapper(org.olat.course.export.CourseEnvironmentMapper)

Example 60 with CourseGroupManager

use of org.olat.course.groupsandrights.CourseGroupManager in project openolat by klemens.

the class MembersMailController method doSend.

private void doSend(UserRequest ureq) {
    ContactList contactList = new ContactList("");
    if (courseEnv == null) {
        if (coachEl != null && coachEl.isAtLeastSelected(1)) {
            List<Long> identityKeys = new ArrayList<>(coachList.size());
            for (Member coach : coachList) {
                identityKeys.add(coach.getKey());
            }
            List<Identity> coaches = securityManager.loadIdentityByKeys(identityKeys);
            contactList.addAllIdentites(coaches);
        }
        if (participantEl != null && participantEl.isAtLeastSelected(1)) {
            List<Long> identityKeys = new ArrayList<>(participantList.size());
            for (Member participant : participantList) {
                identityKeys.add(participant.getKey());
            }
            List<Identity> participants = securityManager.loadIdentityByKeys(identityKeys);
            contactList.addAllIdentites(participants);
        }
        if (waitingEl != null && waitingEl.isAtLeastSelected(1)) {
            List<Long> identityKeys = new ArrayList<>(waitingList.size());
            for (Member waiter : waitingList) {
                identityKeys.add(waiter.getKey());
            }
            List<Identity> waiters = securityManager.loadIdentityByKeys(identityKeys);
            contactList.addAllIdentites(waiters);
        }
    } else {
        if (ownerEl != null && ownerEl.isAtLeastSelected(1)) {
            RepositoryEntry courseRepositoryEntry = courseEnv.getCourseGroupManager().getCourseEntry();
            List<Identity> owners = repositoryService.getMembers(courseRepositoryEntry, GroupRoles.owner.name());
            contactList.addAllIdentites(owners);
        }
        if (coachEl != null && coachEl.isAtLeastSelected(1)) {
            Set<Long> sendToWhatYouSee = new HashSet<>();
            for (Member coach : coachList) {
                sendToWhatYouSee.add(coach.getKey());
            }
            CourseGroupManager cgm = courseEnv.getCourseGroupManager();
            avoidInvisibleMember(cgm.getCoachesFromBusinessGroups(), contactList, sendToWhatYouSee);
            avoidInvisibleMember(cgm.getCoaches(), contactList, sendToWhatYouSee);
        }
        if (participantEl != null && participantEl.isAtLeastSelected(1)) {
            Set<Long> sendToWhatYouSee = new HashSet<>();
            for (Member participant : participantList) {
                sendToWhatYouSee.add(participant.getKey());
            }
            CourseGroupManager cgm = courseEnv.getCourseGroupManager();
            avoidInvisibleMember(cgm.getParticipantsFromBusinessGroups(), contactList, sendToWhatYouSee);
            avoidInvisibleMember(cgm.getParticipants(), contactList, sendToWhatYouSee);
        }
    }
    if (individualEl != null && individualEl.isAtLeastSelected(1) && selectedMembers != null && selectedMembers.size() > 0) {
        List<Long> identityKeys = new ArrayList<>(selectedMembers.size());
        for (Member member : selectedMembers) {
            identityKeys.add(member.getKey());
        }
        List<Identity> selectedIdentities = securityManager.loadIdentityByKeys(identityKeys);
        contactList.addAllIdentites(selectedIdentities);
    }
    if (externalEl != null && externalEl.isAtLeastSelected(1)) {
        String value = externalAddressesEl.getValue();
        if (StringHelper.containsNonWhitespace(value)) {
            for (StringTokenizer tokenizer = new StringTokenizer(value, ",\r\n", false); tokenizer.hasMoreTokens(); ) {
                String email = tokenizer.nextToken().trim();
                contactList.add(new EMailIdentity(email, getLocale()));
            }
        }
    }
    doSendEmailToMember(ureq, contactList);
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) ArrayList(java.util.ArrayList) ContactList(org.olat.core.util.mail.ContactList) RepositoryEntry(org.olat.repository.RepositoryEntry) StringTokenizer(java.util.StringTokenizer) EMailIdentity(org.olat.core.util.mail.ui.EMailIdentity) EMailIdentity(org.olat.core.util.mail.ui.EMailIdentity) Identity(org.olat.core.id.Identity) Member(org.olat.course.nodes.members.Member) HashSet(java.util.HashSet)

Aggregations

CourseGroupManager (org.olat.course.groupsandrights.CourseGroupManager)84 Identity (org.olat.core.id.Identity)28 ICourse (org.olat.course.ICourse)28 BusinessGroup (org.olat.group.BusinessGroup)26 RepositoryEntry (org.olat.repository.RepositoryEntry)22 HashSet (java.util.HashSet)12 Roles (org.olat.core.id.Roles)12 ArrayList (java.util.ArrayList)10 BusinessGroupService (org.olat.group.BusinessGroupService)10 KalendarRenderWrapper (org.olat.commons.calendar.ui.components.KalendarRenderWrapper)8 UserRequest (org.olat.core.gui.UserRequest)8 CourseEditorEnv (org.olat.course.editor.CourseEditorEnv)8 PersistingCourseGroupManager (org.olat.course.groupsandrights.PersistingCourseGroupManager)8 OLATResource (org.olat.resource.OLATResource)8 File (java.io.File)6 Date (java.util.Date)6 CalendarManager (org.olat.commons.calendar.CalendarManager)6 Publisher (org.olat.core.commons.services.notifications.Publisher)6 OLATResourceable (org.olat.core.id.OLATResourceable)6 AssertException (org.olat.core.logging.AssertException)6