use of com.salesmanager.shop.model.order.v0.ReadableOrder in project shopizer by shopizer-ecommerce.
the class CustomerOrdersController method orderDetails.
@PreAuthorize("hasRole('AUTH_CUSTOMER')")
@RequestMapping(value = "/order.html", method = { RequestMethod.GET, RequestMethod.POST })
public String orderDetails(final Model model, final HttpServletRequest request, @RequestParam(value = "orderId", required = true) final String orderId) throws Exception {
MerchantStore store = getSessionAttribute(Constants.MERCHANT_STORE, request);
Language language = (Language) request.getAttribute(Constants.LANGUAGE);
if (StringUtils.isBlank(orderId)) {
LOGGER.error("Order Id can not be null or empty");
}
LOGGER.info("Fetching order details for Id " + orderId);
// get order id
Long lOrderId = null;
try {
lOrderId = Long.parseLong(orderId);
} catch (NumberFormatException nfe) {
LOGGER.error("Cannot parse orderId to long " + orderId);
return "redirect:/" + Constants.SHOP_URI;
}
// check if order belongs to customer logged in
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
Customer customer = null;
if (auth != null && request.isUserInRole("AUTH_CUSTOMER")) {
customer = customerFacade.getCustomerByUserName(auth.getName(), store);
}
if (customer == null) {
return "redirect:/" + Constants.SHOP_URI;
}
ReadableOrder order = orderFacade.getReadableOrder(lOrderId, store, customer.getDefaultLanguage());
model.addAttribute("order", order);
// check if any downloads exist for this order
List<OrderProductDownload> orderProductDownloads = orderProdctDownloadService.getByOrderId(order.getId());
if (CollectionUtils.isNotEmpty(orderProductDownloads)) {
ReadableOrderProductDownloadPopulator populator = new ReadableOrderProductDownloadPopulator();
List<ReadableOrderProductDownload> downloads = new ArrayList<ReadableOrderProductDownload>();
for (OrderProductDownload download : orderProductDownloads) {
ReadableOrderProductDownload view = new ReadableOrderProductDownload();
populator.populate(download, view, store, language);
downloads.add(view);
}
model.addAttribute("downloads", downloads);
}
StringBuilder template = new StringBuilder().append(ControllerConstants.Tiles.Customer.customerOrder).append(".").append(store.getStoreTemplate());
return template.toString();
}
use of com.salesmanager.shop.model.order.v0.ReadableOrder in project shopizer by shopizer-ecommerce.
the class OrderApi method get.
/**
* Order details
* @param id
* @param merchantStore
* @param language
* @return
*/
@RequestMapping(value = { "/private/orders/{id}" }, method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "string", defaultValue = "en") })
public ReadableOrder get(@PathVariable final Long id, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {
String user = authorizationUtils.authenticatedUser();
authorizationUtils.authorizeUser(user, Stream.of(Constants.GROUP_SUPERADMIN, Constants.GROUP_ADMIN, Constants.GROUP_ADMIN_ORDER, Constants.GROUP_ADMIN_RETAIL).collect(Collectors.toList()), merchantStore);
ReadableOrder order = orderFacade.getReadableOrder(id, merchantStore, language);
return order;
}
use of com.salesmanager.shop.model.order.v0.ReadableOrder in project shopizer by shopizer-ecommerce.
the class OrderApi method list.
/**
* List orders for authenticated customers
*
* @param start
* @param count
* @param request
* @param response
* @return
* @throws Exception
*/
@RequestMapping(value = { "/auth/orders" }, method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "string", defaultValue = "en") })
public ReadableOrderList list(@RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "count", required = false) Integer count, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) throws Exception {
Principal principal = request.getUserPrincipal();
String userName = principal.getName();
Customer customer = customerService.getByNick(userName);
if (customer == null) {
response.sendError(401, "Error while listing orders, customer not authorized");
return null;
}
if (page == null) {
page = new Integer(0);
}
if (count == null) {
count = new Integer(100);
}
ReadableCustomer readableCustomer = new ReadableCustomer();
ReadableCustomerPopulator customerPopulator = new ReadableCustomerPopulator();
customerPopulator.populate(customer, readableCustomer, merchantStore, language);
ReadableOrderList returnList = orderFacade.getReadableOrderList(merchantStore, customer, page, count, language);
if (returnList == null) {
returnList = new ReadableOrderList();
}
List<ReadableOrder> orders = returnList.getOrders();
if (!CollectionUtils.isEmpty(orders)) {
for (ReadableOrder order : orders) {
order.setCustomer(readableCustomer);
}
}
return returnList;
}
use of com.salesmanager.shop.model.order.v0.ReadableOrder in project shopizer by shopizer-ecommerce.
the class OrderApi method list.
/**
* Get a list of orders for a given customer accept request parameter
* 'start' start index for count accept request parameter 'max' maximum
* number count, otherwise returns all Used for administrators
*
* @param response
* @return
* @throws Exception
*/
@RequestMapping(value = { "/private/orders/customers/{id}" }, method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "string", defaultValue = "en") })
public ReadableOrderList list(@PathVariable final Long id, @RequestParam(value = "start", required = false) Integer start, @RequestParam(value = "count", required = false) Integer count, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletResponse response) throws Exception {
Customer customer = customerService.getById(id);
if (customer == null) {
LOGGER.error("Customer is null for id " + id);
response.sendError(404, "Customer is null for id " + id);
return null;
}
if (start == null) {
start = new Integer(0);
}
if (count == null) {
count = new Integer(100);
}
ReadableCustomer readableCustomer = new ReadableCustomer();
ReadableCustomerPopulator customerPopulator = new ReadableCustomerPopulator();
customerPopulator.populate(customer, readableCustomer, merchantStore, language);
ReadableOrderList returnList = orderFacade.getReadableOrderList(merchantStore, customer, start, count, language);
List<ReadableOrder> orders = returnList.getOrders();
if (!CollectionUtils.isEmpty(orders)) {
for (ReadableOrder order : orders) {
order.setCustomer(readableCustomer);
}
}
return returnList;
}
use of com.salesmanager.shop.model.order.v0.ReadableOrder in project shopizer by shopizer-ecommerce.
the class OrderApi method getOrder.
/**
* Get a given order by id
*
* @param id
* @param request
* @param response
* @return
* @throws Exception
*/
@RequestMapping(value = { "/auth/orders/{id}" }, method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "string", defaultValue = "en") })
public ReadableOrder getOrder(@PathVariable final Long id, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) throws Exception {
Principal principal = request.getUserPrincipal();
String userName = principal.getName();
Customer customer = customerService.getByNick(userName);
if (customer == null) {
response.sendError(401, "Error while performing checkout customer not authorized");
return null;
}
ReadableOrder order = orderFacade.getReadableOrder(id, merchantStore, language);
if (order == null) {
LOGGER.error("Order is null for id " + id);
response.sendError(404, "Order is null for id " + id);
return null;
}
if (order.getCustomer() == null) {
LOGGER.error("Order is null for customer " + principal);
response.sendError(404, "Order is null for customer " + principal);
return null;
}
if (order.getCustomer().getId() != null && order.getCustomer().getId().longValue() != customer.getId().longValue()) {
LOGGER.error("Order is null for customer " + principal);
response.sendError(404, "Order is null for customer " + principal);
return null;
}
return order;
}
Aggregations