Wednesday May 14, 2008

Extending Project WebSynergy's Tables

Project WebSynergy 

We had recently started work on semantic enabling Project WebSynergy's community feature.

Read my blog on that.

For doing this we had to extend the existing table structure by adding new columns
and  also creating new tables.

In this blog I will show how easy it is do this using
Project WebSynergy's ServiceBuilder framework 

The use case for this example will be to add an ontologyId column
to the existing BlogsEntry table.
We would also create a new BlogsEntryOntologyMapping Table. 

Open the
<synergy-workspace>\\e2demo\\synergy\\liferay\\patch\\portal-impl\\src\\com\\liferay
\\portlet\\blogs\\service.xml

in your favorite IDE (we would recommend NetBeans)

Each <entity> tag corresponds to a table in the DB.

To add "OntologyId" column to the BlogsEntry table
add the following in <entity name="BlogsEntry"> </entity> tag

<column name="ontologyId" type="String" />

We can also add a finder method corresponding to the column that we have just added.
Using this the callers can get the blog entries corresponding to an ontologyId.

        <finder name="OntologyId" return-type="Collection">
            <finder-column name="ontologyId" />
        </finder>
This would generate a findByOntologyId() in the BlogsEntryPersistence
and BlogsEntryPersistenceImpl.

To add a new BlogsEntryOntlogyMapping table add the following 

 <entity name="BlogsEntryOntlogyMapping" local-service="true" remote-service="true">
        <column name="entryId" type="long" primary="true" />
        <column name="ontologyId" type="long" />
    </entity>

Next we need to add getBlogEntriesByOntologyId() to the BlogsEntryLocalServiceImpl class.

public List getBlogEntriesByOntologyId(String ontologyId) throws SystemException{ 

             List blogtnriesList = blogsEntryPersistence.findByOntologyId(ontologyId);

return blogtnriesList;

You will get a compilation error on the blogsEntryPersistence.findByOntologyId(ontologyId) line.
This is because the method is still not added to the BlogsEntryPersistence interface.

But dont mind that as of now :)

After making these changes,
cd to <synergy-workspace>\\e2demo\\synergy\\liferay\\portal\\portal-impl
in the command prompt and run the following ant script.

ant build-service-portlet-blogs 

This generates all the service, util, persistence and  factory classes that are relevant to Blogs.

Open the <synergy-workspace>\\e2demo\\synergy\\liferay\\portal\\portal-service\\src\\com\\liferay\\portlet\\blogs \\service\\persistence\\BlogsEntryPersistence, you will find that the findByOntologyId() is newly generated.

Open the <synergy-workspace>\\e2demo\\synergy\\liferay\\portal\\portal-service\\src\\com\\liferay\\portlet\\blogs\\ service\\BlogsEntryLocalService and BlogsEntryLocalServiceUtil, you will find that the getBlogEntriesByOntologyId() is newly generated.

Now you can call the BlogsEntryLocalServiceUtil .getBlogEntriesByOntologyId() from any portlet class or jsp,
you will get the blog entries that the specific ontologyId applied to that.

Next the changes have to be made in the db scripts.

For this run ant build-db in the command prompt that you opened before.

Open the <synergy-workspace>\\e2demo\\synergy\\liferay\\portal\\sql\\portal-tables.sql and <synergy-workspace>\\e2demo\\synergy\\liferay\\portal\\sql\\create-\*.sql.

You will find that the scripts have been suitably modifled.

For the changes to be reflected on the DB (could be MySQL, HSQL, etc),
drop the existing tables under lPortal database if any, and re-start the server.
The ontologyId column would be added to the BlogsEntry Table and BlogsEntryOntologyMapping table would have been created.

Extending Project WebSynergy's tables is as simple as this. You can extend this example to any other feature like wiki, bookmarks, etc.

 


Tuesday Jun 26, 2007

Mirage - Open Source CMS Based on JSR-170 Standards

Mirage project

The Mirage Project site got launched today on java.net. Check it out here

Mirage is an open source project which aims to deliver a professional open source content management system based on the content repository Java Content Repository (JCR) viz. JSR-170.


You can read more about it at my blog here.

About

atul

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today