2016-09-28 11 views
0

イベントリスナーを登録し、プロジェクトの一部として組織のコンフルエンスウィキでコンテンツの変更が発生したことをリスニングし、データを弾性検索にインデックス登録するようなカーテンアクションをとる予定です。私はリスナーを書くサンプルを見つけました - https://developer.atlassian.com/confdev/confluence-plugin-guide/confluence-plugin-module-types/event-listener-module/writing-an-event-listener-plugin-moduleConfluence atlassian changeイベントリスナー

しかし、私はイベントを取得し始めるようにこのソリューションを既存の合流サービスと統合する方法がわかりませんか?これに向けての実用的なシェアやリードは本当に便利です。

ありがとうございます!

答えて

0

Confluence Serverを使用していると仮定すると、開発マシンではinstall the Atlassian SDKが必要で、Confluence add-onを作成する必要があります。

これをすべて実行したら、スケルトンのConfluenceアドオンが必要です。

次に、あなたがそうのようなあなたのatlassian-plugin.xmlファイルにイベントリスナーcomponenteventPublishercomponent-importを追加する必要があります。

<atlassian-plugin key="${project.groupId}.${project.artifactId}" name="${project.name}" plugins-version="2"> 
    <plugin-info> 
     <description>${project.description}</description> 
     <version>${project.version}</version> 
     <vendor name="${project.organization.name}" url="${project.organization.url}" /> 
    </plugin-info> 

    <component 
     key="scroll-versions-event-listener" 
     class="me.davidsimpson.confluence.addons.example.listener.ScrollVersionsPublishEventListener" 
     name="Scroll Versions Publish Event Listener" 
     > 
    </component> 

    <component-import key="eventPublisher" interface="com.atlassian.event.api.EventPublisher" /> 

</atlassian-plugin> 

次は、イベント・リスナーのクラスファイルを作成する必要があります。ここでは出発点です:この例では

package me.davidsimpson.confluence.addons.example.listener; 

import com.atlassian.event.api.EventPublisher; 
import org.springframework.beans.factory.DisposableBean; 

public class ScrollVersionsPublishEventListener implements DisposableBean 
{ 
    protected final EventPublisher eventPublisher; 

    public ScrollVersionsPublishEventListener(EventPublisher eventPublisher) 
    { 
     this.eventPublisher = eventPublisher; 
     eventPublisher.register(this); 
    } 

    /** 
    * Unregister the listener if the plugin is uninstalled or disabled. 
    */ 
    public void destroy() throws Exception 
    { 
     eventPublisher.unregister(this); 
    } 

    @com.atlassian.event.api.EventListener 
    public void onVersionPublishEvent(Object event) { 

     String eventName = event.getClass().getCanonicalName(); // will work for other people's events, not just Atlassian's 

     // Spit out all events - just to prove the point 
     System.out.println(" ++ an event happened: " + eventName); 

     if (eventName.equals("com.k15t.scroll.platform.event.space.VersionPublishEvent")) { 
      System.out.println(" ++++ Found the right event "); 

      // Do your stuff here... 
     } 
    } 
} 

通知は、すべてのイベントがコンソールに出力されているが、我々は、この例では、特定の非標準的なイベントのためにチェックしています。

興味のあるイベントにif (eventName.equals(...))を変更すると、準備が整いました。

+0

こんにちは、特定のイベントが発生した場合、ページを再レンダリングすることは可能ですか? – JayBee

+0

あなたが意味するものの例を挙げてください。あなたは何らかのクライアントサイドのJavaScriptイベントを意味しますか?または、サーバーサイドのConfluenceイベントですか? 通常のConfluenceイベントには、トリガー時にページを開いた人がいるという概念はありません。 – dvdsmpsn