3.1.2.2.1. Lifecycle

A lifecycle is defined by a simple vertical workflow with steps (states) and profiles (membership). Each lifecycle is related to a Publication plugin.

See the following code:


<external-component-plugins>
    <target-component>org.exoplatform.services.wcm.extensions.publication.PublicationManager</target-component>
    <component-plugin>
      <name>AddLifecycle</name>
      <set-method>addLifecycle</set-method>
      <type>org.exoplatform.services.wcm.extensions.publication.lifecycle.StatesLifecyclePlugin</type>
      <description>Configures</description>
      <priority>1</priority>
      <init-params>
        <object-param>
          <name>lifecycles</name>
          <object type="org.exoplatform.services.wcm.extensions.publication.lifecycle.impl.LifecyclesConfig">
            <field name="lifecycles">
              <collection type="java.util.ArrayList">
                <value>
                  <object type="org.exoplatform.services.wcm.extensions.publication.lifecycle.impl.LifecyclesConfig$Lifecycle">
                    <field name="name"><string>lifecycle1</string></field>
                    <field name="publicationPlugin"><string>Authoring publication</string></field>
                    <field name="states">
                      <collection type="java.util.ArrayList">
                        <value>
                          <object type="org.exoplatform.services.wcm.extensions.publication.lifecycle.impl.LifecyclesConfig$State">
                            <field name="state"><string>draft</string></field>
                            <field name="membership"><string>author:/platform/web-contributors</string></field>
                          </object>
                        </value>
                        <value>
                          <object type="org.exoplatform.services.wcm.extensions.publication.lifecycle.impl.LifecyclesConfig$State">
                            <field name="state"><string>pending</string></field>
                            <field name="membership"><string>author:/platform/web-contributors</string></field>
                          </object>
                        </value>
                        <value>
                          <object type="org.exoplatform.services.wcm.extensions.publication.lifecycle.impl.LifecyclesConfig$State">
                            <field name="state"><string>approved</string></field>
                            <field name="membership"><string>manager:/platform/web-contributors</string></field>
                          </object>
                        </value>
                        <value>
                        <object type="org.exoplatform.services.wcm.extensions.publication.lifecycle.impl.LifecyclesConfig$State">
                          <field name="state"><string>staged</string></field>
                          <field name="membership"><string>publisher:/platform/web-contributors</string></field>
                        </object>
                      </value>
                      <value>
                        <object type="org.exoplatform.services.wcm.extensions.publication.lifecycle.impl.LifecyclesConfig$State">
                          <field name="state"><string>published</string></field>
                          <field name="membership"><string>publisher:/platform/web-contributors</string></field>
                        </object>
                      </value>
                    </collection>
                    </field>
                  </object>
                </value>
              </collection>
            </field>
          </object>
        </object-param>
      </init-params>
    </component-plugin>
    <component-plugin>
      <name>AddContext</name>
      <set-method>addContext</set-method>
      <type>org.exoplatform.services.wcm.extensions.publication.context.ContextPlugin</type>
      <init-params>
        <object-param>
          <name>contexts</name>
          <object type="org.exoplatform.services.wcm.extensions.publication.context.impl.ContextConfig">
            <field name="contexts">
              <collection type="java.util.ArrayList">
                <value>
                  <object type="org.exoplatform.services.wcm.extensions.publication.context.impl.ContextConfig$Context">
                    <field name="name"><string>contextdefault</string></field>
                    <field name="priority"><string>200</string></field>
                    <field name="lifecycle"><string>lifecycle1</string></field>
                  </object>
                </value>
              </collection>
            </field>
          </object>
        </object-param>
      </init-params>
    </component-plugin>
  </external-component-plugins>

In this example, there is one lifecycle with states. This lifecycle is based on AuthoringPublicationPlugin.

Listening to a lifecycle

When a state is changed, you can broadcast an event to add features. The event could look like this:



          listenerService.broadcast(AuthoringPlugin.POST_UPDATE_STATE_EVENT, null, node);

Listener declaration could look like this:


<external-component-plugins>
    <target-component>org.exoplatform.services.listener.ListenerService</target-component>
    <component-plugin>
      <name>PublicationService.event.postUpdateState</name>
      <set-method>addListener</set-method>
      <type>org.exoplatform.services.wcm.publication.listener.post.PostUpdateStateEventListener</type>
      <description>this listener will be called every time a content changes its current state</description>
    </component-plugin>
</external-component-plugins>
Performing tasks when a content's state is updated

To perform some tasks when a content's state is updated, you need to create a listener that handles the task and configure it. Following is the general configuration:


<external-component-plugins>
  <target-component>org.exoplatform.services.listener.ListenerService</target-component>
  <component-plugin>
      <name>PublicationService.event.postUpdateState</name>
      <set-method>addListener</set-method>
      <type>my.package.MyListener</type>
      <description>Your listener description</description>
  </component-plugin>
</external-component-plugins>

With this configuration, your listener my.package.MyListener will be executed each time a content's state is changed.

For example, eXo provides a listener which automatically sends email notifications about the new state to all users of defined groups: org.exoplatform.wcm.authoring.listener.PostUpdateStateEventListener. So, the configuration will be:


<external-component-plugins>
  <target-component>org.exoplatform.services.listener.ListenerService</target-component>
  <component-plugin>
      <name>PublicationService.event.postUpdateState</name>
      <set-method>addListener</set-method>
      <type>org.exoplatform.wcm.authoring.listener.PostUpdateStateEventListener</type>
      <description>This listener will send a mail when there are changes in a content's state</description>
  </component-plugin>
</external-component-plugins>
Copyright ©. All rights reserved. eXo Platform SAS
blog comments powered byDisqus