001
014
015 package com.liferay.portlet.layoutsadmin.lar;
016
017 import com.liferay.portal.kernel.lar.BaseStagedModelDataHandler;
018 import com.liferay.portal.kernel.lar.ExportImportPathUtil;
019 import com.liferay.portal.kernel.lar.PortletDataContext;
020 import com.liferay.portal.kernel.xml.Element;
021 import com.liferay.portal.model.LayoutPrototype;
022 import com.liferay.portal.service.LayoutPrototypeLocalServiceUtil;
023 import com.liferay.portal.service.ServiceContext;
024
025
028 public class LayoutPrototypeStagedModelDataHandler
029 extends BaseStagedModelDataHandler <LayoutPrototype> {
030
031 public static final String[] CLASS_NAMES =
032 {LayoutPrototype.class.getName()};
033
034 @Override
035 public String[] getClassNames() {
036 return CLASS_NAMES;
037 }
038
039 @Override
040 protected void doExportStagedModel(
041 PortletDataContext portletDataContext,
042 LayoutPrototype layoutPrototype)
043 throws Exception {
044
045 Element layoutPrototypeElement =
046 portletDataContext.getExportDataStagedModelElement(layoutPrototype);
047
048 portletDataContext.addClassedModel(
049 layoutPrototypeElement,
050 ExportImportPathUtil.getModelPath(layoutPrototype), layoutPrototype,
051 LayoutPrototypePortletDataHandler.NAMESPACE);
052 }
053
054 @Override
055 protected void doImportStagedModel(
056 PortletDataContext portletDataContext,
057 LayoutPrototype layoutPrototype)
058 throws Exception {
059
060 long userId = portletDataContext.getUserId(
061 layoutPrototype.getUserUuid());
062
063 ServiceContext serviceContext = portletDataContext.createServiceContext(
064 layoutPrototype, LayoutPrototypePortletDataHandler.NAMESPACE);
065
066 LayoutPrototype importedLayoutPrototype = null;
067
068 if (portletDataContext.isDataStrategyMirror()) {
069 LayoutPrototype existingLayoutPrototype =
070 LayoutPrototypeLocalServiceUtil.
071 fetchLayoutPrototypeByUuidAndCompanyId(
072 layoutPrototype.getUuid(),
073 portletDataContext.getCompanyId());
074
075 if (existingLayoutPrototype == null) {
076 serviceContext.setUuid(layoutPrototype.getUuid());
077
078 importedLayoutPrototype =
079 LayoutPrototypeLocalServiceUtil.addLayoutPrototype(
080 userId, portletDataContext.getCompanyId(),
081 layoutPrototype.getNameMap(),
082 layoutPrototype.getDescription(),
083 layoutPrototype.isActive(), serviceContext);
084 }
085 else {
086 importedLayoutPrototype =
087 LayoutPrototypeLocalServiceUtil.updateLayoutPrototype(
088 existingLayoutPrototype.getLayoutPrototypeId(),
089 layoutPrototype.getNameMap(),
090 layoutPrototype.getDescription(),
091 layoutPrototype.isActive(), serviceContext);
092 }
093 }
094 else {
095 importedLayoutPrototype =
096 LayoutPrototypeLocalServiceUtil.addLayoutPrototype(
097 userId, portletDataContext.getCompanyId(),
098 layoutPrototype.getNameMap(),
099 layoutPrototype.getDescription(),
100 layoutPrototype.isActive(), serviceContext);
101 }
102
103 portletDataContext.importClassedModel(
104 layoutPrototype, importedLayoutPrototype,
105 LayoutPrototypePortletDataHandler.NAMESPACE);
106 }
107
108 }