Programatically Add the Site and Page in Liferay:
1) Create Custom Portlet
2) Create Custom Class add the code in Controller Class
@Override
public void doView(RenderRequest renderRequest,
RenderResponse renderResponse) throws IOException, PortletException {
// TODO Auto-generated method stub
ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
ServiceContext serviceContext = new ServiceContext();
serviceContext.setAddCommunityPermissions(true);
serviceContext.setAddGuestPermissions(true);
Group group=null;
Layout layout = null;
try{
group=GroupLocalServiceUtil.getGroup(themeDisplay.getCompanyId(), "Hello");
if(group.getName().equalsIgnoreCase("Hello")){
System.out.println("Group already exists");
}else{
group = GroupServiceUtil.addGroup("Hello", "", GroupConstants.TYPE_SITE_PRIVATE, "", true, true, serviceContext);
layout = LayoutLocalServiceUtil.addLayout(themeDisplay.getUserId(),group.getGroupId(), true, 0, "ShowCase", "", "", LayoutConstants.TYPE_PORTLET, false, "/showcase2/3", serviceContext);
LayoutLocalServiceUtil.updateLayout(layout);
}
}
catch(Exception e){
e.printStackTrace();
}
super.doView(renderRequest, renderResponse);
}
1) Create Custom Portlet
2) Create Custom Class add the code in Controller Class
@Override
public void doView(RenderRequest renderRequest,
RenderResponse renderResponse) throws IOException, PortletException {
// TODO Auto-generated method stub
ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
ServiceContext serviceContext = new ServiceContext();
serviceContext.setAddCommunityPermissions(true);
serviceContext.setAddGuestPermissions(true);
Group group=null;
Layout layout = null;
try{
group=GroupLocalServiceUtil.getGroup(themeDisplay.getCompanyId(), "Hello");
if(group.getName().equalsIgnoreCase("Hello")){
System.out.println("Group already exists");
}else{
group = GroupServiceUtil.addGroup("Hello", "", GroupConstants.TYPE_SITE_PRIVATE, "", true, true, serviceContext);
layout = LayoutLocalServiceUtil.addLayout(themeDisplay.getUserId(),group.getGroupId(), true, 0, "ShowCase", "", "", LayoutConstants.TYPE_PORTLET, false, "/showcase2/3", serviceContext);
LayoutLocalServiceUtil.updateLayout(layout);
}
}
catch(Exception e){
e.printStackTrace();
}
super.doView(renderRequest, renderResponse);
}
No comments:
Post a Comment