List of usage examples for com.liferay.portal.kernel.model Layout getScopeGroup
public Group getScopeGroup() throws com.liferay.portal.kernel.exception.PortalException;
From source file:com.liferay.asset.publisher.internal.util.AssetPublisherHelperImpl.java
License:Open Source License
@Override public long getGroupIdFromScopeId(String scopeId, long siteGroupId, boolean privateLayout) throws PortalException { if (scopeId.startsWith(SCOPE_ID_CHILD_GROUP_PREFIX)) { String scopeIdSuffix = scopeId.substring(SCOPE_ID_CHILD_GROUP_PREFIX.length()); long childGroupId = GetterUtil.getLong(scopeIdSuffix); Group childGroup = _groupLocalService.getGroup(childGroupId); if (!childGroup.hasAncestor(siteGroupId)) { throw new PrincipalException(); }//from ww w . j a v a2 s. c om return childGroupId; } else if (scopeId.startsWith(SCOPE_ID_GROUP_PREFIX)) { String scopeIdSuffix = scopeId.substring(SCOPE_ID_GROUP_PREFIX.length()); if (scopeIdSuffix.equals(GroupConstants.DEFAULT)) { return siteGroupId; } long scopeGroupId = GetterUtil.getLong(scopeIdSuffix); Group scopeGroup = _groupLocalService.getGroup(scopeGroupId); return scopeGroup.getGroupId(); } else if (scopeId.startsWith(SCOPE_ID_LAYOUT_UUID_PREFIX)) { String layoutUuid = scopeId.substring(SCOPE_ID_LAYOUT_UUID_PREFIX.length()); Layout scopeIdLayout = _layoutLocalService.getLayoutByUuidAndGroupId(layoutUuid, siteGroupId, privateLayout); Group scopeIdGroup = _groupLocalService.checkScopeGroup(scopeIdLayout, PrincipalThreadLocal.getUserId()); return scopeIdGroup.getGroupId(); } else if (scopeId.startsWith(SCOPE_ID_LAYOUT_PREFIX)) { // Legacy portlet preferences String scopeIdSuffix = scopeId.substring(SCOPE_ID_LAYOUT_PREFIX.length()); long scopeIdLayoutId = GetterUtil.getLong(scopeIdSuffix); Layout scopeIdLayout = _layoutLocalService.getLayout(siteGroupId, privateLayout, scopeIdLayoutId); Group scopeIdGroup = scopeIdLayout.getScopeGroup(); return scopeIdGroup.getGroupId(); } else if (scopeId.startsWith(SCOPE_ID_PARENT_GROUP_PREFIX)) { String scopeIdSuffix = scopeId.substring(SCOPE_ID_PARENT_GROUP_PREFIX.length()); long parentGroupId = GetterUtil.getLong(scopeIdSuffix); Group parentGroup = _groupLocalService.getGroup(parentGroupId); if (!SitesUtil.isContentSharingWithChildrenEnabled(parentGroup)) { throw new PrincipalException(); } Group group = _groupLocalService.getGroup(siteGroupId); if (!group.hasAncestor(parentGroupId)) { throw new PrincipalException(); } return parentGroupId; } else { throw new IllegalArgumentException("Invalid scope ID " + scopeId); } }
From source file:com.liferay.asset.publisher.web.util.AssetPublisherUtil.java
License:Open Source License
public static long getGroupIdFromScopeId(String scopeId, long siteGroupId, boolean privateLayout) throws PortalException { if (scopeId.startsWith(SCOPE_ID_CHILD_GROUP_PREFIX)) { String scopeIdSuffix = scopeId.substring(SCOPE_ID_CHILD_GROUP_PREFIX.length()); long childGroupId = GetterUtil.getLong(scopeIdSuffix); Group childGroup = _groupLocalService.getGroup(childGroupId); if (!childGroup.hasAncestor(siteGroupId)) { throw new PrincipalException(); }/* w ww . j ava 2 s . co m*/ return childGroupId; } else if (scopeId.startsWith(SCOPE_ID_GROUP_PREFIX)) { String scopeIdSuffix = scopeId.substring(SCOPE_ID_GROUP_PREFIX.length()); if (scopeIdSuffix.equals(GroupConstants.DEFAULT)) { return siteGroupId; } long scopeGroupId = GetterUtil.getLong(scopeIdSuffix); Group scopeGroup = _groupLocalService.getGroup(scopeGroupId); return scopeGroup.getGroupId(); } else if (scopeId.startsWith(SCOPE_ID_LAYOUT_UUID_PREFIX)) { String layoutUuid = scopeId.substring(SCOPE_ID_LAYOUT_UUID_PREFIX.length()); Layout scopeIdLayout = _layoutLocalService.getLayoutByUuidAndGroupId(layoutUuid, siteGroupId, privateLayout); Group scopeIdGroup = _groupLocalService.checkScopeGroup(scopeIdLayout, PrincipalThreadLocal.getUserId()); return scopeIdGroup.getGroupId(); } else if (scopeId.startsWith(SCOPE_ID_LAYOUT_PREFIX)) { // Legacy portlet preferences String scopeIdSuffix = scopeId.substring(SCOPE_ID_LAYOUT_PREFIX.length()); long scopeIdLayoutId = GetterUtil.getLong(scopeIdSuffix); Layout scopeIdLayout = _layoutLocalService.getLayout(siteGroupId, privateLayout, scopeIdLayoutId); Group scopeIdGroup = scopeIdLayout.getScopeGroup(); return scopeIdGroup.getGroupId(); } else if (scopeId.startsWith(SCOPE_ID_PARENT_GROUP_PREFIX)) { String scopeIdSuffix = scopeId.substring(SCOPE_ID_PARENT_GROUP_PREFIX.length()); long parentGroupId = GetterUtil.getLong(scopeIdSuffix); Group parentGroup = _groupLocalService.getGroup(parentGroupId); if (!SitesUtil.isContentSharingWithChildrenEnabled(parentGroup)) { throw new PrincipalException(); } Group group = _groupLocalService.getGroup(siteGroupId); if (!group.hasAncestor(parentGroupId)) { throw new PrincipalException(); } return parentGroupId; } else { throw new IllegalArgumentException("Invalid scope ID " + scopeId); } }
From source file:com.liferay.exportimport.controller.PortletExportController.java
License:Open Source License
protected File doExport(PortletDataContext portletDataContext) throws Exception { boolean exportPermissions = MapUtil.getBoolean(portletDataContext.getParameterMap(), PortletDataHandlerKeys.PERMISSIONS); if (_log.isDebugEnabled()) { _log.debug("Export permissions " + exportPermissions); }/* w ww. ja v a 2 s.c o m*/ StopWatch stopWatch = new StopWatch(); stopWatch.start(); Layout layout = _layoutLocalService.getLayout(portletDataContext.getPlid()); if (!layout.isTypeControlPanel() && !layout.isTypePanel() && !layout.isTypePortlet()) { StringBundler sb = new StringBundler(4); sb.append("Unable to export layout "); sb.append(layout.getPlid()); sb.append(" because it has an invalid type: "); sb.append(layout.getType()); throw new LayoutImportException(sb.toString()); } ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext(); if (serviceContext == null) { serviceContext = new ServiceContext(); serviceContext.setCompanyId(layout.getCompanyId()); serviceContext.setSignedIn(false); long defaultUserId = _userLocalService.getDefaultUserId(layout.getCompanyId()); serviceContext.setUserId(defaultUserId); ServiceContextThreadLocal.pushServiceContext(serviceContext); } long layoutSetBranchId = MapUtil.getLong(portletDataContext.getParameterMap(), "layoutSetBranchId"); serviceContext.setAttribute("layoutSetBranchId", layoutSetBranchId); long scopeGroupId = portletDataContext.getGroupId(); javax.portlet.PortletPreferences jxPortletPreferences = PortletPreferencesFactoryUtil .getLayoutPortletSetup(layout, portletDataContext.getPortletId()); String scopeType = GetterUtil.getString(jxPortletPreferences.getValue("lfrScopeType", null)); String scopeLayoutUuid = GetterUtil.getString(jxPortletPreferences.getValue("lfrScopeLayoutUuid", null)); if (Validator.isNotNull(scopeType)) { Group scopeGroup = null; if (scopeType.equals("company")) { scopeGroup = _groupLocalService.getCompanyGroup(layout.getCompanyId()); } else if (Validator.isNotNull(scopeLayoutUuid)) { scopeGroup = layout.getScopeGroup(); } if (scopeGroup != null) { scopeGroupId = scopeGroup.getGroupId(); } } portletDataContext.setScopeType(scopeType); portletDataContext.setScopeLayoutUuid(scopeLayoutUuid); Document document = SAXReaderUtil.createDocument(); Element rootElement = document.addElement("root"); portletDataContext.setExportDataRootElement(rootElement); Element headerElement = rootElement.addElement("header"); headerElement.addAttribute("available-locales", StringUtil.merge( LanguageUtil.getAvailableLocales(_portal.getSiteGroupId(portletDataContext.getScopeGroupId())))); headerElement.addAttribute("build-number", String.valueOf(ReleaseInfo.getBuildNumber())); headerElement.addAttribute("export-date", Time.getRFC822()); if (portletDataContext.hasDateRange()) { headerElement.addAttribute("start-date", String.valueOf(portletDataContext.getStartDate())); headerElement.addAttribute("end-date", String.valueOf(portletDataContext.getEndDate())); } headerElement.addAttribute("type", portletDataContext.getType()); headerElement.addAttribute("company-id", String.valueOf(portletDataContext.getCompanyId())); headerElement.addAttribute("company-group-id", String.valueOf(portletDataContext.getCompanyGroupId())); headerElement.addAttribute("group-id", String.valueOf(scopeGroupId)); headerElement.addAttribute("user-personal-site-group-id", String.valueOf(portletDataContext.getUserPersonalSiteGroupId())); headerElement.addAttribute("private-layout", String.valueOf(layout.isPrivateLayout())); headerElement.addAttribute("root-portlet-id", portletDataContext.getRootPortletId()); headerElement.addAttribute("schema-version", ExportImportConstants.EXPORT_IMPORT_SCHEMA_VERSION); Element missingReferencesElement = rootElement.addElement("missing-references"); portletDataContext.setMissingReferencesElement(missingReferencesElement); Map<String, Boolean> exportPortletControlsMap = _exportImportHelper.getExportPortletControlsMap( layout.getCompanyId(), portletDataContext.getPortletId(), portletDataContext.getParameterMap()); exportPortlet(portletDataContext, layout.getPlid(), rootElement, exportPermissions, exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_ARCHIVED_SETUPS), exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_DATA), exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_SETUP), exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_USER_PREFERENCES)); exportService(portletDataContext, rootElement, exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_SETUP)); exportAssetLinks(portletDataContext); exportExpandoTables(portletDataContext); exportLocks(portletDataContext); portletDataContext.addDeletionSystemEventStagedModelTypes(new StagedModelType(StagedAssetLink.class)); _deletionSystemEventExporter.exportDeletionSystemEvents(portletDataContext); if (exportPermissions) { _permissionExporter.exportPortletDataPermissions(portletDataContext); } _exportImportHelper.writeManifestSummary(document, portletDataContext.getManifestSummary()); if (_log.isInfoEnabled()) { _log.info("Exporting portlet took " + stopWatch.getTime() + " ms"); } try { portletDataContext.addZipEntry("/manifest.xml", document.formattedString()); } catch (IOException ioe) { throw new SystemException("Unable to create the export LAR manifest file for portlet " + portletDataContext.getPortletId(), ioe); } ZipWriter zipWriter = portletDataContext.getZipWriter(); return zipWriter.getFile(); }
From source file:com.liferay.exportimport.lar.ExportImportHelperImpl.java
License:Open Source License
@Override public void setPortletScope(PortletDataContext portletDataContext, Element portletElement) { // Portlet data scope String scopeLayoutUuid = GetterUtil.getString(portletElement.attributeValue("scope-layout-uuid")); String scopeLayoutType = GetterUtil.getString(portletElement.attributeValue("scope-layout-type")); portletDataContext.setScopeLayoutUuid(scopeLayoutUuid); portletDataContext.setScopeType(scopeLayoutType); // Layout scope try {// w w w . jav a 2s . c o m Group scopeGroup = null; if (scopeLayoutType.equals("company")) { scopeGroup = _groupLocalService.getCompanyGroup(portletDataContext.getCompanyId()); } else if (Validator.isNotNull(scopeLayoutUuid)) { Layout scopeLayout = _layoutLocalService.getLayoutByUuidAndGroupId(scopeLayoutUuid, portletDataContext.getGroupId(), portletDataContext.isPrivateLayout()); scopeGroup = _groupLocalService.checkScopeGroup(scopeLayout, portletDataContext.getUserId(null)); Group group = scopeLayout.getGroup(); if (group.isStaged() && !group.isStagedRemotely()) { try { boolean privateLayout = GetterUtil .getBoolean(portletElement.attributeValue("private-layout")); Layout oldLayout = _layoutLocalService.getLayoutByUuidAndGroupId(scopeLayoutUuid, portletDataContext.getSourceGroupId(), privateLayout); Group oldScopeGroup = oldLayout.getScopeGroup(); if (group.isStagingGroup()) { scopeGroup.setLiveGroupId(oldScopeGroup.getGroupId()); _groupLocalService.updateGroup(scopeGroup); } else { oldScopeGroup.setLiveGroupId(scopeGroup.getGroupId()); _groupLocalService.updateGroup(oldScopeGroup); } } catch (NoSuchLayoutException nsle) { if (_log.isWarnEnabled()) { _log.warn(nsle); } } } if (!ExportImportThreadLocal.isStagingInProcess() && group.isStagingGroup() && !group.isStagedPortlet(portletDataContext.getPortletId())) { scopeGroup = group.getLiveGroup(); Layout scopeLiveLayout = _layoutLocalService.fetchLayoutByUuidAndGroupId(scopeLayoutUuid, group.getLiveGroupId(), portletDataContext.isPrivateLayout()); if (scopeLiveLayout != null) { scopeGroup = _groupLocalService.checkScopeGroup(scopeLiveLayout, portletDataContext.getUserId(null)); } } } else { Group group = _groupLocalService.getGroup(portletDataContext.getGroupId()); if (!ExportImportThreadLocal.isStagingInProcess() && group.isStagingGroup() && !group.isStagedPortlet(portletDataContext.getPortletId())) { scopeGroup = group.getLiveGroup(); } } if (scopeGroup != null) { portletDataContext.setScopeGroupId(scopeGroup.getGroupId()); Map<Long, Long> groupIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Group.class); long oldScopeGroupId = GetterUtil.getLong(portletElement.attributeValue("scope-group-id")); groupIds.put(oldScopeGroupId, scopeGroup.getGroupId()); } } catch (PortalException pe) { // LPS-52675 if (_log.isDebugEnabled()) { _log.debug(pe, pe); } } catch (Exception e) { _log.error(e, e); } }
From source file:com.liferay.exportimport.staging.StagingImpl.java
License:Open Source License
protected long publishPortlet(long userId, long scopeGroupId, long plid, String portletId, Map<String, String[]> parameterMap, boolean copyFromLive) throws PortalException { Layout sourceLayout = _layoutLocalService.getLayout(plid); Group scopeGroup = sourceLayout.getScopeGroup(); Group stagingGroup = null;//from www .j av a 2 s .c o m Group liveGroup = null; Layout targetLayout = null; if (sourceLayout.isTypeControlPanel()) { stagingGroup = _groupLocalService.fetchGroup(scopeGroupId); liveGroup = stagingGroup.getLiveGroup(); targetLayout = sourceLayout; } else if (sourceLayout.hasScopeGroup() && (scopeGroup.getGroupId() == scopeGroupId)) { stagingGroup = scopeGroup; liveGroup = stagingGroup.getLiveGroup(); targetLayout = _layoutLocalService.getLayout(liveGroup.getClassPK()); } else { stagingGroup = sourceLayout.getGroup(); liveGroup = stagingGroup.getLiveGroup(); targetLayout = _layoutLocalService.fetchLayoutByUuidAndGroupId(sourceLayout.getUuid(), liveGroup.getGroupId(), sourceLayout.isPrivateLayout()); } if (copyFromLive) { return publishPortlet(userId, liveGroup.getGroupId(), stagingGroup.getGroupId(), targetLayout.getPlid(), sourceLayout.getPlid(), portletId, parameterMap); } return publishPortlet(userId, stagingGroup.getGroupId(), liveGroup.getGroupId(), sourceLayout.getPlid(), targetLayout.getPlid(), portletId, parameterMap); }
From source file:com.liferay.layout.admin.web.internal.exportimport.data.handler.LayoutStagedModelDataHandler.java
License:Open Source License
protected Map<String, Object[]> getPortletids(PortletDataContext portletDataContext, Layout layout) throws Exception { if (!LayoutStagingUtil.prepareLayoutStagingHandler(portletDataContext, layout) || !layout.isSupportsEmbeddedPortlets()) { // Only portlet type layouts support page scoping return Collections.emptyMap(); }/*from w w w. jav a2 s . c o m*/ Map<String, Object[]> portletIds = new HashMap<>(); LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType(); // The getAllPortlets method returns all effective nonsystem portlets // for any layout type, including embedded portlets, or in the case of // panel type layout, selected portlets for (Portlet portlet : layoutTypePortlet.getAllPortlets(false)) { String portletId = portlet.getPortletId(); Settings portletInstanceSettings = SettingsFactoryUtil .getSettings(new PortletInstanceSettingsLocator(layout, portletId)); String scopeType = portletInstanceSettings.getValue("lfrScopeType", null); String scopeLayoutUuid = portletInstanceSettings.getValue("lfrScopeLayoutUuid", null); long scopeGroupId = portletDataContext.getScopeGroupId(); if (Validator.isNotNull(scopeType)) { Group scopeGroup = null; if (scopeType.equals("company")) { scopeGroup = _groupLocalService.getCompanyGroup(layout.getCompanyId()); } else if (scopeType.equals("layout")) { Layout scopeLayout = null; scopeLayout = _layoutLocalService.fetchLayoutByUuidAndGroupId(scopeLayoutUuid, portletDataContext.getGroupId(), portletDataContext.isPrivateLayout()); if (scopeLayout == null) { continue; } scopeGroup = scopeLayout.getScopeGroup(); } else { throw new IllegalArgumentException("Scope type " + scopeType + " is invalid"); } if (scopeGroup != null) { scopeGroupId = scopeGroup.getGroupId(); } } String key = PortletPermissionUtil.getPrimaryKey(layout.getPlid(), portletId); portletIds.put(key, new Object[] { portletId, scopeGroupId, scopeType, scopeLayoutUuid }); } return portletIds; }
From source file:com.liferay.site.internal.exportimport.data.handler.StagedGroupStagedModelDataHandler.java
License:Open Source License
protected void exportSitePortlets(PortletDataContext portletDataContext, StagedGroup group, Set<String> portletIds, long[] layoutIds) throws Exception { // Prepare XML Element rootElement = portletDataContext.getExportDataRootElement(); Element portletsElement = rootElement.element("site-portlets"); Element servicesElement = rootElement.element("site-services"); String type = portletDataContext.getType(); // Export portlets Map<String, String[]> parameterMap = portletDataContext.getParameterMap(); boolean permissions = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.PERMISSIONS); List<Layout> layouts = _layoutLocalService.getLayouts(group.getGroupId(), portletDataContext.isPrivateLayout()); for (String portletId : portletIds) { // Default scope exportPortlet(portletDataContext, portletId, LayoutConstants.DEFAULT_PLID, portletDataContext.getGroupId(), StringPool.BLANK, StringPool.BLANK, type, portletsElement, servicesElement, permissions); Portlet portlet = _portletLocalService.getPortletById(portletDataContext.getCompanyId(), portletId); if (!portlet.isScopeable()) { continue; }/*from ww w .j ava 2s .com*/ // Scoped data for (Layout layout : layouts) { if (!ArrayUtil.contains(layoutIds, layout.getLayoutId()) || !layout.isTypePortlet() || !layout.hasScopeGroup()) { continue; } LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType(); if (!layoutTypePortlet.hasPortletId(portletId)) { continue; } Group scopeGroup = layout.getScopeGroup(); exportPortlet(portletDataContext, portletId, layout.getPlid(), scopeGroup.getGroupId(), StringPool.BLANK, layout.getUuid(), type, portletsElement, servicesElement, permissions); } } }