com.liferay.commerce.service.impl.CPDefinitionInventoryServiceImpl Maven / Gradle / Ivy
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
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.kernel.exception.PortalException;
import com.liferay.portal.kernel.security.permission.ActionKeys;
import com.liferay.portal.kernel.security.permission.resource.ModelResourcePermission;
import com.liferay.portal.kernel.security.permission.resource.ModelResourcePermissionFactory;
import com.liferay.portal.spring.extender.service.ServiceReference;
/**
* @author Alessio Antonio Rendina
*/
public class CPDefinitionInventoryServiceImpl
extends CPDefinitionInventoryServiceBaseImpl {
@Override
public CPDefinitionInventory addCPDefinitionInventory(
long userId, long cpDefinitionId,
String cpDefinitionInventoryEngine, String lowStockActivity,
boolean displayAvailability, boolean displayStockQuantity,
int minStockQuantity, boolean backOrders, int minOrderQuantity,
int maxOrderQuantity, String allowedOrderQuantities,
int multipleOrderQuantity)
throws PortalException {
_checkCommerceCatalogPermissionByCPDefinitionId(
cpDefinitionId, ActionKeys.UPDATE);
return cpDefinitionInventoryLocalService.addCPDefinitionInventory(
userId, cpDefinitionId, cpDefinitionInventoryEngine,
lowStockActivity, displayAvailability, displayStockQuantity,
minStockQuantity, backOrders, minOrderQuantity, maxOrderQuantity,
allowedOrderQuantities, multipleOrderQuantity);
}
@Override
public void deleteCPDefinitionInventory(long cpDefinitionInventoryId)
throws PortalException {
CPDefinitionInventory cpDefinitionInventory =
cpDefinitionInventoryLocalService.getCPDefinitionInventory(
cpDefinitionInventoryId);
_checkCommerceCatalogPermissionByCPDefinitionId(
cpDefinitionInventory.getCPDefinitionId(), ActionKeys.UPDATE);
cpDefinitionInventoryLocalService.deleteCPDefinitionInventory(
cpDefinitionInventoryId);
}
@Override
public CPDefinitionInventory fetchCPDefinitionInventoryByCPDefinitionId(
long cpDefinitionId)
throws PortalException {
CPDefinitionInventory cpDefinitionInventory =
cpDefinitionInventoryLocalService.
fetchCPDefinitionInventoryByCPDefinitionId(cpDefinitionId);
if (cpDefinitionInventory != null) {
_checkCommerceCatalogPermissionByCPDefinitionId(
cpDefinitionInventory.getCPDefinitionId(), ActionKeys.UPDATE);
}
return cpDefinitionInventory;
}
/**
* @deprecated As of Athanasius (7.3.x)
*/
@Deprecated
@Override
public CPDefinitionInventory updateCPDefinitionInventory(
long groupId, long cpDefinitionInventoryId,
String cpDefinitionInventoryEngine, String lowStockActivity,
boolean displayAvailability, boolean displayStockQuantity,
int minStockQuantity, boolean backOrders, int minOrderQuantity,
int maxOrderQuantity, String allowedOrderQuantities,
int multipleOrderQuantity)
throws PortalException {
CPDefinitionInventory cpDefinitionInventory =
cpDefinitionInventoryLocalService.getCPDefinitionInventory(
cpDefinitionInventoryId);
_checkCommerceCatalogPermissionByCPDefinitionId(
cpDefinitionInventory.getCPDefinitionId(), ActionKeys.UPDATE);
return cpDefinitionInventoryLocalService.updateCPDefinitionInventory(
cpDefinitionInventoryId, cpDefinitionInventoryEngine,
lowStockActivity, displayAvailability, displayStockQuantity,
minStockQuantity, backOrders, minOrderQuantity, maxOrderQuantity,
allowedOrderQuantities, multipleOrderQuantity);
}
@Override
public CPDefinitionInventory updateCPDefinitionInventory(
long cpDefinitionInventoryId, String cpDefinitionInventoryEngine,
String lowStockActivity, boolean displayAvailability,
boolean displayStockQuantity, int minStockQuantity,
boolean backOrders, int minOrderQuantity, int maxOrderQuantity,
String allowedOrderQuantities, int multipleOrderQuantity)
throws PortalException {
CPDefinitionInventory cpDefinitionInventory =
cpDefinitionInventoryLocalService.getCPDefinitionInventory(
cpDefinitionInventoryId);
_checkCommerceCatalogPermissionByCPDefinitionId(
cpDefinitionInventory.getCPDefinitionId(), ActionKeys.UPDATE);
return cpDefinitionInventoryLocalService.updateCPDefinitionInventory(
cpDefinitionInventoryId, cpDefinitionInventoryEngine,
lowStockActivity, displayAvailability, displayStockQuantity,
minStockQuantity, backOrders, minOrderQuantity, maxOrderQuantity,
allowedOrderQuantities, multipleOrderQuantity);
}
private void _checkCommerceCatalogPermissionByCPDefinitionId(
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);
}
private static volatile ModelResourcePermission
_commerceCatalogModelResourcePermission =
ModelResourcePermissionFactory.getInstance(
CPDefinitionInventoryServiceImpl.class,
"_commerceCatalogModelResourcePermission",
CommerceCatalog.class);
@ServiceReference(type = CommerceCatalogLocalService.class)
private CommerceCatalogLocalService _commerceCatalogLocalService;
@ServiceReference(type = CPDefinitionLocalService.class)
private CPDefinitionLocalService _cpDefinitionLocalService;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy