Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
James Coll
WebsiteLocalServiceUtil
November 29, 2012 11:20 PM
Answer

James Coll

Rank: New Member

Posts: 11

Join Date: April 26, 2011

Recent Posts

I want to create a website programmatically in a StartupAction (if it does not already exist).

I see a method:
addWebsite
Website addWebsite(long userId,
String className,
long classPK,
String url,
int typeId,
boolean primary)
throws PortalException,
SystemException

...but I don't have a userId and I don't know what a className is or what a classPK is or what a typeId is or what primary means. Javadocs are no help at all.

Another method:
public com.liferay.portal.model.Website createWebsite(long websiteId);

...but I don't know what websiteId should be. I'd expect to receive the system-generated websiteId from the createWebsite() method.

In Liferay 6.0.6 I created a website using OrganizationLocalServiceUtil, whose methods accepted arbitrary String names, and had the desired side-effect of creating a website. In Liferay 6.1 it appears I can create websites without the extra Organization, but the method prototypes are a complete mystery to me. Can anyone shed some light on this?
Amos Fong
RE: WebsiteLocalServiceUtil
December 4, 2012 12:04 PM
Answer

Amos Fong

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1898

Join Date: October 7, 2008

Recent Posts

see a method:
addWebsite
Website addWebsite(long userId,
String className,
long classPK,
String url,
int typeId,
boolean primary)
throws PortalException,
SystemException


Generally userId is the user who is adding the website.
ClassName is the class for the object that the website is for. For example, it could be a website for a User or Organization.
ClassPK would be the primary key of the class above

A good place to find an example is EditOrganizationAction.java. You can see how websites are added when you edit an organization.
James Coll
RE: WebsiteLocalServiceUtil
December 4, 2012 2:30 PM
Answer

James Coll

Rank: New Member

Posts: 11

Join Date: April 26, 2011

Recent Posts

Hello Amos,

This is very enlightening - thank you!

Just a couple of follow-up questions:

Since I am creating the website in a StartupAction.run(String[] ids) method, could I use as the userId:
long cid = Long.parseLong(ids[0]);
long uid = UserLocalServiceUtil.getDefaultUser(cid).getUserId();

?

And, could I pass an empty string or null as the className, and 0 as the classPK ? The website I am creating is not associated with any particular user or organization.

And, could I pass 0 as the typeId and false as the primary ? Would that perhaps indicate that the website is 'open' or 'private' ? I want to make a private website that users cannot self-register.
Amos Fong
RE: WebsiteLocalServiceUtil
December 10, 2012 5:05 PM
Answer

Amos Fong

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1898

Join Date: October 7, 2008

Recent Posts

And, could I pass an empty string or null as the className, and 0 as the classPK ? The website I am creating is not associated with any particular user or organization.


It looks like it expects a proper className and classPK....you may just want to attach it to some object like the Company. You'll need to add the proper Listtypes though for the company object which you can do before you add the websites. Do a select * from ListType to see the "types" for websites.

And, could I pass 0 as the typeId and false as the primary ? Would that perhaps indicate that the website is 'open' or 'private' ? I want to make a private website that users cannot self-register.


See above for adding a valid type. I don't think primary really matters here. This isn't data users can search and use.

You might just need to try it and see what happens though.
James Coll
RE: WebsiteLocalServiceUtil
December 20, 2012 9:13 AM
Answer

James Coll

Rank: New Member

Posts: 11

Join Date: April 26, 2011

Recent Posts

I have reverted my strategy back to creating a artificial organization to get the website. Using an AutoLogin hook, I add users authenticated by ForgeRock's OpenAM and associate them with the organization. I also have a portal-ext.properties setting servlet.service.events.pre= pointing to an Action-derived class to keep users inside the website.