Search in sources :

Example 1 with ReadableCustomer

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

the class ReadableCustomerReviewPopulator method populate.

@Override
public ReadableCustomerReview populate(CustomerReview source, ReadableCustomerReview target, MerchantStore store, Language language) throws ConversionException {
    try {
        if (target == null) {
            target = new ReadableCustomerReview();
        }
        if (source.getReviewDate() != null) {
            target.setDate(DateUtil.formatDate(source.getReviewDate()));
        }
        ReadableCustomer reviewed = new ReadableCustomer();
        reviewed.setId(source.getReviewedCustomer().getId());
        reviewed.setFirstName(source.getReviewedCustomer().getBilling().getFirstName());
        reviewed.setLastName(source.getReviewedCustomer().getBilling().getLastName());
        target.setId(source.getId());
        target.setCustomerId(source.getCustomer().getId());
        target.setReviewedCustomer(reviewed);
        target.setRating(source.getReviewRating());
        target.setReviewedCustomer(reviewed);
        target.setCustomerId(source.getCustomer().getId());
        Set<CustomerReviewDescription> descriptions = source.getDescriptions();
        if (CollectionUtils.isNotEmpty(descriptions)) {
            CustomerReviewDescription description = null;
            if (descriptions.size() > 1) {
                for (CustomerReviewDescription desc : descriptions) {
                    if (desc.getLanguage().getCode().equals(language.getCode())) {
                        description = desc;
                        break;
                    }
                }
            } else {
                description = descriptions.iterator().next();
            }
            if (description != null) {
                target.setDescription(description.getDescription());
                target.setLanguage(description.getLanguage().getCode());
            }
        }
    } catch (Exception e) {
        throw new ConversionException("Cannot populate ReadableCustomerReview", e);
    }
    return target;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) ReadableCustomerReview(com.salesmanager.shop.model.customer.ReadableCustomerReview) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) ConversionException(com.salesmanager.core.business.exception.ConversionException) CustomerReviewDescription(com.salesmanager.core.model.customer.review.CustomerReviewDescription)

Example 2 with ReadableCustomer

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

the class ReadableShopOrderPopulator method populate.

@Override
public ReadableShopOrder populate(ShopOrder source, ReadableShopOrder target, MerchantStore store, Language language) throws ConversionException {
    try {
        ReadableCustomer customer = new ReadableCustomer();
        PersistableCustomer persistableCustomer = source.getCustomer();
        customer.setEmailAddress(persistableCustomer.getEmailAddress());
        if (persistableCustomer.getBilling() != null) {
            Address address = new Address();
            address.setCity(persistableCustomer.getBilling().getCity());
            address.setCompany(persistableCustomer.getBilling().getCompany());
            address.setFirstName(persistableCustomer.getBilling().getFirstName());
            address.setLastName(persistableCustomer.getBilling().getLastName());
            address.setPostalCode(persistableCustomer.getBilling().getPostalCode());
            address.setPhone(persistableCustomer.getBilling().getPhone());
            if (persistableCustomer.getBilling().getCountry() != null) {
                address.setCountry(persistableCustomer.getBilling().getCountry());
            }
            if (persistableCustomer.getBilling().getZone() != null) {
                address.setZone(persistableCustomer.getBilling().getZone());
            }
            customer.setBilling(address);
        }
        if (persistableCustomer.getDelivery() != null) {
            Address address = new Address();
            address.setCity(persistableCustomer.getDelivery().getCity());
            address.setCompany(persistableCustomer.getDelivery().getCompany());
            address.setFirstName(persistableCustomer.getDelivery().getFirstName());
            address.setLastName(persistableCustomer.getDelivery().getLastName());
            address.setPostalCode(persistableCustomer.getDelivery().getPostalCode());
            address.setPhone(persistableCustomer.getDelivery().getPhone());
            if (persistableCustomer.getDelivery().getCountry() != null) {
                address.setCountry(persistableCustomer.getDelivery().getCountry());
            }
            if (persistableCustomer.getDelivery().getZone() != null) {
                address.setZone(persistableCustomer.getDelivery().getZone());
            }
            customer.setDelivery(address);
        }
        // TODO if ship to billing enabled, set delivery = billing
        /*			if(persistableCustomer.getAttributes()!=null) {
				for(PersistableCustomerAttribute attribute : persistableCustomer.getAttributes()) {
					ReadableCustomerAttribute readableAttribute = new ReadableCustomerAttribute();
					readableAttribute.setId(attribute.getId());
					ReadableCustomerOption option = new ReadableCustomerOption();
					option.setId(attribute.getCustomerOption().getId());
					option.setCode(attribute.getCustomerOption());
					
					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);
					customer.getAttributes().add(readableAttribute);
				}
			}*/
        target.setCustomer(customer);
    } catch (Exception e) {
        throw new ConversionException(e);
    }
    return target;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) Address(com.salesmanager.shop.model.customer.address.Address) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) ConversionException(com.salesmanager.core.business.exception.ConversionException)

Example 3 with ReadableCustomer

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

the class CustomerFacadeImpl method create.

@Override
public ReadableCustomer create(PersistableCustomer customer, MerchantStore store, Language language) {
    Validate.notNull(customer, "Customer cannot be null");
    Validate.notNull(customer.getEmailAddress(), "Customer email address is required");
    // set customer user name
    customer.setUserName(customer.getEmailAddress());
    if (userExist(customer.getUserName())) {
        throw new ServiceRuntimeException("User already exist");
    }
    // end user exists
    Customer customerToPopulate = convertPersistableCustomerToCustomer(customer, store);
    try {
        setCustomerModelDefaultProperties(customerToPopulate, store);
    } catch (Exception e) {
        throw new ServiceRuntimeException("Cannot set default customer properties", e);
    }
    saveCustomer(customerToPopulate);
    customer.setId(customerToPopulate.getId());
    notifyNewCustomer(customer, store, customerToPopulate.getDefaultLanguage());
    // convert to readable
    return convertCustomerToReadableCustomer(customerToPopulate, store, language);
}
Also used : ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) ServiceException(com.salesmanager.core.business.exception.ServiceException) UserAlreadyExistException(com.salesmanager.shop.model.customer.UserAlreadyExistException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ConversionException(com.salesmanager.core.business.exception.ConversionException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 4 with ReadableCustomer

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

the class CustomerFacadeImpl method updateAddress.

@Override
public void updateAddress(String userName, PersistableCustomer customer, MerchantStore store) {
    ReadableCustomer customerModel = getByUserName(userName, store, store.getDefaultLanguage());
    customer.setId(customerModel.getId());
    customer.setUserName(userName);
    updateAddress(customer, store);
}
Also used : ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer)

Example 5 with ReadableCustomer

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

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