REST-style architectures consist of clients and servers. Clients initiate requests to servers; servers process requests and return appropriate responses. Requests and responses are built around the transfer of "representations" of "resources". A resource can be essentially any coherent and meaningful concept that may be addressed. A representation of a resource is typically a document that captures the current or intended state of a resource.

At any particular time, a client can either be in transition between application states or "at rest". A client in a REST state is able to interact with its user, but creates no load and consumes no per-client storage on the set of servers or on the network.

The client begins sending requests when it is ready to make the transition to a new state. While one or more requests are outstanding, the client is considered to be in transition. The representation of each application state contains links that may be used the next time, the client chooses to initiate a new state transition.

REST is initially described in the context of HTTP, but is not limited to that protocol. RESTful architectures can be based on other Application Layer protocols if they already provide a rich and uniform vocabulary for applications based on the transfer of meaningful representational state. RESTful applications maximize the use of the pre-existing, well-defined interface and other built-in capabilities provided by the chosen network protocol, and minimize the addition of new application-specific features on its top.

Here is the convention we should follow:

Method Definition
GET Get a Resource. It should never modify a state
POST Create a Resource (or anything that don't fit elsewhere)
PUT Update a Resource
DELETE Delete a Resource

We should support this format for all our APIs:

  • Json: because it's easy to parse in a lot of language like Javascript, Python or Ruby

  • XML: Java developers like it

  • Atom: It is the standard, it can be used by many applications.

listener

We start to create GetEditedDocumentRESTService that implements from the ResourceContainer interface.

Parameters Definition
@Path("/presentation/document/edit/") Specify the URI path that a resource or class method will serve requests for.
@PathParam("repository") Bind the value repository of a URI parameter or a path segment containing the template parameter to a resource method parameter, resource class field, or resource class bean property.
@QueryParam("showItems") Bind the value showItems of a HTTP query parameter to a resource method parameter, resource class field, or resource class bean property.

This part describes how to create a sample UI extension.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.exoplatform.ecms</groupId>
    <artifactId>exo-ecms-examples-uiextension-framework</artifactId>
    <version>2.2.0-SNAPSHOT</version>
  </parent>
  <artifactId>exo-ecms-examples-uiextension-framework-manage-wcm-cache</artifactId>
  <name>eXo WCM Cache Examples </name>
  <description>eXo WCM Cache Examples </description>
  <dependencies>
    <dependency>
      <groupId>org.exoplatform.kernel</groupId>
      <artifactId>exo.kernel.container</artifactId>
      <version>2.2.13-GA</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.exoplatform.commons</groupId>
      <artifactId>exo.platform.commons.webui.ext</artifactId>
      <version>1.0.10</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.exoplatform.ecms</groupId>
      <artifactId>exo-ecms-core-webui</artifactId>
      <version>2.1.10</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.exoplatform.ecms</groupId>
      <artifactId>exo-ecms-core-webui-administration</artifactId>
      <version>2.1.10</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>
  <build>
    <resources>
      <resource>
        <directory>src/main/java</directory>
        <includes>
          <include>**/*.xml</include>
        </includes>
      </resource>
      <resource>
        <directory>src/main/resources</directory>
        <includes>
          <include>**/*.properties</include>
          <include>**/*.xml</include>
          <include>**/*.jar</include>
          <include>**/*.pom</include>
          <include>**/*.conf</include>
          <include>**/*.gtmpl</include>
          <include>**/*.gif</include>
          <include>**/*.jpg</include>
          <include>**/*.png</include>
        </includes>
      </resource>
    </resources>
  </build>
</project>
<?xml version="1.0" encoding="ISO-8859-1"?>
<configuration
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd http://www.exoplaform.org/xml/ns/kernel_1_1.xsd"
   xmlns="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd">

	<external-component-plugins>
	<target-component>org.exoplatform.webui.ext.UIExtensionManager</target-component>
	<component-plugin>
	    <name>Add.Actions</name>
		<set-method>registerUIExtensionPlugin</set-method>
		<type>org.exoplatform.webui.ext.UIExtensionPlugin</type>
	        <init-params>
		   <object-param>
		        <name>CacheView</name>
		        <object type="org.exoplatform.webui.ext.UIExtension">
                        	<field name="type"><string>org.exoplatform.ecm.dms.UIECMAdminControlPanel</string></field>
			        <field name="name"><string>CacheView</string></field>
				<field name="category"><string>GlobalAdministration</string></field>
				<field name="component"><string>org.exoplatform.wcm.component.cache.UIWCMCacheComponent</string></field>
		   	 </object>
	           </object-param>
     		   <object-param>
		       <name>UIWCMCacheManager</name>
	               <object type="org.exoplatform.webui.ext.UIExtension">
		           <field name="type"><string>org.exoplatform.ecm.dms.UIECMAdminControlPanel</string></field>
		           <field name="name"><string>UIWCMCacheManager</string></field>
		           <field name="category"><string>GlobalAdministration</string></field>
		           <field name="component"><string>org.exoplatform.wcm.manager.cache.UIWCMCacheManagerComponent</string></field>
	               </object>
                   </object-param>
              </init-params>
       </component-plugin>
</external-component-plugins>
</configuration>
	

Launch mvn clean install and copy the file target/exo-ecms-examples-webui-2.1.0-SNAPSHOT.jar into (TOMCATHOME)/lib

Create ExamplePortleten.xml with the following content and add it to src/main/resource package:

<?xml version="1.0" encoding="UTF-8"?>
<bundle>
  <!--
  ################################################################################
  #             org.exoplatform.wcm.component.cache.UIWCMCacheForm #
  ################################################################################
  -->

 <UIWCMCacheForm>
 	 <action>
 	 	<Cancel>Cancel</Cancel>
 	 	<Save>Save</Save>
		<Clear>Clear the cache</Clear>
 	 </action>
	 <label>
		<maxsize>Max size :</maxsize>
		<livetime>Live time in sec :</livetime>
		<isCacheEnable>Cache enabled(should always be on production enviroment)</isCacheEnable>
		<hit>Hit count :</hit>
		<currentSize>Current size</currentSize>
		<miss>Miss count :</miss>
	 </label>
 </UIWCMCacheForm>

<!--
  ################################################################################
  #             org.exoplatform.wcm.manager.cache.UIWCMCacheManagerForm #
  ################################################################################
  -->

 <UIWCMCacheManagerForm>
 	 <action>
 	 	<Cancel>Cancel</Cancel>
 	 	<Save>Save</Save>
		<Clear>Clear the cache</Clear>
 	 </action>
 	 <label>
		<cacheModify>Cache to modify :</cacheModify>
	        <maxsize>Max size :</maxsize>
		<livetime>Live time in sec :</livetime>
		<isCacheEnable>Cache enabled(should always be on production enviroment)</isCacheEnable>
		<hit>Hit count :</hit>
		<currentSize>Current size</currentSize>
		<miss>Miss count :</miss>
	 </label>
 </UIWCMCacheManagerForm>

 <UIECMAdminControlPanel>
    <tab>
      <label>
        <GlobalAdministration>Global Administration</GlobalAdministration>
      </label>
    </tab>
    <label>
      <UIWCMCache>WCM Cache</UIWCMCache>
      <UIWCMCachePanel>WCM Cache Administration</UIWCMCachePanel>
      <UIWCMCacheManager>Managing Caches</UIWCMCacheManager>
      <UIWCMCacheManagerPanel>WCM Cache Management</UIWCMCacheManagerPanel>
    </label>
  </UIECMAdminControlPanel>
</bundle>

You must add the following content to configuration.xml- to register the resource bundle.

Publication addons for WCM 2.1.0

The Publication Manager manages lifecycles and contexts in the WCM Platform. It allows to manages different lifecycles based on different publication plugin in the platform.

A lifecycle is defined by a simple vertical workflow with steps (states) and profiles (membership). Each lifecycle is related to a Publication plugin (to be compliant with JBPM or Bonita business processes). Example : Two lifecycles with/without states

<external-component-plugins>
  <target-component>org.exoplatform.services.wcm.publication.PublicationManager</target-component>
  <component-plugin>
    <name>AddLifecycle</name>
    <set-method>addLifecycle</set-method>
    <type>org.exoplatform.services.wcm.publication.lifecycles.StatesLifecyclePlugin</type>
    <init-params>
      <object-param>
        <name>lifecyles</name>
        <object type="org.exoplatform.services.wcm.publication.lifecycles.impl.LifecyclesConfig">
          <field name="lifecycles">
            <collection type="java.util.ArrayList">
              <value>
                <object type="org.exoplatform.services.wcm.publication.lifecycles.impl.LifecyclesConfig$Lifecycle">
                  <field name="name"><string>lifecycle1</string></field>
                  <field name="publicationPlugin"><string>States and versions based publication</string></field>
                </object>
              </value>
              <value>
                <object type="org.exoplatform.services.wcm.publication.lifecycles.impl.LifecyclesConfig$Lifecycle">
                  <field name="name"><string>lifecycle2</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.publication.lifecycles.impl.LifecyclesConfig$State">
                          <field name="state"><string>draft</string></field>
                          <field name="memberships">
                             <collection type="java.util.ArrayList">
                               <value><string>author:/CA/communicationDG</string></value>
                               <value><string>author:/CA/alerteSanitaire</string></value>
                               <value><string>author:/CA/alerteInformatique</string></value>
                               <value><string>author:/CA/informations</string></value>
                             </collection>
                           </field>
                        </object>
                      </value>
                      <value>
                        <object type="org.exoplatform.services.wcm.publication.lifecycles.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.publication.lifecycles.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.publication.lifecycles.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.publication.lifecycles.impl.LifecyclesConfig$State">
                          <field name="state"><string>published</string></field>
                          <field name="membership"><string>automatic</string></field>
                        </object>
                      </value>
                    </collection>
                  </field>
                </object>
              </value>
              <value>
                <object type="org.exoplatform.services.wcm.publication.lifecycles.impl.LifecyclesConfig$Lifecycle">
                  <field name="name"><string>lifecycle3</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.publication.lifecycles.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.publication.lifecycles.impl.LifecyclesConfig$State">
                          <field name="state"><string>published</string></field>
                          <field name="memberships">
                             <collection type="java.util.ArrayList">
                               <value><string>publisher:/CA/communicationDG</string></value>
                               <value><string>publisher:/CA/alerteSanitaire</string></value>
                               <value><string>publisher:/CA/alerteInformatique</string></value>
                               <value><string>publisher:/CA/informations</string></value>
                             </collection>
                           </field>
                        </object>
                      </value>
                    </collection>
                  </field>
                </object>
              </value>
            </collection>
          </field>
        </object>
      </object-param>
    </init-params>
  </component-plugin>
</external-component-plugins>

In the last example, we have two lifecycles:

A context is defined by simple rules. In WCM 2.1+, we can choose to enroll the content in a specific lifecycle (i.e. publication plugin) based on context parameters. We have 3 parameters we can use to define contexts :

From these parameters, we can easily connect and define contexts based on :

Because each site has a content storage (categories + physical storage), we can choose the right lifecycle for the right storage/site. We can have conflicts on contexts and we will avoid that by setting a priority (less is best)

Example : Different Contexts

<external-component-plugins>
  <target-component>org.exoplatform.services.wcm.publication.PublicationManager</target-component>
  <component-plugin>
    <name>AddContext</name>
    <set-method>addContext</set-method>
    <type>org.exoplatform.services.wcm.publication.context.ContextPlugin</type>
    <init-params>
      <object-param>
        <name>contexts</name>
        <object type="org.exoplatform.services.wcm.publication.context.impl.ContextConfig">
          <field name="contexts">
            <collection type="java.util.ArrayList">
              <value>
                <object type="org.exoplatform.services.wcm.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>
                <object type="org.exoplatform.services.wcm.publication.context.impl.ContextConfig$Context">
                  <field name="name"><string>context1</string></field>
                  <field name="priority"><string>100</string></field>
                  <field name="lifecycle"><string>lifecycle1</string></field>
                  <field name="membership"><string>*:/platform/web-contributors</string></field>
                  <field name="site"><string>acme</string></field>
                  <field name="path"><string>repository:collaboration:/sites content/live/acme/categories</string></field>
                </object>
                <object type="org.exoplatform.services.wcm.publication.context.impl.ContextConfig$Context">
                  <field name="name"><string>context2</string></field>
                  <field name="priority"><string>100</string></field>
                  <field name="lifecycle"><string>lifecycle1</string></field>
                  <field name="site"><string>classic</string></field>
                </object>
                <object type="org.exoplatform.services.wcm.publication.context.impl.ContextConfig$Context">
                  <field name="name"><string>context3</string></field>
                  <field name="priority"><string>80</string></field>
                  <field name="lifecycle"><string>lifecycle3</string></field>
                  <field name="membership"><string>manager:/company/finances</string></field>
                  <field name="path"><string>repository:collaboration:/documents/company/finances</string></field>
                </object>
                <object type="org.exoplatform.services.wcm.publication.context.impl.ContextConfig$Context">
                  <field name="name"><string>context4</string></field>
                  <field name="priority"><string>50</string></field>
                  <field name="lifecycle"><string>lifecycle4</string></field>
                  <field name="memberships">
                    <collection type="java.util.ArrayList">
                       <value><string>manager:/CA/communicationDG</string></value>
                       <value><string>manager:/CA/alerteSanitaire</string></value>
                       <value><string>manager:/CA/alerteInformatique</string></value>
                       <value><string>manager:/CA/informations</string></value>
                     </collection>
                   </field>
                  <field name="path"><string>repository:collaboration:/documents/company/finances</string></field>
                  <field name="nodetype"><string>exo:article</string></field>
                </object>
              </value>
            </collection>
          </field>
        </object>
      </object-param>
    </init-params>
  </component-plugin>
</external-component-plugins>

The logic is very simple. When we create a content, we will go lifecycle by lifecycle starting with the better priority :

We can see that context1 and context2 have the same priority. We can do that if the contexts are different (ex : different sites)

When adding the content in a lifecycle, we set the publication:lifecycle_ property with the corresponding lifecycle.

Each time, we change from one state to another, we set the user who changed the state in publication:lastUser_.