use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class PaymentApi method configure.
@PostMapping(value = "/private/modules/payment")
public void configure(@RequestBody IntegrationModuleConfiguration configuration, @ApiIgnore MerchantStore merchantStore) {
try {
List<IntegrationModule> modules = paymentService.getPaymentMethods(merchantStore);
Map<String, IntegrationModule> map = modules.stream().collect(Collectors.toMap(IntegrationModule::getCode, module -> module));
IntegrationModule config = map.get(configuration.getCode());
if (config == null) {
throw new ResourceNotFoundException("Payment module [" + configuration.getCode() + "] not found");
}
Map<String, IntegrationConfiguration> configuredModules = paymentService.getPaymentModulesConfigured(merchantStore);
IntegrationConfiguration integrationConfiguration = configuredModules.get(configuration.getCode());
if (integrationConfiguration == null) {
integrationConfiguration = new IntegrationConfiguration();
integrationConfiguration.setModuleCode(configuration.getCode());
}
integrationConfiguration.setActive(configuration.isActive());
integrationConfiguration.setDefaultSelected(configuration.isDefaultSelected());
integrationConfiguration.setIntegrationKeys(configuration.getIntegrationKeys());
integrationConfiguration.setIntegrationOptions(configuration.getIntegrationOptions());
paymentService.savePaymentModuleConfiguration(integrationConfiguration, merchantStore);
} catch (ServiceException e) {
LOGGER.error("Error getting payment modules", e);
throw new ServiceRuntimeException("Error saving payment module", e);
}
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ProductApi method changeProductOrder.
/**
* Change product sort order
*
* @param id
* @param position
* @param merchantStore
* @param language
* @throws IOException
*/
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = { "/private/product/{id}", "/auth/product/{id}" }, method = RequestMethod.PATCH)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
@ApiOperation(httpMethod = "POST", value = "Patch product sort order", notes = "Change product sortOrder")
public void changeProductOrder(@PathVariable Long id, @RequestParam(value = "order", required = false, defaultValue = "0") Integer position, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) throws IOException {
try {
Product p = productService.getById(id);
if (p == null) {
throw new ResourceNotFoundException("Product [" + id + "] not found for merchant [" + merchantStore.getCode() + "]");
}
if (p.getMerchantStore().getId() != merchantStore.getId()) {
throw new ResourceNotFoundException("Product [" + id + "] not found for merchant [" + merchantStore.getCode() + "]");
}
/**
* Change order
*/
p.setSortOrder(position);
} catch (Exception e) {
LOGGER.error("Error while updating Product position", e);
throw new ServiceRuntimeException("Product [" + id + "] cannot be edited");
}
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ProductApi method addProductToCategory.
@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(value = { "/private/product/{productId}/category/{categoryId}", "/auth/product/{productId}/category/{categoryId}" }, method = RequestMethod.POST)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
@ResponseBody
public ReadableProduct addProductToCategory(@PathVariable Long productId, @PathVariable Long categoryId, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletResponse response) throws Exception {
try {
// get the product
Product product = productService.getById(productId);
if (product == null) {
throw new ResourceNotFoundException("Product id [" + productId + "] is not found");
}
if (product.getMerchantStore().getId().intValue() != merchantStore.getId().intValue()) {
throw new UnauthorizedException("Product id [" + productId + "] does not belong to store [" + merchantStore.getCode() + "]");
}
Category category = categoryService.getById(categoryId);
if (category == null) {
throw new ResourceNotFoundException("Category id [" + categoryId + "] is not found");
}
if (category.getMerchantStore().getId().intValue() != merchantStore.getId().intValue()) {
throw new UnauthorizedException("Category id [" + categoryId + "] does not belong to store [" + merchantStore.getCode() + "]");
}
return productCommonFacade.addProductToCategory(category, product, language);
} catch (Exception e) {
LOGGER.error("Error while adding product to category", e);
try {
response.sendError(503, "Error while adding product to category " + e.getMessage());
} catch (Exception ignore) {
}
return null;
}
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ProductApi method removeProductFromCategory.
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = { "/private/product/{productId}/category/{categoryId}", "/auth/product/{productId}/category/{categoryId}" }, method = RequestMethod.DELETE)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
@ResponseBody
public ReadableProduct removeProductFromCategory(@PathVariable Long productId, @PathVariable Long categoryId, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletResponse response) {
try {
Product product = productService.getById(productId);
if (product == null) {
throw new ResourceNotFoundException("Product id [" + productId + "] is not found");
}
if (product.getMerchantStore().getId().intValue() != merchantStore.getId().intValue()) {
throw new UnauthorizedException("Product id [" + productId + "] does not belong to store [" + merchantStore.getCode() + "]");
}
Category category = categoryService.getById(categoryId);
if (category == null) {
throw new ResourceNotFoundException("Category id [" + categoryId + "] is not found");
}
if (category.getMerchantStore().getId().intValue() != merchantStore.getId().intValue()) {
throw new UnauthorizedException("Category id [" + categoryId + "] does not belong to store [" + merchantStore.getCode() + "]");
}
return productCommonFacade.removeProductFromCategory(category, product, language);
} catch (Exception e) {
LOGGER.error("Error while removing product from category", e);
try {
response.sendError(503, "Error while removing product from category " + e.getMessage());
} catch (Exception ignore) {
}
return null;
}
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ProductImageApi method imageDetails.
/**
* Patch image (change position)
*
* @param id
* @param files
* @param position
* @param merchantStore
* @param language
* @throws IOException
*/
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = { "/private/products/{id}/image/{imageId}", "/auth/products/{id}/image/{id}" }, method = RequestMethod.PATCH)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public void imageDetails(@PathVariable Long id, @PathVariable Long imageId, @RequestParam(value = "order", required = false, defaultValue = "0") Integer position, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) throws IOException {
try {
Product p = productService.getById(id);
if (p == null) {
throw new ResourceNotFoundException("Product image [" + imageId + "] not found for product id [" + id + "] and merchant [" + merchantStore.getCode() + "]");
}
if (p.getMerchantStore().getId() != merchantStore.getId()) {
throw new ResourceNotFoundException("Product image [" + imageId + "] not found for product id [" + id + "] and merchant [" + merchantStore.getCode() + "]");
}
Optional<ProductImage> productImage = productImageService.getProductImage(imageId, id, merchantStore);
if (productImage.isPresent()) {
productImage.get().setSortOrder(position);
productImageService.updateProductImage(p, productImage.get());
} else {
throw new ResourceNotFoundException("Product image [" + imageId + "] not found for product id [" + id + "] and merchant [" + merchantStore.getCode() + "]");
}
} catch (Exception e) {
LOGGER.error("Error while deleting ProductImage", e);
throw new ServiceRuntimeException("ProductImage [" + imageId + "] cannot be edited");
}
}
Aggregations