001
014
015 package com.liferay.portlet.usersadmin.lar;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.lar.BaseStagedModelDataHandler;
019 import com.liferay.portal.kernel.lar.ExportImportPathUtil;
020 import com.liferay.portal.kernel.lar.PortletDataContext;
021 import com.liferay.portal.kernel.xml.Element;
022 import com.liferay.portal.model.Group;
023 import com.liferay.portal.model.Website;
024 import com.liferay.portal.service.GroupLocalServiceUtil;
025 import com.liferay.portal.service.ServiceContext;
026 import com.liferay.portal.service.WebsiteLocalServiceUtil;
027
028
031 public class WebsiteStagedModelDataHandler
032 extends BaseStagedModelDataHandler<Website> {
033
034 public static final String[] CLASS_NAMES = {Website.class.getName()};
035
036 @Override
037 public void deleteStagedModel(
038 String uuid, long groupId, String className, String extraData)
039 throws PortalException {
040
041 Group group = GroupLocalServiceUtil.getGroup(groupId);
042
043 Website website = fetchStagedModelByUuidAndCompanyId(
044 uuid, group.getCompanyId());
045
046 if (website != null) {
047 WebsiteLocalServiceUtil.deleteWebsite(website);
048 }
049 }
050
051 @Override
052 public Website fetchStagedModelByUuidAndCompanyId(
053 String uuid, long companyId) {
054
055 return WebsiteLocalServiceUtil.fetchWebsiteByUuidAndCompanyId(
056 uuid, companyId);
057 }
058
059 @Override
060 public String[] getClassNames() {
061 return CLASS_NAMES;
062 }
063
064 @Override
065 protected void doExportStagedModel(
066 PortletDataContext portletDataContext, Website website)
067 throws Exception {
068
069 Element websiteElement = portletDataContext.getExportDataElement(
070 website);
071
072 portletDataContext.addClassedModel(
073 websiteElement, ExportImportPathUtil.getModelPath(website),
074 website);
075 }
076
077 @Override
078 protected void doImportStagedModel(
079 PortletDataContext portletDataContext, Website website)
080 throws Exception {
081
082 long userId = portletDataContext.getUserId(website.getUserUuid());
083
084 ServiceContext serviceContext = portletDataContext.createServiceContext(
085 website);
086
087 Website existingWebsite = fetchStagedModelByUuidAndCompanyId(
088 website.getUuid(), portletDataContext.getCompanyGroupId());
089
090 Website importedWebsite = null;
091
092 if (existingWebsite == null) {
093 serviceContext.setUuid(website.getUuid());
094
095 importedWebsite = WebsiteLocalServiceUtil.addWebsite(
096 userId, website.getClassName(), website.getClassPK(),
097 website.getUrl(), website.getTypeId(), website.isPrimary(),
098 serviceContext);
099 }
100 else {
101 importedWebsite = WebsiteLocalServiceUtil.updateWebsite(
102 existingWebsite.getWebsiteId(), website.getUrl(),
103 website.getTypeId(), website.isPrimary());
104 }
105
106 portletDataContext.importClassedModel(website, importedWebsite);
107 }
108
109 }