Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
John O'Neill
Extending an existing service: OrganizationService
October 6, 2012 4:52 AM
Answer

John O'Neill

Rank: Junior Member

Posts: 36

Join Date: September 10, 2010

Recent Posts

I'm trying to extend a few new methods on the OrganizationService, com.liferay.portal.service.OrganizationService. As I follow the directions in the code, it let's me know the following:

 1
 2@JSONWebService
 3@Transactional(isolation = Isolation.PORTAL, rollbackFor =  {
 4    PortalException.class, SystemException.class})
 5public interface OrganizationService {
 6    /*
 7     * NOTE FOR DEVELOPERS:
 8     *
 9     * Never modify or reference this interface directly. Always use {@link OrganizationServiceUtil} to access the organization remote service. Add custom service methods to {@link com.liferay.portal.service.impl.OrganizationServiceImpl} and rerun ServiceBuilder to automatically copy the method declarations to this interface.
10     */


To start I have simply copied an existing method and renamed it. I then went to the liferay/portal-impl/build.xml file to run the ant-task build-service and I have the following error below.

Am I following the best standard to accomplish adding a new method to the OrganizationService?
Is this the correct way to run ServiceBuilder on pre-exisiting Liferay code?
What is wrong with the ant task?

Best,
John O

 1
 2Buildfile: C:\aws\liferay-portal-src-6.1.0-ce-ga1\portal-impl\build.xml
 3build-service:
 4     [java] Loading file:/C:/aws/liferay-portal-src-6.1.0-ce-ga1/portal-impl/classes/system.properties
 5     [java] Oct 6, 2012 6:22:56 AM com.liferay.portal.kernel.log.Jdk14LogImpl info
 6     [java] INFO: Global lib directory
 7     [java] Oct 6, 2012 6:22:56 AM com.liferay.portal.kernel.log.Jdk14LogImpl info
 8     [java] INFO: Portal lib directory /C:/aws/liferay-portal-src-6.1.0-ce-ga1/util-java/classes/
 9     [java] 06:22:56,539 INFO  [EasyConf:122] Refreshed the configuration of all components
10     [java] 06:22:57,169 INFO  [ConfigurationLoader:56] Properties for /C:/aws/liferay-portal-src-6.1.0-ce-ga1/portal-impl/classes/portal loaded from [file:/C:/aws/liferay-portal-src-6.1.0-ce-ga1/portal-impl/classes/com/liferay/portal/tools/dependencies/portal-tools.properties, file:/C:/aws/liferay-portal-src-6.1.0-ce-ga1/portal-impl/classes/portal.properties]
11     [java] Loading file:/C:/aws/liferay-portal-src-6.1.0-ce-ga1/portal-impl/classes/portal.properties
12     [java] Loading file:/C:/aws/liferay-portal-src-6.1.0-ce-ga1/portal-impl/classes/com/liferay/portal/tools/dependencies/portal-tools.properties
13     [java] java.lang.NullPointerException
14     [java]     at com.liferay.portal.kernel.io.unsync.UnsyncStringReader.<init>(UnsyncStringReader.java:33)
15     [java]     at com.liferay.util.xml.XMLSafeReader.<init>(XMLSafeReader.java:25)
16     [java]     at com.liferay.portal.xml.SAXReaderImpl.read(SAXReaderImpl.java:413)
17     [java]     at com.liferay.portal.kernel.xml.SAXReaderUtil.read(SAXReaderUtil.java:151)
18     [java]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder._getContentDocument(ServiceBuilder.java:3833)
19     [java]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder._getContent(ServiceBuilder.java:3756)
20     [java]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder.<init>(ServiceBuilder.java:544)
21     [java]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder.<init>(ServiceBuilder.java:430)
22     [java]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder.main(ServiceBuilder.java:146)
23     [java]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
24     [java]     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
25     [java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
26     [java]     at java.lang.reflect.Method.invoke(Unknown Source)
27     [java]     at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:217)
28     [java]     at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:152)
29     [java]     at org.apache.tools.ant.taskdefs.Java.run(Java.java:771)
30     [java]     at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:221)
31     [java]     at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:135)
32     [java]     at org.apache.tools.ant.taskdefs.Java.execute(Java.java:108)
33     [java]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
34     [java]     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
35     [java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
36     [java]     at java.lang.reflect.Method.invoke(Unknown Source)
37     [java]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
38     [java]     at org.apache.tools.ant.Task.perform(Task.java:348)
39     [java]     at org.apache.tools.ant.Target.execute(Target.java:390)
40     [java]     at org.apache.tools.ant.Target.performTasks(Target.java:411)
41     [java]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
42     [java]     at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
43     [java]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
44     [java]     at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
45     [java]     at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
46     [java]     at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:424)
47     [java]     at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:138)
48compile:
49BUILD SUCCESSFUL
50Total time: 8 seconds
Hitoshi Ozawa
RE: Extending an existing service: OrganizationService
October 7, 2012 5:50 AM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7990

Join Date: March 23, 2010

Recent Posts

Sorry, but the best practice is not to modify liferay's source code. See the following page for information on how to customize liferay.

http://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/extending-and-customizing-lifer-3
John O'Neill
RE: Extending an existing service: OrganizationService
October 8, 2012 6:58 AM
Answer

John O'Neill

Rank: Junior Member

Posts: 36

Join Date: September 10, 2010

Recent Posts

Thank you Hitoshi. If I read the documentation correctly, I should create a new service hook plugin, copy the existing com.liferay.portal.service.impl.OrganizationServiceImpl code, modify to my needs and run the ServiceBuilder on the new service hook? Does this sound right?

Best,
John O
Hitoshi Ozawa
RE: Extending an existing service: OrganizationService
October 8, 2012 4:17 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7990

Join Date: March 23, 2010

Recent Posts

No exactly. You won't be able to run service builder on existing liferay entity definition. You'll need to create a new entity definition that uses liferay's existing services. Run service builder on the newly defined entity definition.

I found this to be better technique than using expando because my entity definition/interfaces will remain separate from liferay's entity definition/interfaces.
John O'Neill
RE: Extending an existing service: OrganizationService
October 14, 2012 3:26 PM
Answer

John O'Neill

Rank: Junior Member

Posts: 36

Join Date: September 10, 2010

Recent Posts

I've tried to implement using the Eclipse Liferay hook for services, extend the OrganizationLocalServiceWrapper, expose the search() methods and mark it as a @JSONWebService. I've run into this problem below... Is there I've missed?

 117:12:43,964 INFO  [pool-2-thread-8][PluginPackageUtil:1033] Reading plugin package for PBPServices-hook
 2Oct 14, 2012 5:12:44 PM org.apache.catalina.core.ApplicationContext log
 3INFO: Initializing Spring root WebApplicationContext
 417:12:44,037 INFO  [pool-2-thread-8][HookHotDeployListener:550] Registering hook for PBPServices-hook
 5#########------------------------------------------#########
 6######### Initiating new PBPCalendarServiceWrapper #########
 7#########------------------------------------------#########
 8#########--------------------------------------------#########
 9######### Initiating new ExtOrganizationLocalService #########
10#########--------------------------------------------#########
1117:12:44,061 INFO  [pool-2-thread-8][HookHotDeployListener:690] Hook for PBPServices-hook is available for use
1217:12:44,076 ERROR [pool-2-thread-8][JSONWebServiceServiceAction:54] java.lang.NullPointerException
13java.lang.NullPointerException
14        at com.liferay.portal.jsonwebservice.JSONWebServiceConfigurator.configure(JSONWebServiceConfigurator.java:101)
15        at com.liferay.portal.jsonwebservice.JSONWebServiceServiceAction.<init>(JSONWebServiceServiceAction.java:51)
16        at com.liferay.portal.jsonwebservice.JSONWebServiceServlet.getJSONAction(JSONWebServiceServlet.java:169)
17        at com.liferay.portal.servlet.JSONServlet.init(JSONServlet.java:52)
18        at com.liferay.portal.kernel.servlet.PortalClassLoaderServlet.portalInit(PortalClassLoaderServlet.java:76)
19        at com.liferay.portal.kernel.util.PortalLifecycleUtil.register(PortalLifecycleUtil.java:64)
20        at com.liferay.portal.kernel.util.PortalLifecycleUtil.register(PortalLifecycleUtil.java:56)
21        at com.liferay.portal.kernel.servlet.PortalClassLoaderServlet.init(PortalClassLoaderServlet.java:47)
22        at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1266)
23        at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1185)
24        at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1080)
25        at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5015)
26        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5302)
27        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
28        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895)
29        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871)
30        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
31        at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1099)
32        at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1621)
33        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
34        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
35        at java.util.concurrent.FutureTask.run(FutureTask.java:138)
36        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
37        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
38        at java.lang.Thread.run(Thread.java:619)
Hitoshi Ozawa
RE: Extending an existing service: OrganizationService
October 14, 2012 4:32 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7990

Join Date: March 23, 2010

Recent Posts

I should have asked this earlier but are you trying to extend OrganizationService to use it in your own portlets or liferay's basic functionality?

Instead of creating a hook, just create a portlet. Make the impl methods call liferay's OrganizationService. That is, instead of doing a java class extend, just use the existing service.
John O'Neill
RE: Extending an existing service: OrganizationService
October 15, 2012 3:40 AM
Answer

John O'Neill

Rank: Junior Member

Posts: 36

Join Date: September 10, 2010

Recent Posts

I'm calling these services in a mobile application, using JSON. My intent is to decorate or compose services on the Liferay framework.

Am I following the right approach? Do you have any ideas on my issue above?

Thanks,
John O
Hitoshi Ozawa
RE: Extending an existing service: OrganizationService
October 15, 2012 4:04 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7990

Join Date: March 23, 2010

Recent Posts

Instead of creating a hook, just create a new portlet and in the service.xml, make sure to enable remote service. In the service.xml, just have key to liferay's organization service and additional column information. In the impl method, just call methods on new columns with liferay's organization service.
John O'Neill
RE: Extending an existing service: OrganizationService
January 6, 2013 1:39 PM
Answer

John O'Neill

Rank: Junior Member

Posts: 36

Join Date: September 10, 2010

Recent Posts

Thank you Hitoshi... This was very helpful!

Best,
John O
John O'Neill
RE: Extending an existing service: OrganizationService
January 10, 2013 8:31 PM
Answer

John O'Neill

Rank: Junior Member

Posts: 36

Join Date: September 10, 2010

Recent Posts

Hitoshi,

I'm trying to return a composite object of Organization and Address from a custom Portlet. As I rebuild using the Service Builder, I get these errors below.
 1
 2     [echo] Building PBPOrganization
 3compile-java:
 4    [javac] Compiling 18 source files to C:\aws\liferay-plugins-sdk-6.1.1\portlets\PBPPortlet-portlet\docroot\WEB-INF\service-classes
 5    [javac] C:\aws\liferay-plugins-sdk-6.1.1\portlets\PBPPortlet-portlet\docroot\WEB-INF\service\com\library\slayer\service\PBPOrganizationService.java:81: package com.library.slayer.service.pbp does not exist
 6    [javac]     public java.util.List<com.library.slayer.service.pbp.PBPOrganizationAddress> findCitiesInRegion(
 7    [javac]                                                         ^
 8    [javac] C:\aws\liferay-plugins-sdk-6.1.1\portlets\PBPPortlet-portlet\docroot\WEB-INF\service\com\library\slayer\service\PBPOrganizationServiceClp.java:211: package com.library.slayer.service.pbp does not exist
 9    [javac]     public java.util.List<com.library.slayer.service.pbp.PBPOrganizationAddress> findCitiesInRegion(
10    [javac]                                                         ^
11    [javac] C:\aws\liferay-plugins-sdk-6.1.1\portlets\PBPPortlet-portlet\docroot\WEB-INF\service\com\library\slayer\service\PBPOrganizationServiceUtil.java:90: package com.library.slayer.service.pbp does not exist
12    [javac]     public static java.util.List<com.library.slayer.service.pbp.PBPOrganizationAddress> findCitiesInRegion(
13    [javac]                                                                ^
14    [javac] C:\aws\liferay-plugins-sdk-6.1.1\portlets\PBPPortlet-portlet\docroot\WEB-INF\service\com\library\slayer\service\PBPOrganizationServiceWrapper.java:83: package com.library.slayer.service.pbp does not exist
15    [javac]     public java.util.List<com.library.slayer.service.pbp.PBPOrganizationAddress> findCitiesInRegion(
16    [javac]                                                         ^
17    [javac] C:\aws\liferay-plugins-sdk-6.1.1\portlets\PBPPortlet-portlet\docroot\WEB-INF\service\com\library\slayer\service\PBPOrganizationServiceClp.java:240: package com.library.slayer.service.pbp does not exist
18    [javac]         return (java.util.List<com.library.slayer.service.pbp.PBPOrganizationAddress>)ClpSerializer.translateOutput(returnObj);
19    [javac]                                                              ^


I've added the following Composite class:
 1package com.library.slayer.service.pbp;
 2
 3import com.liferay.portal.model.Address;
 4import com.liferay.portal.model.Organization;
 5
 6public class PBPOrganizationAddress {
 7
 8    private Organization org = null;
 9    private Address address = null;
10   
11    public PBPOrganizationAddress(Organization org, Address address) {
12        super();
13        this.org = org;
14        this.address = address;
15    }
16   
17    public Organization getOrg() {
18        return org;
19    }
20    public void setOrg(Organization org) {
21        this.org = org;
22    }
23    public Address getAddress() {
24        return address;
25    }
26    public void setAddress(Address address) {
27        this.address = address;
28    }
29}


Any thoughts?

John O