001
014
015 package com.liferay.portal.security.auth;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019 import com.liferay.portal.kernel.util.AutoResetThreadLocal;
020 import com.liferay.portal.kernel.util.LocaleThreadLocal;
021 import com.liferay.portal.kernel.util.TimeZoneThreadLocal;
022 import com.liferay.portal.model.Company;
023 import com.liferay.portal.model.CompanyConstants;
024 import com.liferay.portal.service.CompanyLocalServiceUtil;
025
026
029 public class CompanyThreadLocal {
030
031 public static Long getCompanyId() {
032 Long companyId = _companyId.get();
033
034 if (_log.isDebugEnabled()) {
035 _log.debug("getCompanyId " + companyId);
036 }
037
038 return companyId;
039 }
040
041 public static boolean isDeleteInProcess() {
042 return _deleteInProcess.get();
043 }
044
045 public static void setCompanyId(Long companyId) {
046 if (_log.isDebugEnabled()) {
047 _log.debug("setCompanyId " + companyId);
048 }
049
050 if (companyId > 0) {
051 _companyId.set(companyId);
052
053 try {
054 Company company = CompanyLocalServiceUtil.getCompany(companyId);
055
056 LocaleThreadLocal.setDefaultLocale(company.getLocale());
057 TimeZoneThreadLocal.setDefaultTimeZone(company.getTimeZone());
058 }
059 catch (Exception e) {
060 _log.error(e, e);
061 }
062 }
063 else {
064 _companyId.set(CompanyConstants.SYSTEM);
065
066 LocaleThreadLocal.setDefaultLocale(null);
067 TimeZoneThreadLocal.setDefaultTimeZone(null);
068 }
069 }
070
071 public static void setDeleteInProcess(boolean deleteInProcess) {
072 _deleteInProcess.set(deleteInProcess);
073 }
074
075 private static final Log _log = LogFactoryUtil.getLog(
076 CompanyThreadLocal.class);
077
078 private static final ThreadLocal<Long> _companyId =
079 new AutoResetThreadLocal<>(
080 CompanyThreadLocal.class + "._companyId", CompanyConstants.SYSTEM);
081 private static final ThreadLocal<Boolean> _deleteInProcess =
082 new AutoResetThreadLocal<>(
083 CompanyThreadLocal.class + "._deleteInProcess", false);
084
085 }