Search in sources :

Example 46 with CourseEditorTreeNode

use of org.olat.course.tree.CourseEditorTreeNode in project OpenOLAT by OpenOLAT.

the class PublishProcessTest method testPublishANotReallyNewNode.

/**
 * Publish a course with a node marked as new but the node
 * exists already in the run structure.
 *
 * @throws URISyntaxException
 */
@Test
public void testPublishANotReallyNewNode() throws URISyntaxException {
    Identity author = JunitTestHelper.createAndPersistIdentityAsAdmin("publisher-" + UUID.randomUUID().toString());
    RepositoryEntry re = deployTestCourse("simple_course_err1_new.zip");
    // change node 1
    ICourse course = CourseFactory.loadCourse(re.getOlatResource().getResourceableId());
    CourseEditorTreeModel cetm = course.getEditorTreeModel();
    CourseEditorTreeNode node1 = (CourseEditorTreeNode) cetm.getRootNode().getChildAt(0);
    // publish the course and must survive this without exception
    // as the course has no changes but we try to publish it
    List<String> nodeIds = Collections.singletonList(node1.getIdent());
    publishCourse(nodeIds, re, author);
    // check the change
    ICourse reloadedCourse = CourseFactory.loadCourse(re.getOlatResource().getResourceableId());
    Assert.assertEquals(3, reloadedCourse.getRunStructure().getRootNode().getChildCount());
    INode runNode1 = reloadedCourse.getRunStructure().getRootNode().getChildAt(0);
    Assert.assertNotNull(runNode1);
    CourseNode runNode1Impl = (CourseNode) runNode1;
    Assert.assertEquals("Node 1 not really new", runNode1Impl.getShortTitle());
}
Also used : INode(org.olat.core.util.nodes.INode) CourseEditorTreeModel(org.olat.course.tree.CourseEditorTreeModel) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) CourseNode(org.olat.course.nodes.CourseNode) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 47 with CourseEditorTreeNode

use of org.olat.course.tree.CourseEditorTreeNode in project OpenOLAT by OpenOLAT.

the class CheckListStepRunnerCallback method execute.

@Override
public Step execute(UserRequest ureq, WindowControl wControl, StepsRunContext runContext) {
    GeneratorData data = (GeneratorData) runContext.get("data");
    List<Checkbox> templateCheckbox = data.getCheckboxList();
    ModuleConfiguration templateConfig = data.getModuleConfiguration();
    ICourse course = CourseFactory.getCourseEditSession(courseOres.getResourceableId());
    CourseEnvironment courseEnv = course.getCourseEnvironment();
    CheckboxManager checkboxManager = CoreSpringFactory.getImpl(CheckboxManager.class);
    CourseNode structureNode = createCourseNode(data.getStructureShortTitle(), data.getStructureTitle(), data.getStructureObjectives(), "st");
    CourseEditorTreeNode parentNode = (CourseEditorTreeNode) course.getEditorTreeModel().getRootNode();
    course.getEditorTreeModel().addCourseNode(structureNode, parentNode.getCourseNode());
    List<CheckListNode> nodes = data.getNodes();
    List<String> nodesIdent = new ArrayList<>();
    for (CheckListNode node : nodes) {
        String title = node.getTitle();
        CheckListCourseNode checkNode = (CheckListCourseNode) createCourseNode(title, title, null, "checklist");
        nodesIdent.add(checkNode.getIdent());
        ModuleConfiguration config = checkNode.getModuleConfiguration();
        config.putAll(templateConfig);
        CheckboxList checkboxList = new CheckboxList();
        List<Checkbox> boxes = new ArrayList<>();
        for (Checkbox templateBox : templateCheckbox) {
            Checkbox checkbox = templateBox.clone();
            boxes.add(checkbox);
            if (StringHelper.containsNonWhitespace(templateBox.getFilename())) {
                File path = new File(FolderConfig.getCanonicalTmpDir(), templateBox.getCheckboxId());
                VFSContainer tmpContainer = new LocalFolderImpl(path);
                VFSItem item = tmpContainer.resolve(templateBox.getFilename());
                if (item instanceof VFSLeaf) {
                    VFSContainer container = checkboxManager.getFileContainer(courseEnv, checkNode);
                    VFSManager.copyContent(tmpContainer, container);
                    tmpContainer.deleteSilently();
                }
            }
        }
        checkboxList.setList(boxes);
        config.set(CheckListCourseNode.CONFIG_KEY_CHECKBOX, checkboxList);
        boolean dueDate = node.getDueDate() != null;
        if (dueDate) {
            config.set(CheckListCourseNode.CONFIG_KEY_DUE_DATE, node.getDueDate());
        }
        config.set(CheckListCourseNode.CONFIG_KEY_CLOSE_AFTER_DUE_DATE, new Boolean(dueDate));
        course.getEditorTreeModel().addCourseNode(checkNode, structureNode);
    }
    setScoreCalculation(data, (STCourseNode) structureNode, nodesIdent);
    return StepsMainRunController.DONE_MODIFIED;
}
Also used : CheckboxList(org.olat.course.nodes.cl.model.CheckboxList) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) ModuleConfiguration(org.olat.modules.ModuleConfiguration) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) VFSContainer(org.olat.core.util.vfs.VFSContainer) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem) ICourse(org.olat.course.ICourse) CheckListCourseNode(org.olat.course.nodes.CheckListCourseNode) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl) CheckboxManager(org.olat.course.nodes.cl.CheckboxManager) Checkbox(org.olat.course.nodes.cl.model.Checkbox) CourseNode(org.olat.course.nodes.CourseNode) CheckListCourseNode(org.olat.course.nodes.CheckListCourseNode) STCourseNode(org.olat.course.nodes.STCourseNode) File(java.io.File)

Example 48 with CourseEditorTreeNode

use of org.olat.course.tree.CourseEditorTreeNode in project OpenOLAT by OpenOLAT.

the class CoursesContactElementTest method testFullConfig.

@Test
public void testFullConfig() throws IOException, URISyntaxException {
    assertTrue(conn.login("administrator", "openolat"));
    // create an contact node
    URI newContactUri = getElementsUri(course1).path("contact").queryParam("parentNodeId", rootNodeId).queryParam("position", "0").queryParam("shortTitle", "Contact-1").queryParam("longTitle", "Contact-long-1").queryParam("objectives", "Contact-objectives-1").queryParam("coaches", "true").queryParam("participants", "true").queryParam("groups", "").queryParam("areas", "").queryParam("to", "test@frentix.com;test2@frentix.com").queryParam("defaultSubject", "Hello by contact 1").queryParam("defaultBody", "Hello by contact 1 body").build();
    HttpPut method = conn.createPut(newContactUri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    // check the return values
    assertEquals(200, response.getStatusLine().getStatusCode());
    CourseNodeVO contactNode = conn.parse(response, CourseNodeVO.class);
    assertNotNull(contactNode);
    assertNotNull(contactNode.getId());
    // check the persisted value
    ICourse course = CourseFactory.loadCourse(course1.getResourceableId());
    TreeNode node = course.getEditorTreeModel().getNodeById(contactNode.getId());
    assertNotNull(node);
    CourseEditorTreeNode editorCourseNode = (CourseEditorTreeNode) node;
    CourseNode courseNode = editorCourseNode.getCourseNode();
    ModuleConfiguration config = courseNode.getModuleConfiguration();
    assertNotNull(config);
    assertEquals(config.getBooleanEntry(CONFIG_KEY_EMAILTOCOACHES), true);
    assertEquals(config.getBooleanEntry(CONFIG_KEY_EMAILTOPARTICIPANTS), true);
    @SuppressWarnings("unchecked") List<String> tos = (List<String>) config.get(CONFIG_KEY_EMAILTOADRESSES);
    assertNotNull(tos);
    assertEquals(2, tos.size());
    assertEquals(config.get(CONFIG_KEY_MSUBJECT_DEFAULT), "Hello by contact 1");
    assertEquals(config.get(CONFIG_KEY_MBODY_DEFAULT), "Hello by contact 1 body");
}
Also used : ModuleConfiguration(org.olat.modules.ModuleConfiguration) CourseNodeVO(org.olat.restapi.support.vo.CourseNodeVO) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) HttpResponse(org.apache.http.HttpResponse) ICourse(org.olat.course.ICourse) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) TreeNode(org.olat.core.gui.components.tree.TreeNode) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) List(java.util.List) CourseNode(org.olat.course.nodes.CourseNode) Test(org.junit.Test)

Example 49 with CourseEditorTreeNode

use of org.olat.course.tree.CourseEditorTreeNode in project OpenOLAT by OpenOLAT.

the class PublishProcess method checkUpdates.

private List<StatusDescription> checkUpdates(List<CourseEditorTreeNode> courseEditorTreeNodes, CourseEditorEnv cev) {
    List<StatusDescription> notifications = new ArrayList<StatusDescription>();
    for (Iterator<CourseEditorTreeNode> iter = courseEditorTreeNodes.iterator(); iter.hasNext(); ) {
        CourseEditorTreeNode cetn = iter.next();
        CourseNode cn = cetn.getCourseNode();
        List<StatusDescription> nodeNotes = cn.publishUpdatesExplanations(cev);
        if (nodeNotes != null && nodeNotes.size() > 0) {
            notifications.addAll(nodeNotes);
        }
    }
    return notifications;
}
Also used : ArrayList(java.util.ArrayList) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) CourseNode(org.olat.course.nodes.CourseNode)

Example 50 with CourseEditorTreeNode

use of org.olat.course.tree.CourseEditorTreeNode in project OpenOLAT by OpenOLAT.

the class PublishProcess method assemblePublishConfirmation.

String assemblePublishConfirmation() {
    List<String> nodeIdsToPublish = originalNodeIdsToPublish;
    StringBuilder msg = new StringBuilder();
    OLATResourceable courseRunOres = OresHelper.createOLATResourceableInstance(RunMainController.ORES_TYPE_COURSE_RUN, repositoryEntry.getOlatResource().getResourceableId());
    // -1: Remove myself from list
    int cnt = CoordinatorManager.getInstance().getCoordinator().getEventBus().getListeningIdentityCntFor(courseRunOres) - 1;
    if (cnt > 0) {
        msg.append(translate("pbl.confirm.users", String.valueOf(cnt)));
    } else {
        msg.append(translator.translate("pbl.confirm"));
    }
    if (nodeIdsToPublish != null && nodeIdsToPublish.size() > 0) {
        msg.append("<ul class='list-unstyled'>");
        CourseEditorTreeModel cetm = course.getEditorTreeModel();
        for (int i = 0; i < nodeIdsToPublish.size(); i++) {
            msg.append("<li>");
            String nodeId = nodeIdsToPublish.get(i);
            CourseEditorTreeNode cetn = (CourseEditorTreeNode) cetm.getNodeById(nodeId);
            CourseNode cn = cetm.getCourseNode(nodeId);
            if (cetn.isDeleted() && !cetn.isNewnode()) {
                msg.append("<i class='o_icon o_icon_delete_item'> </i> ");
            } else {
                CourseNodeConfiguration nodeConfig = CourseNodeFactory.getInstance().getCourseNodeConfigurationEvenForDisabledBB(cn.getType());
                if (nodeConfig != null) {
                    msg.append("<i class='o_icon ").append(nodeConfig.getIconCSSClass()).append("'> </i> ");
                }
            }
            msg.append(cn.getShortTitle()).append("</li>");
        }
        msg.append("</ul>");
    }
    return msg.toString();
}
Also used : CourseEditorTreeModel(org.olat.course.tree.CourseEditorTreeModel) OLATResourceable(org.olat.core.id.OLATResourceable) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) CourseNode(org.olat.course.nodes.CourseNode) CourseNodeConfiguration(org.olat.course.nodes.CourseNodeConfiguration)

Aggregations

CourseEditorTreeNode (org.olat.course.tree.CourseEditorTreeNode)88 CourseNode (org.olat.course.nodes.CourseNode)54 ICourse (org.olat.course.ICourse)38 CourseEditorTreeModel (org.olat.course.tree.CourseEditorTreeModel)24 INode (org.olat.core.util.nodes.INode)22 Test (org.junit.Test)20 RepositoryEntry (org.olat.repository.RepositoryEntry)18 Identity (org.olat.core.id.Identity)14 TreeVisitor (org.olat.core.util.tree.TreeVisitor)14 Visitor (org.olat.core.util.tree.Visitor)14 CourseNodeVO (org.olat.restapi.support.vo.CourseNodeVO)12 TreeNode (org.olat.core.gui.components.tree.TreeNode)10 STCourseNode (org.olat.course.nodes.STCourseNode)10 ArrayList (java.util.ArrayList)9 File (java.io.File)8 URI (java.net.URI)8 HttpResponse (org.apache.http.HttpResponse)8 HttpPut (org.apache.http.client.methods.HttpPut)8 Structure (org.olat.course.Structure)8 BCCourseNode (org.olat.course.nodes.BCCourseNode)8