Search in sources :

Example 6 with EventBus

use of org.olat.core.util.event.EventBus in project openolat by klemens.

the class CertificatesOptionsController method doChangeConfig.

private void doChangeConfig(UserRequest ureq) {
    OLATResourceable courseOres = entry.getOlatResource();
    if (CourseFactory.isCourseEditSessionOpen(courseOres.getResourceableId())) {
        showWarning("error.editoralreadylocked", new String[] { "???" });
        return;
    }
    ICourse course = CourseFactory.openCourseEditSession(courseOres.getResourceableId());
    courseConfig = course.getCourseEnvironment().getCourseConfig();
    boolean enableEfficiencyStatment = efficencyEl.isSelected(0);
    boolean updateStatement = courseConfig.isEfficencyStatementEnabled() != enableEfficiencyStatment;
    courseConfig.setEfficencyStatementIsEnabled(enableEfficiencyStatment);
    Collection<String> certificationOptions = pdfCertificatesEl.getSelectedKeys();
    courseConfig.setAutomaticCertificationEnabled(certificationOptions.contains(PDFCertificatesOptions.auto.name()));
    courseConfig.setManualCertificationEnabled(certificationOptions.contains(PDFCertificatesOptions.manual.name()));
    if (selectedTemplate != null) {
        Long templateId = selectedTemplate.getKey();
        courseConfig.setCertificateTemplate(templateId);
    } else {
        courseConfig.setCertificateTemplate(null);
    }
    boolean recertificationEnabled = reCertificationEl.isEnabled() && reCertificationEl.isAtLeastSelected(1);
    courseConfig.setRecertificationEnabled(recertificationEnabled);
    if (recertificationEnabled) {
        int timelapse = reCertificationTimelapseEl.getIntValue();
        courseConfig.setRecertificationTimelapse(timelapse);
        if (reCertificationTimelapseUnitEl.isOneSelected()) {
            String selectedUnit = reCertificationTimelapseUnitEl.getSelectedKey();
            RecertificationTimeUnit timeUnit = RecertificationTimeUnit.valueOf(selectedUnit);
            courseConfig.setRecertificationTimelapseUnit(timeUnit);
        } else {
            courseConfig.setRecertificationTimelapseUnit(RecertificationTimeUnit.month);
        }
    } else {
        courseConfig.setRecertificationTimelapse(0);
        courseConfig.setRecertificationTimelapseUnit(null);
    }
    CourseFactory.setCourseConfig(course.getResourceableId(), courseConfig);
    CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
    if (updateStatement) {
        if (enableEfficiencyStatment) {
            // first create the efficiencies, send event to agency (all courses add link)
            RepositoryEntry courseRe = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
            List<Identity> identitiesWithData = course.getCourseEnvironment().getCoursePropertyManager().getAllIdentitiesWithCourseAssessmentData(null);
            efficiencyStatementManager.updateEfficiencyStatements(courseRe, identitiesWithData);
        } else {
            // delete really the efficiencies of the users.
            RepositoryEntry courseRepoEntry = RepositoryManager.getInstance().lookupRepositoryEntry(course, true);
            efficiencyStatementManager.deleteEfficiencyStatementsFromCourse(courseRepoEntry.getKey());
        }
        // inform everybody else
        EventBus eventBus = CoordinatorManager.getInstance().getCoordinator().getEventBus();
        CourseConfigEvent courseConfigEvent = new CourseConfigEvent(CourseConfigType.efficiencyStatement, course.getResourceableId());
        eventBus.fireEventToListenersOf(courseConfigEvent, course);
        ILoggingAction loggingAction = enableEfficiencyStatment ? LearningResourceLoggingAction.REPOSITORY_ENTRY_PROPERTIES_EFFICIENCY_STATEMENT_ENABLED : LearningResourceLoggingAction.REPOSITORY_ENTRY_PROPERTIES_EFFICIENCY_STATEMENT_DISABLED;
        ThreadLocalUserActivityLogger.log(loggingAction, getClass());
    }
    fireEvent(ureq, Event.CHANGED_EVENT);
}
Also used : CourseConfigEvent(org.olat.course.config.CourseConfigEvent) OLATResourceable(org.olat.core.id.OLATResourceable) ILoggingAction(org.olat.core.logging.activity.ILoggingAction) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) EventBus(org.olat.core.util.event.EventBus) RecertificationTimeUnit(org.olat.course.certificate.RecertificationTimeUnit) Identity(org.olat.core.id.Identity)

Example 7 with EventBus

use of org.olat.core.util.event.EventBus in project openolat by klemens.

the class PublishProcess method applyPublishSet.

/**
 * @param identity
 * @param locale
 * @param newCourse Optimization for new courses, it doesn't call upddateOnPublish of inserted/updated course nodes
 */
public void applyPublishSet(Identity identity, Locale locale, boolean newCourse) {
    // the active runstructure and the new created runstructure
    Structure existingCourseRun = course.getRunStructure();
    EventBus orec = CoordinatorManager.getInstance().getCoordinator().getEventBus();
    /*
		 * use book keeping lists for publish event
		 */
    Set<String> deletedCourseNodeIds = new HashSet<String>();
    if (editorModelDeletedNodes.size() > 0) {
        for (Iterator<CourseEditorTreeNode> iter = editorModelDeletedNodes.iterator(); iter.hasNext(); ) {
            CourseEditorTreeNode cetn = iter.next();
            CourseNode cn = cetn.getCourseNode();
            deletedCourseNodeIds.add(cn.getIdent());
        }
    }
    Set<String> insertedCourseNodeIds = new HashSet<String>();
    if (editorModelInsertedNodes.size() > 0) {
        for (Iterator<CourseEditorTreeNode> iter = editorModelInsertedNodes.iterator(); iter.hasNext(); ) {
            CourseEditorTreeNode cetn = iter.next();
            CourseNode cn = cetn.getCourseNode();
            insertedCourseNodeIds.add(cn.getIdent());
        }
    }
    Set<String> modifiedCourseNodeIds = new HashSet<String>();
    if (editorModelModifiedNodes.size() > 0) {
        for (Iterator<CourseEditorTreeNode> iter = editorModelModifiedNodes.iterator(); iter.hasNext(); ) {
            CourseEditorTreeNode cetn = iter.next();
            CourseNode cn = cetn.getCourseNode();
            modifiedCourseNodeIds.add(cn.getIdent());
        }
    }
    /*
		 * broadcast PRE PUBLISH event that a publish will take place
		 */
    PublishEvent beforePublish = new PublishEvent(course, identity);
    beforePublish.setDeletedCourseNodeIds(deletedCourseNodeIds);
    beforePublish.setInsertedCourseNodeIds(insertedCourseNodeIds);
    beforePublish.setModifiedCourseNodeIds(modifiedCourseNodeIds);
    beforePublish.setState(PublishEvent.PRE_PUBLISH);
    // old course structure accessible
    orec.fireEventToListenersOf(beforePublish, course);
    /*
		 * TODO:pb: discuss with fj: listeners could add information to
		 * beforePublish event such as a right to veto or add identities who is
		 * currently in the course, thus stopping the publishing author from
		 * publishing! i.e. if people are in a test or something like this.... we
		 * could the ask here beforePublish.accepted() and proceed only in this
		 * case.
		 */
    // 
    /*
		 * remove new nodes which were marked as delete and deletion is published.
		 */
    UserManager um = UserManager.getInstance();
    String charset = um.getUserCharset(identity);
    if (editorModelDeletedNodes.size() > 0) {
        for (Iterator<CourseEditorTreeNode> iter = editorModelDeletedNodes.iterator(); iter.hasNext(); ) {
            CourseEditorTreeNode cetn = iter.next();
            CourseNode cn = cetn.getCourseNode();
            CourseNode oldCn = existingCourseRun.getNode(cetn.getIdent());
            // null
            if (oldCn != null) {
                if (!(cn.getIdent().equals(oldCn.getIdent()))) {
                    throw new AssertException("deleted cn.getIdent != oldCn.getIdent");
                }
            }
            cetn.removeFromParent();
            if (!cetn.isNewnode() && oldCn != null) {
                // only clean up and archive of nodes which were already in run
                // save data, remove references
                deleteRefs(oldCn);
                archiveDeletedNode(identity, cn, oldCn, locale, charset);
                // 2) delete all user data
                oldCn.cleanupOnDelete(course);
            }
        }
    }
    /*
		 * mark modified ones as no longer dirty
		 */
    if (editorModelModifiedNodes.size() > 0) {
        for (Iterator<CourseEditorTreeNode> iter = editorModelModifiedNodes.iterator(); iter.hasNext(); ) {
            CourseEditorTreeNode cetn = iter.next();
            CourseNode cn = cetn.getCourseNode();
            CourseNode oldCn = existingCourseRun.getNode(cetn.getIdent());
            // null
            if (oldCn != null) {
                if (!(cn.getIdent().equals(oldCn.getIdent()))) {
                    throw new AssertException("deleted cn.getIdent != oldCn.getIdent");
                }
            }
            cetn.setDirty(false);
            // 
            updateRefs(cn, oldCn);
        }
    }
    /*
		 * mark newly published ones is no longer new and dirty
		 */
    if (editorModelInsertedNodes.size() > 0) {
        for (Iterator<CourseEditorTreeNode> iter = editorModelInsertedNodes.iterator(); iter.hasNext(); ) {
            CourseEditorTreeNode cetn = iter.next();
            CourseNode cn = cetn.getCourseNode();
            CourseNode oldCn = existingCourseRun.getNode(cetn.getIdent());
            if (oldCn != null) {
                throw new AssertException("new node has an oldCN??");
            }
            cetn.setDirty(false);
            cetn.setNewnode(false);
            // 
            updateRefs(cn, null);
        }
    }
    /*
		 * saving
		 */
    long pubtimestamp = System.currentTimeMillis();
    editorTreeModel.setLatestPublishTimestamp(pubtimestamp);
    // set the new runstructure and save it.
    existingCourseRun.setRootNode(resultingCourseRun.getRootNode());
    CourseFactory.saveCourse(course.getResourceableId());
    // on old course, apply update to published nodes
    if (!newCourse) {
        for (CourseEditorTreeNode cetn : editorModelInsertedNodes) {
            cetn.getCourseNode().updateOnPublish(locale, course, identity, publishEvents);
        }
        for (CourseEditorTreeNode cetn : editorModelModifiedNodes) {
            cetn.getCourseNode().updateOnPublish(locale, course, identity, publishEvents);
        }
    }
    // commit all changes before sending an event
    DBFactory.getInstance().commitAndCloseSession();
    /*
		 * broadcast event
		 */
    PublishEvent publishEvent = new PublishEvent(course, identity);
    publishEvent.setDeletedCourseNodeIds(deletedCourseNodeIds);
    publishEvent.setInsertedCourseNodeIds(insertedCourseNodeIds);
    publishEvent.setModifiedCourseNodeIds(modifiedCourseNodeIds);
    // new course structure accessible
    // CourseFactory is one listener, which removes the course from the
    // cache.
    orec.fireEventToListenersOf(publishEvent, course);
/*
		 * END NEW STYLE PUBLISH
		 */
}
Also used : AssertException(org.olat.core.logging.AssertException) UserManager(org.olat.user.UserManager) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) EventBus(org.olat.core.util.event.EventBus) CourseNode(org.olat.course.nodes.CourseNode) Structure(org.olat.course.Structure) HashSet(java.util.HashSet)

Example 8 with EventBus

use of org.olat.core.util.event.EventBus in project OpenOLAT by OpenOLAT.

the class RepositoryManager method sendDeferredEvents.

private void sendDeferredEvents(List<? extends MultiUserEvent> events, OLATResourceable ores) {
    EventBus eventBus = CoordinatorManager.getInstance().getCoordinator().getEventBus();
    for (MultiUserEvent event : events) {
        eventBus.fireEventToListenersOf(event, ores);
        eventBus.fireEventToListenersOf(event, OresHelper.lookupType(RepositoryEntry.class));
    }
}
Also used : EventBus(org.olat.core.util.event.EventBus) MultiUserEvent(org.olat.core.util.event.MultiUserEvent)

Example 9 with EventBus

use of org.olat.core.util.event.EventBus in project OpenOLAT by OpenOLAT.

the class InfoMessageManager method setInfoMessage.

/**
 * @param message The new info message that will show up on the login screen
 * Synchronized to prevent two users creating or updating the info message property
 * at the same time
 */
public void setInfoMessage(final String message) {
    // o_clusterOK synchronized
    OLATResourceable ores = OresHelper.createOLATResourceableInstance(INFO_MSG, KEY);
    coordinatorManager.getCoordinator().getSyncer().doInSync(ores, new SyncerExecutor() {

        public void execute() {
            PropertyManager pm = PropertyManager.getInstance();
            Property p = pm.findProperty(null, null, null, "_o3_", INFO_MSG);
            if (p == null) {
                p = pm.createPropertyInstance(null, null, null, "_o3_", INFO_MSG, null, null, null, "");
                pm.saveProperty(p);
            }
            p.setTextValue(message);
            // set Message in RAM
            InfoMessageManager.infoMessage = message;
            pm.updateProperty(p);
        }
    });
    // end syncerCallback
    EventBus eb = coordinatorManager.getCoordinator().getEventBus();
    MultiUserEvent mue = new MultiUserEvent(message);
    eb.fireEventToListenersOf(mue, INFO_MESSAGE_ORES);
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) PropertyManager(org.olat.properties.PropertyManager) SyncerExecutor(org.olat.core.util.coordinate.SyncerExecutor) EventBus(org.olat.core.util.event.EventBus) Property(org.olat.properties.Property) MultiUserEvent(org.olat.core.util.event.MultiUserEvent)

Example 10 with EventBus

use of org.olat.core.util.event.EventBus in project OpenOLAT by OpenOLAT.

the class PublishProcess method applyPublishSet.

/**
 * @param identity
 * @param locale
 * @param newCourse Optimization for new courses, it doesn't call upddateOnPublish of inserted/updated course nodes
 */
public void applyPublishSet(Identity identity, Locale locale, boolean newCourse) {
    // the active runstructure and the new created runstructure
    Structure existingCourseRun = course.getRunStructure();
    EventBus orec = CoordinatorManager.getInstance().getCoordinator().getEventBus();
    /*
		 * use book keeping lists for publish event
		 */
    Set<String> deletedCourseNodeIds = new HashSet<String>();
    if (editorModelDeletedNodes.size() > 0) {
        for (Iterator<CourseEditorTreeNode> iter = editorModelDeletedNodes.iterator(); iter.hasNext(); ) {
            CourseEditorTreeNode cetn = iter.next();
            CourseNode cn = cetn.getCourseNode();
            deletedCourseNodeIds.add(cn.getIdent());
        }
    }
    Set<String> insertedCourseNodeIds = new HashSet<String>();
    if (editorModelInsertedNodes.size() > 0) {
        for (Iterator<CourseEditorTreeNode> iter = editorModelInsertedNodes.iterator(); iter.hasNext(); ) {
            CourseEditorTreeNode cetn = iter.next();
            CourseNode cn = cetn.getCourseNode();
            insertedCourseNodeIds.add(cn.getIdent());
        }
    }
    Set<String> modifiedCourseNodeIds = new HashSet<String>();
    if (editorModelModifiedNodes.size() > 0) {
        for (Iterator<CourseEditorTreeNode> iter = editorModelModifiedNodes.iterator(); iter.hasNext(); ) {
            CourseEditorTreeNode cetn = iter.next();
            CourseNode cn = cetn.getCourseNode();
            modifiedCourseNodeIds.add(cn.getIdent());
        }
    }
    /*
		 * broadcast PRE PUBLISH event that a publish will take place
		 */
    PublishEvent beforePublish = new PublishEvent(course, identity);
    beforePublish.setDeletedCourseNodeIds(deletedCourseNodeIds);
    beforePublish.setInsertedCourseNodeIds(insertedCourseNodeIds);
    beforePublish.setModifiedCourseNodeIds(modifiedCourseNodeIds);
    beforePublish.setState(PublishEvent.PRE_PUBLISH);
    // old course structure accessible
    orec.fireEventToListenersOf(beforePublish, course);
    /*
		 * TODO:pb: discuss with fj: listeners could add information to
		 * beforePublish event such as a right to veto or add identities who is
		 * currently in the course, thus stopping the publishing author from
		 * publishing! i.e. if people are in a test or something like this.... we
		 * could the ask here beforePublish.accepted() and proceed only in this
		 * case.
		 */
    // 
    /*
		 * remove new nodes which were marked as delete and deletion is published.
		 */
    UserManager um = UserManager.getInstance();
    String charset = um.getUserCharset(identity);
    if (editorModelDeletedNodes.size() > 0) {
        for (Iterator<CourseEditorTreeNode> iter = editorModelDeletedNodes.iterator(); iter.hasNext(); ) {
            CourseEditorTreeNode cetn = iter.next();
            CourseNode cn = cetn.getCourseNode();
            CourseNode oldCn = existingCourseRun.getNode(cetn.getIdent());
            // null
            if (oldCn != null) {
                if (!(cn.getIdent().equals(oldCn.getIdent()))) {
                    throw new AssertException("deleted cn.getIdent != oldCn.getIdent");
                }
            }
            cetn.removeFromParent();
            if (!cetn.isNewnode() && oldCn != null) {
                // only clean up and archive of nodes which were already in run
                // save data, remove references
                deleteRefs(oldCn);
                archiveDeletedNode(identity, cn, oldCn, locale, charset);
                // 2) delete all user data
                oldCn.cleanupOnDelete(course);
            }
        }
    }
    /*
		 * mark modified ones as no longer dirty
		 */
    if (editorModelModifiedNodes.size() > 0) {
        for (Iterator<CourseEditorTreeNode> iter = editorModelModifiedNodes.iterator(); iter.hasNext(); ) {
            CourseEditorTreeNode cetn = iter.next();
            CourseNode cn = cetn.getCourseNode();
            CourseNode oldCn = existingCourseRun.getNode(cetn.getIdent());
            // null
            if (oldCn != null) {
                if (!(cn.getIdent().equals(oldCn.getIdent()))) {
                    throw new AssertException("deleted cn.getIdent != oldCn.getIdent");
                }
            }
            cetn.setDirty(false);
            // 
            updateRefs(cn, oldCn);
        }
    }
    /*
		 * mark newly published ones is no longer new and dirty
		 */
    if (editorModelInsertedNodes.size() > 0) {
        for (Iterator<CourseEditorTreeNode> iter = editorModelInsertedNodes.iterator(); iter.hasNext(); ) {
            CourseEditorTreeNode cetn = iter.next();
            CourseNode cn = cetn.getCourseNode();
            CourseNode oldCn = existingCourseRun.getNode(cetn.getIdent());
            if (oldCn != null) {
                throw new AssertException("new node has an oldCN??");
            }
            cetn.setDirty(false);
            cetn.setNewnode(false);
            // 
            updateRefs(cn, null);
        }
    }
    /*
		 * saving
		 */
    long pubtimestamp = System.currentTimeMillis();
    editorTreeModel.setLatestPublishTimestamp(pubtimestamp);
    // set the new runstructure and save it.
    existingCourseRun.setRootNode(resultingCourseRun.getRootNode());
    CourseFactory.saveCourse(course.getResourceableId());
    // on old course, apply update to published nodes
    if (!newCourse) {
        for (CourseEditorTreeNode cetn : editorModelInsertedNodes) {
            cetn.getCourseNode().updateOnPublish(locale, course, identity, publishEvents);
        }
        for (CourseEditorTreeNode cetn : editorModelModifiedNodes) {
            cetn.getCourseNode().updateOnPublish(locale, course, identity, publishEvents);
        }
    }
    // commit all changes before sending an event
    DBFactory.getInstance().commitAndCloseSession();
    /*
		 * broadcast event
		 */
    PublishEvent publishEvent = new PublishEvent(course, identity);
    publishEvent.setDeletedCourseNodeIds(deletedCourseNodeIds);
    publishEvent.setInsertedCourseNodeIds(insertedCourseNodeIds);
    publishEvent.setModifiedCourseNodeIds(modifiedCourseNodeIds);
    // new course structure accessible
    // CourseFactory is one listener, which removes the course from the
    // cache.
    orec.fireEventToListenersOf(publishEvent, course);
/*
		 * END NEW STYLE PUBLISH
		 */
}
Also used : AssertException(org.olat.core.logging.AssertException) UserManager(org.olat.user.UserManager) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) EventBus(org.olat.core.util.event.EventBus) CourseNode(org.olat.course.nodes.CourseNode) Structure(org.olat.course.Structure) HashSet(java.util.HashSet)

Aggregations

EventBus (org.olat.core.util.event.EventBus)12 OLATResourceable (org.olat.core.id.OLATResourceable)6 MultiUserEvent (org.olat.core.util.event.MultiUserEvent)6 Identity (org.olat.core.id.Identity)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 HashSet (java.util.HashSet)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Test (org.junit.Test)2 Event (org.olat.core.gui.control.Event)2 AssertException (org.olat.core.logging.AssertException)2 ILoggingAction (org.olat.core.logging.activity.ILoggingAction)2 SyncerExecutor (org.olat.core.util.coordinate.SyncerExecutor)2 GenericEventListener (org.olat.core.util.event.GenericEventListener)2 ICourse (org.olat.course.ICourse)2 Structure (org.olat.course.Structure)2 RecertificationTimeUnit (org.olat.course.certificate.RecertificationTimeUnit)2 CourseConfigEvent (org.olat.course.config.CourseConfigEvent)2 CourseNode (org.olat.course.nodes.CourseNode)2 CourseEditorTreeNode (org.olat.course.tree.CourseEditorTreeNode)2 BusinessGroup (org.olat.group.BusinessGroup)2