Search in sources :

Example 1 with PublishTreeModel

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

the class ModifyCourseEvent method publishCourse.

/**
 * Publish the course with some standard options
 * @param course
 * @param locale
 * @param identity
 */
public static void publishCourse(ICourse course, int access, boolean membersOnly, Identity identity, Locale locale) {
    CourseEditorTreeModel cetm = course.getEditorTreeModel();
    PublishProcess publishProcess = PublishProcess.getInstance(course, cetm, locale);
    PublishTreeModel publishTreeModel = publishProcess.getPublishTreeModel();
    int newAccess = (access < RepositoryEntry.ACC_OWNERS || access > RepositoryEntry.ACC_USERS_GUESTS) ? RepositoryEntry.ACC_USERS : access;
    // access rule -> all users can the see course
    // RepositoryEntry.ACC_OWNERS
    // only owners can the see course
    // RepositoryEntry.ACC_OWNERS_AUTHORS //only owners and authors can the see course
    // RepositoryEntry.ACC_USERS_GUESTS // users and guests can see the course
    // fxdiff VCRP-1,2: access control of resources
    publishProcess.changeGeneralAccess(identity, newAccess, membersOnly);
    if (publishTreeModel.hasPublishableChanges()) {
        List<String> nodeToPublish = new ArrayList<String>();
        visitPublishModel(publishTreeModel.getRootNode(), publishTreeModel, nodeToPublish);
        publishProcess.createPublishSetFor(nodeToPublish);
        PublishSetInformations set = publishProcess.testPublishSet(locale);
        StatusDescription[] status = set.getWarnings();
        // publish not possible when there are errors
        for (int i = 0; i < status.length; i++) {
            if (status[i].isError()) {
                log.error("Status error by publish: " + status[i].getLongDescription(locale));
                return;
            }
        }
        try {
            course = CourseFactory.openCourseEditSession(course.getResourceableId());
            publishProcess.applyPublishSet(identity, locale, false);
        } catch (Exception e) {
            log.error("", e);
        } finally {
            closeCourseEditSession(course.getResourceableId(), true);
        }
    }
}
Also used : CourseEditorTreeModel(org.olat.course.tree.CourseEditorTreeModel) StatusDescription(org.olat.course.editor.StatusDescription) PublishTreeModel(org.olat.course.tree.PublishTreeModel) ArrayList(java.util.ArrayList) PublishProcess(org.olat.course.editor.PublishProcess) PublishSetInformations(org.olat.course.editor.PublishSetInformations) AssertException(org.olat.core.logging.AssertException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException)

Example 2 with PublishTreeModel

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

the class EditorMainController method hasPublishableChanges.

public boolean hasPublishableChanges(ICourse course) {
    if (cetm == null || course == null) {
        return false;
    }
    PublishProcess publishProcess = PublishProcess.getInstance(course, cetm, getLocale());
    PublishTreeModel publishTreeModel = publishProcess.getPublishTreeModel();
    return publishTreeModel.hasPublishableChanges();
}
Also used : PublishTreeModel(org.olat.course.tree.PublishTreeModel)

Example 3 with PublishTreeModel

use of org.olat.course.tree.PublishTreeModel 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 4 with PublishTreeModel

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

the class EditorMainController method hasPublishableChanges.

public boolean hasPublishableChanges(ICourse course) {
    if (cetm == null || course == null) {
        return false;
    }
    PublishProcess publishProcess = PublishProcess.getInstance(course, cetm, getLocale());
    PublishTreeModel publishTreeModel = publishProcess.getPublishTreeModel();
    return publishTreeModel.hasPublishableChanges();
}
Also used : PublishTreeModel(org.olat.course.tree.PublishTreeModel)

Example 5 with PublishTreeModel

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

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)

Aggregations

PublishTreeModel (org.olat.course.tree.PublishTreeModel)6 ArrayList (java.util.ArrayList)4 CourseEditorTreeModel (org.olat.course.tree.CourseEditorTreeModel)4 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 TreeNode (org.olat.core.gui.components.tree.TreeNode)2 AssertException (org.olat.core.logging.AssertException)2 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)2 MultiUserEvent (org.olat.core.util.event.MultiUserEvent)2 ICourse (org.olat.course.ICourse)2 PublishProcess (org.olat.course.editor.PublishProcess)2 PublishSetInformations (org.olat.course.editor.PublishSetInformations)2 StatusDescription (org.olat.course.editor.StatusDescription)2