Forums

Home » Liferay IDE » English

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Rana Datra
Returning custom objects with LocalServiceImpl-classes
November 17, 2011 2:18 AM
Answer

Rana Datra

Rank: New Member

Posts: 5

Join Date: September 29, 2011

Recent Posts

Hi,

we have a service.xml with the following entity:

<service-builder package-path="de.my.service.histograph">

<namespace>Histograph</namespace>
<entity name="RevisionEntry" local-service="true"
remote-service="false">

<column name="RevisionEntryId" type="long" primary="true" />
... some content...

</entity>

Which builds some nice service-classes like the RevisionEntryLocalServiceImpl-class. Now the problem:

In this ServiceImpl we're trying to write a method that returns an object of a custom class which is created in eclipse and not declared in the service-xml.
This class has the following name: de.my.core.histograph.HistoryEntry

the Implservice looks like the following:
class RevisionEntryLocalServiceImpl{
public List<HistoryEntry> getHistoryOfObject(){ ... method stuff...}

Now the service.xml-Compiler fails with the following message: "package de.my.core.histograph does not exist" which I suggest is because the service-builder doesn't know about the HistoryEntry-class at all.

How can we create a method that returns custom classes which are not mentioned in the service.xml?

If this description sounds confusing feel free to ask.^^
Jan van der Kaaden
RE: Returning custom objects with LocalServiceImpl-classes
November 23, 2011 2:02 PM
Answer

Jan van der Kaaden

Rank: New Member

Posts: 20

Join Date: March 20, 2011

Recent Posts

Hi Rana,
I think the service layer is typically to talk with your generated model and it is separated from the rest of your application and like you said it does not know about classes outside of your generated model.
A solution for your problem could be a class derived from RevisionEntryLocalServiceImpl like MyRevisionEntryLocalServiceImpl and add your wished functionality.

Hope this was useful,
Sagar A Vyas
RE: Returning custom objects with LocalServiceImpl-classes
November 24, 2011 3:16 AM
Answer

Sagar A Vyas

Rank: Liferay Master

Posts: 669

Join Date: April 17, 2009

Recent Posts

Hi Rana,

In this ServiceImpl we're trying to write a method that returns an object of a custom class which is created in eclipse and not declared in the service-xml.
This class has the following name: de.my.core.histograph.HistoryEntry


You can not access impl class out the word (in your portlet controller)

Service layer is kind of interface between you portlet which called consumers and persistence layer(Demoticon.

If you want to use some method inside the impl i would suggest please use util class for same,

Thanks,
Sagar Vyas
srikanth a
RE: Returning custom objects with LocalServiceImpl-classes
November 24, 2011 3:38 AM
Answer

srikanth a

Rank: Regular Member

Posts: 144

Join Date: February 20, 2011

Recent Posts

Rana Datra:
Hi,

we have a service.xml with the following entity:

<service-builder package-path="de.my.service.histograph">

<namespace>Histograph</namespace>
<entity name="RevisionEntry" local-service="true"
remote-service="false">

<column name="RevisionEntryId" type="long" primary="true" />
... some content...

</entity>

Which builds some nice service-classes like the RevisionEntryLocalServiceImpl-class. Now the problem:

In this ServiceImpl we're trying to write a method that returns an object of a custom class which is created in eclipse and not declared in the service-xml.
This class has the following name: de.my.core.histograph.HistoryEntry

the Implservice looks like the following:
class RevisionEntryLocalServiceImpl{
public List<HistoryEntry> getHistoryOfObject(){ ... method stuff...}

Now the service.xml-Compiler fails with the following message: "package de.my.core.histograph does not exist" which I suggest is because the service-builder doesn't know about the HistoryEntry-class at all.

How can we create a method that returns custom classes which are not mentioned in the service.xml?

If this description sounds confusing feel free to ask.^^



Hi,
Liferay services are build upon the service.xml. It creates all the files which are used to interact with persistant layer from customer.
so it can use only those classes which are creates by service.xml.
Still if you want to create a method which returns your custom object then i suggest you a write a wrapper class which call the your util class and perform you logic and return the custom object.

hope you got it.

regards
Sri
Nagendra Kumar Busam
RE: Returning custom objects with LocalServiceImpl-classes
November 26, 2011 11:43 AM
Answer

Nagendra Kumar Busam

Rank: Liferay Master

Posts: 653

Join Date: July 7, 2009

Recent Posts

Can you give me the reason why you want to return list of other custom class entries

Can you list down all columns of service.xml for RevisionEntry & custom class HistoryEntry properties (I am hoping it is simple bean)

If I am not wrong custom class will be a subset of entries for service.xml Entity
Sagar A Vyas
RE: Returning custom objects with LocalServiceImpl-classes
November 28, 2011 8:49 AM
Answer

Sagar A Vyas

Rank: Liferay Master

Posts: 669

Join Date: April 17, 2009

Recent Posts

Hi Rana,

public List<HistoryEntry> getHistoryOfObject(){ ... method stuff...}


I thought on your requirement and try to find out what could be the solution for such situation.

I come to the conclusion first of all you can not import any class from out side the word(out the service) in IMPL, cause impl is something which is auto generated for respective entity.
It is not good approach to put some method inside your impl which is bind with particular entity,if you do so then you may tightly couple your service.

In alternative you can something like create your own utility class in which you need to create two things
1) Create all methods which are there in IMPL (you can access these method by serviceUtil class)
2) Create your own method which inside that class only .

So it will give you something like "Impl"+ "Your method".this is how we are not tightly couple service,it will full fill you requirement also.

Thanks,
Sagar Vyas
Rana Datra
RE: Returning custom objects with LocalServiceImpl-classes
December 1, 2011 4:11 AM
Answer

Rana Datra

Rank: New Member

Posts: 5

Join Date: September 29, 2011

Recent Posts

Sagar A Vyas:
Hi Rana,

public List<HistoryEntry> getHistoryOfObject(){ ... method stuff...}


In alternative you can something like create your own utility class in which you need to create two things
1) Create all methods which are there in IMPL (you can access these method by serviceUtil class)
2) Create your own method which inside that class only .

So it will give you something like "Impl"+ "Your method".this is how we are not tightly couple service,it will full fill you requirement also.

Thanks,
Sagar Vyas


I think I've got the idea.

I could write a util-class which is doing the following:
HistoryGetterUtil(
{
public static List<HistoryEntry> getHistoryOfObject(long id)
{
Revision rev = RevisionEntryLocalServiceUtil.getRevision(id);
List<HistoryEntry> entries = //...historyGettingMagic ..../
return entries;
}
}

So I've moved the logic about the HistoryEntries from the service to a custom util-class, which cares about the HistoryEntry and is not build by the service-builder. Do you mean something like that?
Sagar A Vyas
RE: Returning custom objects with LocalServiceImpl-classes
December 3, 2011 6:00 AM
Answer

Sagar A Vyas

Rank: Liferay Master

Posts: 669

Join Date: April 17, 2009

Recent Posts

Hi Rana,

Yes Rana, This is what I meant emoticon

This is how you are not messing up with service class and you have clearly separation.

Thanks,
Sagar Vyas
Kailas Lokhande
RE: Returning custom objects with LocalServiceImpl-classes
January 16, 2013 7:52 AM
Answer

Kailas Lokhande

Rank: New Member

Posts: 10

Join Date: November 6, 2012

Recent Posts

But can I use this util class out side portlet?
For example, If I have HistoryGetterUtil in one portlet service and I want to use same util in another portlet, how could I do this?
David H Nebinger
RE: Returning custom objects with LocalServiceImpl-classes
January 16, 2013 8:01 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 12101

Join Date: September 1, 2006

Recent Posts

SB does not support returning custom classes that are not defined as entities.

However, there's an interesting trick documented here that explains how you can define a fake entity that you can use and return.