com.liferay.commerce.service.impl.CPDefinitionInventoryServiceImpl Maven / Gradle / Ivy
/**
* 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.service.impl;
import com.liferay.commerce.model.CPDefinitionInventory;
import com.liferay.commerce.product.exception.NoSuchCPDefinitionException;
import com.liferay.commerce.product.model.CPDefinition;
import com.liferay.commerce.product.model.CommerceCatalog;
import com.liferay.commerce.product.service.CPDefinitionLocalService;
import com.liferay.commerce.product.service.CommerceCatalogLocalService;
import com.liferay.commerce.service.base.CPDefinitionInventoryServiceBaseImpl;
import com.liferay.portal.aop.AopService;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.security.permission.ActionKeys;
import com.liferay.portal.kernel.security.permission.resource.ModelResourcePermission;
import java.math.BigDecimal;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
/**
* @author Alessio Antonio Rendina
*/
@Component(
property = {
"json.web.service.context.name=commerce",
"json.web.service.context.path=CPDefinitionInventory"
},
service = AopService.class
)
public class CPDefinitionInventoryServiceImpl
extends CPDefinitionInventoryServiceBaseImpl {
@Override
public CPDefinitionInventory addCPDefinitionInventory(
long cpDefinitionId, String cpDefinitionInventoryEngine,
String lowStockActivity, boolean displayAvailability,
boolean displayStockQuantity, BigDecimal minStockQuantity,
boolean backOrders, BigDecimal minOrderQuantity,
BigDecimal maxOrderQuantity, String allowedOrderQuantities,
BigDecimal multipleOrderQuantity)
throws PortalException {
_checkCommerceCatalog(cpDefinitionId, ActionKeys.UPDATE);
return cpDefinitionInventoryLocalService.addCPDefinitionInventory(
getUserId(), cpDefinitionId, cpDefinitionInventoryEngine,
lowStockActivity, displayAvailability, displayStockQuantity,
minStockQuantity, backOrders, minOrderQuantity, maxOrderQuantity,
allowedOrderQuantities, multipleOrderQuantity);
}
@Override
public void deleteCPDefinitionInventory(long cpDefinitionInventoryId)
throws PortalException {
CPDefinitionInventory cpDefinitionInventory =
cpDefinitionInventoryLocalService.getCPDefinitionInventory(
cpDefinitionInventoryId);
_checkCommerceCatalog(
cpDefinitionInventory.getCPDefinitionId(), ActionKeys.UPDATE);
cpDefinitionInventoryLocalService.deleteCPDefinitionInventory(
cpDefinitionInventoryId);
}
@Override
public CPDefinitionInventory fetchCPDefinitionInventoryByCPDefinitionId(
long cpDefinitionId)
throws PortalException {
CPDefinitionInventory cpDefinitionInventory =
cpDefinitionInventoryLocalService.
fetchCPDefinitionInventoryByCPDefinitionId(cpDefinitionId);
if (cpDefinitionInventory != null) {
_checkCommerceCatalog(
cpDefinitionInventory.getCPDefinitionId(), ActionKeys.UPDATE);
}
return cpDefinitionInventory;
}
@Override
public CPDefinitionInventory updateCPDefinitionInventory(
long cpDefinitionInventoryId, String cpDefinitionInventoryEngine,
String lowStockActivity, boolean displayAvailability,
boolean displayStockQuantity, BigDecimal minStockQuantity,
boolean backOrders, BigDecimal minOrderQuantity,
BigDecimal maxOrderQuantity, String allowedOrderQuantities,
BigDecimal multipleOrderQuantity)
throws PortalException {
CPDefinitionInventory cpDefinitionInventory =
cpDefinitionInventoryLocalService.getCPDefinitionInventory(
cpDefinitionInventoryId);
_checkCommerceCatalog(
cpDefinitionInventory.getCPDefinitionId(), ActionKeys.UPDATE);
return cpDefinitionInventoryLocalService.updateCPDefinitionInventory(
cpDefinitionInventoryId, cpDefinitionInventoryEngine,
lowStockActivity, displayAvailability, displayStockQuantity,
minStockQuantity, backOrders, minOrderQuantity, maxOrderQuantity,
allowedOrderQuantities, multipleOrderQuantity);
}
private void _checkCommerceCatalog(long cpDefinitionId, String actionId)
throws PortalException {
CPDefinition cpDefinition = _cpDefinitionLocalService.fetchCPDefinition(
cpDefinitionId);
if (cpDefinition == null) {
throw new NoSuchCPDefinitionException();
}
CommerceCatalog commerceCatalog =
_commerceCatalogLocalService.fetchCommerceCatalogByGroupId(
cpDefinition.getGroupId());
_commerceCatalogModelResourcePermission.check(
getPermissionChecker(), commerceCatalog, actionId);
}
@Reference
private CommerceCatalogLocalService _commerceCatalogLocalService;
@Reference(
target = "(model.class.name=com.liferay.commerce.product.model.CommerceCatalog)"
)
private ModelResourcePermission
_commerceCatalogModelResourcePermission;
@Reference
private CPDefinitionLocalService _cpDefinitionLocalService;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy