List of usage examples for com.liferay.portal.kernel.security.auth CompanyThreadLocal getCompanyId
public static Long getCompanyId()
From source file:com.liferay.blogs.internal.atom.BlogsEntryAtomCollectionAdapter.java
License:Open Source License
@Override protected Iterable<BlogsEntry> doGetFeedEntries(AtomRequestContext atomRequestContext) throws Exception { long groupId = atomRequestContext.getLongParameter("groupId"); int status = WorkflowConstants.STATUS_APPROVED; int max = atomRequestContext.getIntParameter("max", SearchContainer.DEFAULT_DELTA); if (groupId > 0) { int page = atomRequestContext.getIntParameter("page"); if (page == 0) { return _blogsEntryService.getGroupEntries(groupId, status, max); }// ww w. j a v a 2 s.c om int count = _blogsEntryService.getGroupEntriesCount(groupId, new Date(), status); AtomPager atomPager = new AtomPager(page, max, count); AtomUtil.saveAtomPagerInRequest(atomRequestContext, atomPager); return _blogsEntryService.getGroupEntries(groupId, new Date(), status, atomPager.getStart(), atomPager.getEnd() + 1); } long organizationId = atomRequestContext.getLongParameter("organizationId"); if (organizationId > 0) { return _blogsEntryService.getOrganizationEntries(organizationId, new Date(), status, max); } long companyId = CompanyThreadLocal.getCompanyId(); if (companyId > 0) { return _blogsEntryService.getCompanyEntries(companyId, new Date(), status, max); } return Collections.emptyList(); }
From source file:com.liferay.dynamic.data.lists.form.web.internal.portlet.action.GetRolesMVCResourceCommand.java
License:Open Source License
@Override protected void doServeResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception { List<Role> roles = _roleService.getRoles(CompanyThreadLocal.getCompanyId(), null); JSONPortletResponseUtil.writeJSON(resourceRequest, resourceResponse, toJSONArray(roles)); }
From source file:com.liferay.dynamic.data.mapping.form.builder.internal.servlet.RolesServlet.java
License:Open Source License
protected JSONArray getRolesJSONArray() { JSONArray jsonArray = _jsonFactory.createJSONArray(); try {// w w w .j av a 2 s. c o m List<Role> roles = _roleService.getRoles(CompanyThreadLocal.getCompanyId(), null); for (Role role : roles) { jsonArray.put(toJSONObject(role)); } return jsonArray; } catch (PortalException pe) { if (_log.isDebugEnabled()) { _log.debug(pe, pe); } } return jsonArray; }
From source file:com.liferay.dynamic.data.mapping.service.impl.DDMStructureLocalServiceImpl.java
License:Open Source License
protected void validate(Map<Locale, String> nameMap, Locale contentDefaultLocale) throws PortalException { String name = nameMap.get(contentDefaultLocale); if (Validator.isNull(name)) { throw new StructureNameException("Name is null for locale " + contentDefaultLocale.getDisplayName()); }//from ww w . j av a2s . c o m if (!LanguageUtil.isAvailableLocale(contentDefaultLocale)) { Long companyId = CompanyThreadLocal.getCompanyId(); LocaleException le = new LocaleException(LocaleException.TYPE_CONTENT, StringBundler.concat("The locale ", String.valueOf(contentDefaultLocale), " is not available in company ", String.valueOf(companyId))); le.setSourceAvailableLocales(Collections.singleton(contentDefaultLocale)); le.setTargetAvailableLocales(LanguageUtil.getAvailableLocales()); throw le; } }
From source file:com.liferay.exportimport.content.processor.base.BaseTextExportImportContentProcessor.java
License:Open Source License
protected boolean isValidateLayoutReferences() throws PortalException { long companyId = CompanyThreadLocal.getCompanyId(); ExportImportServiceConfiguration exportImportServiceConfiguration = ConfigurationProviderUtil .getCompanyConfiguration(ExportImportServiceConfiguration.class, companyId); return exportImportServiceConfiguration.validateLayoutReferences(); }
From source file:com.liferay.exportimport.resources.importer.internal.messaging.ResourcesImporterHotDeployMessageListener.java
License:Open Source License
private void _importResources(Company company, ServletContext servletContext, PluginPackageProperties pluginPackageProperties, String messageResponseId) throws Exception { long companyId = CompanyThreadLocal.getCompanyId(); try {//from www . ja v a 2 s .c o m CompanyThreadLocal.setCompanyId(company.getCompanyId()); Importer importer = _importerFactory.createImporter(company.getCompanyId(), servletContext, pluginPackageProperties); if (!importer.isDeveloperModeEnabled() && importer.isExisting() && !importer.isCompanyGroup()) { if (_log.isInfoEnabled()) { _log.info( "Group or layout set prototype already exists for " + "company " + company.getWebId()); } return; } long startTime = 0; if (_log.isInfoEnabled()) { startTime = System.currentTimeMillis(); } importer.importResources(); if (_log.isInfoEnabled()) { StringBundler sb = new StringBundler(7); sb.append("Importing resources from "); sb.append(servletContext.getServletContextName()); sb.append(" to group "); sb.append(importer.getGroupId()); sb.append(" takes "); long endTime = System.currentTimeMillis() - startTime; sb.append(endTime); sb.append(" ms"); _log.info(sb.toString()); } Message message = new Message(); message.put("companyId", company.getCompanyId()); message.put("servletContextName", servletContext.getServletContextName()); message.put("targetClassName", importer.getTargetClassName()); message.put("targetClassPK", importer.getTargetClassPK()); if (Validator.isNotNull(messageResponseId)) { Map<String, Object> responseMap = new HashMap<>(); responseMap.put("groupId", importer.getTargetClassPK()); message.setPayload(responseMap); message.setResponseId(messageResponseId); } MessageBusUtil.sendMessage("liferay/resources_importer", message); } catch (ImporterException ie) { Message message = new Message(); message.put("companyId", company.getCompanyId()); message.put("error", ie.getMessage()); message.put("servletContextName", servletContext.getServletContextName()); message.put("targetClassName", pluginPackageProperties.getTargetClassName()); message.put("targetClassPK", 0); MessageBusUtil.sendMessage("liferay/resources_importer", message); } finally { CompanyThreadLocal.setCompanyId(companyId); } }
From source file:com.liferay.filesystemaccess.audit.AuditMessageBuilder.java
License:Open Source License
public static AuditMessage buildAuditMessage(String eventType, String className, long classPK, List<Attribute> attributes) { long companyId = CompanyThreadLocal.getCompanyId(); long userId = 0; if (PrincipalThreadLocal.getName() != null) { userId = GetterUtil.getLong(PrincipalThreadLocal.getName()); }/*from w w w.j ava2 s. c om*/ AuditRequestThreadLocal auditRequestThreadLocal = AuditRequestThreadLocal.getAuditThreadLocal(); long realUserId = auditRequestThreadLocal.getRealUserId(); String realUserName = PortalUtil.getUserName(realUserId, StringPool.BLANK); JSONObject additionalInfo = JSONFactoryUtil.createJSONObject(); if ((realUserId > 0) && (userId != realUserId)) { additionalInfo.put("doAsUserId", String.valueOf(userId)); additionalInfo.put("doAsUserName", PortalUtil.getUserName(userId, StringPool.BLANK)); } if (attributes != null) { additionalInfo.put("attributes", _getAttributesJSON(attributes)); } return new AuditMessage(eventType, companyId, realUserId, realUserName, className, String.valueOf(classPK), null, additionalInfo); }
From source file:com.liferay.journal.atom.JournalArticleAtomCollectionProvider.java
License:Open Source License
@Override protected Iterable<JournalArticle> doGetFeedEntries(AtomRequestContext atomRequestContext) throws Exception { List<JournalArticle> journalArticles = new ArrayList<>(); long companyId = CompanyThreadLocal.getCompanyId(); long groupId = atomRequestContext.getLongParameter("groupId"); if ((companyId <= 0) || (groupId <= 0)) { return journalArticles; }/*ww w.ja v a 2s.c o m*/ List<Long> folderIds = Collections.emptyList(); long classNameId = 0; String keywords = null; Double version = null; String ddmStructureKey = null; String ddmTemplateKey = null; Date displayDateGT = null; Date displayDateLT = new Date(); int status = WorkflowConstants.STATUS_APPROVED; Date reviewDate = null; OrderByComparator<JournalArticle> obc = new ArticleVersionComparator(); int count = _journalArticleService.searchCount(companyId, groupId, folderIds, classNameId, keywords, version, ddmStructureKey, ddmTemplateKey, displayDateGT, displayDateLT, status, reviewDate); AtomPager atomPager = new AtomPager(atomRequestContext, count); AtomUtil.saveAtomPagerInRequest(atomRequestContext, atomPager); journalArticles = _journalArticleService.search(companyId, groupId, folderIds, classNameId, keywords, version, ddmStructureKey, ddmTemplateKey, displayDateGT, displayDateLT, status, reviewDate, atomPager.getStart(), atomPager.getEnd() + 1, obc); return journalArticles; }
From source file:com.liferay.journal.exportimport.data.handler.JournalPortletDataHandler.java
License:Open Source License
@Override public boolean isPublishToLiveByDefault() { try {//ww w . j ava2 s. c o m JournalServiceConfiguration journalServiceConfiguration = ConfigurationProviderUtil .getCompanyConfiguration(JournalServiceConfiguration.class, CompanyThreadLocal.getCompanyId()); return journalServiceConfiguration.publishToLiveByDefaultEnabled(); } catch (Exception e) { _log.error(e, e); } return true; }
From source file:com.liferay.journal.search.JournalArticleIndexer.java
License:Open Source License
protected boolean isIndexAllArticleVersions() { JournalServiceConfiguration journalServiceConfiguration = null; try {//from www.j av a2 s . c o m journalServiceConfiguration = _configurationProvider .getCompanyConfiguration(JournalServiceConfiguration.class, CompanyThreadLocal.getCompanyId()); return journalServiceConfiguration.indexAllArticleVersionsEnabled(); } catch (Exception e) { _log.error(e, e); } return false; }