List of usage examples for com.liferay.portal.kernel.util PortletKeys PREFS_OWNER_TYPE_GROUP
int PREFS_OWNER_TYPE_GROUP
To view the source code for com.liferay.portal.kernel.util PortletKeys PREFS_OWNER_TYPE_GROUP.
Click Source Link
From source file:com.liferay.blogs.web.internal.upgrade.v1_0_0.UpgradePortletSettings.java
License:Open Source License
@Override protected void doUpgrade() throws Exception { BlogsGroupServiceSettings.registerSettingsMetadata(); upgradeMainPortlet(BlogsPortletKeys.BLOGS, BlogsConstants.SERVICE_NAME, PortletKeys.PREFS_OWNER_TYPE_GROUP, true);//from ww w. j av a2 s . c o m }
From source file:com.liferay.document.library.web.internal.upgrade.v1_0_0.UpgradePortletSettings.java
License:Open Source License
@Override protected void doUpgrade() throws Exception { DLGroupServiceSettings.registerSettingsMetadata(); DLPortletInstanceSettings.registerSettingsMetadata(); upgradeMainPortlet(DLPortletKeys.DOCUMENT_LIBRARY, DLConstants.SERVICE_NAME, PortletKeys.PREFS_OWNER_TYPE_GROUP, true); upgradeDisplayPortlet(DLPortletKeys.DOCUMENT_LIBRARY, DLConstants.SERVICE_NAME, PortletKeys.PREFS_OWNER_TYPE_LAYOUT); upgradeDisplayPortlet(DLPortletKeys.MEDIA_GALLERY_DISPLAY, DLConstants.SERVICE_NAME, PortletKeys.PREFS_OWNER_TYPE_LAYOUT); }
From source file:com.liferay.exportimport.controller.PortletExportController.java
License:Open Source License
public void exportPortlet(PortletDataContext portletDataContext, long plid, Element parentElement, boolean exportPermissions, boolean exportPortletArchivedSetups, boolean exportPortletData, boolean exportPortletSetup, boolean exportPortletUserPreferences) throws Exception { long layoutId = LayoutConstants.DEFAULT_PARENT_LAYOUT_ID; Layout layout = _layoutLocalService.fetchLayout(plid); if (layout != null) { layoutId = layout.getLayoutId(); }//ww w . j a v a2s . com Portlet portlet = _portletLocalService.getPortletById(portletDataContext.getCompanyId(), portletDataContext.getPortletId()); if ((portlet == null) || portlet.isUndeployedPortlet()) { if (_log.isDebugEnabled()) { _log.debug("Do not export portlet " + portletDataContext.getPortletId() + " because the portlet is not deployed"); } return; } if (!portlet.isInstanceable() && !portlet.isPreferencesUniquePerLayout() && portletDataContext.hasNotUniquePerLayout(portletDataContext.getPortletId())) { return; } if (BackgroundTaskThreadLocal.hasBackgroundTask()) { PortletDataContext clonedPortletDataContext = _portletDataContextFactory .clonePortletDataContext(portletDataContext); ManifestSummary manifestSummary = clonedPortletDataContext.getManifestSummary(); manifestSummary.resetCounters(); PortletDataHandler portletDataHandler = portlet.getPortletDataHandlerInstance(); portletDataHandler.prepareManifestSummary(clonedPortletDataContext); _portletDataHandlerStatusMessageSender.sendStatusMessage("portlet", portletDataContext.getPortletId(), manifestSummary); } Document document = SAXReaderUtil.createDocument(); Element portletElement = document.addElement("portlet"); portletElement.addAttribute("portlet-id", portletDataContext.getPortletId()); portletElement.addAttribute("root-portlet-id", portletDataContext.getRootPortletId()); portletElement.addAttribute("old-plid", String.valueOf(plid)); portletElement.addAttribute("scope-group-id", String.valueOf(portletDataContext.getScopeGroupId())); portletElement.addAttribute("scope-layout-type", portletDataContext.getScopeType()); portletElement.addAttribute("scope-layout-uuid", portletDataContext.getScopeLayoutUuid()); portletElement.addAttribute("private-layout", String.valueOf(portletDataContext.isPrivateLayout())); // Data if (exportPortletData) { javax.portlet.PortletPreferences jxPortletPreferences = null; if (ExportImportThreadLocal.isInitialLayoutStagingInProcess()) { if (layout != null) { Group liveGroup = layout.getGroup(); Group stagingGroup = liveGroup.getStagingGroup(); layout.setGroupId(stagingGroup.getGroupId()); jxPortletPreferences = PortletPreferencesFactoryUtil.getStrictPortletSetup(layout, portletDataContext.getPortletId()); layout.setGroupId(liveGroup.getGroupId()); } else { Group liveGroup = _groupLocalService.getGroup(portletDataContext.getGroupId()); Group stagingGroup = liveGroup.getStagingGroup(); jxPortletPreferences = PortletPreferencesFactoryUtil.getStrictPortletSetup( portletDataContext.getCompanyId(), stagingGroup.getGroupId(), portletDataContext.getPortletId()); } } else { if (layout != null) { jxPortletPreferences = PortletPreferencesFactoryUtil.getStrictPortletSetup(layout, portletDataContext.getPortletId()); } else { jxPortletPreferences = PortletPreferencesFactoryUtil.getStrictPortletSetup( portletDataContext.getCompanyId(), portletDataContext.getGroupId(), portletDataContext.getPortletId()); } } if (!portlet.isPreferencesUniquePerLayout()) { StringBundler sb = new StringBundler(5); sb.append(portletDataContext.getPortletId()); sb.append(StringPool.AT); sb.append(portletDataContext.getScopeType()); sb.append(StringPool.AT); sb.append(portletDataContext.getScopeLayoutUuid()); String dataKey = sb.toString(); if (!portletDataContext.hasNotUniquePerLayout(dataKey)) { portletDataContext.putNotUniquePerLayout(dataKey); exportPortletData(portletDataContext, portlet, layout, jxPortletPreferences, portletElement); } } else { exportPortletData(portletDataContext, portlet, layout, jxPortletPreferences, portletElement); } } // Portlet preferences if (exportPortletSetup) { // Company exportPortletPreferences(portletDataContext, portletDataContext.getCompanyId(), PortletKeys.PREFS_OWNER_TYPE_COMPANY, false, layout, plid, portlet.getRootPortletId(), portletElement); // Group exportPortletPreferences(portletDataContext, portletDataContext.getScopeGroupId(), PortletKeys.PREFS_OWNER_TYPE_GROUP, false, layout, PortletKeys.PREFS_PLID_SHARED, portlet.getRootPortletId(), portletElement); // Group embedded portlets exportPortletPreferences(portletDataContext, portletDataContext.getScopeGroupId(), PortletKeys.PREFS_OWNER_TYPE_LAYOUT, false, layout, PortletKeys.PREFS_PLID_SHARED, portlet.getPortletId(), portletElement); // Layout exportPortletPreferences(portletDataContext, PortletKeys.PREFS_OWNER_ID_DEFAULT, PortletKeys.PREFS_OWNER_TYPE_LAYOUT, false, layout, plid, portletDataContext.getPortletId(), portletElement); } // Portlet user preferences if (exportPortletUserPreferences) { List<PortletPreferences> portletPreferencesList = _portletPreferencesLocalService.getPortletPreferences( PortletKeys.PREFS_OWNER_TYPE_USER, plid, portletDataContext.getPortletId()); for (PortletPreferences portletPreferences : portletPreferencesList) { boolean defaultUser = false; if (portletPreferences.getOwnerId() == PortletKeys.PREFS_OWNER_ID_DEFAULT) { defaultUser = true; } exportPortletPreferences(portletDataContext, portletPreferences.getOwnerId(), PortletKeys.PREFS_OWNER_TYPE_USER, defaultUser, layout, plid, portletDataContext.getPortletId(), portletElement); } try { PortletPreferences groupPortletPreferences = _portletPreferencesLocalService.getPortletPreferences( portletDataContext.getScopeGroupId(), PortletKeys.PREFS_OWNER_TYPE_GROUP, PortletKeys.PREFS_PLID_SHARED, portlet.getRootPortletId()); exportPortletPreference(portletDataContext, portletDataContext.getScopeGroupId(), PortletKeys.PREFS_OWNER_TYPE_GROUP, false, groupPortletPreferences, portlet.getRootPortletId(), PortletKeys.PREFS_PLID_SHARED, portletElement); } catch (NoSuchPortletPreferencesException nsppe) { // LPS-52675 if (_log.isDebugEnabled()) { _log.debug(nsppe, nsppe); } } } // Archived setups if (exportPortletArchivedSetups) { List<PortletItem> portletItems = _portletItemLocalService.getPortletItems( portletDataContext.getGroupId(), portletDataContext.getRootPortletId(), PortletPreferences.class.getName()); for (PortletItem portletItem : portletItems) { exportPortletPreferences(portletDataContext, portletItem.getPortletItemId(), PortletKeys.PREFS_OWNER_TYPE_ARCHIVED, false, null, plid, portletItem.getPortletId(), portletElement); } } // Permissions if (exportPermissions) { _permissionExporter.exportPortletPermissions(portletDataContext, portletDataContext.getPortletId(), layout, portletElement); } // Zip StringBundler pathSB = new StringBundler(4); pathSB.append(ExportImportPathUtil.getPortletPath(portletDataContext)); pathSB.append(StringPool.SLASH); pathSB.append(plid); pathSB.append("/portlet.xml"); String path = pathSB.toString(); Element element = parentElement.addElement("portlet"); element.addAttribute("portlet-id", portletDataContext.getPortletId()); element.addAttribute("layout-id", String.valueOf(layoutId)); element.addAttribute("path", path); element.addAttribute("portlet-data", String.valueOf(exportPortletData)); PortletDataHandler portletDataHandler = portlet.getPortletDataHandlerInstance(); element.addAttribute("schema-version", portletDataHandler.getSchemaVersion()); StringBundler configurationOptionsSB = new StringBundler(6); if (exportPortletSetup) { configurationOptionsSB.append("setup"); configurationOptionsSB.append(StringPool.COMMA); } if (exportPortletArchivedSetups) { configurationOptionsSB.append("archived-setups"); configurationOptionsSB.append(StringPool.COMMA); } if (exportPortletUserPreferences) { configurationOptionsSB.append("user-preferences"); configurationOptionsSB.append(StringPool.COMMA); } if (configurationOptionsSB.index() > 0) { configurationOptionsSB.setIndex(configurationOptionsSB.index() - 1); } element.addAttribute("portlet-configuration", configurationOptionsSB.toString()); try { portletDataContext.addZipEntry(path, document.formattedString()); } catch (IOException ioe) { if (_log.isWarnEnabled()) { _log.warn(ioe.getMessage()); } } }
From source file:com.liferay.exportimport.controller.PortletExportController.java
License:Open Source License
public void exportService(PortletDataContext portletDataContext, Element rootElement, boolean exportServiceSetup) throws Exception { if (!exportServiceSetup) { return;//from w w w .j a va 2 s . c o m } PortletDataHandler portletDataHandler = _portletDataHandlerProvider .provide(portletDataContext.getPortletId()); if (portletDataHandler == null) { return; } String serviceName = portletDataHandler.getServiceName(); if (Validator.isNotNull(serviceName)) { // Company service exportServicePortletPreferences(portletDataContext, portletDataContext.getCompanyId(), PortletKeys.PREFS_OWNER_TYPE_COMPANY, serviceName, rootElement); // Group service exportServicePortletPreferences(portletDataContext, portletDataContext.getScopeGroupId(), PortletKeys.PREFS_OWNER_TYPE_GROUP, serviceName, rootElement); } }
From source file:com.liferay.exportimport.controller.PortletExportController.java
License:Open Source License
protected PortletPreferences getPortletPreferences(long ownerId, int ownerType, long plid, String portletId) throws PortalException { PortletPreferences portletPreferences = null; if ((ownerType == PortletKeys.PREFS_OWNER_TYPE_ARCHIVED) || (ownerType == PortletKeys.PREFS_OWNER_TYPE_COMPANY) || (ownerType == PortletKeys.PREFS_OWNER_TYPE_GROUP)) { portletPreferences = _portletPreferencesLocalService.getPortletPreferences(ownerId, ownerType, LayoutConstants.DEFAULT_PLID, portletId); } else {//from w w w.java2 s . c om portletPreferences = _portletPreferencesLocalService.getPortletPreferences(ownerId, ownerType, plid, portletId); } return portletPreferences; }
From source file:com.liferay.exportimport.controller.PortletImportController.java
License:Open Source License
public void importPortletPreferences(PortletDataContext portletDataContext, long companyId, long groupId, Layout layout, Element parentElement, boolean preserveScopeLayoutId, boolean importPortletArchivedSetups, boolean importPortletData, boolean importPortletSetup, boolean importPortletUserPreferences) throws Exception { long plid = LayoutConstants.DEFAULT_PLID; String scopeType = StringPool.BLANK; String scopeLayoutUuid = StringPool.BLANK; if (layout != null) { plid = layout.getPlid();//from w w w.ja v a 2 s. c om if (preserveScopeLayoutId) { javax.portlet.PortletPreferences jxPortletPreferences = PortletPreferencesFactoryUtil .getLayoutPortletSetup(layout, portletDataContext.getPortletId()); scopeType = GetterUtil.getString(jxPortletPreferences.getValue("lfrScopeType", null)); scopeLayoutUuid = GetterUtil.getString(jxPortletPreferences.getValue("lfrScopeLayoutUuid", null)); portletDataContext.setScopeType(scopeType); portletDataContext.setScopeLayoutUuid(scopeLayoutUuid); } } List<Element> portletPreferencesElements = parentElement.elements("portlet-preferences"); for (Element portletPreferencesElement : portletPreferencesElements) { String path = portletPreferencesElement.attributeValue("path"); if (portletDataContext.isPathNotProcessed(path)) { String xml = null; Element element = null; try { xml = portletDataContext.getZipEntryAsString(path); Document preferencesDocument = SAXReaderUtil.read(xml); element = preferencesDocument.getRootElement(); } catch (DocumentException de) { throw new SystemException( "Unable to parse XML portlet preferences for portlet " + portletDataContext.getPortletId() + " while importing portlet preferences", de); } long ownerId = GetterUtil.getLong(element.attributeValue("owner-id")); int ownerType = GetterUtil.getInteger(element.attributeValue("owner-type")); if ((ownerType == PortletKeys.PREFS_OWNER_TYPE_COMPANY) || !importPortletSetup) { continue; } if ((ownerType == PortletKeys.PREFS_OWNER_TYPE_ARCHIVED) && !importPortletArchivedSetups) { continue; } if ((ownerType == PortletKeys.PREFS_OWNER_TYPE_USER) && (ownerId != PortletKeys.PREFS_OWNER_ID_DEFAULT) && !importPortletUserPreferences) { continue; } long curPlid = plid; String curPortletId = portletDataContext.getPortletId(); if (ownerType == PortletKeys.PREFS_OWNER_TYPE_GROUP) { curPlid = PortletKeys.PREFS_PLID_SHARED; curPortletId = portletDataContext.getRootPortletId(); ownerId = portletDataContext.getScopeGroupId(); } long elementPlid = GetterUtil.getLong(element.attributeValue("plid")); if ((ownerType == PortletKeys.PREFS_OWNER_TYPE_LAYOUT) && (ownerId != PortletKeys.PREFS_OWNER_ID_DEFAULT) && (elementPlid == PortletKeys.PREFS_PLID_SHARED)) { curPlid = PortletKeys.PREFS_PLID_SHARED; ownerId = portletDataContext.getScopeGroupId(); } if (ownerType == PortletKeys.PREFS_OWNER_TYPE_ARCHIVED) { String userUuid = element.attributeValue("archive-user-uuid"); long userId = portletDataContext.getUserId(userUuid); String name = element.attributeValue("archive-name"); curPortletId = portletDataContext.getRootPortletId(); PortletItem portletItem = _portletItemLocalService.updatePortletItem(userId, groupId, name, curPortletId, PortletPreferences.class.getName()); curPlid = LayoutConstants.DEFAULT_PLID; ownerId = portletItem.getPortletItemId(); } if (ownerType == PortletKeys.PREFS_OWNER_TYPE_USER) { String userUuid = element.attributeValue("user-uuid"); ownerId = portletDataContext.getUserId(userUuid); } boolean defaultUser = GetterUtil.getBoolean(element.attributeValue("default-user")); if (defaultUser) { ownerId = _userLocalService.getDefaultUserId(companyId); } javax.portlet.PortletPreferences jxPortletPreferences = PortletPreferencesFactoryUtil .fromXML(companyId, ownerId, ownerType, curPlid, curPortletId, xml); Element importDataRootElement = portletDataContext.getImportDataRootElement(); try { Element preferenceDataElement = portletPreferencesElement.element("preference-data"); if (preferenceDataElement != null) { portletDataContext.setImportDataRootElement(preferenceDataElement); } ExportImportPortletPreferencesProcessor exportImportPortletPreferencesProcessor = ExportImportPortletPreferencesProcessorRegistryUtil .getExportImportPortletPreferencesProcessor( PortletIdCodec.decodePortletName(curPortletId)); if (exportImportPortletPreferencesProcessor != null) { List<Capability> importCapabilities = exportImportPortletPreferencesProcessor .getImportCapabilities(); if (ListUtil.isNotEmpty(importCapabilities)) { for (Capability importCapability : importCapabilities) { importCapability.process(portletDataContext, jxPortletPreferences); } } exportImportPortletPreferencesProcessor.processImportPortletPreferences(portletDataContext, jxPortletPreferences); } else { PortletDataHandler portletDataHandler = _portletDataHandlerProvider .provide(portletDataContext.getCompanyId(), curPortletId); if (portletDataHandler != null) { jxPortletPreferences = portletDataHandler.processImportPortletPreferences( portletDataContext, curPortletId, jxPortletPreferences); } } } finally { portletDataContext.setImportDataRootElement(importDataRootElement); } updatePortletPreferences(portletDataContext, ownerId, ownerType, curPlid, curPortletId, PortletPreferencesFactoryUtil.toXML(jxPortletPreferences), importPortletData); } } if (preserveScopeLayoutId && (layout != null)) { javax.portlet.PortletPreferences jxPortletPreferences = PortletPreferencesFactoryUtil .getLayoutPortletSetup(layout, portletDataContext.getPortletId()); try { jxPortletPreferences.setValue("lfrScopeType", scopeType); jxPortletPreferences.setValue("lfrScopeLayoutUuid", scopeLayoutUuid); jxPortletPreferences.store(); } finally { portletDataContext.setScopeType(scopeType); portletDataContext.setScopeLayoutUuid(scopeLayoutUuid); } } }
From source file:com.liferay.exportimport.controller.PortletImportController.java
License:Open Source License
public void importServicePortletPreferences(PortletDataContext portletDataContext, Element serviceElement) throws PortalException { long ownerId = GetterUtil.getLong(serviceElement.attributeValue("owner-id")); int ownerType = GetterUtil.getInteger(serviceElement.attributeValue("owner-type")); String serviceName = serviceElement.attributeValue("service-name"); if (ownerType == PortletKeys.PREFS_OWNER_TYPE_GROUP) { ownerId = portletDataContext.getGroupId(); } else if (ownerType == PortletKeys.PREFS_OWNER_TYPE_COMPANY) { ownerId = portletDataContext.getCompanyId(); }/*www . j ava 2s . c om*/ PortletPreferences portletPreferences = getPortletPreferences(portletDataContext.getCompanyId(), ownerId, ownerType, LayoutConstants.DEFAULT_PLID, serviceName); for (Attribute attribute : serviceElement.attributes()) { serviceElement.remove(attribute); } String xml = serviceElement.asXML(); portletPreferences.setPreferences(xml); _portletPreferencesLocalService.updatePortletPreferences(portletPreferences); }
From source file:com.liferay.exportimport.controller.PortletImportController.java
License:Open Source License
protected PortletPreferences getPortletPreferences(long companyId, long ownerId, int ownerType, long plid, String serviceName) throws PortalException { PortletPreferences portletPreferences = null; try {/*w w w . jav a 2 s . c om*/ if ((ownerType == PortletKeys.PREFS_OWNER_TYPE_ARCHIVED) || (ownerType == PortletKeys.PREFS_OWNER_TYPE_COMPANY) || (ownerType == PortletKeys.PREFS_OWNER_TYPE_GROUP)) { portletPreferences = _portletPreferencesLocalService.getPortletPreferences(ownerId, ownerType, LayoutConstants.DEFAULT_PLID, serviceName); } else { portletPreferences = _portletPreferencesLocalService.getPortletPreferences(ownerId, ownerType, plid, serviceName); } } catch (NoSuchPortletPreferencesException nsppe) { // LPS-52675 if (_log.isDebugEnabled()) { _log.debug(nsppe, nsppe); } portletPreferences = _portletPreferencesLocalService.addPortletPreferences(companyId, ownerId, ownerType, plid, serviceName, null, null); } return portletPreferences; }
From source file:com.liferay.journal.internal.upgrade.v0_0_5.UpgradePortletSettings.java
License:Open Source License
@Override protected void doUpgrade() throws Exception { upgradeMainPortlet(JournalPortletKeys.JOURNAL, JournalConstants.SERVICE_NAME, PortletKeys.PREFS_OWNER_TYPE_GROUP, false); }
From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
protected void checkArticlesByReviewDate(Date reviewDate) throws PortalException { List<JournalArticle> latestArticles = new ArrayList<>(); List<JournalArticle> articles = journalArticleFinder .findByReviewDate(JournalArticleConstants.CLASSNAME_ID_DEFAULT, reviewDate, _previousCheckDate); for (JournalArticle article : articles) { long groupId = article.getGroupId(); String articleId = article.getArticleId(); double version = article.getVersion(); if (!journalArticleLocalService.isLatestVersion(groupId, articleId, version)) { article = journalArticleLocalService.getLatestArticle(groupId, articleId); }/*from w ww. j a v a2s. co m*/ if (!latestArticles.contains(article)) { if (_log.isDebugEnabled()) { _log.debug("Sending review notification for article " + article.getId()); } latestArticles.add(article); long ownerId = article.getGroupId(); int ownerType = PortletKeys.PREFS_OWNER_TYPE_GROUP; long plid = PortletKeys.PREFS_PLID_SHARED; String portletId = PortletProviderUtil.getPortletId(JournalArticle.class.getName(), PortletProvider.Action.EDIT); PortletPreferences preferences = portletPreferencesLocalService .getPreferences(article.getCompanyId(), ownerId, ownerType, plid, portletId); String articleURL = PortalUtil.getControlPanelFullURL(article.getGroupId(), portletId, null); articleURL = buildArticleURL(articleURL, article.getGroupId(), article.getFolderId(), article.getArticleId()); sendEmail(article, articleURL, preferences, "review", new ServiceContext()); } } }