Step1-we have to create hook select custom jsp and select edit_instance and add some other field inside edit_instance
Step2-we have to create custom portlet for service.xml put field inside service.xml and build than deploy so table will be generated after copy that jar file from lib folder and paste inside tomcate lib/ext like this (D:\SEPTEMBER_TL\SERVER\liferay-portal-6.2-ce-ga2\tomcat-7.0.42\lib\ext)
restart the server and direct deploy of ext
Step3-we have to created ext plugin and will put action class (from portal master) inside src full package
like this src/com.liferay.portlet.admin.action/EditInstanceAction and goto inside EditInstanceAction and 1st get all field which we needed and than create object(create instance) set values and than update instance
(in ext there is one drawback when ever we modify action class we must have restart server)
example of ext
/**
* Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.portlet.admin.action;
import com.liferay.counter.service.CounterLocalServiceUtil;
import com.liferay.portal.CompanyMxException;
import com.liferay.portal.CompanyVirtualHostException;
import com.liferay.portal.CompanyWebIdException;
import com.liferay.portal.NoSuchCompanyException;
import com.liferay.portal.RequiredCompanyException;
import com.liferay.portal.kernel.servlet.SessionErrors;
import com.liferay.portal.kernel.util.Constants;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.model.Company;
import com.liferay.portal.security.auth.PrincipalException;
import com.liferay.portal.service.CompanyServiceUtil;
import com.liferay.portal.struts.PortletAction;
import com.liferay.portal.theme.ThemeDisplay;
import com.liferay.portal.util.PortalInstances;
import com.liferay.portal.util.PropsValues;
import com.liferay.portal.util.WebKeys;
import com.slayer.model.PortalCustomInstance;
import com.slayer.service.PortalCustomInstanceLocalServiceClp;
import com.slayer.service.PortalCustomInstanceLocalServiceUtil;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.servlet.ServletContext;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
/**
* @author Brian Wing Shun Chan
*/
public class EditInstanceAction extends PortletAction {
@Override
public void processAction(
ActionMapping actionMapping, ActionForm actionForm,
PortletConfig portletConfig, ActionRequest actionRequest,
ActionResponse actionResponse)
throws Exception {
String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
try {
if (cmd.equals(Constants.DELETE)) {
deleteInstance(actionRequest);
}
else {
updateInstance(actionRequest);
}
sendRedirect(actionRequest, actionResponse);
}
catch (Exception e) {
if (e instanceof NoSuchCompanyException ||
e instanceof PrincipalException) {
SessionErrors.add(actionRequest, e.getClass());
setForward(actionRequest, "portlet.admin.error");
}
else if (e instanceof CompanyMxException ||
e instanceof CompanyVirtualHostException ||
e instanceof CompanyWebIdException) {
SessionErrors.add(actionRequest, e.getClass());
}
else if (e instanceof RequiredCompanyException) {
SessionErrors.add(actionRequest, e.getClass());
sendRedirect(actionRequest, actionResponse);
}
else {
throw e;
}
}
}
@Override
public ActionForward render(
ActionMapping actionMapping, ActionForm actionForm,
PortletConfig portletConfig, RenderRequest renderRequest,
RenderResponse renderResponse)
throws Exception {
try {
ActionUtil.getInstance(renderRequest);
}
catch (Exception e) {
if (e instanceof NoSuchCompanyException ||
e instanceof PrincipalException) {
SessionErrors.add(renderRequest, e.getClass());
return actionMapping.findForward("portlet.admin.error");
}
else {
throw e;
}
}
return actionMapping.findForward(
getForward(renderRequest, "portlet.admin.edit_instance"));
}
protected void deleteInstance(ActionRequest actionRequest)
throws Exception {
long companyId = ParamUtil.getLong(actionRequest, "companyId");
CompanyServiceUtil.deleteCompany(companyId);
}
protected void updateInstance(ActionRequest actionRequest)
throws Exception {
ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
long companyId = ParamUtil.getLong(actionRequest, "companyId");
String webId = ParamUtil.getString(actionRequest, "webId");
String tenantName = ParamUtil.getString(actionRequest, "tenantName");
String companyName = ParamUtil.getString(actionRequest, "companyName");
String tenantadminName = ParamUtil.getString(actionRequest, "tenantadminName");
String virtualHostname = ParamUtil.getString(
actionRequest, "virtualHostname");
String mx = ParamUtil.getString(actionRequest, "mx");
String shardName = ParamUtil.getString(
actionRequest, "shardName", PropsValues.SHARD_DEFAULT_NAME);
boolean system = false;
int maxUsers = ParamUtil.getInteger(actionRequest, "maxUsers", 0);
long videoTranscodingLength = ParamUtil.getLong(actionRequest, "videoTranscodingLength");
long storageLimit = ParamUtil.getLong(actionRequest, "storageLimit");
long billingCycle = ParamUtil.getLong(actionRequest, "billingCycle");
boolean active = ParamUtil.getBoolean(actionRequest, "active");
if (companyId <= 0) {
// Add instance
Company company = CompanyServiceUtil.addCompany(
webId, virtualHostname, mx, shardName, system, maxUsers,
active);
int tenantId = PortalCustomInstanceLocalServiceUtil.getPortalCustomInstancesCount() + 1;
PortalCustomInstance portalCustomInstance = PortalCustomInstanceLocalServiceUtil
.createPortalCustomInstance(tenantId);
portalCustomInstance.setTenantName(tenantName);
portalCustomInstance.setCompanyId(themeDisplay.getCompanyId());
portalCustomInstance.setCompanyName(companyName);
portalCustomInstance.setTenantadminName(tenantadminName);
portalCustomInstance.setVideoTranscodingLength(videoTranscodingLength);
portalCustomInstance.setStorageLimit(storageLimit);
portalCustomInstance.setBillingCycle(billingCycle);
PortalCustomInstanceLocalServiceUtil.addPortalCustomInstance(portalCustomInstance);
ServletContext servletContext =
(ServletContext)actionRequest.getAttribute(WebKeys.CTX);
PortalInstances.initCompany(servletContext, company.getWebId());
}
else {
// Update instance
CompanyServiceUtil.updateCompany(
companyId, virtualHostname, mx, maxUsers, active);
PortalCustomInstance portalCustomInstance=null;
PortalCustomInstanceLocalServiceUtil.updatePortalCustomInstance(portalCustomInstance);
}
}
}
Step2-we have to create custom portlet for service.xml put field inside service.xml and build than deploy so table will be generated after copy that jar file from lib folder and paste inside tomcate lib/ext like this (D:\SEPTEMBER_TL\SERVER\liferay-portal-6.2-ce-ga2\tomcat-7.0.42\lib\ext)
restart the server and direct deploy of ext
Step3-we have to created ext plugin and will put action class (from portal master) inside src full package
like this src/com.liferay.portlet.admin.action/EditInstanceAction and goto inside EditInstanceAction and 1st get all field which we needed and than create object(create instance) set values and than update instance
(in ext there is one drawback when ever we modify action class we must have restart server)
example of ext
/**
* Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.portlet.admin.action;
import com.liferay.counter.service.CounterLocalServiceUtil;
import com.liferay.portal.CompanyMxException;
import com.liferay.portal.CompanyVirtualHostException;
import com.liferay.portal.CompanyWebIdException;
import com.liferay.portal.NoSuchCompanyException;
import com.liferay.portal.RequiredCompanyException;
import com.liferay.portal.kernel.servlet.SessionErrors;
import com.liferay.portal.kernel.util.Constants;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.model.Company;
import com.liferay.portal.security.auth.PrincipalException;
import com.liferay.portal.service.CompanyServiceUtil;
import com.liferay.portal.struts.PortletAction;
import com.liferay.portal.theme.ThemeDisplay;
import com.liferay.portal.util.PortalInstances;
import com.liferay.portal.util.PropsValues;
import com.liferay.portal.util.WebKeys;
import com.slayer.model.PortalCustomInstance;
import com.slayer.service.PortalCustomInstanceLocalServiceClp;
import com.slayer.service.PortalCustomInstanceLocalServiceUtil;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.servlet.ServletContext;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
/**
* @author Brian Wing Shun Chan
*/
public class EditInstanceAction extends PortletAction {
@Override
public void processAction(
ActionMapping actionMapping, ActionForm actionForm,
PortletConfig portletConfig, ActionRequest actionRequest,
ActionResponse actionResponse)
throws Exception {
String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
try {
if (cmd.equals(Constants.DELETE)) {
deleteInstance(actionRequest);
}
else {
updateInstance(actionRequest);
}
sendRedirect(actionRequest, actionResponse);
}
catch (Exception e) {
if (e instanceof NoSuchCompanyException ||
e instanceof PrincipalException) {
SessionErrors.add(actionRequest, e.getClass());
setForward(actionRequest, "portlet.admin.error");
}
else if (e instanceof CompanyMxException ||
e instanceof CompanyVirtualHostException ||
e instanceof CompanyWebIdException) {
SessionErrors.add(actionRequest, e.getClass());
}
else if (e instanceof RequiredCompanyException) {
SessionErrors.add(actionRequest, e.getClass());
sendRedirect(actionRequest, actionResponse);
}
else {
throw e;
}
}
}
@Override
public ActionForward render(
ActionMapping actionMapping, ActionForm actionForm,
PortletConfig portletConfig, RenderRequest renderRequest,
RenderResponse renderResponse)
throws Exception {
try {
ActionUtil.getInstance(renderRequest);
}
catch (Exception e) {
if (e instanceof NoSuchCompanyException ||
e instanceof PrincipalException) {
SessionErrors.add(renderRequest, e.getClass());
return actionMapping.findForward("portlet.admin.error");
}
else {
throw e;
}
}
return actionMapping.findForward(
getForward(renderRequest, "portlet.admin.edit_instance"));
}
protected void deleteInstance(ActionRequest actionRequest)
throws Exception {
long companyId = ParamUtil.getLong(actionRequest, "companyId");
CompanyServiceUtil.deleteCompany(companyId);
}
protected void updateInstance(ActionRequest actionRequest)
throws Exception {
ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
long companyId = ParamUtil.getLong(actionRequest, "companyId");
String webId = ParamUtil.getString(actionRequest, "webId");
String tenantName = ParamUtil.getString(actionRequest, "tenantName");
String companyName = ParamUtil.getString(actionRequest, "companyName");
String tenantadminName = ParamUtil.getString(actionRequest, "tenantadminName");
String virtualHostname = ParamUtil.getString(
actionRequest, "virtualHostname");
String mx = ParamUtil.getString(actionRequest, "mx");
String shardName = ParamUtil.getString(
actionRequest, "shardName", PropsValues.SHARD_DEFAULT_NAME);
boolean system = false;
int maxUsers = ParamUtil.getInteger(actionRequest, "maxUsers", 0);
long videoTranscodingLength = ParamUtil.getLong(actionRequest, "videoTranscodingLength");
long storageLimit = ParamUtil.getLong(actionRequest, "storageLimit");
long billingCycle = ParamUtil.getLong(actionRequest, "billingCycle");
boolean active = ParamUtil.getBoolean(actionRequest, "active");
if (companyId <= 0) {
// Add instance
Company company = CompanyServiceUtil.addCompany(
webId, virtualHostname, mx, shardName, system, maxUsers,
active);
int tenantId = PortalCustomInstanceLocalServiceUtil.getPortalCustomInstancesCount() + 1;
PortalCustomInstance portalCustomInstance = PortalCustomInstanceLocalServiceUtil
.createPortalCustomInstance(tenantId);
portalCustomInstance.setTenantName(tenantName);
portalCustomInstance.setCompanyId(themeDisplay.getCompanyId());
portalCustomInstance.setCompanyName(companyName);
portalCustomInstance.setTenantadminName(tenantadminName);
portalCustomInstance.setVideoTranscodingLength(videoTranscodingLength);
portalCustomInstance.setStorageLimit(storageLimit);
portalCustomInstance.setBillingCycle(billingCycle);
PortalCustomInstanceLocalServiceUtil.addPortalCustomInstance(portalCustomInstance);
ServletContext servletContext =
(ServletContext)actionRequest.getAttribute(WebKeys.CTX);
PortalInstances.initCompany(servletContext, company.getWebId());
}
else {
// Update instance
CompanyServiceUtil.updateCompany(
companyId, virtualHostname, mx, maxUsers, active);
PortalCustomInstance portalCustomInstance=null;
PortalCustomInstanceLocalServiceUtil.updatePortalCustomInstance(portalCustomInstance);
}
}
}
No comments:
Post a Comment