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(int companyId) {
046 setCompanyId(Long.valueOf(companyId));
047 }
048
049 public static void setCompanyId(Long companyId) {
050 if (_log.isDebugEnabled()) {
051 _log.debug("setCompanyId " + companyId);
052 }
053
054 if (companyId > 0) {
055 try {
056 Company company = CompanyLocalServiceUtil.getCompany(companyId);
057
058 LocaleThreadLocal.setDefaultLocale(company.getLocale());
059 TimeZoneThreadLocal.setDefaultTimeZone(company.getTimeZone());
060 }
061 catch (Exception e) {
062 _log.error(e, e);
063 }
064
065 _companyId.set(companyId);
066 }
067 else {
068 LocaleThreadLocal.setDefaultLocale(null);
069 TimeZoneThreadLocal.setDefaultTimeZone(null);
070
071 _companyId.set(CompanyConstants.SYSTEM);
072 }
073 }
074
075 public static void setDeleteInProcess(boolean deleteInProcess) {
076 _deleteInProcess.set(deleteInProcess);
077 }
078
079 private static Log _log = LogFactoryUtil.getLog(CompanyThreadLocal.class);
080
081 private static ThreadLocal<Long> _companyId =
082 new AutoResetThreadLocal<Long>(
083 CompanyThreadLocal.class + "._companyId", CompanyConstants.SYSTEM);
084 private static ThreadLocal<Boolean> _deleteInProcess =
085 new AutoResetThreadLocal<Boolean>(
086 CompanyThreadLocal.class + "._deleteInProcess", false);
087
088 }