Search in sources :

Example 1 with ReadableCustomerReview

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

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

the class CustomerFacadeImpl method getAllCustomerReviewsByReviewed.

@Override
public List<ReadableCustomerReview> getAllCustomerReviewsByReviewed(Long customerId, MerchantStore store, Language language) {
    // customer exist
    Customer customer = getCustomerById(customerId);
    Validate.notNull(customer, "Reviewed customer cannot be null");
    return customerReviewService.getByReviewedCustomer(customer).stream().map(customerReview -> convertCustomerReviewToReadableCustomerReview(customerReview, store, language)).collect(Collectors.toList());
}
Also used : ShoppingCart(com.salesmanager.core.model.shoppingcart.ShoppingCart) PermissionService(com.salesmanager.core.business.services.user.PermissionService) CustomerList(com.salesmanager.core.model.customer.CustomerList) CustomerEntityPopulator(com.salesmanager.shop.populator.customer.CustomerEntityPopulator) Date(java.util.Date) EmailConstants(com.salesmanager.shop.constants.EmailConstants) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) LanguageService(com.salesmanager.core.business.services.reference.language.LanguageService) ServiceException(com.salesmanager.core.business.exception.ServiceException) CustomerOptinService(com.salesmanager.core.business.services.customer.optin.CustomerOptinService) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) CustomerReviewService(com.salesmanager.core.business.services.customer.review.CustomerReviewService) UserAlreadyExistException(com.salesmanager.shop.model.customer.UserAlreadyExistException) Locale(java.util.Locale) Map(java.util.Map) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) CustomerService(com.salesmanager.core.business.services.customer.CustomerService) CountryService(com.salesmanager.core.business.services.reference.country.CountryService) UUID(org.jgroups.util.UUID) ReadableCustomerReview(com.salesmanager.shop.model.customer.ReadableCustomerReview) CustomerEntity(com.salesmanager.shop.model.customer.CustomerEntity) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) GrantedAuthority(org.springframework.security.core.GrantedAuthority) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) List(java.util.List) CustomerBillingAddressPopulator(com.salesmanager.shop.populator.customer.CustomerBillingAddressPopulator) LocaleUtils(com.salesmanager.shop.utils.LocaleUtils) CoreConfiguration(com.salesmanager.core.business.utils.CoreConfiguration) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) Optional(java.util.Optional) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Optin(com.salesmanager.core.model.system.optin.Optin) Authentication(org.springframework.security.core.Authentication) Address(com.salesmanager.shop.model.customer.address.Address) EmailService(com.salesmanager.core.business.services.system.EmailService) OptinType(com.salesmanager.core.model.system.optin.OptinType) Async(org.springframework.scheduling.annotation.Async) Email(com.salesmanager.core.business.modules.email.Email) Group(com.salesmanager.core.model.user.Group) Constants(com.salesmanager.shop.constants.Constants) ReadableCustomerPopulator(com.salesmanager.shop.populator.customer.ReadableCustomerPopulator) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) Zone(com.salesmanager.core.model.reference.zone.Zone) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) ZoneService(com.salesmanager.core.business.services.reference.zone.ZoneService) Inject(javax.inject.Inject) Language(com.salesmanager.core.model.reference.language.Language) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) Permission(com.salesmanager.core.model.user.Permission) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) LabelUtils(com.salesmanager.shop.utils.LabelUtils) Service(org.springframework.stereotype.Service) Qualifier(org.springframework.beans.factory.annotation.Qualifier) EmailUtils(com.salesmanager.shop.utils.EmailUtils) CustomerDeliveryAddressPopulator(com.salesmanager.shop.populator.customer.CustomerDeliveryAddressPopulator) CustomerPopulator(com.salesmanager.shop.populator.customer.CustomerPopulator) CustomerReview(com.salesmanager.core.model.customer.review.CustomerReview) PersistableCustomerReview(com.salesmanager.shop.model.customer.PersistableCustomerReview) ShoppingCartService(com.salesmanager.core.business.services.shoppingcart.ShoppingCartService) Logger(org.slf4j.Logger) AuthenticationManager(org.springframework.security.authentication.AuthenticationManager) Country(com.salesmanager.core.model.reference.country.Country) Customer(com.salesmanager.core.model.customer.Customer) CustomerCriteria(com.salesmanager.core.model.customer.CustomerCriteria) CustomerOptin(com.salesmanager.core.model.system.optin.CustomerOptin) ImageFilePath(com.salesmanager.shop.utils.ImageFilePath) EmailTemplatesUtils(com.salesmanager.shop.utils.EmailTemplatesUtils) PersistableCustomerBillingAddressPopulator(com.salesmanager.shop.populator.customer.PersistableCustomerBillingAddressPopulator) PersistableCustomerShippingAddressPopulator(com.salesmanager.shop.populator.customer.PersistableCustomerShippingAddressPopulator) GroupType(com.salesmanager.core.model.user.GroupType) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) Validate(org.apache.commons.lang3.Validate) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) PersistableCustomerOptin(com.salesmanager.shop.model.customer.optin.PersistableCustomerOptin) GroupService(com.salesmanager.core.business.services.user.GroupService) ConversionException(com.salesmanager.core.business.exception.ConversionException) OptinService(com.salesmanager.core.business.services.system.optin.OptinService) PersistableCustomerReviewPopulator(com.salesmanager.shop.populator.customer.PersistableCustomerReviewPopulator) ReadableCustomerReviewPopulator(com.salesmanager.shop.populator.customer.ReadableCustomerReviewPopulator) ReadableCustomerList(com.salesmanager.shop.populator.customer.ReadableCustomerList) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer)

Aggregations

ConversionException (com.salesmanager.core.business.exception.ConversionException)2 ReadableCustomer (com.salesmanager.shop.model.customer.ReadableCustomer)2 ReadableCustomerReview (com.salesmanager.shop.model.customer.ReadableCustomerReview)2 ServiceException (com.salesmanager.core.business.exception.ServiceException)1 Email (com.salesmanager.core.business.modules.email.Email)1 CustomerService (com.salesmanager.core.business.services.customer.CustomerService)1 CustomerOptinService (com.salesmanager.core.business.services.customer.optin.CustomerOptinService)1 CustomerReviewService (com.salesmanager.core.business.services.customer.review.CustomerReviewService)1 CountryService (com.salesmanager.core.business.services.reference.country.CountryService)1 LanguageService (com.salesmanager.core.business.services.reference.language.LanguageService)1 ZoneService (com.salesmanager.core.business.services.reference.zone.ZoneService)1 ShoppingCartService (com.salesmanager.core.business.services.shoppingcart.ShoppingCartService)1 EmailService (com.salesmanager.core.business.services.system.EmailService)1 OptinService (com.salesmanager.core.business.services.system.optin.OptinService)1 GroupService (com.salesmanager.core.business.services.user.GroupService)1 PermissionService (com.salesmanager.core.business.services.user.PermissionService)1 CoreConfiguration (com.salesmanager.core.business.utils.CoreConfiguration)1 Customer (com.salesmanager.core.model.customer.Customer)1 CustomerCriteria (com.salesmanager.core.model.customer.CustomerCriteria)1 CustomerList (com.salesmanager.core.model.customer.CustomerList)1