Search in sources :

Example 81 with Language

use of com.salesmanager.core.model.reference.language.Language 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 82 with Language

use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.

the class SearchFacadeImpl method convertToSearchProductList.

@Override
public SearchProductList convertToSearchProductList(SearchResponse searchResponse, MerchantStore merchantStore, int start, int count, Language language) {
    SearchProductList returnList = new SearchProductList();
    List<SearchEntry> entries = searchResponse.getEntries();
    if (CollectionUtils.isNotEmpty(entries)) {
        List<Long> ids = entries.stream().map(SearchEntry::getIndexProduct).map(IndexProduct::getId).map(Long::parseLong).collect(Collectors.toList());
        ProductCriteria searchCriteria = new ProductCriteria();
        searchCriteria.setMaxCount(count);
        searchCriteria.setStartIndex(start);
        searchCriteria.setProductIds(ids);
        searchCriteria.setAvailable(true);
        ProductList productList = productService.listByStore(merchantStore, language, searchCriteria);
        List<ReadableProduct> readableProducts = productList.getProducts().stream().map(product -> convertProductToReadableProduct(product, merchantStore, language)).collect(Collectors.toList());
        returnList.getProducts().addAll(readableProducts);
        returnList.setProductCount(productList.getProducts().size());
    }
    // Facets
    Map<String, List<SearchFacet>> facets = Optional.ofNullable(searchResponse.getFacets()).orElse(Collections.emptyMap());
    List<ReadableCategory> categoryProxies = getCategoryFacets(merchantStore, language, facets);
    returnList.setCategoryFacets(categoryProxies);
    List<SearchFacet> manufacturersFacets = facets.entrySet().stream().filter(e -> MANUFACTURER_FACET_NAME.equals(e.getKey())).findFirst().map(Entry::getValue).orElse(Collections.emptyList());
    if (CollectionUtils.isNotEmpty(manufacturersFacets)) {
    // TODO add manufacturer facets
    }
    return returnList;
}
Also used : ProductService(com.salesmanager.core.business.services.catalog.product.ProductService) Async(org.springframework.scheduling.annotation.Async) LoggerFactory(org.slf4j.LoggerFactory) AutoCompleteRequest(com.salesmanager.shop.store.model.search.AutoCompleteRequest) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ServiceException(com.salesmanager.core.business.exception.ServiceException) Inject(javax.inject.Inject) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) Service(org.springframework.stereotype.Service) Map(java.util.Map) Qualifier(org.springframework.beans.factory.annotation.Qualifier) PricingService(com.salesmanager.core.business.services.catalog.product.PricingService) ReadableCategoryPopulator(com.salesmanager.shop.populator.catalog.ReadableCategoryPopulator) CategoryService(com.salesmanager.core.business.services.catalog.category.CategoryService) SearchKeywords(com.salesmanager.core.model.search.SearchKeywords) SearchProductRequest(com.salesmanager.shop.model.catalog.SearchProductRequest) SearchFacet(com.salesmanager.core.model.search.SearchFacet) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) ProductCriteria(com.salesmanager.core.model.catalog.product.ProductCriteria) Logger(org.slf4j.Logger) SearchService(com.salesmanager.core.business.services.search.SearchService) ImageFilePath(com.salesmanager.shop.utils.ImageFilePath) ProductList(com.salesmanager.core.model.catalog.product.ProductList) Collectors(java.util.stream.Collectors) SearchEntry(com.salesmanager.core.model.search.SearchEntry) Category(com.salesmanager.core.model.catalog.category.Category) List(java.util.List) ValueList(com.salesmanager.shop.model.entity.ValueList) CoreConfiguration(com.salesmanager.core.business.utils.CoreConfiguration) ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) SearchProductList(com.salesmanager.shop.model.catalog.SearchProductList) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) Entry(java.util.Map.Entry) SearchResponse(com.salesmanager.core.model.search.SearchResponse) Optional(java.util.Optional) ConversionException(com.salesmanager.core.business.exception.ConversionException) Collections(java.util.Collections) IndexProduct(com.salesmanager.core.model.search.IndexProduct) ProductCriteria(com.salesmanager.core.model.catalog.product.ProductCriteria) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) IndexProduct(com.salesmanager.core.model.search.IndexProduct) ProductList(com.salesmanager.core.model.catalog.product.ProductList) SearchProductList(com.salesmanager.shop.model.catalog.SearchProductList) SearchFacet(com.salesmanager.core.model.search.SearchFacet) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) ProductList(com.salesmanager.core.model.catalog.product.ProductList) List(java.util.List) ValueList(com.salesmanager.shop.model.entity.ValueList) SearchProductList(com.salesmanager.shop.model.catalog.SearchProductList) SearchEntry(com.salesmanager.core.model.search.SearchEntry) SearchProductList(com.salesmanager.shop.model.catalog.SearchProductList)

Example 83 with Language

use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.

the class ShippingFacadeImpl method shipToCountry.

@Override
public List<ReadableCountry> shipToCountry(MerchantStore store, Language language) {
    try {
        List<Country> countries = shippingService.getShipToCountryList(store, language);
        List<ReadableCountry> countryList = new ArrayList<ReadableCountry>();
        if (!CollectionUtils.isEmpty(countries)) {
            countryList = countries.stream().map(c -> {
                try {
                    return convert(c, store, language);
                } catch (ConversionException e) {
                    throw new ConversionRuntimeException("Error converting Country to readable country,e");
                }
            }).sorted(Comparator.comparing(ReadableCountry::getName)).collect(Collectors.toList());
        }
        return countryList;
    } catch (Exception e) {
        throw new ServiceRuntimeException("Error getting shipping country", e);
    }
}
Also used : ExpeditionConfiguration(com.salesmanager.shop.model.shipping.ExpeditionConfiguration) ShippingOrigin(com.salesmanager.core.model.shipping.ShippingOrigin) ShippingType(com.salesmanager.core.model.shipping.ShippingType) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Zone(com.salesmanager.core.model.reference.zone.Zone) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) ServiceException(com.salesmanager.core.business.exception.ServiceException) ZoneService(com.salesmanager.core.business.services.reference.zone.ZoneService) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ShippingOriginService(com.salesmanager.core.business.services.shipping.ShippingOriginService) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Service(org.springframework.stereotype.Service) ReadableCountryPopulator(com.salesmanager.shop.populator.references.ReadableCountryPopulator) ShippingService(com.salesmanager.core.business.services.shipping.ShippingService) ReadableCountry(com.salesmanager.shop.model.references.ReadableCountry) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) CountryService(com.salesmanager.core.business.services.reference.country.CountryService) Validate(org.jsoup.helper.Validate) Logger(org.slf4j.Logger) Country(com.salesmanager.core.model.reference.country.Country) Collectors(java.util.stream.Collectors) List(java.util.List) ShippingPackageType(com.salesmanager.core.model.shipping.ShippingPackageType) PackageDetails(com.salesmanager.core.model.shipping.PackageDetails) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ConversionException(com.salesmanager.core.business.exception.ConversionException) PersistableAddress(com.salesmanager.shop.model.references.PersistableAddress) ReadableAddress(com.salesmanager.shop.model.references.ReadableAddress) ShippingConfiguration(com.salesmanager.core.model.shipping.ShippingConfiguration) Comparator(java.util.Comparator) ConversionException(com.salesmanager.core.business.exception.ConversionException) ArrayList(java.util.ArrayList) ReadableCountry(com.salesmanager.shop.model.references.ReadableCountry) Country(com.salesmanager.core.model.reference.country.Country) ReadableCountry(com.salesmanager.shop.model.references.ReadableCountry) ServiceException(com.salesmanager.core.business.exception.ServiceException) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ConversionException(com.salesmanager.core.business.exception.ConversionException) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 84 with Language

use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.

the class ProductImageApi method images.

/**
 * Get product images
 * @param id
 * @param imageId
 * @param merchantStore
 * @param language
 * @return
 */
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = { "/products/{productId}/images" }, method = RequestMethod.GET)
@ApiOperation(httpMethod = "GET", value = "Get images for a given product")
@ApiResponses(value = { @ApiResponse(code = 200, message = "List of ProductImage found", response = List.class) })
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public List<ReadableImage> images(@PathVariable Long productId, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {
    Product p = productService.getById(productId);
    if (p == null) {
        throw new ResourceNotFoundException("Product images not found for product id [" + productId + "] and merchant [" + merchantStore.getCode() + "]");
    }
    if (p.getMerchantStore().getId() != merchantStore.getId()) {
        throw new ResourceNotFoundException("Product images not found for product id [" + productId + "] and merchant [" + merchantStore.getCode() + "]");
    }
    List<ReadableImage> target = new ArrayList<ReadableImage>();
    Set<ProductImage> images = p.getImages();
    if (images != null && images.size() > 0) {
        target = images.stream().map(i -> image(i, merchantStore, language)).sorted(Comparator.comparingInt(ReadableImage::getOrder)).collect(Collectors.toList());
    }
    return target;
}
Also used : ProductService(com.salesmanager.core.business.services.catalog.product.ProductService) PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Controller(org.springframework.stereotype.Controller) ApiResponses(io.swagger.annotations.ApiResponses) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Valid(javax.validation.Valid) Language(com.salesmanager.core.model.reference.language.Language) ApiOperation(io.swagger.annotations.ApiOperation) HttpServletRequest(javax.servlet.http.HttpServletRequest) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ReadableImage(com.salesmanager.shop.model.catalog.product.ReadableImage) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Api(io.swagger.annotations.Api) Tag(io.swagger.annotations.Tag) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) Product(com.salesmanager.core.model.catalog.product.Product) Logger(org.slf4j.Logger) MediaType(org.springframework.http.MediaType) ApiImplicitParam(io.swagger.annotations.ApiImplicitParam) HttpServletResponse(javax.servlet.http.HttpServletResponse) Set(java.util.Set) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) IOException(java.io.IOException) ReadableProductImageMapper(com.salesmanager.shop.mapper.catalog.ReadableProductImageMapper) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) Collectors(java.util.stream.Collectors) ProductImageService(com.salesmanager.core.business.services.catalog.product.image.ProductImageService) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) ApiIgnore(springfox.documentation.annotations.ApiIgnore) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) NameEntity(com.salesmanager.shop.model.entity.NameEntity) SwaggerDefinition(io.swagger.annotations.SwaggerDefinition) ProductImage(com.salesmanager.core.model.catalog.product.image.ProductImage) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ApiResponse(io.swagger.annotations.ApiResponse) Optional(java.util.Optional) MultipartFile(org.springframework.web.multipart.MultipartFile) Comparator(java.util.Comparator) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ReadableImage(com.salesmanager.shop.model.catalog.product.ReadableImage) ProductImage(com.salesmanager.core.model.catalog.product.image.ProductImage) ArrayList(java.util.ArrayList) Product(com.salesmanager.core.model.catalog.product.Product) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 85 with Language

use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.

the class InitializationDatabaseImpl method createLanguages.

private void createLanguages() throws ServiceException {
    LOGGER.info(String.format("%s : Populating Languages ", name));
    for (String code : SchemaConstant.LANGUAGE_ISO_CODE) {
        Language language = new Language(code);
        languageService.create(language);
    }
}
Also used : Language(com.salesmanager.core.model.reference.language.Language)

Aggregations

Language (com.salesmanager.core.model.reference.language.Language)148 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)115 ArrayList (java.util.ArrayList)58 List (java.util.List)56 ServiceException (com.salesmanager.core.business.exception.ServiceException)55 Collectors (java.util.stream.Collectors)50 Product (com.salesmanager.core.model.catalog.product.Product)45 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)44 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)42 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)38 Autowired (org.springframework.beans.factory.annotation.Autowired)35 ConversionException (com.salesmanager.core.business.exception.ConversionException)30 Category (com.salesmanager.core.model.catalog.category.Category)30 Validate (org.apache.commons.lang3.Validate)29 Customer (com.salesmanager.core.model.customer.Customer)28 Optional (java.util.Optional)28 Inject (javax.inject.Inject)28 Service (org.springframework.stereotype.Service)28 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)27 ImageFilePath (com.salesmanager.shop.utils.ImageFilePath)25