¶ ↑
Liferay & ActiveRecordThis is a collection of Liferay v5 models for ActiveRecord.
Current stable version only supports PostgreSQL, due to differences in the Liferay schema between databases. The development version in master contains partial MySQL solution, with model alterations that have broken PostgreSQL as well, so the absolute HEAD is not ready. __Use the branch 1.0 (still hosted on Rubyforge git) until author imports the branch to Github.__
¶ ↑
Follow these steps for PostgreSQL-
Setup Liferay database
-
gem install lportal
# version 1.0.18 -
Configure ActiveRecord to use the Liferay database. See example configurations
-
require 'lportal'
in your Ruby code
The models heavily pollutes the namespace, which is intentional. Follow the API RDoc. If you are working in the context of the portal, having your users modeled by User is more convenient rather than having to reference them as “Lportal::Users”. Try, for example:
User.all()
If you want to create new rows to the database, or have better portlet runtime analytics, run the included migrations at your own risk.
For running the stable PostgreSQL-only 1.0 branch from git:
$ git checkout 1.0
¶ ↑
Other databases (MySQL, Oracle, …)You need some knowledge of Ruby and the database you want to hack^H^Hve support for. Start by setting up the test suite. You may also contact the author.
NOTICE: do not use the gem. Run the code from the master branch and link the lportal directory to Rails’ lib/.
$ git clone git://github.com/lamikae/lportal.git
Or build your own gem:
$ cd lportal $ vim version.rb # fix version number to build the gem $ gem build lportal.gemspec $ gem install lportal-1.2.0.gem
¶ ↑
General notions and examples¶ ↑
MigrationsTo create new instances you need to run the migrations. Liferay’s ORM, Hibernate, does not seem to use database sequences, but ActiveRecord assumes they exist. So each table’s PK needs to be modified to run as a sequence.
The second migration stores data from Liferay’s portlet XML to the database.
¶ ↑
LayoutsEach Group can have public and private pages. In both cases, there has to first exist a Web::LayoutSet, which is automatically created for a new Group. The individual pages (class Web::Layout) belong to this set, but they are not directly linked (in 5.1.1 at least). Instead, they belong to the Group and are either public or private. The models have methods to query the relations.
Say you create a new Group “group”.
company = Company.first group = Group.create( :company => company, :creatoruserid => company.administrators.first.id, :name => 'Example' ) => #<Group groupid: 8400004, companyid: 10109, creatoruserid: 10129, classnameid: 0, classpk: 0, parentgroupid: 0, livegroupid: 0, name: "Example", description: "", type_: 1, typesettings: "", friendlyurl: "/example", active_: true>
The LayoutSets can then be queried:
group.public_layoutset => #<Web::LayoutSet layoutsetid: 8400011, groupid: 8400004, companyid: 10109, privatelayout: false, logo: false, logoid: 0, themeid: "", colorschemeid: "01", wapthemeid: "mobile", wapcolorschemeid: "01", css: "", pagecount: 0, virtualhost: ""> group.private_layoutset => #<Web::LayoutSet layoutsetid: 8400010, groupid: 8400004, companyid: 10109, privatelayout: true, logo: false, logoid: 0, themeid: "", colorschemeid: "01", wapthemeid: "mobile", wapcolorschemeid: "01", css: "", pagecount: 0, virtualhost: ""> group.layoutsets.size => 2
And a new empty Layout can be created:
layout = Web::Layout.create( :group => group, :privatelayout => true, :name => 'Private page' ) => #<Web::Layout plid: 8400000, groupid: 8400004, companyid: 10109, privatelayout: true, layoutid: 1, parentlayoutid: 0, name: "<?xml version='1.0' encoding='UTF-8'?><root availab...", title: "<root />", description: "", type_: "portlet", typesettings: "layout-template-id=2_columns_ii\n", hidden_: false, friendlyurl: "/1", iconimage: false, iconimageid: 0, themeid: nil, colorschemeid: nil, wapthemeid: nil, wapcolorschemeid: nil, css: nil, priority: 0, dlfolderid: 0>
You can view this page in the Liferay “Communities” portlet via “Available Communities” => “Actions” => “Manage Pages” => “Private Pages” => “View Pages”.
¶ ↑
Portlets and CaterpillarTo add new portlets the Caterpillar mixins and migrations are required. This data does not live in the lportal database, and this library does not understand about the environment in which Liferay is. Caterpillar, however, does. It parses some Liferay XML configuration files and makes the data available by defining a couple of new methods to classes in the Web module.
The Layout settings are configured via Web::Typesettings. The ”settings” method handles the conversion between the ”typesettings” string and the object model. To add a message_boards portlet into column 2:
layout.settings = Web::Typesettings.new.message_boards(:column => 2) => "layout-template-id=2_columns_ii\ncolumn-2=19,"
The other way around, find the private layouts of “group” that have the Message Board portlet:
layouts = group.select_layouts_with('message_boards',:private)
Which is a short form for:
layouts = group.private_layouts.select{|l| l.settings.include?('message_boards')} => [#<Web::Layout plid: 8400000, groupid: 8400004, companyid: 10109, privatelayout: true, layoutid: 1, parentlayoutid: 0, name: "<?xml version='1.0' encoding='UTF-8'?><root availab...", title: "<root />", description: "", type_: "portlet", typesettings: "layout-template-id=2_columns_ii\ncolumn-2=19,", hidden_: false, friendlyurl: "/1", iconimage: false, iconimageid: 0, themeid: nil, colorschemeid: nil, wapthemeid: nil, wapcolorschemeid: nil, css: nil, priority: 0, dlfolderid: 0>]
Or query what portlets are in the Layout:
layouts.first.portlets.each{|p| puts p.title} Message Boards => [#<Web::PortletPreferences portletpreferencesid: 10210, ownerid: 0, ownertype: 3, plid: 10146, portletid: "19", preferences: "<portlet-preferences xmlns=\"http://java.sun.com/xml...">]
Or whether the layouts include a specific portlet:
group.layouts_include?('message_boards') => true group.layouts_include?('message_boards',:private) => true group.layouts_include?('message_boards',:public) => false
Copyright © 2008,2009 Mikael Lammentausta, released under the MIT license