Package org.olat.core.util.event

Examples of org.olat.core.util.event.EventBus


  private String serviceName;
 
  public SingleService( String serviceName) {
    this.serviceName = serviceName;
    final OLATResourceable ores = OresHelper.createOLATResourceableType(SingleService.class.getCanonicalName());
    EventBus eventBus = CoordinatorManager.getCoordinator().getEventBus();
    // first fire event, second register as listener because we want not to receive our 'Started event'
    eventBus.fireEventToListenersOf(new ServiceStartedEvent(serviceName), ores );
    log.debug("fireEventToListenersOf serviceName=" + serviceName + "  ores=" + ores.getResourceableTypeName() + ":" + ores.getResourceableId());
    eventBus.registerFor(this, null, ores);
  }
View Full Code Here


   * @param locale
   */
  void applyPublishSet(Identity identity, Locale locale) {
    // the active runstructure and the new created runstructure
    Structure existingCourseRun = course.getRunStructure();
    EventBus orec = CoordinatorManager.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(editorTreeModel.getLatestPublishTimestamp(), course, PublishEvent.EVENT_IDENTIFIER);
    beforePublish.setDeletedCourseNodeIds(deletedCourseNodeIds);
    beforePublish.setInsertedCourseNodeIds(insertedCourseNodeIds);
    beforePublish.setModifiedCourseNodeIds(modifiedCourseNodeIds);
    beforePublish.setState(PublishEvent.PRE_PUBLISH);
    // old course structure accessible
    orec.fireEventToListenersOf(beforePublish, course);
    /*
     * TODO:pb: disucss 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.
     */
    File exportDirectory = CourseFactory.getOrCreateDataExportDirectory(identity, course.getCourseTitle());
    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());
        // moved node with a parent deleted (deletion published) -> oldCn ==
        // null
        if (oldCn != null) {
          if (!(cn.getIdent().equals(oldCn.getIdent()))) { throw new AssertException("deleted cn.getIdent != oldCn.getIdent"); }
        }
        cetn.removeFromParent();
        if (!cetn.isNewnode()) {
          // only clean up and archive of nodes which were already in run
          // save data, remove references
          deleteRefs(oldCn);
          oldCn.archiveNodeData(locale, course, exportDirectory, 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());
        // moved node with a parent deleted (deletion published) -> oldCn ==
        // 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());
   
    /*
     * broadcast event
     */
    PublishEvent publishEvent = new PublishEvent(pubtimestamp, course, PublishEvent.EVENT_IDENTIFIER);
    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
     */

  }
 
View Full Code Here

            // delete really the efficiencies of the users.
            RepositoryEntry courseRepoEntry = RepositoryManager.getInstance().lookupRepositoryEntry(course, true);
            EfficiencyStatementManager.getInstance().deleteEfficiencyStatementsFromCourse(courseRepoEntry.getKey());           
          }
          //inform everybody else   
          EventBus eventBus = CoordinatorManager.getCoordinator().getEventBus();
          CourseConfigEvent courseConfigEvent = new CourseConfigEvent(CourseConfigEvent.EFFICIENCY_STATEMENT_TYPE, course.getResourceableId());
          eventBus.fireEventToListenersOf(courseConfigEvent, course);
          ThreadLocalUserActivityLogger.log(ceffC.getLoggingAction(), getClass());
        }
        // CourseCalendarConfigController
        if(changedCourseConfig.isCalendarEnabled()!= initialCourseConfig.isCalendarEnabled() && calCfgCtr.getLoggingAction()!=null) {
          ThreadLocalUserActivityLogger.log(calCfgCtr.getLoggingAction(), getClass());
          // notify calendar components to refresh their calendars
          CoordinatorManager.getCoordinator().getEventBus().fireEventToListenersOf(new KalendarModifiedEvent(), OresHelper.lookupType(CalendarManager.class));
        }
        // CourseConfigGlossaryController
        if((changedCourseConfig.getGlossarySoftKey()==null && initialCourseConfig.getGlossarySoftKey()!=null)
            || (changedCourseConfig.getGlossarySoftKey()!=null && initialCourseConfig.getGlossarySoftKey()==null)
            && cglosCtr.getLoggingAction()!=null) {
         
          final String glossarySoftKey = changedCourseConfig.getGlossarySoftKey();
          LoggingResourceable lri = null;
          if (glossarySoftKey!=null) {
            lri = LoggingResourceable.wrapNonOlatResource(StringResourceableType.glossarySoftKey, glossarySoftKey, glossarySoftKey);
          }
          ThreadLocalUserActivityLogger.log(cglosCtr.getLoggingAction(), getClass(), lri);
          if(changedCourseConfig.getGlossarySoftKey()==null) {
            // update references
            ReferenceManager refM = ReferenceManager.getInstance();
            List repoRefs = refM.getReferences(course);
            for (Iterator iter = repoRefs.iterator(); iter.hasNext();) {
              ReferenceImpl ref = (ReferenceImpl) iter.next();
              if (ref.getUserdata().equals(GlossaryManager.GLOSSARY_REPO_REF_IDENTIFYER)) {
                refM.delete(ref);
                continue;
              }
            }
          } else if(changedCourseConfig.getGlossarySoftKey()!=null) {
            // update references
            RepositoryManager rm = RepositoryManager.getInstance();
            RepositoryEntry repoEntry = rm.lookupRepositoryEntryBySoftkey(changedCourseConfig.getGlossarySoftKey(), false);
            ReferenceManager.getInstance().addReference(course, repoEntry.getOlatResource(), GlossaryManager.GLOSSARY_REPO_REF_IDENTIFYER);
          }
        }
        //course config transaction fihished
        initialCourseConfig = course.getCourseEnvironment().getCourseConfig().clone();       
       
        //fire CourseConfigEvent for this course channel
        EventBus eventBus = CoordinatorManager.getCoordinator().getEventBus();
        CourseConfigEvent courseConfigEvent = new CourseConfigEvent(CourseConfigEvent.CALENDAR_TYPE, course.getResourceableId());
        eventBus.fireEventToListenersOf(courseConfigEvent, course);
       
        this.fireEvent(ureq, Event.DONE_EVENT);
      } else if(!DialogBoxUIFactory.isYesEvent(event) || DialogBoxUIFactory.isYesEvent(event)) {       
        this.fireEvent(ureq, Event.DONE_EVENT);
      }
View Full Code Here

        InfoMessageManager.infoMessage = message;
        pm.updateProperty(p);
      }
     
    });//end syncerCallback
    EventBus eb = CoordinatorManager.getCoordinator().getEventBus();
    MultiUserEvent mue = new MultiUserEvent(message);
    eb.fireEventToListenersOf(mue, INFO_MESSAGE_ORES);
  }
View Full Code Here

   */
  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.getCoordinator().getEventBus();
    if (bus instanceof ClusterEventBus) {
      // send and wait some time until a message should arrive at the latest.
      ores1 = OresHelper.createOLATResourceableInstance("hellojms", new Long(123));
     
      bus.registerFor(new GenericEventListener(){

        public void event(Event event) {
          // TODO Auto-generated method stub
          System.out.println("event received!"+event);
          JMSTest.this.event = event;
        }}, id1, ores1);
     
     
      MultiUserEvent mue = new MultiUserEvent("amuecommand");
      bus.fireEventToListenersOf(mue, ores1);
      try {
        Thread.sleep(2000);
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
View Full Code Here

TOP

Related Classes of org.olat.core.util.event.EventBus

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.