package com.business.awaz;
import java.io.IOException;
import java.util.List;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletModeException;
import javax.portlet.ReadOnlyException;
import javax.portlet.ValidatorException;
import javax.portlet.WindowStateException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.servlet.SessionErrors;
import com.liferay.portal.kernel.util.HtmlUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.UnicodeProperties;
import com.liferay.portal.model.Group;
import com.liferay.portal.model.LayoutConstants;
import com.liferay.portal.model.LayoutSet;
import com.liferay.portal.model.LayoutSetPrototype;
import com.liferay.portal.service.GroupServiceUtil;
import com.liferay.portal.service.GroupLocalServiceUtil;
import com.liferay.portal.service.LayoutServiceUtil;
import com.liferay.portal.service.LayoutSetLocalServiceUtil;
import com.liferay.portal.service.LayoutSetPrototypeServiceUtil;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.service.ServiceContextFactory;
import com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil;
import javax.portlet.PortletPreferences;
//import com.liferay.portlet.sites.util.SitesUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;
/**
* Portlet implementation class Business
*/
public class Business extends MVCPortlet {
public void fiveplan(ActionRequest fiveplanrequest,ActionResponse
fiveplanresponse) throws ReadOnlyException, ValidatorException,
IOException, PortletModeException, WindowStateException
{
String fiveplane=fiveplanrequest.getParameter("basicplan");
PortletPreferences fiveplanpref=fiveplanrequest.getPreferences();
if(fiveplane !=null)
{
fiveplanpref.setValue("commonvalue", fiveplane);
fiveplanpref.store();
fiveplanresponse.setRenderParameter("jspPage","/html/business/createsite.jsp");
}
}
public void Create(ActionRequest actionRequest ,ActionResponse res) throws Exception
{
try {
String sitename=actionRequest.getParameter("sitename");
String findsitename="";
List<Group> siteobj=GroupLocalServiceUtil.getGroups(0, GroupLocalServiceUtil.getGroupsCount());
for(int k=0;k<siteobj.size();k++)
{
if(sitename.equals(siteobj.get(k).getName()))
{
//SessionErrors.add(actionRequest, "sitename");
findsitename=siteobj.get(k).getName();
}
}
String commonvalue=actionRequest.getParameter("commonvalue");
long liveGroupId = Long.parseLong(actionRequest.getParameter("liveGroupId"));
long companyid=Long.parseLong(actionRequest.getParameter("companyid"));
String languageid=actionRequest.getParameter("languageid");
String discription=actionRequest.getParameter("discription");
System.out.println("Here is domain name"+sitename);
System.out.println("Here is group name"+liveGroupId);
int type = ParamUtil.getInteger(actionRequest, "type");
String friendlyURL = ParamUtil.getString(actionRequest, "friendlyURL");
System.out.println("Friendlay URL is :"+friendlyURL);
ServiceContext serviceContext = ServiceContextFactory.getInstance(Group.class.getName(), actionRequest);
Group liveGroup = null;
String oldFriendlyURL = null;
String oldStagingFriendlyURL = null;
long privateLayoutSetPrototypeId = ParamUtil.getLong(actionRequest, "privateLayoutSetPrototypeId");
long publicLayoutSetPrototypeId = ParamUtil.getLong(actionRequest, "publicLayoutSetPrototypeId");
System.out.println("Here are private id: :"+privateLayoutSetPrototypeId);
System.out.println("Here are public id: :"+publicLayoutSetPrototypeId);
System.out.println("Here are servicecontext id: :"+serviceContext);
ServiceContext serviceContexta = new ServiceContext();
Group liveGroups = null;
List<LayoutSetPrototype> layoutSetPrototypes =
LayoutSetPrototypeServiceUtil.search(companyid, Boolean.TRUE, null);
String uuid=null;
for (LayoutSetPrototype curLayoutSetPrototype : layoutSetPrototypes)
{
UnicodeProperties settingsProperties = curLayoutSetPrototype.getSettingsProperties();
String servletContextName =
settingsProperties.getProperty("customJspServletContextName",
StringPool.BLANK);
String name=HtmlUtil.escape(curLayoutSetPrototype.getName(languageid));
System.out.println("hi this is :"+ curLayoutSetPrototype.getLayoutSetPrototypeId());
if(commonvalue.equals(name))
{
uuid= curLayoutSetPrototype.getUuid();
}
name="";
}
if(!uuid.equals(""))
{
if(findsitename.equals(""))
{
GroupServiceUtil.addGroup(sitename,discription, 1, friendlyURL, true, true ,serviceContext);
Group groupobj=GroupLocalServiceUtil.fetchGroup(companyid, sitename);
long groupid=groupobj.getGroupId();
System.out.println("Site is creates");
LayoutSet layoutsets=LayoutSetLocalServiceUtil.getLayoutSet(groupid,false);
layoutsets.setLayoutSetId(layoutsets.getLayoutSetId());
layoutsets.setGroupId(layoutsets.getGroupId());
layoutsets.setCompanyId(layoutsets.getCompanyId());
layoutsets.setCreateDate(layoutsets.getCreateDate());
layoutsets.setModifiedDate(layoutsets.getModifiedDate());
layoutsets.setPrivateLayout(layoutsets.getPrivateLayout());
layoutsets.setLogo(layoutsets.getLogo());
layoutsets.setLogoId(layoutsets.getLogoId());
layoutsets.setThemeId(layoutsets.getThemeId());
layoutsets.setColorSchemeId(layoutsets.getColorSchemeId());
layoutsets.setWapThemeId(layoutsets.getWapThemeId());
layoutsets.setWapColorSchemeId(layoutsets.getWapColorSchemeId());
layoutsets.setCss(layoutsets.getCss());
layoutsets.setPageCount(1);
layoutsets.setSettings(layoutsets.getSettings());
layoutsets.setLayoutSetPrototypeUuid(uuid);
layoutsets.setLayoutSetPrototypeLinkEnabled(true);
LayoutSetLocalServiceUtil.updateLayoutSet(layoutsets);
boolean privateLayout = ParamUtil.getBoolean(actionRequest, "privateLayout");
long parentLayoutId = ParamUtil.getLong(actionRequest, "parentLayoutId");
String name1 = ParamUtil.getString(actionRequest, "name", "home");
String title = StringPool.BLANK;
String description = StringPool.BLANK;
boolean hidden = false;
String friendlyURL1 = StringPool.BLANK;
ServiceContext serviceContext1 = ServiceContextFactory.getInstance(actionRequest);
System.out.println("Service cintext is "+serviceContext1);
System.out.println("Here are new site id"+groupid);
LayoutServiceUtil.addLayout(groupid,
false ,parentLayoutId ,name1 ,title ,description
,LayoutConstants.TYPE_PORTLET ,false ,friendlyURL1,serviceContext);
res.setRenderParameter("jspPage", "/html/business/createsite.jsp");
}
else
{
SessionErrors.add(actionRequest, "sitename");
}
}
}
catch (SystemException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
No comments:
Post a Comment