List of usage examples for com.liferay.portal.kernel.service ServiceContextThreadLocal popServiceContext
public static ServiceContext popServiceContext()
From source file:com.liferay.adaptive.media.document.library.thumbnails.internal.commands.test.AdaptiveMediaThumbnailsOSGiCommandsTest.java
License:Open Source License
@After public void tearDown() throws Exception { _adaptiveMediaImageConfigurationHelper.forceDeleteAdaptiveMediaImageConfigurationEntry( _company.getCompanyId(), _THUMBNAIL_CONFIGURATION + 100); _adaptiveMediaImageConfigurationHelper.forceDeleteAdaptiveMediaImageConfigurationEntry( _company.getCompanyId(), _THUMBNAIL_CONFIGURATION + 300); FileVersion latestFileVersion = _pngFileEntry.getFileVersion(); AdaptiveMediaImageEntryLocalServiceUtil.deleteAdaptiveMediaImageEntryFileVersion(latestFileVersion); GroupLocalServiceUtil.deleteGroup(_group); CompanyLocalServiceUtil.deleteCompany(_company); ServiceContextThreadLocal.popServiceContext(); }
From source file:com.liferay.adaptive.media.document.library.thumbnails.internal.osgi.commands.test.AMThumbnailsOSGiCommandsTest.java
License:Open Source License
@After public void tearDown() throws Exception { _amImageConfigurationHelper.forceDeleteAMImageConfigurationEntry(_company.getCompanyId(), _THUMBNAIL_CONFIGURATION + 100); _amImageConfigurationHelper.forceDeleteAMImageConfigurationEntry(_company.getCompanyId(), _THUMBNAIL_CONFIGURATION + 300); FileVersion latestFileVersion = _pngFileEntry.getFileVersion(); AMImageEntryLocalServiceUtil.deleteAMImageEntryFileVersion(latestFileVersion); GroupLocalServiceUtil.deleteGroup(_group); CompanyLocalServiceUtil.deleteCompany(_company); ServiceContextThreadLocal.popServiceContext(); }
From source file:com.liferay.exportimport.controller.LayoutExportController.java
License:Open Source License
protected File doExport(PortletDataContext portletDataContext) throws Exception { Map<String, String[]> parameterMap = portletDataContext.getParameterMap(); boolean ignoreLastPublishDate = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.IGNORE_LAST_PUBLISH_DATE); boolean permissions = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.PERMISSIONS); if (_log.isDebugEnabled()) { _log.debug("Export permissions " + permissions); }/*from w w w .j a v a 2s . c o m*/ long companyId = portletDataContext.getCompanyId(); long defaultUserId = _userLocalService.getDefaultUserId(companyId); ServiceContext serviceContext = ServiceContextThreadLocal.popServiceContext(); if (serviceContext == null) { serviceContext = new ServiceContext(); } serviceContext.setCompanyId(companyId); serviceContext.setSignedIn(true); if (BackgroundTaskThreadLocal.hasBackgroundTask()) { BackgroundTask backgroundTask = _backgroundTaskLocalService .getBackgroundTask(BackgroundTaskThreadLocal.getBackgroundTaskId()); serviceContext.setUserId(backgroundTask.getUserId()); } else { serviceContext.setUserId(defaultUserId); } serviceContext.setAttribute("exporting", Boolean.TRUE); long layoutSetBranchId = MapUtil.getLong(parameterMap, "layoutSetBranchId"); serviceContext.setAttribute("layoutSetBranchId", layoutSetBranchId); ServiceContextThreadLocal.pushServiceContext(serviceContext); if (ignoreLastPublishDate) { portletDataContext.setEndDate(null); portletDataContext.setStartDate(null); } StopWatch stopWatch = new StopWatch(); stopWatch.start(); 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(portletDataContext.getScopeGroupId()))); headerElement.addAttribute("build-number", String.valueOf(ReleaseInfo.getBuildNumber())); headerElement.addAttribute("schema-version", ExportImportConstants.EXPORT_IMPORT_SCHEMA_VERSION); 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("company-id", String.valueOf(portletDataContext.getCompanyId())); headerElement.addAttribute("company-group-id", String.valueOf(portletDataContext.getCompanyGroupId())); headerElement.addAttribute("group-id", String.valueOf(portletDataContext.getGroupId())); headerElement.addAttribute("user-personal-site-group-id", String.valueOf(portletDataContext.getUserPersonalSiteGroupId())); headerElement.addAttribute("private-layout", String.valueOf(portletDataContext.isPrivateLayout())); Group group = _groupLocalService.fetchGroup(portletDataContext.getGroupId()); String type = "layout-set"; if (group.isLayoutPrototype()) { type = "layout-prototype"; LayoutPrototype layoutPrototype = _layoutPrototypeLocalService.getLayoutPrototype(group.getClassPK()); headerElement.addAttribute("type-uuid", layoutPrototype.getUuid()); } else if (group.isLayoutSetPrototype()) { type = "layout-set-prototype"; LayoutSetPrototype layoutSetPrototype = _layoutSetPrototypeLocalService .getLayoutSetPrototype(group.getClassPK()); headerElement.addAttribute("type-uuid", layoutSetPrototype.getUuid()); } headerElement.addAttribute("type", type); portletDataContext.setType(type); Element missingReferencesElement = rootElement.addElement("missing-references"); portletDataContext.setMissingReferencesElement(missingReferencesElement); rootElement.addElement("site-portlets"); rootElement.addElement("site-services"); // Export the group LayoutSet layoutSet = _layoutSetLocalService.getLayoutSet(portletDataContext.getGroupId(), portletDataContext.isPrivateLayout()); String layoutSetPrototypeUuid = layoutSet.getLayoutSetPrototypeUuid(); boolean layoutSetPrototypeSettings = MapUtil.getBoolean(portletDataContext.getParameterMap(), PortletDataHandlerKeys.LAYOUT_SET_PROTOTYPE_SETTINGS); if (!group.isStaged() && Validator.isNotNull(layoutSetPrototypeUuid) && layoutSetPrototypeSettings) { LayoutSetPrototype layoutSetPrototype = _layoutSetPrototypeLocalService .getLayoutSetPrototypeByUuidAndCompanyId(layoutSetPrototypeUuid, companyId); headerElement.addAttribute("layout-set-prototype-uuid", layoutSetPrototypeUuid); headerElement.addAttribute("layout-set-prototype-name", layoutSetPrototype.getName(LocaleUtil.getDefault())); } StagedGroup stagedGroup = ModelAdapterUtil.adapt(group, Group.class, StagedGroup.class); StagedModelDataHandlerUtil.exportStagedModel(portletDataContext, stagedGroup); // Export other models _portletExportController.exportAssetLinks(portletDataContext); _portletExportController.exportExpandoTables(portletDataContext); _portletExportController.exportLocks(portletDataContext); portletDataContext.addDeletionSystemEventStagedModelTypes(new StagedModelType(StagedAssetLink.class)); _deletionSystemEventExporter.exportDeletionSystemEvents(portletDataContext); if (permissions) { _permissionExporter.exportPortletDataPermissions(portletDataContext); } _exportImportHelper.writeManifestSummary(document, portletDataContext.getManifestSummary()); if (_log.isInfoEnabled()) { _log.info("Exporting layouts takes " + stopWatch.getTime() + " ms"); } portletDataContext.addZipEntry("/manifest.xml", document.formattedString()); ZipWriter zipWriter = portletDataContext.getZipWriter(); return zipWriter.getFile(); }
From source file:com.liferay.exportimport.internal.background.task.BaseStagingBackgroundTaskExecutor.java
License:Open Source License
protected void initThreadLocals(long groupId, boolean privateLayout) throws PortalException { ServiceContext serviceContext = ServiceContextThreadLocal.popServiceContext(); if (serviceContext == null) { serviceContext = new ServiceContext(); }/* w ww. j a v a 2s .com*/ LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(groupId, privateLayout); serviceContext.setCompanyId(layoutSet.getCompanyId()); serviceContext.setSignedIn(false); long defaultUserId = UserLocalServiceUtil.getDefaultUserId(layoutSet.getCompanyId()); serviceContext.setUserId(defaultUserId); ServiceContextThreadLocal.pushServiceContext(serviceContext); }
From source file:com.liferay.exportimport.messaging.BasePublisherMessageListener.java
License:Open Source License
protected void resetThreadLocals() { CompanyThreadLocal.setCompanyId(CompanyConstants.SYSTEM); PermissionThreadLocal.setPermissionChecker(null); PrincipalThreadLocal.setName(null);//from w w w .j a v a 2 s . co m ServiceContextThreadLocal.popServiceContext(); }
From source file:com.liferay.exportimport.resources.importer.internal.util.FileSystemImporter.java
License:Open Source License
protected void addLayout(boolean privateLayout, long parentLayoutId, JSONObject layoutJSONObject) throws Exception { if (targetClassName.equals(LayoutSetPrototype.class.getName())) { privateLayout = true;/* w ww .ja va 2 s . co m*/ } Map<Locale, String> nameMap = getMap(layoutJSONObject, "name"); Map<Locale, String> titleMap = getMap(layoutJSONObject, "title"); String type = layoutJSONObject.getString("type"); if (Validator.isNull(type)) { type = LayoutConstants.TYPE_PORTLET; } String typeSettings = layoutJSONObject.getString("typeSettings"); boolean hidden = layoutJSONObject.getBoolean("hidden"); String themeId = layoutJSONObject.getString("themeId"); String layoutCss = layoutJSONObject.getString("layoutCss"); String colorSchemeId = layoutJSONObject.getString("colorSchemeId"); Map<Locale, String> friendlyURLMap = new HashMap<>(); String friendlyURL = layoutJSONObject.getString("friendlyURL"); if (Validator.isNotNull(friendlyURL) && !friendlyURL.startsWith(StringPool.SLASH)) { friendlyURL = StringPool.SLASH + friendlyURL; } friendlyURLMap.put(LocaleUtil.getDefault(), friendlyURL); ServiceContext serviceContext = new ServiceContext(); serviceContext.setCompanyId(companyId); serviceContext.setScopeGroupId(groupId); serviceContext.setUserId(userId); ServiceContextThreadLocal.pushServiceContext(serviceContext); try { String layoutPrototypeName = layoutJSONObject.getString("layoutPrototypeName"); String layoutPrototypeUuid = null; if (Validator.isNotNull(layoutPrototypeName)) { LayoutPrototype layoutPrototype = getLayoutPrototype(companyId, layoutPrototypeName); layoutPrototypeUuid = layoutPrototype.getUuid(); } else { layoutPrototypeUuid = layoutJSONObject.getString("layoutPrototypeUuid"); } if (Validator.isNotNull(layoutPrototypeUuid)) { boolean layoutPrototypeLinkEnabled = GetterUtil .getBoolean(layoutJSONObject.getString("layoutPrototypeLinkEnabled")); serviceContext.setAttribute("layoutPrototypeLinkEnabled", layoutPrototypeLinkEnabled); serviceContext.setAttribute("layoutPrototypeUuid", layoutPrototypeUuid); } Layout layout = layoutLocalService.fetchLayoutByFriendlyURL(groupId, privateLayout, friendlyURL); if (layout != null) { if (!developerModeEnabled) { if (_log.isInfoEnabled()) { _log.info("Layout with friendly URL " + friendlyURL + " already exists"); } return; } if (!updateModeEnabled) { layoutLocalService.deleteLayout(layout); } } if (!updateModeEnabled || (layout == null)) { layout = layoutLocalService.addLayout(userId, groupId, privateLayout, parentLayoutId, nameMap, titleMap, null, null, null, type, typeSettings, hidden, friendlyURLMap, serviceContext); } else { resetLayoutColumns(layout); layout = layoutLocalService.updateLayout(groupId, privateLayout, layout.getLayoutId(), parentLayoutId, nameMap, titleMap, layout.getDescriptionMap(), layout.getKeywordsMap(), layout.getRobotsMap(), type, hidden, friendlyURLMap, layout.getIconImage(), null, serviceContext); } if (Validator.isNotNull(themeId) || Validator.isNotNull(colorSchemeId)) { // If the theme ID or the color scheme ID are not null, then the // layout has a custom look and feel and should be updated in // the database layoutLocalService.updateLookAndFeel(groupId, privateLayout, layout.getLayoutId(), themeId, colorSchemeId, layoutCss); } LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType(); String layoutTemplateId = layoutJSONObject.getString("layoutTemplateId", _defaultLayoutTemplateId); if (Validator.isNotNull(layoutTemplateId)) { layoutTypePortlet.setLayoutTemplateId(userId, layoutTemplateId, false); } JSONArray columnsJSONArray = layoutJSONObject.getJSONArray("columns"); addLayoutColumns(layout, LayoutTypePortletConstants.COLUMN_PREFIX, columnsJSONArray); layoutLocalService.updateLayout(groupId, layout.isPrivateLayout(), layout.getLayoutId(), layout.getTypeSettings()); JSONArray layoutsJSONArray = layoutJSONObject.getJSONArray("layouts"); addLayouts(privateLayout, layout.getLayoutId(), layoutsJSONArray); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn("Unable to import layout " + layoutJSONObject, e); } throw e; } finally { ServiceContextThreadLocal.popServiceContext(); } }
From source file:com.liferay.exportimport.test.util.lar.BaseStagedModelDataHandlerTestCase.java
License:Open Source License
@After public void tearDown() throws Exception { ServiceContextThreadLocal.popServiceContext(); }
From source file:com.liferay.staging.test.StagingImplTest.java
License:Open Source License
protected void enableLocalStaging(boolean branching) throws Exception { ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId()); Map<String, Serializable> attributes = serviceContext.getAttributes(); attributes.putAll(ExportImportConfigurationParameterMapFactory.buildParameterMap()); if (branching) { serviceContext.setSignedIn(true); }/*from ww w. j a v a 2 s. com*/ ServiceContextThreadLocal.pushServiceContext(serviceContext); enableLocalStaging(branching, serviceContext); ServiceContextThreadLocal.popServiceContext(); if (!branching) { return; } UnicodeProperties typeSettingsProperties = _group.getTypeSettingsProperties(); Assert.assertTrue(GetterUtil.getBoolean(typeSettingsProperties.getProperty("branchingPrivate"))); Assert.assertTrue(GetterUtil.getBoolean(typeSettingsProperties.getProperty("branchingPublic"))); Group stagingGroup = _group.getStagingGroup(); LayoutSetBranch layoutSetBranch = LayoutSetBranchLocalServiceUtil.fetchLayoutSetBranch( stagingGroup.getGroupId(), false, LayoutSetBranchConstants.MASTER_BRANCH_NAME); Assert.assertNotNull(layoutSetBranch); layoutSetBranch = LayoutSetBranchLocalServiceUtil.fetchLayoutSetBranch(stagingGroup.getGroupId(), true, LayoutSetBranchConstants.MASTER_BRANCH_NAME); Assert.assertNotNull(layoutSetBranch); }