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

com.liferay.commerce.bom.model.impl.CommerceBOMFolderImpl Maven / Gradle / Ivy

There is a newer version: 5.0.3
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.commerce.bom.model.impl;

import com.liferay.commerce.bom.constants.CommerceBOMFolderConstants;
import com.liferay.commerce.bom.model.CommerceBOMFolder;
import com.liferay.commerce.bom.service.CommerceBOMFolderLocalServiceUtil;
import com.liferay.portal.kernel.exception.PortalException;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Alessio Antonio Rendina
 */
public class CommerceBOMFolderImpl extends CommerceBOMFolderBaseImpl {

	public CommerceBOMFolderImpl() {
	}

	@Override
	public List getAncestorCommerceBOMFolderIds() throws PortalException {
		List ancestorFolderIds = new ArrayList<>();

		CommerceBOMFolder commerceBOMFolder = this;

		while (!commerceBOMFolder.isRoot()) {
			commerceBOMFolder = commerceBOMFolder.getParentCommerceBOMFolder();

			ancestorFolderIds.add(commerceBOMFolder.getCommerceBOMFolderId());
		}

		return ancestorFolderIds;
	}

	@Override
	public List getAncestors() throws PortalException {
		List ancestors = new ArrayList<>();

		CommerceBOMFolder commerceBOMFolder = this;

		while (!commerceBOMFolder.isRoot()) {
			commerceBOMFolder = commerceBOMFolder.getParentCommerceBOMFolder();

			ancestors.add(commerceBOMFolder);
		}

		return ancestors;
	}

	@Override
	public CommerceBOMFolder getParentCommerceBOMFolder()
		throws PortalException {

		if (getParentCommerceBOMFolderId() ==
				CommerceBOMFolderConstants.DEFAULT_COMMERCE_BOM_FOLDER_ID) {

			return null;
		}

		return CommerceBOMFolderLocalServiceUtil.getCommerceBOMFolder(
			getParentCommerceBOMFolderId());
	}

	@Override
	public boolean isRoot() {
		if (getParentCommerceBOMFolderId() ==
				CommerceBOMFolderConstants.DEFAULT_COMMERCE_BOM_FOLDER_ID) {

			return true;
		}

		return false;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy