use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException 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.ServiceRuntimeException 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");
}
}
use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class ShippingConfigurationApi method shippingModule.
/**
* Get merchant shipping module details
*
* @param code
* @param merchantStore
* @param language
* @return
*/
@GetMapping("/private/modules/shipping/{code}")
@ApiOperation(httpMethod = "GET", value = "Shipping module by code", produces = "application/json", response = List.class)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT") })
public IntegrationConfiguration shippingModule(@PathVariable String code, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {
try {
// configured modules
List<IntegrationModule> modules = shippingService.getShippingMethods(merchantStore);
// check if exist
Optional<IntegrationModule> checkIfExist = modules.stream().filter(m -> m.getCode().equals(code)).findAny();
if (!checkIfExist.isPresent()) {
throw new ResourceNotFoundException("Shipping module [" + code + "] not found");
}
IntegrationConfiguration config = shippingService.getShippingConfiguration(code, merchantStore);
if (config == null) {
config = new IntegrationConfiguration();
}
/**
* Build return object for now this is a read copy
*/
config.setActive(config.isActive());
config.setDefaultSelected(config.isDefaultSelected());
config.setIntegrationKeys(config.getIntegrationKeys());
config.setIntegrationOptions(config.getIntegrationOptions());
return config;
} catch (ServiceException e) {
LOGGER.error("Error getting shipping module [" + code + "]", e);
throw new ServiceRuntimeException("Error getting shipping module [" + code + "]", e);
}
}
use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class OrderFacadeImpl method updateOrderCustomre.
@Override
public void updateOrderCustomre(Long orderId, PersistableCustomer customer, MerchantStore store) {
try {
// get order by order id
Order modelOrder = orderService.getOrder(orderId, store);
if (modelOrder == null) {
throw new ResourceNotFoundException("Order id [" + orderId + "] not found for store [" + store.getCode() + "]");
}
// set customer information
modelOrder.setCustomerEmailAddress(customer.getEmailAddress());
modelOrder.setBilling(this.convertBilling(customer.getBilling()));
modelOrder.setDelivery(this.convertDelivery(customer.getDelivery()));
orderService.saveOrUpdate(modelOrder);
} catch (Exception e) {
throw new ServiceRuntimeException("An error occured while updating order customer", e);
}
}
use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class OrderFacadeImpl method listTransactions.
@Override
public List<ReadableTransaction> listTransactions(Long orderId, MerchantStore store) {
Validate.notNull(orderId, "orderId must not be null");
Validate.notNull(store, "MerchantStore must not be null");
List<ReadableTransaction> trx = new ArrayList<ReadableTransaction>();
try {
Order modelOrder = orderService.getOrder(orderId, store);
if (modelOrder == null) {
throw new ResourceNotFoundException("Order id [" + orderId + "] not found for store [" + store.getCode() + "]");
}
List<Transaction> transactions = transactionService.listTransactions(modelOrder);
ReadableTransaction transaction = null;
ReadableTransactionPopulator trxPopulator = null;
for (Transaction tr : transactions) {
transaction = new ReadableTransaction();
trxPopulator = new ReadableTransactionPopulator();
trxPopulator.setOrderService(orderService);
trxPopulator.setPricingService(pricingService);
trxPopulator.populate(tr, transaction, store, store.getDefaultLanguage());
trx.add(transaction);
}
return trx;
} catch (Exception e) {
LOGGER.error("Error while getting transactions for order [" + orderId + "] and store code [" + store.getCode() + "]");
throw new ServiceRuntimeException("Error while getting transactions for order [" + orderId + "] and store code [" + store.getCode() + "]");
}
}
Aggregations