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