use of com.salesmanager.shop.model.order.v0.ReadableOrderList in project shopizer by shopizer-ecommerce.
the class OrderRESTController method listOrders.
/**
* Get a list of orders for a given customer
* accept request parameter 'lang' [en,fr...] otherwise store dafault language
* accept request parameter 'start' start index for count
* accept request parameter 'max' maximum number count, otherwise returns all
* @param store
* @param order
* @param request
* @param response
* @return
* @throws Exception
*/
@RequestMapping(value = "/{store}/orders/customer/{id}", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.ACCEPTED)
@ResponseBody
public ReadableOrderList listOrders(@PathVariable final String store, @PathVariable final Long id, HttpServletRequest request, HttpServletResponse response) throws Exception {
MerchantStore merchantStore = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
if (merchantStore != null) {
if (!merchantStore.getCode().equals(store)) {
merchantStore = null;
}
}
if (merchantStore == null) {
merchantStore = merchantStoreService.getByCode(store);
}
if (merchantStore == null) {
LOGGER.error("Merchant store is null for code " + store);
response.sendError(503, "Merchant store is null for code " + store);
return null;
}
// get additional request parameters for orders
String lang = request.getParameter(Constants.LANG);
String start = request.getParameter(Constants.START);
String max = request.getParameter(Constants.MAX);
int startCount = 0;
int maxCount = 0;
if (StringUtils.isBlank(lang)) {
lang = merchantStore.getDefaultLanguage().getCode();
}
Language language = languageService.getByCode(lang);
if (language == null) {
LOGGER.error("Language is null for code " + lang);
response.sendError(503, "Language is null for code " + lang);
return null;
}
try {
startCount = Integer.parseInt(start);
} catch (Exception e) {
LOGGER.info("Invalid value for start " + start);
}
try {
maxCount = Integer.parseInt(max);
} catch (Exception e) {
LOGGER.info("Invalid value for max " + max);
}
Customer customer = customerService.getById(id);
if (customer == null) {
LOGGER.error("Customer is null for id " + id);
response.sendError(503, "Customer is null for id " + id);
return null;
}
if (customer.getMerchantStore().getId().intValue() != merchantStore.getId().intValue()) {
LOGGER.error("Customer is null for id " + id + " and store id " + store);
response.sendError(503, "Customer is null for id " + id + " and store id " + store);
return null;
}
ReadableOrderList returnList = orderFacade.getReadableOrderList(merchantStore, startCount, maxCount, language);
return returnList;
}
use of com.salesmanager.shop.model.order.v0.ReadableOrderList in project shopizer by shopizer-ecommerce.
the class OrderPaymentApi method listCapturableOrders.
/**
* An order can be pre-authorized but un captured. This metho returns all
* order subject to be capturable For a given time frame
*
* @param startDate
* @param endDate
* @param request
* @param response
* @return ReadableOrderList
* @throws Exception
*/
@RequestMapping(value = { "/private/orders/payment/capturable" }, method = RequestMethod.GET)
@ResponseStatus(HttpStatus.ACCEPTED)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public ReadableOrderList listCapturableOrders(@RequestParam(value = "startDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate, @RequestParam(value = "endDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) {
try {
// if startdate or enddate are null use default range (last 24
// hours) DD-1 to DD
Calendar cal = Calendar.getInstance();
Date sDate = null;
if (startDate != null) {
sDate = Date.from(startDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
} else {
cal.add(Calendar.DATE, -1);
sDate = cal.getTime();
}
Date eDate = null;
if (endDate != null) {
eDate = Date.from(endDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
} else {
eDate = new Date();
}
ReadableOrderList returnList = orderFacade.getCapturableOrderList(merchantStore, sDate, eDate, language);
return returnList;
} catch (Exception e) {
LOGGER.error("Error while getting capturable payments", e);
try {
response.sendError(503, "Error while getting capturable payments " + e.getMessage());
} catch (Exception ignore) {
}
return null;
}
}
use of com.salesmanager.shop.model.order.v0.ReadableOrderList 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.ReadableOrderList 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.ReadableOrderList in project shopizer by shopizer-ecommerce.
the class OrderApi method list.
/**
* This method returns list of all the orders for a store.This is not
* bound to any specific stores and will get list of all the orders
* available for this instance
*
* @param start
* @param count
* @return List of orders
* @throws Exception
*/
@RequestMapping(value = { "/private/orders" }, method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public ReadableOrderList list(@RequestParam(value = "count", required = false, defaultValue = DEFAULT_ORDER_LIST_COUNT) Integer count, @RequestParam(value = "page", required = false, defaultValue = "0") Integer page, @RequestParam(value = "name", required = false) String name, @RequestParam(value = "id", required = false) Long id, @RequestParam(value = "status", required = false) String status, @RequestParam(value = "phone", required = false) String phone, @RequestParam(value = "email", required = false) String email, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {
OrderCriteria orderCriteria = new OrderCriteria();
orderCriteria.setPageSize(count);
orderCriteria.setStartPage(page);
orderCriteria.setCustomerName(name);
orderCriteria.setCustomerPhone(phone);
orderCriteria.setStatus(status);
orderCriteria.setEmail(email);
orderCriteria.setId(id);
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);
ReadableOrderList orders = orderFacade.getReadableOrderList(orderCriteria, merchantStore);
return orders;
}
Aggregations