Search in sources :

Example 1 with ReadableOrder

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();
}
Also used : ReadableOrderProductDownloadPopulator(com.salesmanager.shop.populator.order.ReadableOrderProductDownloadPopulator) Customer(com.salesmanager.core.model.customer.Customer) ReadableOrderProductDownload(com.salesmanager.shop.model.order.ReadableOrderProductDownload) ArrayList(java.util.ArrayList) ReadableOrder(com.salesmanager.shop.model.order.v0.ReadableOrder) Language(com.salesmanager.core.model.reference.language.Language) Authentication(org.springframework.security.core.Authentication) OrderProductDownload(com.salesmanager.core.model.order.orderproduct.OrderProductDownload) ReadableOrderProductDownload(com.salesmanager.shop.model.order.ReadableOrderProductDownload) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ReadableOrder

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;
}
Also used : ReadableOrder(com.salesmanager.shop.model.order.v0.ReadableOrder) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with ReadableOrder

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;
}
Also used : ReadableOrderList(com.salesmanager.shop.model.order.v0.ReadableOrderList) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) Principal(java.security.Principal) ReadableCustomerPopulator(com.salesmanager.shop.populator.customer.ReadableCustomerPopulator) ReadableOrder(com.salesmanager.shop.model.order.v0.ReadableOrder) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with ReadableOrder

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;
}
Also used : ReadableOrderList(com.salesmanager.shop.model.order.v0.ReadableOrderList) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) ReadableCustomerPopulator(com.salesmanager.shop.populator.customer.ReadableCustomerPopulator) ReadableOrder(com.salesmanager.shop.model.order.v0.ReadableOrder) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with ReadableOrder

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;
}
Also used : ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) Principal(java.security.Principal) ReadableOrder(com.salesmanager.shop.model.order.v0.ReadableOrder) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ReadableOrder (com.salesmanager.shop.model.order.v0.ReadableOrder)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 Customer (com.salesmanager.core.model.customer.Customer)4 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)4 PersistableCustomer (com.salesmanager.shop.model.customer.PersistableCustomer)3 ReadableCustomer (com.salesmanager.shop.model.customer.ReadableCustomer)3 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)2 OrderProductDownload (com.salesmanager.core.model.order.orderproduct.OrderProductDownload)2 Language (com.salesmanager.core.model.reference.language.Language)2 ReadableOrderProductDownload (com.salesmanager.shop.model.order.ReadableOrderProductDownload)2 ReadableOrderList (com.salesmanager.shop.model.order.v0.ReadableOrderList)2 ReadableCustomerPopulator (com.salesmanager.shop.populator.customer.ReadableCustomerPopulator)2 ReadableOrderProductDownloadPopulator (com.salesmanager.shop.populator.order.ReadableOrderProductDownloadPopulator)2 Principal (java.security.Principal)2 ArrayList (java.util.ArrayList)2 Order (com.salesmanager.core.model.order.Order)1 Country (com.salesmanager.core.model.reference.country.Country)1 Zone (com.salesmanager.core.model.reference.zone.Zone)1