Foren

Two Custom Portlets==>referencing services defined in one into other por

J J G, geändert vor 13 Jahren.

Two Custom Portlets==>referencing services defined in one into other por

New Member Beiträge: 16 Beitrittsdatum: 08.06.07 Neueste Beiträge
Liferay version : 6.0.5
Two portlets deployed individually as WAR files.

Portlet structure is as follows
test-1-portlet
    build.xml
    -docroot
        -css
        -js
        -jsp
        -WEB-INF
           -lib
           -sql
           -tld
           liferay-display.xml
           liferay-plugin-package.properties
           liferay-portlet.xml
           portlet.xml
           service.xml
           web.xml


test-2-portlet
    build.xml
    -docroot
        -css
        -js
        -jsp
        -WEB-INF
           -lib
           -sql
           -tld
           liferay-display.xml
           liferay-plugin-package.properties
           liferay-portlet.xml
           portlet.xml
           service.xml
           web.xml


Both portlets test-1-portlet and test-2-portlet are deployed on tomcat as individual WAR files like test-1-portlet.WAR and test-2-portlet.WAR


=============================test-1-portlet service.xml

<service-builder package-path="com.sample.portlets.services">
	<namespace>Sample</namespace>
	<entity name="CourseType" local-service="true" remote-service="true">
		<!-- PK fields -->
		<column name="courseTypeId" type="long" primary="true" />
		
		<!-- Group Instance -->
		<column name="groupId" type="long" />
		
		<!-- Audit fields -->
		<column name="companyId" type="long" />
		<column name="modifiedDate" type="Date" />
		<column name="modifiedBy" type="long" />
		
		<!-- Other fields -->
		<column name="courseTypeName" type="String" />
		
		<!-- Order -->
		<order by="asc">
			<order-column name="courseTypeName" case-sensitive="false" />
		</order>
	</entity>
	
	<entity name="StudentType" local-service="true" remote-service="true">
		<!-- PK fields -->
		<column name="studentTypeId" type="long" primary="true" />
		
		<!-- Group Instance -->
		<column name="groupId" type="long" />
		
		<!-- Audit fields -->
		<column name="companyId" type="long" />
		<column name="modifiedDate" type="Date" />
		<column name="modifiedBy" type="long" />
		
		<!-- Other fields -->
		<column name="studentTypeName" type="String" />
		
		<!-- Order -->
		<order by="asc">
			<order-column name="studentTypeName" case-sensitive="false" />
		</order>
	</entity>
</service-builder>


=============================test-2-portlet service.xml

<service-builder package-path="com.sample.programs.services">
	<namespace>Sample</namespace>
    <entity name="Course" local-service="true" remote-service="true">
        <!-- PK field -->
        <column name="courseId" type="long" primary="true" />
        
        <!-- Other fields -->
        <column name="courseName" type="String" />
        <column name="courseSummary" type="String" />
        
        
        <!-- References -->
        <reference package-path="com.liferay.portal" entity="WorkflowInstanceLink" />
        
        <reference package-path="com.sample.portlets.services" entity="CourseType" />
        <reference package-path="com.sample.portlets.services" entity="StudentType" />
   </entity>

</service-builder>



As can be seen in test-2-portlet.xml I need references of CourseType and StudentType services in Course type defined in test-1-portlet.xml.

But when I execute "build-service" target from test-2-portlet I face the following error:

Buildfile: E:\Liferay\portlets\sample-programs-portlet\build.xml
build-service:
     [java] Loading jar:file:/D:/Development/Liferay/ee-6.0/lprtl-ee-tomcat-6.0/tomcat-6.0.29/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/system.properties
     [java] Loading jar:file:/D:/Development/Liferay/ee-6.0/lprtl-ee-tomcat-6.0/tomcat-6.0.29/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/portal.properties
     [java] Loading file:/D:/Development/Liferay/ee-6.0/lprtl-ee-tomcat-6.0/tomcat-6.0.29/webapps/ROOT/WEB-INF/classes/portal-ext.properties
     [java] Loading jar:file:/D:/Development/Liferay/ee-6.0/lprtl-ee-tomcat-6.0/tomcat-6.0.29/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/com/liferay/portal/tools/dependencies/portal-tools.properties
     [java] 12:36:40,515 INFO  [PortalImpl:277] Global lib directory /D:/Development/Liferay/ee-6.0/lprtl-ee-tomcat-6.0/tomcat-6.0.29/lib/ext/
     [java] 12:36:40,515 INFO  [PortalImpl:297] Portal lib directory /D:/Development/Liferay/ee-6.0/lprtl-ee-tomcat-6.0/tomcat-6.0.29/webapps/ROOT/WEB-INF/lib/
     [java] java.io.IOException: Unable to open resource in class loader com/sample/portlets/services/service.xml
     [java] 	at com.liferay.portal.kernel.util.StringUtil.read(StringUtil.java:604)
     [java] 	at com.liferay.portal.kernel.util.StringUtil.read(StringUtil.java:567)
     [java] 	at com.liferay.portal.tools.servicebuilder.ServiceBuilder.getEntity(ServiceBuilder.java:1246)
     [java] 	at com.liferay.portal.tools.servicebuilder.ServiceBuilder.<init>(ServiceBuilder.java:960)
     [java] 	at com.liferay.portal.tools.servicebuilder.ServiceBuilder.<init>(ServiceBuilder.java:396)
     [java] 	at com.liferay.portal.tools.servicebuilder.ServiceBuilder.main(ServiceBuilder.java:176)</init></init>



How can we achieve the communication of services residing in one custom portlet(in my case it is test-1-portlet) into other custom portlet(in my case it is test-2-portlet) and NOT the communication between the services residing in ROOT webapp of Liferay bundled tomcat and custom portlet services for e.g. shown by having a reference of WorkflowInstanceLink in test-2-portlet service.xml?

Thanks.
thumbnail
Mohammed Azam, geändert vor 13 Jahren.

RE: Two Custom Portlets==>referencing services defined in one into other

Regular Member Beiträge: 159 Beitrittsdatum: 06.11.09 Neueste Beiträge
I hope this will give u some Idea!
One service.xml
J J G, geändert vor 13 Jahren.

RE: Two Custom Portlets==>referencing services defined in one into other

New Member Beiträge: 16 Beitrittsdatum: 08.06.07 Neueste Beiträge
Thanks Mohammed.
That would surely works and have successfully implemented 4 portlets in a single WAR file using that method.
But the scenario mentioned in my earlier post is quite different as per my requirements and I am looking for a solution to make that work, in case it is possible.
In case I am unable to find any I can always switch to the method you suggested.

In the meanwhile if you or anybody in the community has some suggestions on how to make portlets work as per the details mentioned in my earlier post I would really thankful.

Thanks.
thumbnail
Mohammed Azam, geändert vor 13 Jahren.

RE: Two Custom Portlets==>referencing services defined in one into other

Regular Member Beiträge: 159 Beitrittsdatum: 06.11.09 Neueste Beiträge
J J G:
Thanks Mohammed.
That would surely works and have successfully implemented 4 portlets in a single WAR file using that method.
But the scenario mentioned in my earlier post is quite different as per my requirements and I am looking for a solution to make that work, in case it is possible.
In case I am unable to find any I can always switch to the method you suggested.

In the meanwhile if you or anybody in the community has some suggestions on how to make portlets work as per the details mentioned in my earlier post I would really thankful.

Thanks.

Hi,

The reason of using the workflow... in your portlet 2 is because the .class file is available in the portal level. If you want similar approach then Check this link
A S, geändert vor 11 Jahren.

RE: Two Custom Portlets==>referencing services defined in one into other

New Member Beiträge: 19 Beitrittsdatum: 30.04.12 Neueste Beiträge
Did you ever find a solution to this? I've got the same issue and I'm pretty sure there's a simple solution, it's just escaping me at the minute. I've tried all the stuff about including the JAR and specifying dependencies in the liferay-plugin-package.properties but that didn't fix it. Not surprising really though as the error says it's looking for the service.xml, so it's after the data definitions for the imported object so far as I can tell, not the classes.

Any advice much appreciated.
A S, geändert vor 11 Jahren.

RE: Two Custom Portlets==>referencing services defined in one into other

New Member Beiträge: 19 Beitrittsdatum: 30.04.12 Neueste Beiträge
It seems that the solution is to place the "service.xml" from the linked portlet into the Portlet you're developing, at "docroot/WEB-INF/src", matching the folder structure to the package structure, so in the case in the thread "docroot/WEB-INF/src/com/sample/portlets/services/service.xml". Not sure this is a good idea though as it duplicates the "service.xml" file?

Also, service builder then builds code which tries to reference the ".model.impl.***Impl" which it then can't find in the "****-service.jar" in the lib folder. So the auto-generated code won't even compile.

If anyone has any ideas that would be really helpful.

Cheers.
thumbnail
David H Nebinger, geändert vor 11 Jahren.

RE: Two Custom Portlets==>referencing services defined in one into other

Liferay Legend Beiträge: 14914 Beitrittsdatum: 02.09.06 Neueste Beiträge
A S:
It seems that the solution is to place the "service.xml" from the linked portlet into the Portlet you're developing, at "docroot/WEB-INF/src", matching the folder structure to the package structure, so in the case in the thread "docroot/WEB-INF/src/com/sample/portlets/services/service.xml". Not sure this is a good idea though as it duplicates the "service.xml" file?


This is a bad idea. Even the original responder's idea of putting the jar file into tomcat's lib/ext directory is old school...

Basically any time there would be overlap between two service.xml files, you should only use one.

So from the OP's thing where there is Course in portlet A and CourseType in portlet B, the service.xml file should reside in portlet A and have both types defined in it. Portlet A becomes the host for all of the data services related to Course objects.

Even though the code in portlet A may not reference the CourseType object or services, it still hosts them.

Portlet B will then list portlet A as a required deployment context in the liferay-plugin-package.properties file. The Liferay IDE will ensure that the service jar from portlet A is copied into the WEB-INF/lib folder of portlet B, so it will have no problem accessing the CourseType objects and services from portlet A.

Never ever copy the same service.xml or entities from a service.xml file to other portlets. When other portlets need access to the entities and services, they will list the portlet providing the service as a required deployment context and the IDE will keep things together.

Now if portlet B also needs it's own entities that do not have a connection to portlet A's Course entities, then it should have it's own service.xml file that contains only it's entities, not any of the entities in portlet A's service.xml.

If necessary, once portlet B has portlet A listed as a required deployment context the IDE will copy portlet A's service jar to portlet B's WEB-INF/lib directory and portlet B's service.xml can then reference the entities from the jar. But this should be avoided because it's just going to add a layer of confusion (i.e. portlet C lists portlet B as a required deployment context so it gets portlet B's service jar, but since it doesn't list portlet A as a required deployment context it will get class not found exceptions; is much easier if portlet A hosts all of the entities rather than trying to split them apart).
A S, geändert vor 11 Jahren.

RE: Two Custom Portlets==>referencing services defined in one into other

New Member Beiträge: 19 Beitrittsdatum: 30.04.12 Neueste Beiträge
Surely this ends up with Portlet A listing a whole load of entities from everywhere though?

So, if Portlet A is a Department, and a Course (Portlet emoticon needs to reference it, we put the Course Data Service into A

Then because a Year references a Course, that goes in there too.

Then a Module references a year, so that then goes in there.

Then a Person (Portlet C) needs a department, so that goes into A as well.

Department has a type, so that'll be in Portlet A too

Along with Institution, as that is linked to department.

Over time that's going to be rather a monolithic service.xml surely? If we only avoid putting something into Portlet A when it's not related to any of the other variety of things now living in Portlet A. I do however take the point that copying the XML is not wise, and ultimately doesn't work anyway because SB generates code that doesn't work, probably best to move off that one.

Is the "official" recommendation to just stick the data services for anything that may reference anything else into a "data service holder" portlet do you know? I don't think I'd call it department in my case, as that may confuse.

Cheers.
thumbnail
David H Nebinger, geändert vor 11 Jahren.

RE: Two Custom Portlets==>referencing services defined in one into other

Liferay Legend Beiträge: 14914 Beitrittsdatum: 02.09.06 Neueste Beiträge
A S:
Over time that's going to be rather a monolithic service.xml surely?


Certainly does, but the other option is that a new portlet has required deployment context dependencies on many other portlets providing services...

I don't think there is an official position, but if you look at Liferay, for example, they use a monolithic service file to provide services to all portlets, whether the internal or external portlets.

I don't think a monolithic service file is bad thing. It keeps your data needs centralized rather than spreading it out over different portlets, promotes reuse as much as possible, ...

Locally we have a 'data-services' portlet plugin that we keep updating the service.xml in, adding new entities and service methods. The development team knows to use this portlet for the required deployment context and we maximize re-use.