Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
John O'Neill
New Return Type for Portlet Services
January 19, 2013 5:47 AM
Answer

John O'Neill

Rank: Junior Member

Posts: 36

Join Date: September 10, 2010

Recent Posts

I have a portlet which I am using for exposing customized JSON services to a mobile application. I've been successful in building services that return the Core Liferay objects, but am having trouble returning other object types. Below are the errors I am getting when trying to rebuild with Service Builder for the composite object tying together Organization and Address.

 1[echo] Building PBPOrganization
 2 3compile-java:
 3 4    [javac] Compiling 18 source files to C:\aws\liferay-plugins-sdk-6.1.1\portlets\PBPPortlet-portlet\docroot\WEB-INF\service-classes
 4 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
 5 6    [javac]     public java.util.List<com.library.slayer.service.pbp.PBPOrganizationAddress> findCitiesInRegion(
 6 7    [javac]                                                         ^
 7 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
 8 9    [javac]     public java.util.List<com.library.slayer.service.pbp.PBPOrganizationAddress> findCitiesInRegion(
 910    [javac]                                                         ^
1011    [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
1112    [javac]     public static java.util.List<com.library.slayer.service.pbp.PBPOrganizationAddress> findCitiesInRegion(
1213    [javac]                                                                ^
1314    [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
1415    [javac]     public java.util.List<com.library.slayer.service.pbp.PBPOrganizationAddress> findCitiesInRegion(
1516    [javac]                                                         ^
1617    [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
1718    [javac]         return (java.util.List<com.library.slayer.service.pbp.PBPOrganizationAddress>)ClpSerializer.translateOutput(returnObj);
1819    [javac]                                                              ^


I've added the following Composite class:
 11package com.library.slayer.service.pbp;
 2 2
 3 3import com.liferay.portal.model.Address;
 4 4import com.liferay.portal.model.Organization;
 5 5
 6 6public class PBPOrganizationAddress {
 7 7
 8 8    private Organization org = null;
 9 9    private Address address = null;
1010   
1111    public PBPOrganizationAddress(Organization org, Address address) {
1212        super();
1313        this.org = org;
1414        this.address = address;
1515    }
1616   
1717    public Organization getOrg() {
1818        return org;
1919    }
2020    public void setOrg(Organization org) {
2121        this.org = org;
2222    }
2323    public Address getAddress() {
2424        return address;
2525    }
2626    public void setAddress(Address address) {
2727        this.address = address;
2828    }
2929}


Any thoughts?

John O
David H Nebinger
RE: New Return Type for Portlet Services
January 19, 2013 9:21 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11771

Join Date: September 1, 2006

Recent Posts

Service builder methods can only return service builder entities, primitives (or their object counterparts), collections of service builder entities, and collections of primitives (as their object counterparts).

To do your custom class, you will need to define it as an entity. There's a suggestion here how to create fake db entities.
John O'Neill
RE: New Return Type for Portlet Services
January 27, 2013 10:01 AM
Answer

John O'Neill

Rank: Junior Member

Posts: 36

Join Date: September 10, 2010

Recent Posts

Thanks for the response David. I've implemented the suggestion above and it builds fine. I have a few questions:

1. On deploying, I get a response similar to this LPS-26849 . Is this still an issue or have I implemented this wrong?
2. I do not see setters/getters for the LR Entities Organization and Address which are referenced in the service buider. I was thinking I'd be able to see these exposed in the new Service Builder Entity PBPOrganizationAddress that I've defined below. I can see code using the mapping-key to return Entity objects, but do not see how I'll access them after exposing this custom portlet as a JSON service. Am I missing something?

 1<service-builder package-path="com.pbp.lr.srvc">
 2    <author>john</author>
 3    <namespace>PBPOrganizationAddress</namespace>
 4
 5    <entity name="PBPOrganizationAddress" local-service="true" remote-service="true">
 6       
 7        <column name="orgAddId" type="long" primary="true"></column>
 8        <column name="organizationId" type="long" primary="false"></column>
 9        <column name="addressId" type="long" primary="false"></column>
10        <column entity="com.liferay.portal.Address" name="address" type="Collection" mapping-key="addressId"></column>
11        <column entity="com.liferay.portal.Organization" name="organization" type="Collection" mapping-key="organizationId"></column>
12
13        <reference entity="Address" package-path="com.liferay.portal"></reference>
14        <reference entity="Organization" package-path="com.liferay.portal"></reference>
15    </entity>
16</service-builder>


Thanks - John O
David H Nebinger
RE: New Return Type for Portlet Services
January 27, 2013 10:08 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11771

Join Date: September 1, 2006

Recent Posts

Hey, John, the issue is related to that LPS, and you solve it just like the LPS indicates. Use the long id as keys (not actual objects), then use the service layer to handle the retrieval of the actual Liferay entities separately.
John O'Neill
RE: New Return Type for Portlet Services
January 27, 2013 2:34 PM
Answer

John O'Neill

Rank: Junior Member

Posts: 36

Join Date: September 10, 2010

Recent Posts

Thanks David. So If I did want to aggregate the Organization and Address Entity objects in one response at this point, I'd need to create a new Service Builder Entity representing all of the primitives from both Entities?

John O
John O'Neill
RE: New Return Type for Portlet Services
May 18, 2013 6:10 AM
Answer

John O'Neill

Rank: Junior Member

Posts: 36

Join Date: September 10, 2010

Recent Posts

Sorry I haven't closed this last question... your response has worked for me very well.

Thanks,
John O
John O'Neill
RE: New Return Type for Portlet Services
May 18, 2013 6:11 AM
Answer

John O'Neill

Rank: Junior Member

Posts: 36

Join Date: September 10, 2010

Recent Posts

Thanks, this works David.