use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class OrderFacadeImpl method nextTransaction.
@Override
public TransactionType nextTransaction(Long orderId, MerchantStore store) {
try {
Order modelOrder = orderService.getOrder(orderId, store);
if (modelOrder == null) {
throw new ResourceNotFoundException("Order id [" + orderId + "] not found for store [" + store.getCode() + "]");
}
Transaction last = transactionService.lastTransaction(modelOrder, store);
if (last.getTransactionType().name().equals(TransactionType.AUTHORIZE.name())) {
return TransactionType.CAPTURE;
} else if (last.getTransactionType().name().equals(TransactionType.AUTHORIZECAPTURE.name())) {
return TransactionType.REFUND;
} else if (last.getTransactionType().name().equals(TransactionType.CAPTURE.name())) {
return TransactionType.REFUND;
} else if (last.getTransactionType().name().equals(TransactionType.REFUND.name())) {
return TransactionType.OK;
} else {
return TransactionType.OK;
}
} catch (Exception e) {
throw new ServiceRuntimeException("Error while getting last transaction for order [" + orderId + "]", e);
}
}
use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class OrderFacadeImpl method createOrderStatus.
@Override
public void createOrderStatus(PersistableOrderStatusHistory status, Long id, MerchantStore store) {
Validate.notNull(status, "OrderStatusHistory must not be null");
Validate.notNull(id, "Order id must not be null");
Validate.notNull(store, "MerchantStore must not be null");
// retrieve original order
Order order = orderService.getOrder(id, store);
if (order == null) {
throw new ResourceNotFoundException("Order with id [" + id + "] does not exist for merchant [" + store.getCode() + "]");
}
try {
OrderStatusHistory history = new OrderStatusHistory();
history.setComments(status.getComments());
history.setDateAdded(DateUtil.getDate(status.getDate()));
history.setOrder(order);
history.setStatus(status.getStatus());
orderService.addOrderStatusHistory(order, history);
} catch (Exception e) {
throw new ServiceRuntimeException("An error occured while converting orderstatushistory", e);
}
}
use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class OrderFacadeImpl method getReadableOrder.
@Override
public com.salesmanager.shop.model.order.v0.ReadableOrder getReadableOrder(Long orderId, MerchantStore store, Language language) {
Validate.notNull(store, "MerchantStore cannot be null");
Order modelOrder = orderService.getOrder(orderId, store);
if (modelOrder == null) {
throw new ResourceNotFoundException("Order not found with id " + orderId);
}
com.salesmanager.shop.model.order.v0.ReadableOrder readableOrder = new com.salesmanager.shop.model.order.v0.ReadableOrder();
Long customerId = modelOrder.getCustomerId();
if (customerId != null) {
ReadableCustomer readableCustomer = customerFacade.getCustomerById(customerId, store, language);
if (readableCustomer == null) {
LOGGER.warn("Customer id " + customerId + " not found in order " + orderId);
} else {
readableOrder.setCustomer(readableCustomer);
}
}
try {
readableOrderPopulator.populate(modelOrder, readableOrder, store, language);
// order products
List<ReadableOrderProduct> orderProducts = new ArrayList<ReadableOrderProduct>();
for (OrderProduct p : modelOrder.getOrderProducts()) {
ReadableOrderProductPopulator orderProductPopulator = new ReadableOrderProductPopulator();
orderProductPopulator.setProductService(productService);
orderProductPopulator.setPricingService(pricingService);
orderProductPopulator.setimageUtils(imageUtils);
ReadableOrderProduct orderProduct = new ReadableOrderProduct();
orderProductPopulator.populate(p, orderProduct, store, language);
orderProducts.add(orderProduct);
}
readableOrder.setProducts(orderProducts);
} catch (Exception e) {
throw new ServiceRuntimeException("Error while getting order [" + orderId + "]");
}
return readableOrder;
}
use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class SecurityApi method listPermissions.
@ResponseStatus(HttpStatus.OK)
@GetMapping({ "/private/{group}/permissions" })
@ApiOperation(httpMethod = "GET", value = "Get permissions by group", notes = "", produces = MediaType.APPLICATION_JSON_VALUE, response = List.class)
public List<ReadablePermission> listPermissions(@PathVariable String group) {
Group g = null;
try {
g = groupService.findByName(group);
if (g == null) {
throw new ResourceNotFoundException("Group [" + group + "] does not exist");
}
} catch (Exception e) {
LOGGER.error("An error occured while getting group [" + group + "]", e);
throw new ServiceRuntimeException("An error occured while getting group [" + group + "]");
}
Set<Permission> permissions = g.getPermissions();
List<ReadablePermission> readablePermissions = new ArrayList<ReadablePermission>();
for (Permission permission : permissions) {
ReadablePermission readablePermission = new ReadablePermission();
readablePermission.setName(permission.getPermissionName());
readablePermission.setId(permission.getId());
readablePermissions.add(readablePermission);
}
return readablePermissions;
}
use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class ShippingConfigurationApi method shippingModules.
/**
* Get available shipping modules
*
* @param merchantStore
* @param language
* @return
*/
@GetMapping("/private/modules/shipping")
@ApiOperation(httpMethod = "GET", value = "List list of shipping modules", notes = "Requires administration access", produces = "application/json", response = List.class)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT") })
public List<IntegrationModuleSummaryEntity> shippingModules(@ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {
try {
List<IntegrationModule> modules = shippingService.getShippingMethods(merchantStore);
// configured modules
Map<String, IntegrationConfiguration> configuredModules = shippingService.getShippingModulesConfigured(merchantStore);
return modules.stream().map(m -> integrationModule(m, configuredModules)).collect(Collectors.toList());
} catch (ServiceException e) {
LOGGER.error("Error getting shipping modules", e);
throw new ServiceRuntimeException("Error getting shipping modules", e);
}
}
Aggregations