Search in sources :

Example 11 with PersistableProduct

use of com.salesmanager.shop.model.catalog.product.PersistableProduct 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)

Example 12 with PersistableProduct

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

the class ProductFacadeImpl method saveProduct.

@Override
public PersistableProduct saveProduct(MerchantStore store, PersistableProduct product, Language language) {
    String manufacturer = Manufacturer.DEFAULT_MANUFACTURER;
    if (product.getProductSpecifications() != null) {
        manufacturer = product.getProductSpecifications().getManufacturer();
    } else {
        ProductSpecification specifications = new ProductSpecification();
        specifications.setManufacturer(manufacturer);
    }
    Product target = null;
    if (product.getId() != null && product.getId().longValue() > 0) {
        target = productService.getById(product.getId());
    } else {
        target = new Product();
    }
    try {
        persistableProductPopulator.populate(product, target, store, language);
        if (target.getId() != null && target.getId() > 0) {
            productService.update(target);
        } else {
            productService.create(target);
            product.setId(target.getId());
        }
        return product;
    } catch (Exception e) {
        throw new ServiceRuntimeException(e);
    }
}
Also used : PersistableProduct(com.salesmanager.shop.model.catalog.product.PersistableProduct) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) LightPersistableProduct(com.salesmanager.shop.model.catalog.product.LightPersistableProduct) ServiceException(com.salesmanager.core.business.exception.ServiceException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ProductSpecification(com.salesmanager.shop.model.catalog.product.ProductSpecification) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Aggregations

PersistableProduct (com.salesmanager.shop.model.catalog.product.PersistableProduct)12 ProductSpecification (com.salesmanager.shop.model.catalog.product.ProductSpecification)7 ArrayList (java.util.ArrayList)6 Product (com.salesmanager.core.model.catalog.product.Product)5 Category (com.salesmanager.shop.model.catalog.category.Category)5 PersistableCategory (com.salesmanager.shop.model.catalog.category.PersistableCategory)5 ReadableProduct (com.salesmanager.shop.model.catalog.product.ReadableProduct)5 Test (org.junit.Test)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 HttpEntity (org.springframework.http.HttpEntity)5 LightPersistableProduct (com.salesmanager.shop.model.catalog.product.LightPersistableProduct)4 CategoryDescription (com.salesmanager.shop.model.catalog.category.CategoryDescription)3 ProductDescription (com.salesmanager.shop.model.catalog.product.ProductDescription)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)2 ConversionException (com.salesmanager.core.business.exception.ConversionException)2 ServiceException (com.salesmanager.core.business.exception.ServiceException)2 OperationNotAllowedException (com.salesmanager.shop.store.api.exception.OperationNotAllowedException)2 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)2 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)2