List of usage examples for com.liferay.portal.kernel.model Group isStagedRemotely
public boolean isStagedRemotely();
From source file:com.liferay.asset.publisher.web.internal.exportimport.portlet.preferences.processor.AssetPublisherExportImportPortletPreferencesProcessor.java
License:Open Source License
protected void updateExportScopeIds(PortletDataContext portletDataContext, PortletPreferences portletPreferences, String key, long plid) throws Exception { String[] oldValues = portletPreferences.getValues(key, null); if (oldValues == null) { return;//w ww . j a v a 2 s. c om } Layout layout = _layoutLocalService.getLayout(plid); String companyGroupScopeId = AssetPublisherUtil.SCOPE_ID_GROUP_PREFIX + portletDataContext.getCompanyGroupId(); String[] newValues = new String[oldValues.length]; Element rootElement = portletDataContext.getExportDataRootElement(); Element groupIdMappingsElement = rootElement.addElement("group-id-mappings"); for (int i = 0; i < oldValues.length; i++) { String oldValue = oldValues[i]; if (oldValue.startsWith(AssetPublisherUtil.SCOPE_ID_GROUP_PREFIX)) { newValues[i] = StringUtil.replace(oldValue, companyGroupScopeId, "[$COMPANY_GROUP_SCOPE_ID$]"); if (newValues[i].contains("[$COMPANY_GROUP_SCOPE_ID$]")) { continue; } } else if (oldValue.startsWith(AssetPublisherUtil.SCOPE_ID_LAYOUT_PREFIX)) { // Legacy preferences String scopeIdSuffix = oldValue.substring(AssetPublisherUtil.SCOPE_ID_LAYOUT_PREFIX.length()); long scopeIdLayoutId = GetterUtil.getLong(scopeIdSuffix); Layout scopeIdLayout = _layoutLocalService.getLayout(layout.getGroupId(), layout.isPrivateLayout(), scopeIdLayoutId); if (plid != scopeIdLayout.getPlid()) { StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, portletDataContext.getPortletId(), scopeIdLayout); } newValues[i] = AssetPublisherUtil.SCOPE_ID_LAYOUT_UUID_PREFIX + scopeIdLayout.getUuid(); } else if (oldValue.startsWith(AssetPublisherUtil.SCOPE_ID_LAYOUT_UUID_PREFIX)) { String scopeLayoutUuid = oldValue .substring(AssetPublisherUtil.SCOPE_ID_LAYOUT_UUID_PREFIX.length()); Layout scopeUuidLayout = _layoutLocalService.getLayoutByUuidAndGroupId(scopeLayoutUuid, portletDataContext.getGroupId(), portletDataContext.isPrivateLayout()); if (plid != scopeUuidLayout.getPlid()) { StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, portletDataContext.getPortletId(), scopeUuidLayout); } newValues[i] = oldValue; } else { newValues[i] = oldValue; } long groupId = AssetPublisherUtil.getGroupIdFromScopeId(newValues[i], portletDataContext.getGroupId(), portletDataContext.isPrivateLayout()); Group group = _groupLocalService.fetchGroup(groupId); long liveGroupId = 0; if (group != null) { liveGroupId = group.getLiveGroupId(); if (group.isStagedRemotely()) { liveGroupId = group.getRemoteLiveGroupId(); } } if ((groupId == 0) || (liveGroupId == 0)) { continue; } newValues[i] = String.valueOf(groupId); Element groupIdMappingElement = groupIdMappingsElement.addElement("group-id-mapping"); groupIdMappingElement.addAttribute("group-id", String.valueOf(groupId)); groupIdMappingElement.addAttribute("live-group-id", String.valueOf(liveGroupId)); } portletPreferences.setValues(key, newValues); }
From source file:com.liferay.asset.publisher.web.internal.portlet.toolbar.contributor.AssetPublisherPortletToolbarContributor.java
License:Open Source License
private URLMenuItem _getPortletTitleAddAssetEntryMenuItem(ThemeDisplay themeDisplay, AssetPublisherDisplayContext assetPublisherDisplayContext, long groupId, AssetPublisherAddItemHolder assetPublisherAddItemHolder) { URLMenuItem urlMenuItem = new URLMenuItem(); Map<String, Object> data = new HashMap<>(); PortletDisplay portletDisplay = themeDisplay.getPortletDisplay(); data.put("id", HtmlUtil.escape(portletDisplay.getNamespace()) + "editAsset"); String message = assetPublisherAddItemHolder.getModelResource(); String title = LanguageUtil.format(themeDisplay.getLocale(), "new-x", message, false); data.put("title", title); urlMenuItem.setData(data);/*www . ja va 2 s . co m*/ urlMenuItem.setLabel(HtmlUtil.escape(message)); long curGroupId = groupId; Group group = _groupLocalService.fetchGroup(groupId); if (!group.isStagedPortlet(assetPublisherAddItemHolder.getPortletId()) && !group.isStagedRemotely()) { curGroupId = group.getLiveGroupId(); } boolean addDisplayPageParameter = _assetPublisherWebUtil.isDefaultAssetPublisher(themeDisplay.getLayout(), portletDisplay.getId(), assetPublisherDisplayContext.getPortletResource()); String url = _assetHelper.getAddURLPopUp(curGroupId, themeDisplay.getPlid(), assetPublisherAddItemHolder.getPortletURL(), addDisplayPageParameter, themeDisplay.getLayout()); urlMenuItem.setURL(url); urlMenuItem.setUseDialog(true); return urlMenuItem; }
From source file:com.liferay.asset.taglib.internal.display.context.InputAssetLinksDisplayContext.java
License:Open Source License
private boolean _isStagedLocally() { if (_stagedLocally != null) { return _stagedLocally; }/*from w w w . ja v a 2 s . c o m*/ Group scopeGroup = _themeDisplay.getScopeGroup(); if (scopeGroup.isStaged() && !scopeGroup.isStagedRemotely()) { _stagedLocally = true; } else { _stagedLocally = false; } return _stagedLocally; }
From source file:com.liferay.exportimport.changeset.web.internal.portlet.action.ExportImportEntityMVCActionCommand.java
License:Open Source License
private void _processExportAndPublishAction(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortalException { String[] exportingEntities;/*w ww . jav a 2 s .c o m*/ if (Validator.isNotNull(actionRequest.getParameter("exportingEntities"))) { exportingEntities = ParamUtil.getStringValues(actionRequest, "exportingEntities"); } else if (Validator.isNotNull(actionRequest.getParameter("classNameId")) && Validator.isNotNull(actionRequest.getParameter("uuid"))) { long classNameId = ParamUtil.getLong(actionRequest, "classNameId"); long groupId = ParamUtil.getLong(actionRequest, "groupId"); String uuid = ParamUtil.getString(actionRequest, "uuid"); StringBundler sb = new StringBundler(5); sb.append(classNameId); sb.append(StringPool.POUND); sb.append(groupId); sb.append(StringPool.POUND); sb.append(uuid); exportingEntities = new String[] { sb.toString() }; } else { SessionErrors.add(actionRequest, ExportImportEntityException.class, new ExportImportEntityException(ExportImportEntityException.TYPE_NO_DATA_FOUND)); return; } Map<String, String[]> parameterMap = ExportImportConfigurationParameterMapFactory.buildParameterMap(); parameterMap.put("exportingEntities", exportingEntities); ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); String cmd = ParamUtil.getString(actionRequest, "cmd"); String portletId = MapUtil.getString(actionRequest.getParameterMap(), "portletId"); Portlet portlet = _portletLocalService.getPortletById(portletId); long backgroundTaskId = 0; if (cmd.equals(Constants.EXPORT)) { Map<String, Serializable> settingsMap = ExportImportConfigurationSettingsMapFactory .buildExportPortletSettingsMap(themeDisplay.getUser(), themeDisplay.getPlid(), themeDisplay.getScopeGroupId(), ChangesetPortletKeys.CHANGESET, parameterMap, _exportImportHelper.getPortletExportFileName(portlet)); ExportImportConfiguration exportImportConfiguration = _exportImportConfigurationLocalService .addDraftExportImportConfiguration(themeDisplay.getUserId(), portletId, ExportImportConfigurationConstants.TYPE_EXPORT_PORTLET, settingsMap); backgroundTaskId = _exportImportLocalService .exportPortletInfoAsFileInBackground(themeDisplay.getUserId(), exportImportConfiguration); } else if (cmd.equals(Constants.PUBLISH)) { Group scopeGroup = themeDisplay.getScopeGroup(); if (!scopeGroup.isStagingGroup() && !scopeGroup.isStagedRemotely()) { SessionErrors.add(actionRequest, ExportImportEntityException.class, new ExportImportEntityException(ExportImportEntityException.TYPE_GROUP_NOT_STAGED)); return; } if (!scopeGroup.isStagedPortlet(portletId)) { SessionErrors.add(actionRequest, ExportImportEntityException.class, new ExportImportEntityException(ExportImportEntityException.TYPE_PORTLET_NOT_STAGED)); return; } long liveGroupId = 0; if (scopeGroup.isStagingGroup()) { liveGroupId = scopeGroup.getLiveGroupId(); } else if (scopeGroup.isStagedRemotely()) { liveGroupId = scopeGroup.getRemoteLiveGroupId(); } Map<String, Serializable> settingsMap = ExportImportConfigurationSettingsMapFactory .buildPublishPortletSettingsMap(themeDisplay.getUser(), themeDisplay.getScopeGroupId(), themeDisplay.getPlid(), liveGroupId, themeDisplay.getPlid(), ChangesetPortletKeys.CHANGESET, parameterMap); ExportImportConfiguration exportImportConfiguration = _exportImportConfigurationLocalService .addDraftExportImportConfiguration(themeDisplay.getUserId(), portletId, ExportImportConfigurationConstants.TYPE_PUBLISH_PORTLET, settingsMap); backgroundTaskId = _staging.publishPortlet(themeDisplay.getUserId(), exportImportConfiguration); } sendRedirect(actionRequest, actionResponse, backgroundTaskId); }
From source file:com.liferay.exportimport.content.processor.base.BaseTextExportImportContentProcessor.java
License:Open Source License
protected String replaceExportDLReferences(PortletDataContext portletDataContext, StagedModel stagedModel, String content, boolean exportReferencedContent) throws Exception { Group group = GroupLocalServiceUtil.getGroup(portletDataContext.getGroupId()); if (group.isStagingGroup()) { group = group.getLiveGroup();//from www . jav a 2s. c o m } if (group.isStaged() && !group.isStagedRemotely() && !group.isStagedPortlet(PortletKeys.DOCUMENT_LIBRARY)) { return content; } StringBuilder sb = new StringBuilder(content); String contextPath = PortalUtil.getPathContext(); String[] patterns = { contextPath.concat("/c/document_library/get_file?"), contextPath.concat("/documents/"), contextPath.concat("/image/image_gallery?") }; int beginPos = -1; int endPos = content.length(); while (true) { beginPos = StringUtil.lastIndexOfAny(content, patterns, endPos); if (beginPos == -1) { break; } Map<String, String[]> dlReferenceParameters = getDLReferenceParameters( portletDataContext.getScopeGroupId(), content, beginPos + contextPath.length(), endPos); FileEntry fileEntry = getFileEntry(dlReferenceParameters); if (fileEntry == null) { endPos = beginPos - 1; continue; } endPos = MapUtil.getInteger(dlReferenceParameters, "endPos"); try { if (exportReferencedContent && !fileEntry.isInTrash()) { StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, stagedModel, fileEntry, PortletDataContext.REFERENCE_TYPE_DEPENDENCY); } else { Element entityElement = portletDataContext.getExportDataElement(stagedModel); String referenceType = PortletDataContext.REFERENCE_TYPE_DEPENDENCY; if (fileEntry.isInTrash()) { referenceType = PortletDataContext.REFERENCE_TYPE_DEPENDENCY_DISPOSABLE; } portletDataContext.addReferenceElement(stagedModel, entityElement, fileEntry, referenceType, true); } String path = ExportImportPathUtil.getModelPath(fileEntry); StringBundler exportedReferenceSB = new StringBundler(6); exportedReferenceSB.append("[$dl-reference="); exportedReferenceSB.append(path); exportedReferenceSB.append("$]"); if (fileEntry.isInTrash()) { String originalReference = sb.substring(beginPos, endPos); exportedReferenceSB.append("[#dl-reference="); exportedReferenceSB.append(originalReference); exportedReferenceSB.append("#]"); } sb.replace(beginPos, endPos, exportedReferenceSB.toString()); int deleteTimestampParametersOffset = beginPos; if (fileEntry.isInTrash()) { deleteTimestampParametersOffset = sb.indexOf("[#dl-reference=", beginPos); } deleteTimestampParameters(sb, deleteTimestampParametersOffset); } catch (Exception e) { if (_log.isDebugEnabled()) { _log.debug(e, e); } else if (_log.isWarnEnabled()) { StringBundler exceptionSB = new StringBundler(6); exceptionSB.append("Unable to process file entry "); exceptionSB.append(fileEntry.getFileEntryId()); exceptionSB.append(" for staged model "); exceptionSB.append(stagedModel.getModelClassName()); exceptionSB.append(" with primary key "); exceptionSB.append(stagedModel.getPrimaryKeyObj()); _log.warn(exceptionSB.toString()); } } endPos = beginPos - 1; } return sb.toString(); }
From source file:com.liferay.exportimport.content.processor.base.BaseTextExportImportContentProcessor.java
License:Open Source License
protected String replaceExportLayoutReferences(PortletDataContext portletDataContext, StagedModel stagedModel, String content) throws Exception { Group group = GroupLocalServiceUtil.getGroup(portletDataContext.getScopeGroupId()); StringBuilder sb = new StringBuilder(content); String[] patterns = { "href=", "[[" }; int beginPos = -1; int endPos = content.length(); int offset = 0; while (true) { if (beginPos > -1) { endPos = beginPos - 1;//from w w w. j a v a 2 s . com } beginPos = StringUtil.lastIndexOfAny(content, patterns, endPos); if (beginPos == -1) { break; } if (content.startsWith("href=", beginPos)) { offset = 5; char c = content.charAt(beginPos + offset); if ((c == CharPool.APOSTROPHE) || (c == CharPool.QUOTE)) { offset++; } } else if (content.charAt(beginPos) == CharPool.OPEN_BRACKET) { offset = 2; } endPos = StringUtil.indexOfAny(content, LAYOUT_REFERENCE_STOP_CHARS, beginPos + offset, endPos); if (endPos == -1) { continue; } String url = content.substring(beginPos + offset, endPos); if (url.endsWith(StringPool.SLASH)) { url = url.substring(0, url.length() - 1); } StringBundler urlSB = new StringBundler(6); try { url = replaceExportHostname(portletDataContext.getScopeGroupId(), url, urlSB); if (!url.startsWith(StringPool.SLASH)) { continue; } String pathContext = PortalUtil.getPathContext(); if (pathContext.length() > 1) { if (!url.startsWith(pathContext)) { continue; } urlSB.append(DATA_HANDLER_PATH_CONTEXT); url = url.substring(pathContext.length()); } if (!url.startsWith(StringPool.SLASH)) { continue; } int pos = url.indexOf(StringPool.SLASH, 1); String localePath = StringPool.BLANK; Locale locale = null; if (pos != -1) { localePath = url.substring(0, pos); locale = LocaleUtil.fromLanguageId(localePath.substring(1), true, false); } if (locale != null) { String urlWithoutLocale = url.substring(localePath.length()); if (urlWithoutLocale.startsWith(PRIVATE_GROUP_SERVLET_MAPPING) || urlWithoutLocale.startsWith(PRIVATE_USER_SERVLET_MAPPING) || urlWithoutLocale.startsWith(PUBLIC_GROUP_SERVLET_MAPPING)) { urlSB.append(localePath); url = urlWithoutLocale; } } boolean privateLayout = false; if (url.startsWith(PRIVATE_GROUP_SERVLET_MAPPING)) { urlSB.append(DATA_HANDLER_PRIVATE_GROUP_SERVLET_MAPPING); url = url.substring(PRIVATE_GROUP_SERVLET_MAPPING.length() - 1); privateLayout = true; } else if (url.startsWith(PRIVATE_USER_SERVLET_MAPPING)) { urlSB.append(DATA_HANDLER_PRIVATE_USER_SERVLET_MAPPING); url = url.substring(PRIVATE_USER_SERVLET_MAPPING.length() - 1); privateLayout = true; } else if (url.startsWith(PUBLIC_GROUP_SERVLET_MAPPING)) { urlSB.append(DATA_HANDLER_PUBLIC_SERVLET_MAPPING); url = url.substring(PUBLIC_GROUP_SERVLET_MAPPING.length() - 1); } else { String urlSBString = urlSB.toString(); LayoutSet layoutSet = null; if (urlSBString.contains(DATA_HANDLER_PUBLIC_LAYOUT_SET_SECURE_URL) || urlSBString.contains(DATA_HANDLER_PUBLIC_LAYOUT_SET_URL)) { layoutSet = group.getPublicLayoutSet(); } else if (urlSBString.contains(DATA_HANDLER_PRIVATE_LAYOUT_SET_SECURE_URL) || urlSBString.contains(DATA_HANDLER_PRIVATE_LAYOUT_SET_URL)) { layoutSet = group.getPrivateLayoutSet(); } if (layoutSet == null) { continue; } privateLayout = layoutSet.isPrivateLayout(); LayoutFriendlyURL layoutFriendlyUrl = LayoutFriendlyURLLocalServiceUtil .fetchFirstLayoutFriendlyURL(group.getGroupId(), privateLayout, url); if (layoutFriendlyUrl == null) { continue; } if (privateLayout) { if (group.isUser()) { urlSB.append(DATA_HANDLER_PRIVATE_USER_SERVLET_MAPPING); } else { urlSB.append(DATA_HANDLER_PRIVATE_GROUP_SERVLET_MAPPING); } } else { urlSB.append(DATA_HANDLER_PUBLIC_SERVLET_MAPPING); } urlSB.append(DATA_HANDLER_GROUP_FRIENDLY_URL); continue; } long groupId = group.getGroupId(); Layout layout = LayoutLocalServiceUtil.fetchLayoutByFriendlyURL(groupId, privateLayout, url); if (layout != null) { Element entityElement = portletDataContext.getExportDataElement(stagedModel); portletDataContext.addReferenceElement(stagedModel, entityElement, layout, PortletDataContext.REFERENCE_TYPE_DEPENDENCY, true); continue; } pos = url.indexOf(StringPool.SLASH, 1); String groupFriendlyURL = url; if (pos != -1) { groupFriendlyURL = url.substring(0, pos); } Group urlGroup = GroupLocalServiceUtil.fetchFriendlyURLGroup(group.getCompanyId(), groupFriendlyURL); if (urlGroup == null) { throw new NoSuchLayoutException(); } urlSB.append(DATA_HANDLER_GROUP_FRIENDLY_URL); // Append the UUID. This information will be used during the // import process when looking up the proper group for the link. urlSB.append(StringPool.AT); if (urlGroup.isStagedRemotely()) { String remoteGroupUuid = urlGroup.getTypeSettingsProperty("remoteGroupUUID"); if (Validator.isNotNull(remoteGroupUuid)) { urlSB.append(remoteGroupUuid); } } else if (urlGroup.isStaged()) { Group liveGroup = urlGroup.getLiveGroup(); urlSB.append(liveGroup.getUuid()); } else if (group.getGroupId() == urlGroup.getGroupId()) { urlSB.append(urlGroup.getFriendlyURL()); } else { urlSB.append(urlGroup.getUuid()); } urlSB.append(StringPool.AT); String siteAdminURL = GroupConstants.CONTROL_PANEL_FRIENDLY_URL + PropsValues.CONTROL_PANEL_LAYOUT_FRIENDLY_URL; if (url.endsWith(siteAdminURL)) { urlSB.append(DATA_HANDLER_SITE_ADMIN_URL); url = StringPool.BLANK; continue; } if (pos == -1) { url = StringPool.BLANK; continue; } url = url.substring(pos); layout = LayoutLocalServiceUtil.getFriendlyURLLayout(urlGroup.getGroupId(), privateLayout, url); Element entityElement = portletDataContext.getExportDataElement(stagedModel); portletDataContext.addReferenceElement(stagedModel, entityElement, layout, PortletDataContext.REFERENCE_TYPE_DEPENDENCY, true); } catch (Exception e) { if (e instanceof NoSuchLayoutException && !isValidateLayoutReferences()) { continue; } if (_log.isDebugEnabled()) { _log.debug(e, e); } else if (_log.isWarnEnabled()) { StringBundler exceptionSB = new StringBundler(6); exceptionSB.append("Unable to process layout URL "); exceptionSB.append(url); exceptionSB.append(" for staged model "); exceptionSB.append(stagedModel.getModelClassName()); exceptionSB.append(" with primary key "); exceptionSB.append(stagedModel.getPrimaryKeyObj()); _log.warn(exceptionSB.toString()); } } finally { if (urlSB.length() > 0) { urlSB.append(url); url = urlSB.toString(); } sb.replace(beginPos + offset, endPos, url); } } return sb.toString(); }
From source file:com.liferay.exportimport.internal.content.processor.DLReferencesExportImportContentProcessor.java
License:Open Source License
protected String replaceExportDLReferences(PortletDataContext portletDataContext, StagedModel stagedModel, String content, boolean exportReferencedContent) throws Exception { Group group = _groupLocalService.getGroup(portletDataContext.getGroupId()); if (group.isStagingGroup()) { group = group.getLiveGroup();/*from w w w.j a v a 2 s .co m*/ } if (group.isStaged() && !group.isStagedRemotely() && !group.isStagedPortlet(PortletKeys.DOCUMENT_LIBRARY)) { return content; } StringBuilder sb = new StringBuilder(content); String contextPath = _portal.getPathContext(); String[] patterns = { contextPath.concat("/c/document_library/get_file?"), contextPath.concat("/documents/"), contextPath.concat("/image/image_gallery?") }; int beginPos = -1; int endPos = content.length(); while (true) { beginPos = StringUtil.lastIndexOfAny(content, patterns, endPos); if (beginPos == -1) { break; } Map<String, String[]> dlReferenceParameters = getDLReferenceParameters( portletDataContext.getScopeGroupId(), content, beginPos + contextPath.length(), endPos); FileEntry fileEntry = getFileEntry(dlReferenceParameters); if (fileEntry == null) { endPos = beginPos - 1; continue; } endPos = MapUtil.getInteger(dlReferenceParameters, "endPos"); try { if (exportReferencedContent && !fileEntry.isInTrash()) { StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, stagedModel, fileEntry, PortletDataContext.REFERENCE_TYPE_DEPENDENCY); } else { Element entityElement = portletDataContext.getExportDataElement(stagedModel); String referenceType = PortletDataContext.REFERENCE_TYPE_DEPENDENCY; if (fileEntry.isInTrash()) { referenceType = PortletDataContext.REFERENCE_TYPE_DEPENDENCY_DISPOSABLE; } portletDataContext.addReferenceElement(stagedModel, entityElement, fileEntry, referenceType, true); } String path = ExportImportPathUtil.getModelPath(fileEntry); StringBundler exportedReferenceSB = new StringBundler(6); exportedReferenceSB.append("[$dl-reference="); exportedReferenceSB.append(path); exportedReferenceSB.append("$]"); if (fileEntry.isInTrash()) { String originalReference = sb.substring(beginPos, endPos); exportedReferenceSB.append("[#dl-reference="); exportedReferenceSB.append(originalReference); exportedReferenceSB.append("#]"); } sb.replace(beginPos, endPos, exportedReferenceSB.toString()); int deleteTimestampParametersOffset = beginPos; if (fileEntry.isInTrash()) { deleteTimestampParametersOffset = sb.indexOf("[#dl-reference=", beginPos); } deleteTimestampParameters(sb, deleteTimestampParametersOffset); } catch (Exception e) { if (_log.isDebugEnabled()) { _log.debug(e, e); } else if (_log.isWarnEnabled()) { StringBundler exceptionSB = new StringBundler(6); exceptionSB.append("Unable to process file entry "); exceptionSB.append(fileEntry.getFileEntryId()); exceptionSB.append(" for staged model "); exceptionSB.append(stagedModel.getModelClassName()); exceptionSB.append(" with primary key "); exceptionSB.append(stagedModel.getPrimaryKeyObj()); _log.warn(exceptionSB.toString()); } } endPos = beginPos - 1; } return sb.toString(); }
From source file:com.liferay.exportimport.internal.content.processor.LayoutReferencesExportImportContentProcessor.java
License:Open Source License
protected String replaceExportLayoutReferences(PortletDataContext portletDataContext, StagedModel stagedModel, String content) throws Exception { Group group = _groupLocalService.getGroup(portletDataContext.getScopeGroupId()); StringBuilder sb = new StringBuilder(content); String[] patterns = { "href=", "[[" }; int beginPos = -1; int endPos = content.length(); int offset = 0; while (true) { if (beginPos > -1) { endPos = beginPos - 1;/*from w w w . ja v a2 s. c om*/ } beginPos = StringUtil.lastIndexOfAny(content, patterns, endPos); if (beginPos == -1) { break; } if (content.startsWith("href=", beginPos)) { offset = 5; char c = content.charAt(beginPos + offset); if ((c == CharPool.APOSTROPHE) || (c == CharPool.QUOTE)) { offset++; } } else if (content.charAt(beginPos) == CharPool.OPEN_BRACKET) { offset = 2; } endPos = StringUtil.indexOfAny(content, _LAYOUT_REFERENCE_STOP_CHARS, beginPos + offset, endPos); if (endPos == -1) { continue; } String url = content.substring(beginPos + offset, endPos); if (url.endsWith(StringPool.SLASH)) { url = url.substring(0, url.length() - 1); } StringBundler urlSB = new StringBundler(6); try { url = replaceExportHostname(portletDataContext.getScopeGroupId(), url, urlSB); if (!url.startsWith(StringPool.SLASH)) { continue; } String pathContext = _portal.getPathContext(); if (pathContext.length() > 1) { if (!url.startsWith(pathContext)) { continue; } urlSB.append(_DATA_HANDLER_PATH_CONTEXT); url = url.substring(pathContext.length()); } if (!url.startsWith(StringPool.SLASH)) { continue; } int pos = url.indexOf(StringPool.SLASH, 1); String localePath = StringPool.BLANK; Locale locale = null; if (pos != -1) { localePath = url.substring(0, pos); locale = LocaleUtil.fromLanguageId(localePath.substring(1), true, false); } if (locale != null) { String urlWithoutLocale = url.substring(localePath.length()); if (urlWithoutLocale.startsWith(_PRIVATE_GROUP_SERVLET_MAPPING) || urlWithoutLocale.startsWith(_PRIVATE_USER_SERVLET_MAPPING) || urlWithoutLocale.startsWith(_PUBLIC_GROUP_SERVLET_MAPPING)) { urlSB.append(localePath); url = urlWithoutLocale; } } boolean privateLayout = false; if (url.startsWith(_PRIVATE_GROUP_SERVLET_MAPPING)) { urlSB.append(_DATA_HANDLER_PRIVATE_GROUP_SERVLET_MAPPING); url = url.substring(_PRIVATE_GROUP_SERVLET_MAPPING.length() - 1); privateLayout = true; } else if (url.startsWith(_PRIVATE_USER_SERVLET_MAPPING)) { urlSB.append(_DATA_HANDLER_PRIVATE_USER_SERVLET_MAPPING); url = url.substring(_PRIVATE_USER_SERVLET_MAPPING.length() - 1); privateLayout = true; } else if (url.startsWith(_PUBLIC_GROUP_SERVLET_MAPPING)) { urlSB.append(_DATA_HANDLER_PUBLIC_SERVLET_MAPPING); url = url.substring(_PUBLIC_GROUP_SERVLET_MAPPING.length() - 1); } else { String urlSBString = urlSB.toString(); LayoutSet layoutSet = null; if (urlSBString.contains(_DATA_HANDLER_PUBLIC_LAYOUT_SET_SECURE_URL) || urlSBString.contains(_DATA_HANDLER_PUBLIC_LAYOUT_SET_URL)) { layoutSet = group.getPublicLayoutSet(); } else if (urlSBString.contains(_DATA_HANDLER_PRIVATE_LAYOUT_SET_SECURE_URL) || urlSBString.contains(_DATA_HANDLER_PRIVATE_LAYOUT_SET_URL)) { layoutSet = group.getPrivateLayoutSet(); } if (layoutSet == null) { continue; } privateLayout = layoutSet.isPrivateLayout(); LayoutFriendlyURL layoutFriendlyUrl = _layoutFriendlyURLLocalService .fetchFirstLayoutFriendlyURL(group.getGroupId(), privateLayout, url); if (layoutFriendlyUrl == null) { continue; } if (privateLayout) { if (group.isUser()) { urlSB.append(_DATA_HANDLER_PRIVATE_USER_SERVLET_MAPPING); } else { urlSB.append(_DATA_HANDLER_PRIVATE_GROUP_SERVLET_MAPPING); } } else { urlSB.append(_DATA_HANDLER_PUBLIC_SERVLET_MAPPING); } urlSB.append(_DATA_HANDLER_GROUP_FRIENDLY_URL); continue; } long groupId = group.getGroupId(); Layout layout = _layoutLocalService.fetchLayoutByFriendlyURL(groupId, privateLayout, url); if (layout != null) { Element entityElement = portletDataContext.getExportDataElement(stagedModel); portletDataContext.addReferenceElement(stagedModel, entityElement, layout, PortletDataContext.REFERENCE_TYPE_DEPENDENCY, true); continue; } pos = url.indexOf(StringPool.SLASH, 1); String groupFriendlyURL = url; if (pos != -1) { groupFriendlyURL = url.substring(0, pos); } Group urlGroup = _groupLocalService.fetchFriendlyURLGroup(group.getCompanyId(), groupFriendlyURL); if (urlGroup == null) { throw new NoSuchLayoutException(); } urlSB.append(_DATA_HANDLER_GROUP_FRIENDLY_URL); // Append the UUID. This information will be used during the // import process when looking up the proper group for the link. urlSB.append(StringPool.AT); if (urlGroup.isStagedRemotely()) { String remoteGroupUuid = urlGroup.getTypeSettingsProperty("remoteGroupUUID"); if (Validator.isNotNull(remoteGroupUuid)) { urlSB.append(remoteGroupUuid); } } else if (urlGroup.isStaged()) { Group liveGroup = urlGroup.getLiveGroup(); urlSB.append(liveGroup.getUuid()); } else if (group.getGroupId() == urlGroup.getGroupId()) { urlSB.append(urlGroup.getFriendlyURL()); } else { urlSB.append(urlGroup.getUuid()); } urlSB.append(StringPool.AT); String siteAdminURL = GroupConstants.CONTROL_PANEL_FRIENDLY_URL + PropsValues.CONTROL_PANEL_LAYOUT_FRIENDLY_URL; if (url.endsWith(siteAdminURL)) { urlSB.append(_DATA_HANDLER_SITE_ADMIN_URL); url = StringPool.BLANK; continue; } if (pos == -1) { url = StringPool.BLANK; continue; } url = url.substring(pos); layout = _layoutLocalService.getFriendlyURLLayout(urlGroup.getGroupId(), privateLayout, url); Element entityElement = portletDataContext.getExportDataElement(stagedModel); portletDataContext.addReferenceElement(stagedModel, entityElement, layout, PortletDataContext.REFERENCE_TYPE_DEPENDENCY, true); } catch (Exception e) { if (e instanceof NoSuchLayoutException && !_exportImportServiceConfiguration.validateLayoutReferences()) { continue; } if (_log.isDebugEnabled()) { _log.debug(e, e); } else if (_log.isWarnEnabled()) { StringBundler exceptionSB = new StringBundler(6); exceptionSB.append("Unable to process layout URL "); exceptionSB.append(url); exceptionSB.append(" for staged model "); exceptionSB.append(stagedModel.getModelClassName()); exceptionSB.append(" with primary key "); exceptionSB.append(stagedModel.getPrimaryKeyObj()); _log.warn(exceptionSB.toString()); } } finally { if (urlSB.length() > 0) { urlSB.append(url); url = urlSB.toString(); } sb.replace(beginPos + offset, endPos, url); } } return sb.toString(); }
From source file:com.liferay.exportimport.internal.lifecycle.EventRemotePropagatorExportImportLifecycleListener.java
License:Open Source License
private boolean _eventNeedsToBePropagated(ExportImportLifecycleEvent exportImportLifecycleEvent) { if (!_propagatedEventTypes.contains(exportImportLifecycleEvent.getCode())) { return false; }/*w w w. ja v a 2s . c om*/ Optional<ExportImportConfiguration> exportImportConfigurationOptional = _getExportImportConfiguration( exportImportLifecycleEvent); Optional<Map<String, Serializable>> settingsMapOptional = exportImportConfigurationOptional .map(exportImportConfiguration -> exportImportConfiguration.getSettingsMap()); Serializable sourceGroupIdSerializable = settingsMapOptional .map(settingsMap -> settingsMap.get("sourceGroupId")).orElse(GroupConstants.ANY_PARENT_GROUP_ID); long sourceGroupId = GetterUtil.getLong(sourceGroupIdSerializable); Group sourceGroup = _groupLocalService.fetchGroup(sourceGroupId); if (Validator.isNull(sourceGroup) || !sourceGroup.isStagedRemotely()) { return false; } Serializable targetGroupIdSerializable = settingsMapOptional .map(settingsMap -> settingsMap.get("targetGroupId")).orElse(GroupConstants.ANY_PARENT_GROUP_ID); long targetGroupId = GetterUtil.getLong(targetGroupIdSerializable); Group targetGroup = _groupLocalService.fetchGroup(targetGroupId); UnicodeProperties typeSettings = sourceGroup.getTypeSettingsProperties(); String remoteGroupUUID = typeSettings.getProperty("remoteGroupUUID"); // If the target group can be found and the UUID's also match, then we // must not propagate the event because it means remote staging is // configured between two sites on the same portal instance if (Validator.isNotNull(remoteGroupUUID) && Validator.isNotNull(targetGroup) && StringUtil.equals(remoteGroupUUID, targetGroup.getUuid())) { return false; } return true; }
From source file:com.liferay.exportimport.internal.upgrade.v1_0_0.UpgradePublisherRequest.java
License:Open Source License
protected void updateScheduledPublications(Group group) throws PortalException { try (LoggingTimer loggingTimer = new LoggingTimer(String.valueOf(group.getGroupId()))) { boolean localStaging = true; if (group.isStagedRemotely() || group.hasRemoteStagingGroup()) { localStaging = false;//from w w w. ja va 2 s. co m } List<SchedulerResponse> scheduledJobs = _schedulerEngineHelper.getScheduledJobs( getSchedulerGroupName(group.getGroupId(), localStaging), StorageType.PERSISTED); for (SchedulerResponse schedulerResponse : scheduledJobs) { if (localStaging) { updateScheduledLocalPublication(schedulerResponse); } else { updateScheduleRemotePublication(schedulerResponse); } } } }