All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.liferay.change.tracking.internal.CTCollectionIdSupplierImpl Maven / Gradle / Ivy

There is a newer version: 3.0.108
Show newest version
/**
 * SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
 * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
 */

package com.liferay.change.tracking.internal;

import com.liferay.change.tracking.constants.CTConstants;
import com.liferay.change.tracking.model.CTPreferences;
import com.liferay.change.tracking.service.CTPreferencesLocalService;
import com.liferay.portal.kernel.change.tracking.CTCollectionIdSupplier;
import com.liferay.portal.kernel.model.CompanyConstants;
import com.liferay.portal.kernel.model.UserConstants;
import com.liferay.portal.kernel.security.auth.CompanyThreadLocal;
import com.liferay.portal.kernel.security.auth.PrincipalThreadLocal;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

/**
 * @author Preston Crary
 */
@Component(service = CTCollectionIdSupplier.class)
public class CTCollectionIdSupplierImpl implements CTCollectionIdSupplier {

	@Override
	public long getCTCollectionId() {
		long ctCollectionId =
			CTCollectionPreviewThreadLocal.getCTCollectionId();

		if (ctCollectionId > -1) {
			return ctCollectionId;
		}

		long companyId = CompanyThreadLocal.getCompanyId();

		long userId = PrincipalThreadLocal.getUserId();

		if ((companyId == CompanyConstants.SYSTEM) &&
			(userId == UserConstants.USER_ID_DEFAULT)) {

			return CTConstants.CT_COLLECTION_ID_PRODUCTION;
		}

		CTPreferences ctPreferences =
			_ctPreferencesLocalService.fetchCTPreferences(companyId, userId);

		if (ctPreferences == null) {
			return CTConstants.CT_COLLECTION_ID_PRODUCTION;
		}

		return ctPreferences.getCtCollectionId();
	}

	@Reference
	private CTPreferencesLocalService _ctPreferencesLocalService;

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy