Search in sources :

Example 11 with ReadableCustomer

use of com.salesmanager.shop.model.customer.ReadableCustomer 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);
    }
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) ProductReviewDescription(com.salesmanager.core.model.catalog.product.review.ProductReviewDescription) ReadableCustomerPopulator(com.salesmanager.shop.populator.customer.ReadableCustomerPopulator) ConversionException(com.salesmanager.core.business.exception.ConversionException)

Example 12 with ReadableCustomer

use of com.salesmanager.shop.model.customer.ReadableCustomer 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 13 with ReadableCustomer

use of com.salesmanager.shop.model.customer.ReadableCustomer in project shopizer by shopizer-ecommerce.

the class ReadableCustomerPopulator method populate.

@Override
public ReadableCustomer populate(Customer source, ReadableCustomer target, MerchantStore store, Language language) throws ConversionException {
    try {
        if (target == null) {
            target = new ReadableCustomer();
        }
        if (source.getId() != null && source.getId() > 0) {
            target.setId(source.getId());
        }
        target.setEmailAddress(source.getEmailAddress());
        if (StringUtils.isNotEmpty(source.getNick())) {
            target.setUserName(source.getNick());
        }
        if (source.getDefaultLanguage() != null) {
            target.setLanguage(source.getDefaultLanguage().getCode());
        }
        if (source.getGender() != null) {
            target.setGender(source.getGender().name());
        }
        if (StringUtils.isNotEmpty(source.getProvider())) {
            target.setProvider(source.getProvider());
        }
        if (source.getBilling() != null) {
            Address address = new Address();
            address.setAddress(source.getBilling().getAddress());
            address.setCity(source.getBilling().getCity());
            address.setCompany(source.getBilling().getCompany());
            address.setFirstName(source.getBilling().getFirstName());
            address.setLastName(source.getBilling().getLastName());
            address.setPostalCode(source.getBilling().getPostalCode());
            address.setPhone(source.getBilling().getTelephone());
            if (source.getBilling().getCountry() != null) {
                address.setCountry(source.getBilling().getCountry().getIsoCode());
            }
            if (source.getBilling().getZone() != null) {
                address.setZone(source.getBilling().getZone().getCode());
            }
            if (source.getBilling().getState() != null) {
                address.setStateProvince(source.getBilling().getState());
            }
            target.setFirstName(address.getFirstName());
            target.setLastName(address.getLastName());
            target.setBilling(address);
        }
        if (source.getCustomerReviewAvg() != null) {
            target.setRating(source.getCustomerReviewAvg().doubleValue());
        }
        if (source.getCustomerReviewCount() != null) {
            target.setRatingCount(source.getCustomerReviewCount().intValue());
        }
        if (source.getDelivery() != null) {
            Address address = new Address();
            address.setCity(source.getDelivery().getCity());
            address.setAddress(source.getDelivery().getAddress());
            address.setCompany(source.getDelivery().getCompany());
            address.setFirstName(source.getDelivery().getFirstName());
            address.setLastName(source.getDelivery().getLastName());
            address.setPostalCode(source.getDelivery().getPostalCode());
            address.setPhone(source.getDelivery().getTelephone());
            if (source.getDelivery().getCountry() != null) {
                address.setCountry(source.getDelivery().getCountry().getIsoCode());
            }
            if (source.getDelivery().getZone() != null) {
                address.setZone(source.getDelivery().getZone().getCode());
            }
            if (source.getDelivery().getState() != null) {
                address.setStateProvince(source.getDelivery().getState());
            }
            target.setDelivery(address);
        }
        if (source.getAttributes() != null) {
            for (CustomerAttribute attribute : source.getAttributes()) {
                ReadableCustomerAttribute readableAttribute = new ReadableCustomerAttribute();
                readableAttribute.setId(attribute.getId());
                readableAttribute.setTextValue(attribute.getTextValue());
                ReadableCustomerOption option = new ReadableCustomerOption();
                option.setId(attribute.getCustomerOption().getId());
                option.setCode(attribute.getCustomerOption().getCode());
                CustomerOptionDescription d = new CustomerOptionDescription();
                d.setDescription(attribute.getCustomerOption().getDescriptionsSettoList().get(0).getDescription());
                d.setName(attribute.getCustomerOption().getDescriptionsSettoList().get(0).getName());
                option.setDescription(d);
                readableAttribute.setCustomerOption(option);
                ReadableCustomerOptionValue optionValue = new ReadableCustomerOptionValue();
                optionValue.setId(attribute.getCustomerOptionValue().getId());
                CustomerOptionValueDescription vd = new CustomerOptionValueDescription();
                vd.setDescription(attribute.getCustomerOptionValue().getDescriptionsSettoList().get(0).getDescription());
                vd.setName(attribute.getCustomerOptionValue().getDescriptionsSettoList().get(0).getName());
                optionValue.setCode(attribute.getCustomerOptionValue().getCode());
                optionValue.setDescription(vd);
                readableAttribute.setCustomerOptionValue(optionValue);
                target.getAttributes().add(readableAttribute);
            }
            if (source.getGroups() != null) {
                for (Group group : source.getGroups()) {
                    ReadableGroup readableGroup = new ReadableGroup();
                    readableGroup.setId(group.getId().longValue());
                    readableGroup.setName(group.getGroupName());
                    readableGroup.setType(group.getGroupType().name());
                    target.getGroups().add(readableGroup);
                }
            }
        }
    } catch (Exception e) {
        throw new ConversionException(e);
    }
    return target;
}
Also used : CustomerOptionDescription(com.salesmanager.shop.model.customer.attribute.CustomerOptionDescription) ReadableGroup(com.salesmanager.shop.model.security.ReadableGroup) ConversionException(com.salesmanager.core.business.exception.ConversionException) Group(com.salesmanager.core.model.user.Group) ReadableGroup(com.salesmanager.shop.model.security.ReadableGroup) Address(com.salesmanager.shop.model.customer.address.Address) ReadableCustomerOptionValue(com.salesmanager.shop.model.customer.attribute.ReadableCustomerOptionValue) ReadableCustomerAttribute(com.salesmanager.shop.model.customer.attribute.ReadableCustomerAttribute) CustomerAttribute(com.salesmanager.core.model.customer.attribute.CustomerAttribute) ReadableCustomerOption(com.salesmanager.shop.model.customer.attribute.ReadableCustomerOption) CustomerOptionValueDescription(com.salesmanager.shop.model.customer.attribute.CustomerOptionValueDescription) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) ReadableCustomerAttribute(com.salesmanager.shop.model.customer.attribute.ReadableCustomerAttribute) ConversionException(com.salesmanager.core.business.exception.ConversionException)

Example 14 with ReadableCustomer

use of com.salesmanager.shop.model.customer.ReadableCustomer 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;
}
Also used : Language(com.salesmanager.core.model.reference.language.Language) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) Customer(com.salesmanager.core.model.customer.Customer) Authentication(org.springframework.security.core.Authentication) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ReadableCustomerPopulator(com.salesmanager.shop.populator.customer.ReadableCustomerPopulator) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ReadableCustomer (com.salesmanager.shop.model.customer.ReadableCustomer)14 ConversionException (com.salesmanager.core.business.exception.ConversionException)7 Customer (com.salesmanager.core.model.customer.Customer)7 PersistableCustomer (com.salesmanager.shop.model.customer.PersistableCustomer)6 ReadableCustomerPopulator (com.salesmanager.shop.populator.customer.ReadableCustomerPopulator)5 ServiceException (com.salesmanager.core.business.exception.ServiceException)3 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)3 Language (com.salesmanager.core.model.reference.language.Language)3 Address (com.salesmanager.shop.model.customer.address.Address)3 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)3 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 LanguageService (com.salesmanager.core.business.services.reference.language.LanguageService)2 Order (com.salesmanager.core.model.order.Order)2 OrderProduct (com.salesmanager.core.model.order.orderproduct.OrderProduct)2 Group (com.salesmanager.core.model.user.Group)2 ReadableOrderProduct (com.salesmanager.shop.model.order.ReadableOrderProduct)2 LabelUtils (com.salesmanager.shop.utils.LabelUtils)2 ArrayList (java.util.ArrayList)2