Foros de discusión

Liferay Service Builder

Aswin Giridhar, modificado hace 12 años.

Liferay Service Builder

New Member Mensajes: 15 Fecha de incorporación: 9/02/11 Mensajes recientes
Hey guys,

I am currently stuck in a problem where I have the following scenario:

I am creating a table called "Region", which has a relationship with the existing liferay table "Country". So the scenario is something like this, one region can have many countries.

In order to achieve this, I am creating a table regioncountry, which holds the foreign key of Region and Country table.

DB Schema:
Region: RegionId, Name
RegionCountry: RegionId, CountryId

How do i achieve this using Liferay Service builder ?

I have seen something similar in Liferay Portal service.xml (for relationship between Groups and Organization), but i I am not able to find any entity Groups_Orgs on the service.xml.

What is the best solution for this scenario ?
- Going for the above method
- Creating new column regionid on the existing liferay table Country
- Creating a new table altogether ?

Any help will be appreciated.

Thanks,
thumbnail
David H Nebinger, modificado hace 12 años.

RE: Liferay Service Builder

Liferay Legend Mensajes: 14914 Fecha de incorporación: 2/09/06 Mensajes recientes
If region contains multiple countries, then region would be an entity w/ a collection of countries, and country would be an entity w/ a region id.

You don't need the many to many relationship join table.
Aswin Giridhar, modificado hace 12 años.

RE: Liferay Service Builder

New Member Mensajes: 15 Fecha de incorporación: 9/02/11 Mensajes recientes
David H Nebinger:
If region contains multiple countries, then region would be an entity w/ a collection of countries, and country would be an entity w/ a region id.

You don't need the many to many relationship join table.


Hi David,

Thanks for your reply.
So, that would mean overriding existing Liferay Country table to add the regionId there ?
I am just skeptical to change existing Liferay Entities, is that advisable to do ?
thumbnail
David H Nebinger, modificado hace 12 años.

RE: Liferay Service Builder

Liferay Legend Mensajes: 14914 Fecha de incorporación: 2/09/06 Mensajes recientes
Oh, the part about wanting to use the Liferay country entity was not apparent.

You're right about not wanting to modify the Liferay entities, it would make upgrades difficult.

So instead I'd do the Region entity that has a collection of "MyCountry" entities. The MyCountry entity would have the region id and the Liferay Country as an entity. That should give you what you're looking for, correct?
Aswin Giridhar, modificado hace 12 años.

RE: Liferay Service Builder

New Member Mensajes: 15 Fecha de incorporación: 9/02/11 Mensajes recientes
David H Nebinger:
Oh, the part about wanting to use the Liferay country entity was not apparent.

You're right about not wanting to modify the Liferay entities, it would make upgrades difficult.

So instead I'd do the Region entity that has a collection of "MyCountry" entities. The MyCountry entity would have the region id and the Liferay Country as an entity. That should give you what you're looking for, correct?



How do we do that ?
is this something like this ?
<entity name="myRegion" local-service="true" remote-service="true">

<column name="regionId" primary="true" type="long"></column>

<column name="name" type="String"></column>
<column name="defaultLanguage" type="long"></column>
<column name="countries" type="Collection" entity="MyCountry" mapping-key="regionId" />

</entity>
<entity name="myCountry" local-service="true" remote-service="true">

<column name="countryId" primary="true" type="long"></column>
<column name="regionId" type="long"></column>

<column name="countries" type="Collection" entity="Country" mapping-key="countryId" />
<reference entity="Country" package-path="com.liferay.portal"/>
</entity>
thumbnail
Joaquin Cabal, modificado hace 12 años.

RE: Liferay Service Builder

Regular Member Mensajes: 106 Fecha de incorporación: 7/09/09 Mensajes recientes
Hi Aswin,

It would be like that

<entity name="myRegion" local-service="true" remote-service="true">
<column name="regionId" primary="true" type="long"></column>

<column name="name" type="String"></column>
<column name="defaultLanguage" type="long"></column>
<column name="countries" type="Collection" entity="MyCountry" mapping-key="regionId" />

</entity>
<entity name="myCountry" local-service="true" remote-service="true">

<column name="countryId" primary="true" type="long"></column>
<column name="regionId" type="long"></column>
</entity>

MyCountry is only for have a relation to Liferay Country
Aswin Giridhar, modificado hace 12 años.

RE: Liferay Service Builder

New Member Mensajes: 15 Fecha de incorporación: 9/02/11 Mensajes recientes
Joaquin Cabal:
Hi Aswin,

It would be like that

<entity name="myRegion" local-service="true" remote-service="true">
<column name="regionId" primary="true" type="long"></column>

<column name="name" type="String"></column>
<column name="defaultLanguage" type="long"></column>
<column name="countries" type="Collection" entity="MyCountry" mapping-key="regionId" />

</entity>
<entity name="myCountry" local-service="true" remote-service="true">

<column name="countryId" primary="true" type="long"></column>
<column name="regionId" type="long"></column>
</entity>

MyCountry is only for have a relation to Liferay Country



So when we use mycountry, we create a custom finder and add methods on that mycountry service and then query the liferay country (CountryLocalServiceUtil) to populate myCountry right ?
thumbnail
Joaquin Cabal, modificado hace 12 años.

RE: Liferay Service Builder

Regular Member Mensajes: 106 Fecha de incorporación: 7/09/09 Mensajes recientes
Exactly! when you add some Country for the region, you get the Liferay Country id, with CountryLocalServiceUtil
thumbnail
sheela mk, modificado hace 11 años.

RE: Liferay Service Builder

Regular Member Mensajes: 111 Fecha de incorporación: 17/02/12 Mensajes recientes
Oh My God..Got Solution!!!

emoticon
thumbnail
Joaquin Cabal, modificado hace 12 años.

RE: Liferay Service Builder

Regular Member Mensajes: 106 Fecha de incorporación: 7/09/09 Mensajes recientes
Hi David,
Is ok the modeling, but what would be the way for create these services?
If I have to create a new service I would create it in a new portlet for example, but if a have a relationship with an existing Liferay model like "Country", How would be this? Could be in a Hook plugin or maybe an Ext plugin , overriding the portal service builder?
thumbnail
David H Nebinger, modificado hace 12 años.

RE: Liferay Service Builder

Liferay Legend Mensajes: 14914 Fecha de incorporación: 2/09/06 Mensajes recientes
No, you'd stick w/ your regular portlet w/ the service builder in there.

You will still have access to Liferay's CountryLocalServiceUtil (or whatever it is) for fetching countries, you'd just be setting the result into the MyCountry entity...
thumbnail
David H Nebinger, modificado hace 12 años.

RE: Liferay Service Builder

Liferay Legend Mensajes: 14914 Fecha de incorporación: 2/09/06 Mensajes recientes
David H Nebinger:
No, you'd stick w/ your regular portlet w/ the service builder in there.

You will still have access to Liferay's CountryLocalServiceUtil (or whatever it is) for fetching countries, you'd just be setting the result into the MyCountry entity...


The more I think about this, I realize it's not going to work. The Country object you get back from Liferay is actually an interface to an instance from another class loader.

I guess I would make the MyCountry entity hold the region id and the country id. Get the list of MyCountry entities using the region, then you'd have to manually call the CountryLocalServiceUtil (or whatever it is) to pull back the country instance.

Adding it as an EXT plugin would get around this issue, but SB usage in EXT plugins is either deprecated now or will be in the future (I know I saw a note about that somewhere). Since a hook is in a different class loader, it would face the same issue as a regular portlet implementation...
thumbnail
Joaquin Cabal, modificado hace 12 años.

RE: Liferay Service Builder

Regular Member Mensajes: 106 Fecha de incorporación: 7/09/09 Mensajes recientes
Thanks David, I have sent last post, viewing only your first post.
Is a good idea to have two entities for this case, and MyCountry entity having a relation to Liferay Country