Search in sources :

Example 6 with CatalogManager

use of org.olat.repository.manager.CatalogManager in project OpenOLAT by OpenOLAT.

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 7 with CatalogManager

use of org.olat.repository.manager.CatalogManager in project OpenOLAT by OpenOLAT.

the class PublishProcess method publishToCatalog.

protected void publishToCatalog(String choiceValue, List<CategoryLabel> labels) {
    CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
    CourseNode rootNode = course.getRunStructure().getRootNode();
    Property prop = cpm.findCourseNodeProperty(rootNode, null, null, "catalog-choice");
    if (prop == null) {
        prop = cpm.createCourseNodePropertyInstance(rootNode, null, null, "catalog-choice", null, null, choiceValue, null);
        cpm.saveProperty(prop);
    } else {
        prop.setStringValue(choiceValue);
        cpm.updateProperty(prop);
    }
    CatalogManager cm = CoreSpringFactory.getImpl(CatalogManager.class);
    List<CatalogEntry> refParentCategories = cm.getCatalogCategoriesFor(repositoryEntry);
    a_a: for (CategoryLabel label : labels) {
        CatalogEntry category = label.getCategory();
        CatalogEntry parentCategory = label.getParentCategory();
        if (label.isDeleted()) {
            // test
            if (category.getKey() != null) {
                List<CatalogEntry> children = cm.getChildrenOf(category);
                for (CatalogEntry child : children) {
                    if (child.getRepositoryEntry() != null && child.getRepositoryEntry().equalsByPersistableKey(repositoryEntry)) {
                        cm.deleteCatalogEntry(child);
                    }
                }
            }
        } else if (category.getKey() == null) {
            // it's a new entry -> check if not already in catalog at this position
            for (Iterator<CatalogEntry> refIt = refParentCategories.iterator(); refIt.hasNext(); ) {
                CatalogEntry refParentCategory = refIt.next();
                if (refParentCategory.equalsByPersistableKey(parentCategory)) {
                    refIt.remove();
                    break a_a;
                }
            }
            category.setOwnerGroup(BaseSecurityManager.getInstance().createAndPersistSecurityGroup());
            cm.addCatalogEntry(parentCategory, category);
        } else {
            for (Iterator<CatalogEntry> refIt = refParentCategories.iterator(); refIt.hasNext(); ) {
                CatalogEntry refParentCategory = refIt.next();
                if (refParentCategory.equalsByPersistableKey(category)) {
                    refIt.remove();
                }
            }
        }
    }
}
Also used : CatalogEntry(org.olat.repository.CatalogEntry) List(java.util.List) ArrayList(java.util.ArrayList) CourseNode(org.olat.course.nodes.CourseNode) CategoryLabel(org.olat.course.editor.PublishStepCatalog.CategoryLabel) Property(org.olat.properties.Property) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager) CatalogManager(org.olat.repository.manager.CatalogManager)

Example 8 with CatalogManager

use of org.olat.repository.manager.CatalogManager in project openolat by klemens.

the class CatalogHelper method buildCatalogNode.

protected static final TreeNode buildCatalogNode(final CatalogEntry rootEntry) {
    final CatalogManager cm = CoreSpringFactory.getImpl(CatalogManager.class);
    List<CatalogEntry> children = cm.getChildrenOf(rootEntry);
    GenericTreeNode ctn = new GenericTreeNode(rootEntry.getName(), rootEntry);
    ctn.setAccessible(true);
    for (int i = 0; i < children.size(); i++) {
        // add child itself
        CatalogEntry cchild = children.get(i);
        if (cchild.getType() == CatalogEntry.TYPE_NODE) {
            TreeNode ctchild = buildCatalogNode(cchild);
            ((GenericTreeNode) ctchild).setAccessible(true);
            ctn.addChild(ctchild);
        }
    }
    return ctn;
}
Also used : GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) TreeNode(org.olat.core.gui.components.tree.TreeNode) CatalogEntry(org.olat.repository.CatalogEntry) CatalogManager(org.olat.repository.manager.CatalogManager)

Aggregations

CatalogEntry (org.olat.repository.CatalogEntry)8 CatalogManager (org.olat.repository.manager.CatalogManager)8 ArrayList (java.util.ArrayList)4 CourseNode (org.olat.course.nodes.CourseNode)4 RepositoryManager (org.olat.repository.RepositoryManager)4 List (java.util.List)2 CollaborationTools (org.olat.collaboration.CollaborationTools)2 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)2 TreeNode (org.olat.core.gui.components.tree.TreeNode)2 Condition (org.olat.course.condition.Condition)2 CourseAccessAndProperties (org.olat.course.editor.CourseAccessAndProperties)2 PublishProcess (org.olat.course.editor.PublishProcess)2 PublishSetInformations (org.olat.course.editor.PublishSetInformations)2 CategoryLabel (org.olat.course.editor.PublishStepCatalog.CategoryLabel)2 StatusDescription (org.olat.course.editor.StatusDescription)2 BCCourseNode (org.olat.course.nodes.BCCourseNode)2 COCourseNode (org.olat.course.nodes.COCourseNode)2 ENCourseNode (org.olat.course.nodes.ENCourseNode)2 FOCourseNode (org.olat.course.nodes.FOCourseNode)2 SPCourseNode (org.olat.course.nodes.SPCourseNode)2