Foren

Create a Community with the API

thumbnail
Christian Schulze, geändert vor 12 Jahren.

Create a Community with the API

Junior Member Beiträge: 87 Beitrittsdatum: 19.11.09 Neueste Beiträge
I want to add a new Community with an UpgradeProcess inside a Hook.

I want to use this:


GroupLocalServiceUtil.addGroup(defaultUserId,
					Group.class.getName(), 1, "myCommunity",
					"myCummunity Desc",
					GroupConstants.TYPE_COMMUNITY_OPEN, "http://localhost:8080", true,
					serviceContext);


First question, what is arg2 classname and what mean classpk?
Second question, what is friendlyURL?

regards
Chris
Oliver Bayer, geändert vor 12 Jahren.

RE: Create a Community with the API

Liferay Master Beiträge: 894 Beitrittsdatum: 18.02.09 Neueste Beiträge
Hi Chris,

classname is the name of the model while classpk is the same as the groupId (in case of a group model). The friendlyURL defines the part after /web or /group so if you name it "/my-community" (do not use http://localhost:8080) then you can access your created group with the following url:

public pages via http://localhost:8080/web/my-community
private pages vid http://localhost:8080/group/my-community

Take a look at "GroupLocalServiceImpl.addGroup(.....)" to see the implementation.

Greets Oli
thumbnail
Christian Schulze, geändert vor 12 Jahren.

RE: Create a Community with the API

Junior Member Beiträge: 87 Beitrittsdatum: 19.11.09 Neueste Beiträge
ok, the following code works.

	
ServiceContext serviceContext = new ServiceContext();	
		String friendlyUrl = "/myCommunity";
		long classID = PortalUtil.getClassNameId(Group.class);		
		try {
			GroupLocalServiceUtil.addGroup(defaultUserId,
					Group.class.getName(), classID, "myCommunity",
					"myCommunity durch den Hook",
					GroupConstants.TYPE_COMMUNITY_OPEN, friendlyUrl, true,
					serviceContext);
		} catch (PortalException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SystemException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}


But one question is remaining? How I get a correct classID, is this the right way with PortalUtil.getClassNameId(Group.class)?

regards
Chris
thumbnail
Sandeep Nair, geändert vor 12 Jahren.

RE: Create a Community with the API

Liferay Legend Beiträge: 1744 Beitrittsdatum: 06.11.08 Neueste Beiträge
Yes thats correct or you can use the following

ClassNameLocalServiceUtil.getClassNameId(classObj)

PortalUtil.getClassNameId internally calls the above method

Regards,
Sandeep
Alagammai Kasi, geändert vor 11 Jahren.

RE: Create a Community with the API

Regular Member Beiträge: 149 Beitrittsdatum: 01.08.12 Neueste Beiträge
Hi,

I know its an old thread, but I am looking for an API to create communities using it.

Would like to know on how to go about this?

Where do I run this code? at my database?

Please advice.

Thank You,
Alagu
thumbnail
Hitoshi Ozawa, geändert vor 11 Jahren.

RE: Create a Community with the API

Liferay Legend Beiträge: 7942 Beitrittsdatum: 24.03.10 Neueste Beiträge
Do you know the difference between community and group?
Alagammai Kasi, geändert vor 11 Jahren.

RE: Create a Community with the API

Regular Member Beiträge: 149 Beitrittsdatum: 01.08.12 Neueste Beiträge
As far as I know a community is a group and a user is also a group.

Correct me if I am wrong.
thumbnail
Hitoshi Ozawa, geändert vor 11 Jahren.

RE: Create a Community with the API

Liferay Legend Beiträge: 7942 Beitrittsdatum: 24.03.10 Neueste Beiträge
As far as I know a community is a group


So, your question is answered in the earlier posts.
Alagammai Kasi, geändert vor 11 Jahren.

RE: Create a Community with the API

Regular Member Beiträge: 149 Beitrittsdatum: 01.08.12 Neueste Beiträge
Dear Hitoshi,

Where should I be running that little script?

So far I have only worked with Liferay's drag and drop features.

Thanks in advance for your help.
Oliver Bayer, geändert vor 11 Jahren.

RE: Create a Community with the API

Liferay Master Beiträge: 894 Beitrittsdatum: 18.02.09 Neueste Beiträge
Hi Alagammai,

you can put this code snippet into a custom portlet if you want to use it several times. If you only want to run it once you can use a workaround/ "hack" and add it to a jsp page, call the page and remove it afterwards. The much more cleaner solution would be to write a custom portlet e.g. by using the liferay sdk with the eclipse ide.

HTH Oli
Alagammai Kasi, geändert vor 11 Jahren.

RE: Create a Community with the API

Regular Member Beiträge: 149 Beitrittsdatum: 01.08.12 Neueste Beiträge
Dear Oliver,

Thank you so much for your reply.

Any links that shows some examples on how to do scripting in Liferay?

Thank You so much!
Oliver Bayer, geändert vor 10 Jahren.

RE: Create a Community with the API

Liferay Master Beiträge: 894 Beitrittsdatum: 18.02.09 Neueste Beiträge
Hi Algammai,

sorry for the late reply.
You can use the development wiki (wiki) as a starting point. Another good source is the "Liferay in Action" book.

Oli
Alagammai Kasi, geändert vor 10 Jahren.

RE: Create a Community with the API

Regular Member Beiträge: 149 Beitrittsdatum: 01.08.12 Neueste Beiträge
Hi Oliver,

Thanks for your reply.

I will catch up with that.

Besides that, I just realised that I am not even able to create communities manually using Liferay, now.

I have opened another thread for this issue.

Please help....

Thank You,