Search in sources :

Example 1 with SearchProductList

use of com.salesmanager.shop.model.catalog.SearchProductList 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 2 with SearchProductList

use of com.salesmanager.shop.model.catalog.SearchProductList in project shopizer by shopizer-ecommerce.

the class SearchApiIntegrationTest method searchItem.

/**
 * Add a product then search for it
 * This tests is disabled since it requires Elastic search server started
 *
 * @throws Exception
 */
@Test
public void searchItem() throws Exception {
    PersistableProduct product = super.product("TESTPRODUCT");
    final HttpEntity<PersistableProduct> entity = new HttpEntity<>(product, getHeader());
    final ResponseEntity<PersistableProduct> response = testRestTemplate.postForEntity("/api/v1/private/product?store=" + Constants.DEFAULT_STORE, entity, PersistableProduct.class);
    assertThat(response.getStatusCode(), is(CREATED));
    SearchProductRequest searchRequest = new SearchProductRequest();
    searchRequest.setQuery("TEST");
    final HttpEntity<SearchProductRequest> searchEntity = new HttpEntity<>(searchRequest, getHeader());
    final ResponseEntity<SearchProductList> searchResponse = testRestTemplate.postForEntity("/api/v1/search?store=" + Constants.DEFAULT_STORE, searchEntity, SearchProductList.class);
    assertThat(searchResponse.getStatusCode(), is(CREATED));
}
Also used : HttpEntity(org.springframework.http.HttpEntity) PersistableProduct(com.salesmanager.shop.model.catalog.product.PersistableProduct) SearchProductRequest(com.salesmanager.shop.model.catalog.SearchProductRequest) SearchProductList(com.salesmanager.shop.model.catalog.SearchProductList) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

SearchProductList (com.salesmanager.shop.model.catalog.SearchProductList)2 SearchProductRequest (com.salesmanager.shop.model.catalog.SearchProductRequest)2 ConversionException (com.salesmanager.core.business.exception.ConversionException)1 ServiceException (com.salesmanager.core.business.exception.ServiceException)1 CategoryService (com.salesmanager.core.business.services.catalog.category.CategoryService)1 PricingService (com.salesmanager.core.business.services.catalog.product.PricingService)1 ProductService (com.salesmanager.core.business.services.catalog.product.ProductService)1 SearchService (com.salesmanager.core.business.services.search.SearchService)1 CoreConfiguration (com.salesmanager.core.business.utils.CoreConfiguration)1 Category (com.salesmanager.core.model.catalog.category.Category)1 Product (com.salesmanager.core.model.catalog.product.Product)1 ProductCriteria (com.salesmanager.core.model.catalog.product.ProductCriteria)1 ProductList (com.salesmanager.core.model.catalog.product.ProductList)1 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)1 Language (com.salesmanager.core.model.reference.language.Language)1 IndexProduct (com.salesmanager.core.model.search.IndexProduct)1 SearchEntry (com.salesmanager.core.model.search.SearchEntry)1 SearchFacet (com.salesmanager.core.model.search.SearchFacet)1 SearchKeywords (com.salesmanager.core.model.search.SearchKeywords)1 SearchResponse (com.salesmanager.core.model.search.SearchResponse)1