Search in sources :

Example 11 with CourseEditorTreeModel

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

the class QuickPublishController method doAutoPublish.

private boolean doAutoPublish() {
    ICourse course = CourseFactory.loadCourse(courseOres);
    CourseEditorTreeModel cetm = course.getEditorTreeModel();
    PublishProcess publishProcess = PublishProcess.getInstance(course, cetm, getLocale());
    PublishTreeModel publishTreeModel = publishProcess.getPublishTreeModel();
    if (publishTreeModel.hasPublishableChanges()) {
        List<String> nodeToPublish = new ArrayList<String>();
        visitPublishModel(publishTreeModel.getRootNode(), publishTreeModel, nodeToPublish);
        // only add selection if changes were possible
        for (Iterator<String> selectionIt = nodeToPublish.iterator(); selectionIt.hasNext(); ) {
            String ident = selectionIt.next();
            TreeNode node = publishProcess.getPublishTreeModel().getNodeById(ident);
            if (!publishTreeModel.isSelectable(node)) {
                selectionIt.remove();
            }
        }
        publishProcess.createPublishSetFor(nodeToPublish);
        PublishSetInformations set = publishProcess.testPublishSet(getLocale());
        StatusDescription[] status = set.getWarnings();
        // publish not possible when there are errors
        StringBuilder errMsg = new StringBuilder();
        for (int i = 0; i < status.length; i++) {
            if (status[i].isError()) {
                errMsg.append(status[i].getLongDescription(getLocale()));
                logError("Status error by publish: " + status[i].getLongDescription(getLocale()), null);
            }
        }
        if (errMsg.length() > 0) {
            getWindowControl().setWarning(errMsg.toString());
            return false;
        }
        PublishEvents publishEvents = publishProcess.getPublishEvents();
        try {
            publishProcess.applyPublishSet(getIdentity(), getLocale(), false);
        } catch (Exception e) {
            logError("", e);
        }
        if (publishEvents.getPostPublishingEvents().size() > 0) {
            for (MultiUserEvent event : publishEvents.getPostPublishingEvents()) {
                CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(event, courseOres);
            }
        }
    }
    return true;
}
Also used : CourseEditorTreeModel(org.olat.course.tree.CourseEditorTreeModel) PublishTreeModel(org.olat.course.tree.PublishTreeModel) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) TreeNode(org.olat.core.gui.components.tree.TreeNode) MultiUserEvent(org.olat.core.util.event.MultiUserEvent)

Example 12 with CourseEditorTreeModel

use of org.olat.course.tree.CourseEditorTreeModel in project openolat by klemens.

the class CoursesElementsTest method testUpdateRootNodeCoursePostWithFile.

@Test
public // fxdiff FXOLAT-122: course management
void testUpdateRootNodeCoursePostWithFile() throws IOException, URISyntaxException {
    assertTrue(conn.login("administrator", "openolat"));
    // create an empty course
    URI uri = getCoursesUri().queryParam("shortTitle", "course5").queryParam("title", "course5 long name").build();
    HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    CourseVO course = conn.parse(response, CourseVO.class);
    assertNotNull(course);
    assertNotNull(course.getKey());
    assertNotNull(course.getEditorRootNodeId());
    // the page
    URL pageUrl = CoursesElementsTest.class.getResource("singlepage.html");
    assertNotNull(pageUrl);
    File page = new File(pageUrl.toURI());
    // update the root node
    URI rootUri = getElementsUri(course).path("structure").path(course.getEditorRootNodeId()).build();
    HttpPost newStructureMethod = conn.createPost(rootUri, MediaType.APPLICATION_JSON);
    HttpEntity entity = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE).addBinaryBody("file", page, ContentType.APPLICATION_OCTET_STREAM, page.getName()).addTextBody("filename", page.getName()).addTextBody("parentNodeId", course.getEditorRootNodeId()).addTextBody("position", "1").addTextBody("shortTitle", "Structure-0-with-file").addTextBody("longTitle", "Structure-long-0-with-file").addTextBody("objectives", "Structure-objectives-0-with-file").addTextBody("displayType", "file").build();
    newStructureMethod.setEntity(entity);
    HttpResponse newStructureCode = conn.execute(newStructureMethod);
    assertTrue(newStructureCode.getStatusLine().getStatusCode() == 200 || newStructureCode.getStatusLine().getStatusCode() == 201);
    // check the response
    CourseNodeVO structureNode = conn.parse(newStructureCode, CourseNodeVO.class);
    assertNotNull(structureNode);
    assertNotNull(structureNode.getId());
    assertEquals(structureNode.getShortTitle(), "Structure-0-with-file");
    assertEquals(structureNode.getLongTitle(), "Structure-long-0-with-file");
    assertEquals(structureNode.getLearningObjectives(), "Structure-objectives-0-with-file");
    assertEquals(structureNode.getId(), course.getEditorRootNodeId());
    // check the real node
    ICourse realCourse = CourseFactory.loadCourse(course.getKey());
    CourseEditorTreeModel editorTreeModel = realCourse.getEditorTreeModel();
    CourseEditorTreeNode rootNode = (CourseEditorTreeNode) editorTreeModel.getRootNode();
    assertNotNull(rootNode);
    assertNotNull(rootNode.getIdent());
    assertNotNull(rootNode.getCourseNode());
    assertEquals(rootNode.getCourseNode().getShortTitle(), "Structure-0-with-file");
    assertEquals(rootNode.getCourseNode().getLongTitle(), "Structure-long-0-with-file");
    assertEquals(rootNode.getCourseNode().getLearningObjectives(), "Structure-objectives-0-with-file");
}
Also used : CourseVO(org.olat.restapi.support.vo.CourseVO) HttpPost(org.apache.http.client.methods.HttpPost) CourseEditorTreeModel(org.olat.course.tree.CourseEditorTreeModel) HttpEntity(org.apache.http.HttpEntity) 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) File(java.io.File) HttpPut(org.apache.http.client.methods.HttpPut) URL(java.net.URL) Test(org.junit.Test)

Example 13 with CourseEditorTreeModel

use of org.olat.course.tree.CourseEditorTreeModel in project openolat by klemens.

the class CoursesElementsTest method testUpdateRootNodeCoursePost.

@Test
public // fxdiff FXOLAT-122: course management
void testUpdateRootNodeCoursePost() throws IOException, URISyntaxException {
    assertTrue(conn.login("administrator", "openolat"));
    // create an empty course
    URI uri = getCoursesUri().queryParam("shortTitle", "course4").queryParam("title", "course4 long name").build();
    HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    CourseVO course = conn.parse(response, CourseVO.class);
    assertNotNull(course);
    assertNotNull(course.getKey());
    assertNotNull(course.getEditorRootNodeId());
    // update the root node
    URI rootUri = getElementsUri(course).path("structure").path(course.getEditorRootNodeId()).build();
    HttpPost updateMethod = conn.createPost(rootUri, MediaType.APPLICATION_JSON);
    HttpEntity entity = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE).addTextBody("shortTitle", "Structure-0b").addTextBody("longTitle", "Structure-long-0b").addTextBody("objectives", "Structure-objectives-0b").build();
    updateMethod.setEntity(entity);
    HttpResponse newStructureResponse = conn.execute(updateMethod);
    int newStructureCode = newStructureResponse.getStatusLine().getStatusCode();
    assertTrue(newStructureCode == 200 || newStructureCode == 201);
    // check the response
    CourseNodeVO structureNode = conn.parse(newStructureResponse, CourseNodeVO.class);
    assertNotNull(structureNode);
    assertNotNull(structureNode.getId());
    assertEquals(structureNode.getShortTitle(), "Structure-0b");
    assertEquals(structureNode.getLongTitle(), "Structure-long-0b");
    assertEquals(structureNode.getLearningObjectives(), "Structure-objectives-0b");
    assertEquals(structureNode.getId(), course.getEditorRootNodeId());
    // check the real node
    ICourse realCourse = CourseFactory.loadCourse(course.getKey());
    CourseEditorTreeModel editorTreeModel = realCourse.getEditorTreeModel();
    CourseEditorTreeNode rootNode = (CourseEditorTreeNode) editorTreeModel.getRootNode();
    assertNotNull(rootNode);
    assertNotNull(rootNode.getIdent());
    assertNotNull(rootNode.getCourseNode());
    assertEquals(rootNode.getCourseNode().getShortTitle(), "Structure-0b");
    assertEquals(rootNode.getCourseNode().getLongTitle(), "Structure-long-0b");
    assertEquals(rootNode.getCourseNode().getLearningObjectives(), "Structure-objectives-0b");
}
Also used : CourseVO(org.olat.restapi.support.vo.CourseVO) HttpPost(org.apache.http.client.methods.HttpPost) CourseEditorTreeModel(org.olat.course.tree.CourseEditorTreeModel) HttpEntity(org.apache.http.HttpEntity) 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) Test(org.junit.Test)

Example 14 with CourseEditorTreeModel

use of org.olat.course.tree.CourseEditorTreeModel in project openolat by klemens.

the class AssessmentModeEditController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    formLayout.setElementCssClass("o_sel_assessment_mode_edit_form");
    setFormContextHelp("Assessment mode");
    if (StringHelper.containsNonWhitespace(assessmentMode.getName())) {
        setFormTitle("form.mode.title", new String[] { assessmentMode.getName() });
    } else {
        setFormTitle("form.mode.title.add");
    }
    setFormDescription("form.mode.description");
    ICourse course = CourseFactory.loadCourse(courseOres);
    if (StringHelper.containsNonWhitespace(assessmentMode.getStartElement())) {
        CourseNode startElement = course.getRunStructure().getNode(assessmentMode.getStartElement());
        if (startElement == null) {
            setFormWarning("warning.missing.start.element");
        }
    }
    if (StringHelper.containsNonWhitespace(assessmentMode.getElementList())) {
        String elements = assessmentMode.getElementList();
        for (String element : elements.split(",")) {
            CourseNode node = course.getRunStructure().getNode(element);
            if (node == null) {
                setFormWarning("warning.missing.element");
            }
        }
    }
    Status status = assessmentMode.getStatus();
    String name = assessmentMode.getName();
    nameEl = uifactory.addTextElement("mode.name", "mode.name", 255, name, formLayout);
    nameEl.setElementCssClass("o_sel_assessment_mode_name");
    nameEl.setMandatory(true);
    nameEl.setEnabled(status != Status.followup && status != Status.end);
    String desc = assessmentMode.getDescription();
    descriptionEl = uifactory.addRichTextElementForStringData("mode.description", "mode.description", desc, 6, -1, false, null, null, formLayout, ureq.getUserSession(), getWindowControl());
    descriptionEl.setEnabled(status != Status.followup && status != Status.end);
    beginEl = uifactory.addDateChooser("mode.begin", assessmentMode.getBegin(), formLayout);
    beginEl.setElementCssClass("o_sel_assessment_mode_begin");
    beginEl.setDateChooserTimeEnabled(true);
    beginEl.setMandatory(true);
    beginEl.setEnabled(status == Status.none || status == Status.leadtime);
    int leadTime = assessmentMode.getLeadTime();
    if (leadTime < 0) {
        leadTime = 0;
    }
    leadTimeEl = uifactory.addIntegerElement("mode.leadTime", leadTime, formLayout);
    leadTimeEl.setElementCssClass("o_sel_assessment_mode_leadtime");
    leadTimeEl.setDisplaySize(3);
    leadTimeEl.setEnabled(status == Status.none || status == Status.leadtime);
    endEl = uifactory.addDateChooser("mode.end", assessmentMode.getEnd(), formLayout);
    endEl.setElementCssClass("o_sel_assessment_mode_end");
    endEl.setDateChooserTimeEnabled(true);
    endEl.setDefaultValue(beginEl);
    endEl.setMandatory(true);
    endEl.setEnabled(status != Status.end);
    int followupTime = assessmentMode.getFollowupTime();
    if (followupTime < 0) {
        followupTime = 0;
    }
    followupTimeEl = uifactory.addIntegerElement("mode.followupTime", followupTime, formLayout);
    followupTimeEl.setElementCssClass("o_sel_assessment_mode_followuptime");
    followupTimeEl.setDisplaySize(3);
    followupTimeEl.setEnabled(status != Status.end);
    String[] startModeValues = new String[] { translate("mode.beginend.automatic"), translate("mode.beginend.manual") };
    startModeEl = uifactory.addDropdownSingleselect("mode.beginend", formLayout, startModeKeys, startModeValues, null);
    startModeEl.setElementCssClass("o_sel_assessment_mode_start_mode");
    if (assessmentMode.isManualBeginEnd()) {
        startModeEl.select(startModeKeys[1], true);
    } else {
        startModeEl.select(startModeKeys[0], true);
    }
    startModeEl.setEnabled(status != Status.end);
    String[] audienceKeys = new String[] { AssessmentMode.Target.courseAndGroups.name(), AssessmentMode.Target.course.name(), AssessmentMode.Target.groups.name() };
    String[] audienceValues = new String[] { translate("target.courseAndGroups"), translate("target.course"), translate("target.groups") };
    targetEl = uifactory.addRadiosVertical("audience", "mode.target", formLayout, audienceKeys, audienceValues);
    targetEl.setElementCssClass("o_sel_assessment_mode_audience");
    targetEl.setEnabled(status != Status.end);
    Target target = assessmentMode.getTargetAudience();
    if (target != null) {
        for (String audienceKey : audienceKeys) {
            if (audienceKey.equals(target.name())) {
                targetEl.select(audienceKey, true);
            }
        }
    }
    if (!targetEl.isOneSelected()) {
        targetEl.select(audienceKeys[0], true);
    }
    // choose groups
    String groupPage = velocity_root + "/choose_groups.html";
    chooseGroupsCont = FormLayoutContainer.createCustomFormLayout("chooseGroups", getTranslator(), groupPage);
    chooseGroupsCont.setRootForm(mainForm);
    formLayout.add(chooseGroupsCont);
    chooseGroupsButton = uifactory.addFormLink("choose.groups", chooseGroupsCont, Link.BUTTON);
    chooseGroupsButton.setEnabled(status != Status.end);
    chooseAreasButton = uifactory.addFormLink("choose.areas", chooseGroupsCont, Link.BUTTON);
    chooseAreasButton.setEnabled(status != Status.end);
    groupKeys = new ArrayList<>();
    groupNames = new ArrayList<>();
    for (AssessmentModeToGroup modeToGroup : assessmentMode.getGroups()) {
        BusinessGroup group = modeToGroup.getBusinessGroup();
        groupKeys.add(group.getKey());
        groupNames.add(StringHelper.escapeHtml(group.getName()));
    }
    chooseGroupsCont.getFormItemComponent().contextPut("groupNames", groupNames);
    areaKeys = new ArrayList<>();
    areaNames = new ArrayList<>();
    for (AssessmentModeToArea modeToArea : assessmentMode.getAreas()) {
        BGArea area = modeToArea.getArea();
        areaKeys.add(area.getKey());
        areaNames.add(StringHelper.escapeHtml(area.getName()));
    }
    chooseGroupsCont.getFormItemComponent().contextPut("areaNames", areaNames);
    // course elements
    courseElementsRestrictionEl = uifactory.addCheckboxesHorizontal("cer", "mode.course.element.restriction", formLayout, onKeys, onValues);
    courseElementsRestrictionEl.addActionListener(FormEvent.ONCHANGE);
    courseElementsRestrictionEl.select(onKeys[0], assessmentMode.isRestrictAccessElements());
    courseElementsRestrictionEl.setEnabled(status != Status.end);
    String coursePage = velocity_root + "/choose_elements.html";
    chooseElementsCont = FormLayoutContainer.createCustomFormLayout("chooseElements", getTranslator(), coursePage);
    chooseElementsCont.setRootForm(mainForm);
    formLayout.add(chooseElementsCont);
    chooseElementsCont.setVisible(assessmentMode.isRestrictAccessElements());
    CourseEditorTreeModel treeModel = course.getEditorTreeModel();
    elementKeys = new ArrayList<>();
    elementNames = new ArrayList<>();
    String elements = assessmentMode.getElementList();
    if (StringHelper.containsNonWhitespace(elements)) {
        for (String element : elements.split(",")) {
            String courseNodeName = getCourseNodeName(element, treeModel);
            if (StringHelper.containsNonWhitespace(courseNodeName)) {
                elementKeys.add(element);
                elementNames.add(courseNodeName);
            }
        }
    }
    chooseElementsCont.getFormItemComponent().contextPut("elementNames", elementNames);
    chooseElementsButton = uifactory.addFormLink("choose.elements", chooseElementsCont, Link.BUTTON);
    chooseElementsButton.setEnabled(status != Status.end);
    startElementKey = assessmentMode.getStartElement();
    String startElementName = "";
    if (StringHelper.containsNonWhitespace(startElementKey)) {
        startElementName = getCourseNodeName(startElementKey, treeModel);
    }
    startElementEl = uifactory.addStaticTextElement("mode.start.element", "mode.start.element", startElementName, formLayout);
    chooseStartElementButton = uifactory.addFormLink("choose.start.element", formLayout, Link.BUTTON);
    chooseStartElementButton.setEnabled(status != Status.end);
    // ips
    ipsEl = uifactory.addCheckboxesHorizontal("ips", "mode.ips", formLayout, onKeys, onValues);
    ipsEl.select(onKeys[0], assessmentMode.isRestrictAccessIps());
    ipsEl.addActionListener(FormEvent.ONCHANGE);
    ipsEl.setEnabled(status != Status.end);
    String ipList = assessmentMode.getIpList();
    ipListEl = uifactory.addTextAreaElement("mode.ips.list", "mode.ips.list", 4096, 4, 60, false, ipList, formLayout);
    ipListEl.setVisible(assessmentMode.isRestrictAccessIps());
    ipListEl.setEnabled(status != Status.end);
    safeExamBrowserEl = uifactory.addCheckboxesHorizontal("safeexam", "mode.safeexambrowser", formLayout, onKeys, onValues);
    safeExamBrowserEl.select(onKeys[0], assessmentMode.isSafeExamBrowser());
    safeExamBrowserEl.addActionListener(FormEvent.ONCHANGE);
    safeExamBrowserEl.setEnabled(status != Status.end);
    String key = assessmentMode.getSafeExamBrowserKey();
    safeExamBrowserKeyEl = uifactory.addTextAreaElement("safeexamkey", "mode.safeexambrowser.key", 4096, 6, 60, false, key, formLayout);
    safeExamBrowserKeyEl.setVisible(assessmentMode.isSafeExamBrowser());
    safeExamBrowserKeyEl.setEnabled(status != Status.end);
    String hint = assessmentMode.getSafeExamBrowserHint();
    safeExamBrowserHintEl = uifactory.addRichTextElementForStringData("safeexamhint", "mode.safeexambrowser.hint", hint, 10, -1, false, null, null, formLayout, ureq.getUserSession(), getWindowControl());
    safeExamBrowserHintEl.setVisible(assessmentMode.isSafeExamBrowser());
    safeExamBrowserHintEl.setEnabled(status != Status.end);
    forCoachEl = uifactory.addCheckboxesHorizontal("forcoach", "mode.for.coach", formLayout, onKeys, onValues);
    forCoachEl.select(onKeys[0], assessmentMode.isApplySettingsForCoach());
    forCoachEl.setEnabled(status != Status.end);
    FormLayoutContainer buttonCont = FormLayoutContainer.createButtonLayout("button", getTranslator());
    formLayout.add(buttonCont);
    if (status != Status.end) {
        uifactory.addFormSubmitButton("save", buttonCont);
    }
    uifactory.addFormCancelButton("cancel", buttonCont, ureq, getWindowControl());
}
Also used : Status(org.olat.course.assessment.AssessmentMode.Status) CourseEditorTreeModel(org.olat.course.tree.CourseEditorTreeModel) BusinessGroup(org.olat.group.BusinessGroup) AssessmentModeToGroup(org.olat.course.assessment.AssessmentModeToGroup) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) ICourse(org.olat.course.ICourse) AssessmentModeToArea(org.olat.course.assessment.AssessmentModeToArea) Target(org.olat.course.assessment.AssessmentMode.Target) BGArea(org.olat.group.area.BGArea) CourseNode(org.olat.course.nodes.CourseNode)

Example 15 with CourseEditorTreeModel

use of org.olat.course.tree.CourseEditorTreeModel in project openolat by klemens.

the class PublishProcessTest method testPublishANotPublishedNode.

/**
 * Publish an unchanged course. We try to publish a node which
 * was not changed nor deleted.
 *
 * @throws URISyntaxException
 */
@Test
public void testPublishANotPublishedNode() throws URISyntaxException {
    Identity author = JunitTestHelper.createAndPersistIdentityAsAdmin("publisher-" + UUID.randomUUID().toString());
    RepositoryEntry re = deployTestCourse("simple_course.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);
}
Also used : CourseEditorTreeModel(org.olat.course.tree.CourseEditorTreeModel) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Aggregations

CourseEditorTreeModel (org.olat.course.tree.CourseEditorTreeModel)46 ICourse (org.olat.course.ICourse)26 CourseNode (org.olat.course.nodes.CourseNode)26 CourseEditorTreeNode (org.olat.course.tree.CourseEditorTreeNode)24 Test (org.junit.Test)18 RepositoryEntry (org.olat.repository.RepositoryEntry)16 Identity (org.olat.core.id.Identity)14 INode (org.olat.core.util.nodes.INode)12 ArrayList (java.util.ArrayList)6 CourseNodeConfiguration (org.olat.course.nodes.CourseNodeConfiguration)6 File (java.io.File)4 URI (java.net.URI)4 HttpEntity (org.apache.http.HttpEntity)4 HttpResponse (org.apache.http.HttpResponse)4 HttpPost (org.apache.http.client.methods.HttpPost)4 HttpPut (org.apache.http.client.methods.HttpPut)4 AssertException (org.olat.core.logging.AssertException)4 CourseConfig (org.olat.course.config.CourseConfig)4 PublishProcess (org.olat.course.editor.PublishProcess)4 PublishSetInformations (org.olat.course.editor.PublishSetInformations)4