« Back to Development

Extending a portal service from a plugin

Tags: development

Introduction #

This article's goal is to add a new method that grants all plugins access to Util class from the portal.

More Info #

The example is done using JournalArticleUtil's method fetchByUUID_G, which is non-accessible as long as it's not included in JournalArticleLocalServiceImpl.java (Don't worry: this is going to be fixed for Liferay 6! - update: this has been fixed in this ticket).

Example #

Steps #

1. In a new plugin's service.xml file, add an empty entity with a reference to JournalArticle (the service we want to extend):

<?xml version="1.0"?>
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 5.2.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_5_2_0.dtd">

<service-builder package-path="com.ext.portlet.test">
  <namespace>MyJournal</namespace>

  <entity name="MyJournal" local-service="true" remote-service="true">
     <reference package-path="com.liferay.portlet.journal" entity="JournalArticle" />
  </entity>	
</service-builder>

2. Launch ant build-service task.

3. In MyJournalLocalServiceImpl.java (automaticaly generated by the service builder) add your desired method:

	public class MyJournalLocalServiceImpl extends MyJournalLocalServiceBaseImpl {


		public JournalArticle getArticleByUUID_G(String uuid, long groupId)
			throws SystemException {


			return JournalArticleUtil.fetchByUUID_G(uuid, groupId);
		}
        }

4. Repeat step 2.

5. The 4th step has generated a .jar library in WEB-INF/lib which is necesary for the rest of the portlets to access our new method. It should look like something like "my-custom-portlet-service.jar".

This is the CLP inter-portlet communication (see this wiki article: CLP Communication).

6. Copy this .jar to the lib folder of your application service (in Tomcat /lib/ext) and the delete the original jar.

7. Restart the application server, and now you can access your method in other plugins.

0 Attachments
15695 Views
Average (3 Votes)
The average rating is 3.33333333333333 stars out of 5.
Comments
Threaded Replies Author Date
Good start! A couple comments I have are: -... Derek Nerenberg April 27, 2010 3:17 PM

Good start! A couple comments I have are:

- using build.${username}.properties did not properly set my environment; I had to directly edit build.properties
- it would be helpful if you identified which folder under plugins the service.xml should be in
- the !DOCTYPE line end incorrectly which results in a " Content is not allowed in prolog" error
- even if there is an error running ant build-service because of the prolog error, it still shows as BUILD SUCCESSFUL
- without adding import statements to MyJournalLocalServiceImpl, the class does not compile.

import com.liferay.portlet.journal.service.persistence.JournalArticleUtil;
import com.liferay.portlet.journal.model.JournalArticle;
Posted on 4/27/10 3:17 PM.