3.2.3. Answers

AnswerEventLifeCycle installs event updates for the Answers data that is injected while saving answers, saving questions or posting comments.

Configuration plug-in

You can find the configuration file of this component here.

For example, to add Answers to a space of the Social application and keep new activities of Answers updated to the activities of space, do as follows:


<external-component-plugins>
  <target-component>org.exoplatform.faq.service.FAQService</target-component>
  <component-plugin>
    <name>AnswerEventListener</name>
    <set-method>addListenerPlugin</set-method>
    <type>org.exoplatform.forum.ext.impl.AnswersSpaceActivityPublisher</type>
  </component-plugin>
</external-component-plugins>

In which, AnswersSpaceActivityPublisher is the class to implement ForumEventLifeCycle.

Tutorial

To use the AnswerEventLifeCycle class, do the following steps:

  1. Create a new class that extends AnswerEventListener.

    For example: ABCActivityPublisher

    public class ABCActivityPublisher extends AnswerEventListener {
    
      ....
    }
  2. Override functions in this created class. In each function, you can write anything to meet your needs.

    public class ABCActivityPublisher extends AnswerEventListener {
    
    
      public void saveQuestion(Question question, boolean isNew){
        ....
      }
      public void saveAnswer(String questionId, Answer answer, boolean isNew){
        ....
      }
      public void saveAnswer(String questionId, Answer[] answers, boolean isNew){
        ....
      }
      public void saveComment(String questionId, Comment comment, boolean isNew){
        ....
      }
    }
    • The saveQuestion function is called when a question is added and/or edited.

    • The saveAnswer function is called when an answer is added and/or edited.

    • The saveAnswer function is called when answers are added and/or edited.

    • The saveComment function is called when a comment is added and/or edited.

  3. Add a new configuration to the configuration.xml file with the type that is the class created in the Step 1.

    
    <external-component-plugins>
      <target-component>org.exoplatform.faq.service.FAQService</target-component>
      <component-plugin>
        <name>AnswerEventListener</name>
        <set-method>addListenerPlugin</set-method>
        <type>{package}.{class name}</type>
      <!-- example
      <type>org.exoplatform.forum.ext.impl.ABCActivityPublisher</type>
      -->
      </component-plugin>
    </external-component-plugins>
Copyright ©. All rights reserved. eXo Platform SAS
blog comments powered byDisqus