Fórum

Returning custom objects with LocalServiceImpl-classes

Rana Datra, modificado 12 Anos atrás.

Returning custom objects with LocalServiceImpl-classes

New Member Postagens: 5 Data de Entrada: 29/09/11 Postagens Recentes
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.^^
thumbnail
Jan van der Kaaden, modificado 12 Anos atrás.

RE: Returning custom objects with LocalServiceImpl-classes

Junior Member Postagens: 28 Data de Entrada: 20/03/11 Postagens Recentes
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,
thumbnail
Sagar A Vyas, modificado 12 Anos atrás.

RE: Returning custom objects with LocalServiceImpl-classes

Liferay Master Postagens: 679 Data de Entrada: 17/04/09 Postagens Recentes
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
thumbnail
srikanth a, modificado 12 Anos atrás.

RE: Returning custom objects with LocalServiceImpl-classes

Regular Member Postagens: 144 Data de Entrada: 21/02/11 Postagens Recentes
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
thumbnail
Nagendra Kumar Busam, modificado 12 Anos atrás.

RE: Returning custom objects with LocalServiceImpl-classes

Liferay Master Postagens: 678 Data de Entrada: 07/07/09 Postagens Recentes
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
thumbnail
Sagar A Vyas, modificado 12 Anos atrás.

RE: Returning custom objects with LocalServiceImpl-classes

Liferay Master Postagens: 679 Data de Entrada: 17/04/09 Postagens Recentes
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, modificado 12 Anos atrás.

RE: Returning custom objects with LocalServiceImpl-classes

New Member Postagens: 5 Data de Entrada: 29/09/11 Postagens Recentes
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?
thumbnail
Sagar A Vyas, modificado 12 Anos atrás.

RE: Returning custom objects with LocalServiceImpl-classes

Liferay Master Postagens: 679 Data de Entrada: 17/04/09 Postagens Recentes
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, modificado 11 Anos atrás.

RE: Returning custom objects with LocalServiceImpl-classes

New Member Postagens: 10 Data de Entrada: 07/11/12 Postagens Recentes
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?
thumbnail
David H Nebinger, modificado 11 Anos atrás.

RE: Returning custom objects with LocalServiceImpl-classes

Liferay Legend Postagens: 14916 Data de Entrada: 02/09/06 Postagens Recentes
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.