Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
Christian Schulze
Create a Community with the API
October 12, 2011 1:21 AM
Answer

Christian Schulze

Rank: Junior Member

Posts: 87

Join Date: November 19, 2009

Recent Posts

I want to add a new Community with an UpgradeProcess inside a Hook.

I want to use this:

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


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

regards
Chris
Oliver Bayer
RE: Create a Community with the API
October 12, 2011 1:37 AM
Answer

Oliver Bayer

Rank: Liferay Master

Posts: 878

Join Date: February 18, 2009

Recent Posts

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
Christian Schulze
RE: Create a Community with the API
October 12, 2011 2:55 AM
Answer

Christian Schulze

Rank: Junior Member

Posts: 87

Join Date: November 19, 2009

Recent Posts

ok, the following code works.

 1   
 2ServiceContext serviceContext = new ServiceContext();   
 3        String friendlyUrl = "/myCommunity";
 4        long classID = PortalUtil.getClassNameId(Group.class);       
 5        try {
 6            GroupLocalServiceUtil.addGroup(defaultUserId,
 7                    Group.class.getName(), classID, "myCommunity",
 8                    "myCommunity durch den Hook",
 9                    GroupConstants.TYPE_COMMUNITY_OPEN, friendlyUrl, true,
10                    serviceContext);
11        } catch (PortalException e) {
12            // TODO Auto-generated catch block
13            e.printStackTrace();
14        } catch (SystemException e) {
15            // TODO Auto-generated catch block
16            e.printStackTrace();
17        }


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

regards
Chris
Sandeep Nair
RE: Create a Community with the API
October 12, 2011 3:06 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1692

Join Date: November 5, 2008

Recent Posts

Yes thats correct or you can use the following

ClassNameLocalServiceUtil.getClassNameId(classObj)

PortalUtil.getClassNameId internally calls the above method

Regards,
Sandeep
Alagammai Kasi
RE: Create a Community with the API
March 26, 2013 3:18 AM
Answer

Alagammai Kasi

Rank: Regular Member

Posts: 149

Join Date: July 31, 2012

Recent Posts

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
Hitoshi Ozawa
RE: Create a Community with the API
March 26, 2013 6:06 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7954

Join Date: March 23, 2010

Recent Posts

Do you know the difference between community and group?
Alagammai Kasi
RE: Create a Community with the API
March 26, 2013 6:23 PM
Answer

Alagammai Kasi

Rank: Regular Member

Posts: 149

Join Date: July 31, 2012

Recent Posts

As far as I know a community is a group and a user is also a group.

Correct me if I am wrong.
Hitoshi Ozawa
RE: Create a Community with the API
March 26, 2013 10:57 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7954

Join Date: March 23, 2010

Recent Posts

As far as I know a community is a group


So, your question is answered in the earlier posts.
Alagammai Kasi
RE: Create a Community with the API
March 27, 2013 1:22 AM
Answer

Alagammai Kasi

Rank: Regular Member

Posts: 149

Join Date: July 31, 2012

Recent Posts

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
RE: Create a Community with the API
March 27, 2013 9:33 AM
Answer

Oliver Bayer

Rank: Liferay Master

Posts: 878

Join Date: February 18, 2009

Recent Posts

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
RE: Create a Community with the API
March 27, 2013 5:29 PM
Answer

Alagammai Kasi

Rank: Regular Member

Posts: 149

Join Date: July 31, 2012

Recent Posts

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
RE: Create a Community with the API
April 4, 2013 2:10 AM
Answer

Oliver Bayer

Rank: Liferay Master

Posts: 878

Join Date: February 18, 2009

Recent Posts

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
RE: Create a Community with the API
April 5, 2013 1:30 AM
Answer

Alagammai Kasi

Rank: Regular Member

Posts: 149

Join Date: July 31, 2012

Recent Posts

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,