Search in sources :

Example 1 with EventBus

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

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 2 with EventBus

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

the class BusinessGroupModifiedEvent method fireModifiedGroupEvents.

/**
 * Fires event to all listeners of this business group and the listeners of
 * the ressources associated with the group context of this group
 *
 * @param command The event identifyer, one of CONFIGURATION_MODIFIED_EVENT,
 *          IDENTITY_ADDED_EVENT or IDENTITY_REMOVED_EVENT
 * @param group The group affected by the modification
 * @param identity The identity affected by the modification
 */
public static void fireModifiedGroupEvents(String command, BusinessGroup group, Identity identity) {
    BusinessGroupModifiedEvent modifiedEvent = new BusinessGroupModifiedEvent(command, group, identity);
    EventBus eventBus = CoordinatorManager.getInstance().getCoordinator().getEventBus();
    // 1) notify listeners of group events
    eventBus.fireEventToListenersOf(modifiedEvent, group);
    eventBus.fireEventToListenersOf(modifiedEvent, OresHelper.lookupType(BusinessGroup.class));
    // 2) notify listeners of learning resources of this group
    BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    List<RepositoryEntry> repoEntries = bgs.findRepositoryEntries(Collections.singletonList(group), 0, -1);
    for (RepositoryEntry entry : repoEntries) {
        eventBus.fireEventToListenersOf(modifiedEvent, entry);
    }
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) BusinessGroupService(org.olat.group.BusinessGroupService) EventBus(org.olat.core.util.event.EventBus) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 3 with EventBus

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

the class JMSTest method testSendReceive.

@Test
public void testSendReceive() {
    // enable test only if we have the cluster configuration enabled.
    // this test requires that an JMS Provider is running
    // (see file serviceconfig/org/olat/core/_spring/coreextconfig.xml)
    EventBus bus = CoordinatorManager.getInstance().getCoordinator().getEventBus();
    if (bus instanceof ClusterEventBus) {
        Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("jms");
        // send and wait some time until a message should arrive at the latest.
        final OLATResourceable ores = OresHelper.createOLATResourceableInstance("hellojms", new Long(123));
        final CountDownLatch doneSignal = new CountDownLatch(1);
        bus.registerFor(new GenericEventListener() {

            @Override
            public void event(Event event) {
                log.audit("Event received: " + event);
                doneSignal.countDown();
            }
        }, id, ores);
        MultiUserEvent mue = new MultiUserEvent("amuecommand");
        bus.fireEventToListenersOf(mue, ores);
        try {
            boolean interrupt = doneSignal.await(5, TimeUnit.SECONDS);
            assertTrue("Test takes too long (more than 5s)", interrupt);
        } catch (InterruptedException e) {
            fail("" + e.getMessage());
        }
    }
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) MultiUserEvent(org.olat.core.util.event.MultiUserEvent) Event(org.olat.core.gui.control.Event) EventBus(org.olat.core.util.event.EventBus) GenericEventListener(org.olat.core.util.event.GenericEventListener) Identity(org.olat.core.id.Identity) CountDownLatch(java.util.concurrent.CountDownLatch) MultiUserEvent(org.olat.core.util.event.MultiUserEvent) Test(org.junit.Test)

Example 4 with EventBus

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

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 5 with EventBus

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

the class BusinessGroupModifiedEvent method fireModifiedGroupEvents.

/**
 * Fires event to all listeners of this business group and the listeners of
 * the ressources associated with the group context of this group
 *
 * @param command The event identifyer, one of CONFIGURATION_MODIFIED_EVENT,
 *          IDENTITY_ADDED_EVENT or IDENTITY_REMOVED_EVENT
 * @param group The group affected by the modification
 * @param identity The identity affected by the modification
 */
public static void fireModifiedGroupEvents(String command, BusinessGroup group, Identity identity) {
    BusinessGroupModifiedEvent modifiedEvent = new BusinessGroupModifiedEvent(command, group, identity);
    EventBus eventBus = CoordinatorManager.getInstance().getCoordinator().getEventBus();
    // 1) notify listeners of group events
    eventBus.fireEventToListenersOf(modifiedEvent, group);
    eventBus.fireEventToListenersOf(modifiedEvent, OresHelper.lookupType(BusinessGroup.class));
    // 2) notify listeners of learning resources of this group
    BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    List<RepositoryEntry> repoEntries = bgs.findRepositoryEntries(Collections.singletonList(group), 0, -1);
    for (RepositoryEntry entry : repoEntries) {
        eventBus.fireEventToListenersOf(modifiedEvent, entry);
    }
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) BusinessGroupService(org.olat.group.BusinessGroupService) EventBus(org.olat.core.util.event.EventBus) RepositoryEntry(org.olat.repository.RepositoryEntry)

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