Search in sources :

Example 41 with BusinessGroupService

use of org.olat.group.BusinessGroupService in project openolat by klemens.

the class MembersPeekViewController method readFormData.

protected void readFormData(ModuleConfiguration config) {
    CourseGroupManager cgm = courseEnv.getCourseGroupManager();
    RepositoryEntry courseRepositoryEntry = courseEnv.getCourseGroupManager().getCourseEntry();
    List<Identity> owners = MembersHelpers.getOwners(repositoryService, courseRepositoryEntry);
    List<Identity> coaches = new ArrayList<>();
    MembersHelpers.addCoaches(config, cgm, businessGroupService, coaches);
    List<Identity> participants = new ArrayList<>();
    MembersHelpers.addParticipants(config, cgm, businessGroupService, participants);
    Set<Long> duplicateCatcher = new HashSet<Long>();
    List<Identity> filteredOwners = owners.stream().filter(ident -> {
        if (duplicateCatcher.contains(ident.getKey())) {
            return false;
        }
        duplicateCatcher.add(ident.getKey());
        return true;
    }).collect(Collectors.toList());
    List<Identity> filteredCoaches = coaches.stream().filter(ident -> {
        if (duplicateCatcher.contains(ident.getKey())) {
            return false;
        }
        duplicateCatcher.add(ident.getKey());
        return true;
    }).collect(Collectors.toList());
    List<Identity> filteredParticipants = participants.stream().filter(ident -> {
        if (duplicateCatcher.contains(ident.getKey())) {
            return false;
        }
        duplicateCatcher.add(ident.getKey());
        return true;
    }).collect(Collectors.toList());
    entries.add(new Row(translate("members.owners"), Integer.toString(filteredOwners.size())));
    entries.add(new Row(translate("members.coaches"), Integer.toString(filteredCoaches.size())));
    entries.add(new Row(translate("members.participants"), Integer.toString(filteredParticipants.size())));
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) ColumnDescriptor(org.olat.core.gui.components.table.ColumnDescriptor) RepositoryService(org.olat.repository.RepositoryService) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) DefaultColumnDescriptor(org.olat.core.gui.components.table.DefaultColumnDescriptor) WindowControl(org.olat.core.gui.control.WindowControl) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) RepositoryEntry(org.olat.repository.RepositoryEntry) Component(org.olat.core.gui.components.Component) Collectors(java.util.stream.Collectors) ModuleConfiguration(org.olat.modules.ModuleConfiguration) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Event(org.olat.core.gui.control.Event) BasicController(org.olat.core.gui.control.controller.BasicController) CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) DefaultTableDataModel(org.olat.core.gui.components.table.DefaultTableDataModel) List(java.util.List) Identity(org.olat.core.id.Identity) UserRequest(org.olat.core.gui.UserRequest) TableGuiConfiguration(org.olat.core.gui.components.table.TableGuiConfiguration) TableController(org.olat.core.gui.components.table.TableController) CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) HashSet(java.util.HashSet)

Example 42 with BusinessGroupService

use of org.olat.group.BusinessGroupService in project openolat by klemens.

the class MyForumsWebService method getForums.

/**
 * Retrieves a list of forums on a user base. All forums of groups
 * where the user is participant/tutor + all forums in course where
 * the user is a participant (owner, tutor or participant)
 * @response.representation.200.qname {http://www.example.com}forumVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The forums
 * @response.representation.200.example {@link org.olat.modules.fo.restapi.Examples#SAMPLE_FORUMVO}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @param identityKey The key of the user (IdentityImpl)
 * @param httpRequest The HTTP request
 * @return The forums
 */
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getForums(@PathParam("identityKey") Long identityKey, @Context HttpServletRequest httpRequest) {
    Roles roles;
    Identity retrievedUser = getIdentity(httpRequest);
    if (retrievedUser == null) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    } else if (!identityKey.equals(retrievedUser.getKey())) {
        if (isAdmin(httpRequest)) {
            retrievedUser = BaseSecurityManager.getInstance().loadIdentityByKey(identityKey);
            roles = BaseSecurityManager.getInstance().getRoles(retrievedUser);
        } else {
            return Response.serverError().status(Status.UNAUTHORIZED).build();
        }
    } else {
        roles = getRoles(httpRequest);
    }
    Map<Long, Long> groupNotified = new HashMap<Long, Long>();
    Map<Long, Collection<Long>> courseNotified = new HashMap<Long, Collection<Long>>();
    final Set<Long> subscriptions = new HashSet<Long>();
    NotificationsManager man = NotificationsManager.getInstance();
    {
        // collect subscriptions
        List<String> notiTypes = Collections.singletonList("Forum");
        List<Subscriber> subs = man.getSubscribers(retrievedUser, notiTypes);
        for (Subscriber sub : subs) {
            String resName = sub.getPublisher().getResName();
            Long forumKey = Long.parseLong(sub.getPublisher().getData());
            subscriptions.add(forumKey);
            if ("BusinessGroup".equals(resName)) {
                Long groupKey = sub.getPublisher().getResId();
                groupNotified.put(groupKey, forumKey);
            } else if ("CourseModule".equals(resName)) {
                Long courseKey = sub.getPublisher().getResId();
                if (!courseNotified.containsKey(courseKey)) {
                    courseNotified.put(courseKey, new ArrayList<Long>());
                }
                courseNotified.get(courseKey).add(forumKey);
            }
        }
    }
    final List<ForumVO> forumVOs = new ArrayList<ForumVO>();
    final IdentityEnvironment ienv = new IdentityEnvironment(retrievedUser, roles);
    for (Map.Entry<Long, Collection<Long>> e : courseNotified.entrySet()) {
        final Long courseKey = e.getKey();
        final Collection<Long> forumKeys = e.getValue();
        final ICourse course = CourseFactory.loadCourse(courseKey);
        new CourseTreeVisitor(course, ienv).visit(new Visitor() {

            @Override
            public void visit(INode node) {
                if (node instanceof FOCourseNode) {
                    FOCourseNode forumNode = (FOCourseNode) node;
                    ForumVO forumVo = ForumCourseNodeWebService.createForumVO(course, forumNode, subscriptions);
                    if (forumKeys.contains(forumVo.getForumKey())) {
                        forumVOs.add(forumVo);
                    }
                }
            }
        }, new VisibleTreeFilter());
    }
    /*
		RepositoryManager rm = RepositoryManager.getInstance();
		ACService acManager = CoreSpringFactory.getImpl(ACService.class);
		SearchRepositoryEntryParameters repoParams = new SearchRepositoryEntryParameters(retrievedUser, roles, "CourseModule");
		repoParams.setOnlyExplicitMember(true);
		List<RepositoryEntry> entries = rm.genericANDQueryWithRolesRestriction(repoParams, 0, -1, true);
		for(RepositoryEntry entry:entries) {
			AccessResult result = acManager.isAccessible(entry, retrievedUser, false);
			if(result.isAccessible()) {
				try {
					final ICourse course = CourseFactory.loadCourse(entry.getOlatResource());
					final IdentityEnvironment ienv = new IdentityEnvironment(retrievedUser, roles);
					new CourseTreeVisitor(course, ienv).visit(new Visitor() {
						@Override
						public void visit(INode node) {
							if(node instanceof FOCourseNode) {
								FOCourseNode forumNode = (FOCourseNode)node;	
								ForumVO forumVo = ForumCourseNodeWebService.createForumVO(course, forumNode, subscriptions);
								forumVOs.add(forumVo);
							}
						}
					});
				} catch (Exception e) {
					log.error("", e);
				}
			}
		}*/
    // start found forums in groups
    BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    SearchBusinessGroupParams params = new SearchBusinessGroupParams(retrievedUser, true, true);
    params.addTools(CollaborationTools.TOOL_FORUM);
    List<BusinessGroup> groups = bgs.findBusinessGroups(params, null, 0, -1);
    // list forum keys
    List<Long> groupIds = new ArrayList<Long>();
    Map<Long, BusinessGroup> groupsMap = new HashMap<Long, BusinessGroup>();
    for (BusinessGroup group : groups) {
        if (groupNotified.containsKey(group.getKey())) {
            ForumVO forumVo = new ForumVO();
            forumVo.setName(group.getName());
            forumVo.setGroupKey(group.getKey());
            forumVo.setForumKey(groupNotified.get(group.getKey()));
            forumVo.setSubscribed(true);
            forumVOs.add(forumVo);
            groupIds.remove(group.getKey());
        } else {
            groupIds.add(group.getKey());
            groupsMap.put(group.getKey(), group);
        }
    }
    PropertyManager pm = PropertyManager.getInstance();
    List<Property> forumProperties = pm.findProperties(OresHelper.calculateTypeName(BusinessGroup.class), groupIds, PROP_CAT_BG_COLLABTOOLS, KEY_FORUM);
    for (Property prop : forumProperties) {
        Long forumKey = prop.getLongValue();
        if (forumKey != null && groupsMap.containsKey(prop.getResourceTypeId())) {
            BusinessGroup group = groupsMap.get(prop.getResourceTypeId());
            ForumVO forumVo = new ForumVO();
            forumVo.setName(group.getName());
            forumVo.setGroupKey(group.getKey());
            forumVo.setForumKey(prop.getLongValue());
            forumVo.setSubscribed(false);
            forumVOs.add(forumVo);
        }
    }
    ForumVOes voes = new ForumVOes();
    voes.setForums(forumVOs.toArray(new ForumVO[forumVOs.size()]));
    voes.setTotalCount(forumVOs.size());
    return Response.ok(voes).build();
}
Also used : INode(org.olat.core.util.nodes.INode) Visitor(org.olat.core.util.tree.Visitor) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) HashMap(java.util.HashMap) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) PropertyManager(org.olat.properties.PropertyManager) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) FOCourseNode(org.olat.course.nodes.FOCourseNode) Subscriber(org.olat.core.commons.services.notifications.Subscriber) ArrayList(java.util.ArrayList) List(java.util.List) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) Identity(org.olat.core.id.Identity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) Property(org.olat.properties.Property) HashSet(java.util.HashSet) BusinessGroup(org.olat.group.BusinessGroup) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) RestSecurityHelper.getRoles(org.olat.restapi.security.RestSecurityHelper.getRoles) Roles(org.olat.core.id.Roles) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) BusinessGroupService(org.olat.group.BusinessGroupService) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 43 with BusinessGroupService

use of org.olat.group.BusinessGroupService in project openolat by klemens.

the class COCourseNode method isConfigValid.

/**
 * @see org.olat.course.nodes.CourseNode#isConfigValid(org.olat.course.run.userview.UserCourseEnvironment)
 */
public StatusDescription[] isConfigValid(CourseEditorEnv cev) {
    oneClickStatusCache = null;
    // only here we know which translator to take for translating condition
    // error messages
    String translatorStr = Util.getPackageName(ConditionEditController.class);
    List<StatusDescription> condErrs = isConfigValidWithTranslator(cev, translatorStr, getConditionExpressions());
    List<StatusDescription> missingNames = new ArrayList<StatusDescription>();
    /*
         * check group and area names for existence
         */
    String nodeId = getIdent();
    ModuleConfiguration mc = getModuleConfiguration();
    @SuppressWarnings("unchecked") List<Long> areaKeys = (List<Long>) mc.get(COEditController.CONFIG_KEY_EMAILTOCOACHES_AREA_IDS);
    if (areaKeys != null) {
        BGAreaManager areaManager = CoreSpringFactory.getImpl(BGAreaManager.class);
        List<BGArea> areas = areaManager.loadAreas(areaKeys);
        a_a: for (Long areaKey : areaKeys) {
            for (BGArea area : areas) {
                if (area.getKey().equals(areaKey)) {
                    continue a_a;
                }
            }
            StatusDescription sd = new StatusDescription(StatusDescription.WARNING, "error.notfound.name", "solution.checkgroupmanagement", new String[] { "NONE", areaKey.toString() }, translatorStr);
            sd.setDescriptionForUnit(nodeId);
            missingNames.add(sd);
        }
    } else {
        String areaStr = (String) mc.get(COEditController.CONFIG_KEY_EMAILTOCOACHES_AREA);
        if (areaStr != null) {
            String[] areas = areaStr.split(",");
            for (int i = 0; i < areas.length; i++) {
                String trimmed = areas[i] != null ? areas[i].trim() : areas[i];
                if (!trimmed.equals("") && !cev.existsArea(trimmed)) {
                    StatusDescription sd = new StatusDescription(StatusDescription.WARNING, "error.notfound.name", "solution.checkgroupmanagement", new String[] { "NONE", trimmed }, translatorStr);
                    sd.setDescriptionForUnit(nodeId);
                    missingNames.add(sd);
                }
            }
        }
    }
    @SuppressWarnings("unchecked") List<Long> groupKeys = (List<Long>) mc.get(COEditController.CONFIG_KEY_EMAILTOCOACHES_GROUP_ID);
    if (groupKeys != null) {
        BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
        List<BusinessGroupShort> groups = bgs.loadShortBusinessGroups(groupKeys);
        a_a: for (Long activeGroupKey : groupKeys) {
            for (BusinessGroupShort group : groups) {
                if (group.getKey().equals(activeGroupKey)) {
                    continue a_a;
                }
            }
            StatusDescription sd = new StatusDescription(StatusDescription.WARNING, "error.notfound.name", "solution.checkgroupmanagement", new String[] { "NONE", activeGroupKey.toString() }, translatorStr);
            sd.setDescriptionForUnit(nodeId);
            missingNames.add(sd);
        }
    } else {
        String groupStr = (String) mc.get(COEditController.CONFIG_KEY_EMAILTOCOACHES_GROUP);
        if (groupStr != null) {
            String[] groups = groupStr.split(",");
            for (int i = 0; i < groups.length; i++) {
                String trimmed = groups[i] != null ? groups[i].trim() : groups[i];
                if (!trimmed.equals("") && !cev.existsGroup(trimmed)) {
                    StatusDescription sd = new StatusDescription(StatusDescription.WARNING, "error.notfound.name", "solution.checkgroupmanagement", new String[] { "NONE", trimmed }, translatorStr);
                    sd.setDescriptionForUnit(nodeId);
                    missingNames.add(sd);
                }
            }
        }
    }
    missingNames.addAll(condErrs);
    oneClickStatusCache = StatusDescriptionHelper.sort(missingNames);
    return oneClickStatusCache;
}
Also used : ModuleConfiguration(org.olat.modules.ModuleConfiguration) ArrayList(java.util.ArrayList) BGArea(org.olat.group.area.BGArea) BusinessGroupService(org.olat.group.BusinessGroupService) StatusDescription(org.olat.course.editor.StatusDescription) ArrayList(java.util.ArrayList) List(java.util.List) BusinessGroupShort(org.olat.group.BusinessGroupShort) BGAreaManager(org.olat.group.area.BGAreaManager)

Example 44 with BusinessGroupService

use of org.olat.group.BusinessGroupService in project openolat by klemens.

the class CourseCreationHelper method finalizeWorkflow.

/**
 * Finalizes the course creation workflow via wizard.
 * @param ureq
 */
public void finalizeWorkflow(final UserRequest ureq) {
    // --------------------------
    // 1. insert the course nodes
    // --------------------------
    // single page node
    CourseNode singlePageNode = null;
    if (courseConfig.isCreateSinglePage()) {
        singlePageNode = CourseExtensionHelper.createSinglePageNode(course, translator.translate("cce.informationpage"), translator.translate("cce.informationpage.descr"));
        if (singlePageNode instanceof SPCourseNode) {
            final String relPath = CourseEditorHelper.createUniqueRelFilePathFromShortTitle(singlePageNode, course.getCourseFolderContainer());
            HTMLDocumentHelper.createHtmlDocument(course, relPath, courseConfig.getSinglePageText(translator));
            ((SPCourseNode) singlePageNode).getModuleConfiguration().set(SPEditController.CONFIG_KEY_FILE, relPath);
        }
    }
    // enrollment node
    CourseNode enCourseNode = null;
    if (courseConfig.isCreateEnrollment()) {
        enCourseNode = CourseExtensionHelper.createEnrollmentNode(course, translator.translate("cce.enrollment"), translator.translate("cce.enrollment.descr"));
    }
    // download folder node
    CourseNode downloadFolderNode = null;
    if (courseConfig.isCreateDownloadFolder()) {
        downloadFolderNode = CourseExtensionHelper.createDownloadFolderNode(course, translator.translate("cce.downloadfolder"), translator.translate("cce.downloadfolder.descr"));
    }
    // forum node
    CourseNode forumNode = null;
    if (courseConfig.isCreateForum()) {
        forumNode = CourseExtensionHelper.createForumNode(course, translator.translate("cce.forum"), translator.translate("cce.forum.descr"));
    }
    // contact form node
    CourseNode contactNode = null;
    if (courseConfig.isCreateContactForm()) {
        contactNode = CourseExtensionHelper.createContactFormNode(course, translator.translate("cce.contactform"), translator.translate("cce.contactform.descr"));
        if (contactNode instanceof COCourseNode) {
            final List<String> emails = new ArrayList<String>();
            String subject = translator.translate("cce.contactform.subject") + " " + courseConfig.getCourseTitle();
            String email = ureq.getIdentity().getUser().getProperty(UserConstants.EMAIL, ureq.getLocale());
            if (StringHelper.containsNonWhitespace(email)) {
                emails.add(email);
            }
            COCourseNode cocn = (COCourseNode) contactNode;
            cocn.getModuleConfiguration().set(COEditController.CONFIG_KEY_EMAILTOADRESSES, emails);
            cocn.getModuleConfiguration().set(COEditController.CONFIG_KEY_MSUBJECT_DEFAULT, subject);
        }
    }
    // enrollment node
    if (courseConfig.isCreateEnrollment()) {
        // --------------------------
        // 2. setup enrollment
        // --------------------------
        final String groupBaseName = createGroupBaseName();
        final BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
        // get default context for learning groups
        // create n learning groups with m allowed members
        String comma = "";
        String tmpGroupList = "";
        String groupNamesList = "";
        for (int i = 0; i < courseConfig.getGroupCount(); i++) {
            // create group
            String name = groupBaseName + " " + (i + 1);
            BusinessGroup learningGroup = bgs.createBusinessGroup(ureq.getIdentity(), name, null, 0, courseConfig.getSubscriberCount(), courseConfig.getEnableWaitlist(), courseConfig.getEnableFollowup(), addedEntry);
            // enable the contact collaboration tool
            CollaborationTools ct = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(learningGroup);
            ct.setToolEnabled(CollaborationTools.TOOL_CONTACT, true);
            // append to current learning group list
            groupNamesList = tmpGroupList + comma + learningGroup.getName();
            enCourseNode.getModuleConfiguration().set(ENCourseNode.CONFIG_GROUPNAME, groupNamesList);
            if (i == 0) {
                comma = ",";
            }
            tmpGroupList = (String) enCourseNode.getModuleConfiguration().get(ENCourseNode.CONFIG_GROUPNAME);
        }
        // set signout property
        enCourseNode.getModuleConfiguration().set(ENCourseNode.CONF_CANCEL_ENROLL_ENABLED, courseConfig.getEnableSignout());
        // access limits on chosen course elements
        if (courseConfig.getEnableAccessLimit()) {
            if (courseConfig.isEnableAclContactForm()) {
                if (contactNode instanceof COCourseNode) {
                    Condition c = ((COCourseNode) contactNode).getPreConditionVisibility();
                    c.setEasyModeGroupAccess(groupNamesList);
                    ((COCourseNode) contactNode).setNoAccessExplanation(translator.translate("noaccessexplain"));
                    // calculate expression from easy mode form
                    String condString = c.getConditionFromEasyModeConfiguration();
                    c.setConditionExpression(condString);
                    c.setExpertMode(false);
                }
            }
            if (courseConfig.isEnableAclSinglePage()) {
                if (singlePageNode instanceof SPCourseNode) {
                    Condition c = ((SPCourseNode) singlePageNode).getPreConditionVisibility();
                    c.setEasyModeGroupAccess(groupNamesList);
                    ((SPCourseNode) singlePageNode).setNoAccessExplanation(translator.translate("noaccessexplain"));
                    // calculate expression from easy mode form
                    String condString = c.getConditionFromEasyModeConfiguration();
                    c.setConditionExpression(condString);
                    c.setExpertMode(false);
                }
            }
            if (courseConfig.isEnableAclForum()) {
                if (forumNode instanceof FOCourseNode) {
                    Condition c = ((FOCourseNode) forumNode).getPreConditionVisibility();
                    c.setEasyModeGroupAccess(groupNamesList);
                    ((FOCourseNode) forumNode).setNoAccessExplanation(translator.translate("noaccessexplain"));
                    // calculate expression from easy mode form
                    String condString = c.getConditionFromEasyModeConfiguration();
                    c.setConditionExpression(condString);
                    c.setExpertMode(false);
                }
            }
            if (courseConfig.isEnableAclDownloadFolder()) {
                if (downloadFolderNode instanceof BCCourseNode) {
                    Condition c = ((BCCourseNode) downloadFolderNode).getPreConditionVisibility();
                    c.setEasyModeGroupAccess(groupNamesList);
                    ((BCCourseNode) downloadFolderNode).setNoAccessExplanation(translator.translate("noaccessexplain"));
                    // calculate expression from easy mode form
                    String condString = c.getConditionFromEasyModeConfiguration();
                    c.setConditionExpression(condString);
                    c.setExpertMode(false);
                }
            }
        }
    }
    // --------------------------
    if (courseConfig.getPublish()) {
        CourseAccessAndProperties accessAndProps = courseConfig.getAccessAndProperties();
        RepositoryManager manager = RepositoryManager.getInstance();
        addedEntry = manager.setAccessAndProperties(accessAndProps.getRepositoryEntry(), accessAndProps.getAccess(), accessAndProps.isMembersOnly(), accessAndProps.isCanCopy(), accessAndProps.isCanReference(), accessAndProps.isCanDownload());
        addedEntry = manager.setLeaveSetting(addedEntry, accessAndProps.getSetting());
        List<OfferAccess> offerAccess = accessAndProps.getOfferAccess();
        ACService acService = CoreSpringFactory.getImpl(ACService.class);
        for (OfferAccess newLink : offerAccess) {
            acService.saveOfferAccess(newLink);
        }
    }
    course = CourseFactory.openCourseEditSession(course.getResourceableId());
    course.getRunStructure().getRootNode().setShortTitle(addedEntry.getDisplayname());
    course.getRunStructure().getRootNode().setLongTitle(addedEntry.getDisplayname());
    CourseFactory.saveCourse(course.getResourceableId());
    final CourseEditorTreeModel cetm = course.getEditorTreeModel();
    final CourseNode rootNode = cetm.getCourseNode(course.getRunStructure().getRootNode().getIdent());
    rootNode.setShortTitle(addedEntry.getDisplayname());
    rootNode.setLongTitle(addedEntry.getDisplayname());
    course.getEditorTreeModel().nodeConfigChanged(course.getRunStructure().getRootNode());
    CourseFactory.saveCourseEditorTreeModel(course.getResourceableId());
    // --------------------------
    // 3.2 publish the course
    // --------------------------
    // fetch publish process
    final PublishProcess pp = PublishProcess.getInstance(course, cetm, ureq.getLocale());
    final StatusDescription[] sds;
    // create publish node list
    List<String> nodeIds = new ArrayList<String>();
    nodeIds.add(cetm.getRootNode().getIdent());
    for (int i = 0; i < cetm.getRootNode().getChildCount(); i++) {
        nodeIds.add(cetm.getRootNode().getChildAt(i).getIdent());
    }
    pp.createPublishSetFor(nodeIds);
    PublishSetInformations set = pp.testPublishSet(ureq.getLocale());
    sds = set.getWarnings();
    boolean isValid = sds.length == 0;
    if (!isValid) {
        // no error and no warnings -> return immediate
        log.error("Course Publishing failed", new AssertionError());
    }
    pp.applyPublishSet(ureq.getIdentity(), ureq.getLocale(), true);
    CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
    // save catalog entry
    if (getConfiguration().getSelectedCatalogEntry() != null) {
        CatalogManager cm = CoreSpringFactory.getImpl(CatalogManager.class);
        CatalogEntry newEntry = cm.createCatalogEntry();
        newEntry.setRepositoryEntry(addedEntry);
        newEntry.setName(addedEntry.getDisplayname());
        newEntry.setDescription(addedEntry.getDescription());
        newEntry.setType(CatalogEntry.TYPE_LEAF);
        newEntry.setOwnerGroup(BaseSecurityManager.getInstance().createAndPersistSecurityGroup());
        // save entry
        cm.addCatalogEntry(getConfiguration().getSelectedCatalogEntry(), newEntry);
    }
}
Also used : OfferAccess(org.olat.resource.accesscontrol.OfferAccess) ArrayList(java.util.ArrayList) CatalogEntry(org.olat.repository.CatalogEntry) FOCourseNode(org.olat.course.nodes.FOCourseNode) PublishProcess(org.olat.course.editor.PublishProcess) StatusDescription(org.olat.course.editor.StatusDescription) RepositoryManager(org.olat.repository.RepositoryManager) FOCourseNode(org.olat.course.nodes.FOCourseNode) ENCourseNode(org.olat.course.nodes.ENCourseNode) CourseNode(org.olat.course.nodes.CourseNode) COCourseNode(org.olat.course.nodes.COCourseNode) BCCourseNode(org.olat.course.nodes.BCCourseNode) SPCourseNode(org.olat.course.nodes.SPCourseNode) COCourseNode(org.olat.course.nodes.COCourseNode) Condition(org.olat.course.condition.Condition) CourseEditorTreeModel(org.olat.course.tree.CourseEditorTreeModel) BusinessGroup(org.olat.group.BusinessGroup) SPCourseNode(org.olat.course.nodes.SPCourseNode) CourseAccessAndProperties(org.olat.course.editor.CourseAccessAndProperties) PublishSetInformations(org.olat.course.editor.PublishSetInformations) CatalogManager(org.olat.repository.manager.CatalogManager) BCCourseNode(org.olat.course.nodes.BCCourseNode) BusinessGroupService(org.olat.group.BusinessGroupService) CollaborationTools(org.olat.collaboration.CollaborationTools) ACService(org.olat.resource.accesscontrol.ACService)

Example 45 with BusinessGroupService

use of org.olat.group.BusinessGroupService in project OpenOLAT by OpenOLAT.

the class CourseAssessmentWebService method loadUsers.

private List<Identity> loadUsers(ICourse course) {
    List<Identity> identities = new ArrayList<Identity>();
    List<BusinessGroup> groups = course.getCourseEnvironment().getCourseGroupManager().getAllBusinessGroups();
    Set<Long> check = new HashSet<Long>();
    BusinessGroupService businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class);
    List<Identity> participants = businessGroupService.getMembers(groups, GroupRoles.participant.name());
    for (Identity participant : participants) {
        if (!check.contains(participant.getKey())) {
            identities.add(participant);
            check.add(participant.getKey());
        }
    }
    RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
    RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(course, false);
    if (re != null) {
        List<Identity> ids = repositoryService.getMembers(re, GroupRoles.participant.name());
        for (Identity id : ids) {
            if (!check.contains(id.getKey())) {
                identities.add(id);
                check.add(id.getKey());
            }
        }
    }
    return identities;
}
Also used : 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)

Aggregations

BusinessGroupService (org.olat.group.BusinessGroupService)102 BusinessGroup (org.olat.group.BusinessGroup)84 Identity (org.olat.core.id.Identity)58 Path (javax.ws.rs.Path)38 Produces (javax.ws.rs.Produces)30 GET (javax.ws.rs.GET)24 CollaborationTools (org.olat.collaboration.CollaborationTools)18 SearchBusinessGroupParams (org.olat.group.model.SearchBusinessGroupParams)18 ArrayList (java.util.ArrayList)16 GroupVO (org.olat.restapi.support.vo.GroupVO)16 RepositoryEntry (org.olat.repository.RepositoryEntry)14 List (java.util.List)12 UserRequest (org.olat.core.gui.UserRequest)12 ICourse (org.olat.course.ICourse)10 HashSet (java.util.HashSet)8 PUT (javax.ws.rs.PUT)8 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)8 Roles (org.olat.core.id.Roles)8 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)6 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)6