use of com.salesmanager.shop.populator.customer.ReadableCustomerPopulator 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.populator.customer.ReadableCustomerPopulator in project shopizer by shopizer-ecommerce.
the class ReadableProductReviewPopulator method populate.
@Override
public ReadableProductReview populate(ProductReview source, ReadableProductReview target, MerchantStore store, Language language) throws ConversionException {
try {
ReadableCustomerPopulator populator = new ReadableCustomerPopulator();
ReadableCustomer customer = new ReadableCustomer();
populator.populate(source.getCustomer(), customer, store, language);
target.setId(source.getId());
target.setDate(DateUtil.formatDate(source.getReviewDate()));
target.setCustomer(customer);
target.setRating(source.getReviewRating());
target.setProductId(source.getProduct().getId());
Set<ProductReviewDescription> descriptions = source.getDescriptions();
if (descriptions != null) {
for (ProductReviewDescription description : descriptions) {
target.setDescription(description.getDescription());
target.setLanguage(description.getLanguage().getCode());
break;
}
}
return target;
} catch (Exception e) {
throw new ConversionException("Cannot populate ProductReview", e);
}
}
use of com.salesmanager.shop.populator.customer.ReadableCustomerPopulator 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.populator.customer.ReadableCustomerPopulator in project shopizer by shopizer-ecommerce.
the class CustomerAccountController method customerInformation.
@RequestMapping(value = "/accountSummary.json", method = RequestMethod.GET)
@ResponseBody
public ReadableCustomer customerInformation(@RequestParam String userName, Model model, HttpServletRequest request, HttpServletResponse response) throws Exception {
MerchantStore store = getSessionAttribute(Constants.MERCHANT_STORE, request);
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
Customer customer = null;
if (auth != null && request.isUserInRole("AUTH_CUSTOMER")) {
customer = customerFacade.getCustomerByUserName(auth.getName(), store);
} else {
response.sendError(401, "Customer not authenticated");
return null;
}
if (StringUtils.isBlank(userName)) {
response.sendError(403, "Customer name required");
return null;
}
if (customer == null) {
response.sendError(401, "Customer not authenticated");
return null;
}
if (!customer.getNick().equals(userName)) {
response.sendError(401, "Customer not authenticated");
return null;
}
ReadableCustomer readableCustomer = new ReadableCustomer();
Language lang = languageUtils.getRequestLanguage(request, response);
ReadableCustomerPopulator readableCustomerPopulator = new ReadableCustomerPopulator();
readableCustomerPopulator.populate(customer, readableCustomer, store, lang);
return readableCustomer;
}
Aggregations