Search in sources :

Example 6 with PublishTreeModel

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

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)

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