Search in sources :

Example 46 with Customer

use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.

the class CustomerFacadeImpl method checkIfUserExists.

/**
 * <p>
 * Method to check if given user exists for given username under given store. System treat
 * username as unique for a given store, customer is not allowed to use same username twice for a
 * given store, however it can be used for different stores.
 * </p>
 *
 * @param userName Customer slected userName
 * @param store store for which customer want to register
 * @return boolean flag indicating if user exists for given store or not
 * @throws Exception
 */
@Override
public boolean checkIfUserExists(final String userName, final MerchantStore store) throws Exception {
    if (StringUtils.isNotBlank(userName) && store != null) {
        Customer customer = customerService.getByNick(userName, store.getId());
        if (customer != null) {
            LOG.info("Customer with userName {} already exists for store {} ", userName, store.getStorename());
            return true;
        }
        LOG.info("No customer found with userName {} for store {} ", userName, store.getStorename());
        return false;
    }
    LOG.info("Either userName is empty or we have not found any value for store");
    return false;
}
Also used : ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer)

Example 47 with Customer

use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.

the class CustomerFacadeImpl method convertCustomerListToReadableCustomerList.

private ReadableCustomerList convertCustomerListToReadableCustomerList(CustomerList customerList, MerchantStore store, Language language) {
    List<ReadableCustomer> readableCustomers = customerList.getCustomers().stream().map(customer -> convertCustomerToReadableCustomer(customer, store, language)).collect(Collectors.toList());
    ReadableCustomerList readableCustomerList = new ReadableCustomerList();
    readableCustomerList.setCustomers(readableCustomers);
    readableCustomerList.setTotalPages(Math.toIntExact(customerList.getTotalCount()));
    return readableCustomerList;
}
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) ReadableCustomerList(com.salesmanager.shop.populator.customer.ReadableCustomerList) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer)

Example 48 with Customer

use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.

the class CustomerFacadeImpl method deleteByNick.

@Override
public void deleteByNick(String userName) {
    Customer customer = getByNick(userName);
    delete(customer);
}
Also used : ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer)

Example 49 with Customer

use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.

the class CustomerFacadeImpl method getByUserName.

@Override
public ReadableCustomer getByUserName(String userName, MerchantStore merchantStore, Language language) {
    Validate.notNull(userName, "Username cannot be null");
    Validate.notNull(merchantStore, "MerchantStore cannot be null");
    Customer customerModel = getCustomerByNickAndStoreId(userName, merchantStore);
    return convertCustomerToReadableCustomer(customerModel, merchantStore, language);
}
Also used : ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer)

Example 50 with Customer

use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.

the class CustomerFacadeImpl method getAddress.

@Override
public Address getAddress(Long userId, final MerchantStore merchantStore, boolean isBillingAddress) throws Exception {
    LOG.info("Fetching customer for id {} ", userId);
    Address address = null;
    final Customer customerModel = customerService.getById(userId);
    if (customerModel == null) {
        LOG.error("Customer with ID {} does not exists..", userId);
        // throw new CustomerNotFoundException( "customer with given id does not exists" );
        throw new Exception("customer with given id does not exists");
    }
    if (isBillingAddress) {
        LOG.info("getting billing address..");
        CustomerBillingAddressPopulator billingAddressPopulator = new CustomerBillingAddressPopulator();
        address = billingAddressPopulator.populate(customerModel, merchantStore, merchantStore.getDefaultLanguage());
        address.setBillingAddress(true);
        return address;
    }
    LOG.info("getting Delivery address..");
    CustomerDeliveryAddressPopulator deliveryAddressPopulator = new CustomerDeliveryAddressPopulator();
    return deliveryAddressPopulator.populate(customerModel, merchantStore, merchantStore.getDefaultLanguage());
}
Also used : Address(com.salesmanager.shop.model.customer.address.Address) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) CustomerDeliveryAddressPopulator(com.salesmanager.shop.populator.customer.CustomerDeliveryAddressPopulator) CustomerBillingAddressPopulator(com.salesmanager.shop.populator.customer.CustomerBillingAddressPopulator) PersistableCustomerBillingAddressPopulator(com.salesmanager.shop.populator.customer.PersistableCustomerBillingAddressPopulator) 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)

Aggregations

Customer (com.salesmanager.core.model.customer.Customer)71 PersistableCustomer (com.salesmanager.shop.model.customer.PersistableCustomer)33 ReadableCustomer (com.salesmanager.shop.model.customer.ReadableCustomer)32 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)31 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)30 Language (com.salesmanager.core.model.reference.language.Language)26 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)17 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)17 ConversionException (com.salesmanager.core.business.exception.ConversionException)16 ServiceException (com.salesmanager.core.business.exception.ServiceException)16 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)16 ShoppingCart (com.salesmanager.core.model.shoppingcart.ShoppingCart)12 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)12 Authentication (org.springframework.security.core.Authentication)12 Date (java.util.Date)11 ConversionRuntimeException (com.salesmanager.shop.store.api.exception.ConversionRuntimeException)10 ArrayList (java.util.ArrayList)10 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)10 Product (com.salesmanager.core.model.catalog.product.Product)9 Country (com.salesmanager.core.model.reference.country.Country)9