Foren

WebsiteLocalServiceUtil

James Coll, geändert vor 11 Jahren.

WebsiteLocalServiceUtil

New Member Beiträge: 11 Beitrittsdatum: 26.04.11 Neueste Beiträge
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?
thumbnail
Amos Fong, geändert vor 11 Jahren.

RE: WebsiteLocalServiceUtil

Liferay Legend Beiträge: 2047 Beitrittsdatum: 07.10.08 Neueste Beiträge
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, geändert vor 11 Jahren.

RE: WebsiteLocalServiceUtil

New Member Beiträge: 11 Beitrittsdatum: 26.04.11 Neueste Beiträge
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.
thumbnail
Amos Fong, geändert vor 11 Jahren.

RE: WebsiteLocalServiceUtil

Liferay Legend Beiträge: 2047 Beitrittsdatum: 07.10.08 Neueste Beiträge
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, geändert vor 11 Jahren.

RE: WebsiteLocalServiceUtil

New Member Beiträge: 11 Beitrittsdatum: 26.04.11 Neueste Beiträge
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.