Chapter 5. Extensions

REST Services
UI Extensions

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 next time the client chooses to initiate a new state transition.

REST was 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 top of it.

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/") Specified the URI path that a resource or class method will serve requests for.
@PathParam("repository") Binds 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") Binds the value showItems of a HTTP query parameter to a resource method parameter, resource class field, or resource class bean property.

This article's goal to describe how to create an sample of ui extension.

Create a pom.xml from the following content

<?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.5-GA</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.exoplatform.commons</groupId>
      <artifactId>exo.platform.commons.webui.ext</artifactId>
      <version>1.0.1</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.exoplatform.ecms</groupId>
      <artifactId>exo-ecms-core-webui</artifactId>
      <version>2.1.1</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.exoplatform.ecms</groupId>
      <artifactId>exo-ecms-core-webui-administration</artifactId>
      <version>2.1.1</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>

Create the directories src/main/java and start launching mvn eclipse:eclipse* You can then, launch your eclipse and import this new project

Create a new class called org.exoplatform.wcm.component.cache.UIWCMCacheComponent that extends org.exoplatform.ecm.webui.component.admin.manager.UIAbstractManagerComponent

<?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 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>

We have to add the following content to configuration.xml to register the resource bundle.