use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class OrderFacadeImpl method getReadableOrderHistory.
@Override
public List<ReadableOrderStatusHistory> getReadableOrderHistory(Long orderId, MerchantStore store, Language language) {
Order order = orderService.getOrder(orderId, store);
if (order == null) {
throw new ResourceNotFoundException("Order id [" + orderId + "] not found for merchand [" + store.getId() + "]");
}
Set<OrderStatusHistory> historyList = order.getOrderHistory();
List<ReadableOrderStatusHistory> returnList = historyList.stream().map(f -> mapToReadbleOrderStatusHistory(f)).collect(Collectors.toList());
return returnList;
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException 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.ResourceNotFoundException 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.ResourceNotFoundException 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.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ShippingConfigurationApi method configure.
@PostMapping(value = "/private/modules/shipping")
public void configure(@RequestBody IntegrationModuleConfiguration configuration, @ApiIgnore MerchantStore merchantStore) {
try {
List<IntegrationModule> modules = shippingService.getShippingMethods(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("Shipping module [" + configuration.getCode() + "] not found");
}
Map<String, IntegrationConfiguration> configuredModules = shippingService.getShippingModulesConfigured(merchantStore);
IntegrationConfiguration integrationConfiguration = configuredModules.get(configuration.getCode());
if (integrationConfiguration == null) {
integrationConfiguration = new IntegrationConfiguration();
}
/**
* Build return object for now this is a read copy
*/
integrationConfiguration.setActive(configuration.isActive());
integrationConfiguration.setDefaultSelected(configuration.isDefaultSelected());
integrationConfiguration.setIntegrationKeys(configuration.getIntegrationKeys());
integrationConfiguration.setIntegrationOptions(configuration.getIntegrationOptions());
shippingService.saveShippingQuoteModuleConfiguration(integrationConfiguration, merchantStore);
} catch (ServiceException e) {
LOGGER.error("Error saving shipping modules", e);
throw new ServiceRuntimeException("Error saving shipping module", e);
}
}
Aggregations