Search in sources :

Example 6 with Manufacturer

use of com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer in project shopizer by shopizer-ecommerce.

the class ManufacturerFacadeImpl method getByProductInCategory.

@Override
public List<ReadableManufacturer> getByProductInCategory(MerchantStore store, Language language, Long categoryId) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(language, "Language cannot be null");
    Validate.notNull(categoryId, "Category id cannot be null");
    Category category = categoryService.getById(categoryId, store.getId());
    if (category == null) {
        throw new ResourceNotFoundException("Category with id [" + categoryId + "] not found");
    }
    if (category.getMerchantStore().getId().longValue() != store.getId().longValue()) {
        throw new UnauthorizedException("Merchant [" + store.getCode() + "] not authorized");
    }
    try {
        List<Manufacturer> manufacturers = manufacturerService.listByProductsInCategory(store, category, language);
        List<ReadableManufacturer> manufacturersList = manufacturers.stream().sorted(new Comparator<Manufacturer>() {

            @Override
            public int compare(final Manufacturer object1, final Manufacturer object2) {
                return object1.getCode().compareTo(object2.getCode());
            }
        }).map(manuf -> readableManufacturerConverter.convert(manuf, store, language)).collect(Collectors.toList());
        return manufacturersList;
    } catch (ServiceException e) {
        throw new ServiceRuntimeException(e);
    }
}
Also used : Autowired(org.springframework.beans.factory.annotation.Autowired) LanguageService(com.salesmanager.core.business.services.reference.language.LanguageService) ArrayList(java.util.ArrayList) ServiceException(com.salesmanager.core.business.exception.ServiceException) Inject(javax.inject.Inject) Language(com.salesmanager.core.model.reference.language.Language) ListCriteria(com.salesmanager.shop.model.entity.ListCriteria) PersistableManufacturerPopulator(com.salesmanager.shop.populator.manufacturer.PersistableManufacturerPopulator) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Service(org.springframework.stereotype.Service) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) CategoryService(com.salesmanager.core.business.services.catalog.category.CategoryService) ManufacturerService(com.salesmanager.core.business.services.catalog.product.manufacturer.ManufacturerService) Mapper(com.salesmanager.shop.mapper.Mapper) PersistableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.PersistableManufacturer) ReadableManufacturerList(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturerList) Validate(org.jsoup.helper.Validate) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) ReadableManufacturerPopulator(com.salesmanager.shop.populator.manufacturer.ReadableManufacturerPopulator) Category(com.salesmanager.core.model.catalog.category.Category) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) List(java.util.List) ManufacturerFacade(com.salesmanager.shop.store.controller.manufacturer.facade.ManufacturerFacade) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) Comparator(java.util.Comparator) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) Category(com.salesmanager.core.model.catalog.category.Category) ServiceException(com.salesmanager.core.business.exception.ServiceException) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) PersistableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.PersistableManufacturer) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 7 with Manufacturer

use of com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer in project shopizer by shopizer-ecommerce.

the class ManufacturerFacadeImpl method listByStore.

@Override
public ReadableManufacturerList listByStore(MerchantStore store, Language language, ListCriteria criteria, int page, int count) {
    ReadableManufacturerList readableList = new ReadableManufacturerList();
    try {
        /**
         * Is this a pageable request
         */
        List<Manufacturer> manufacturers = null;
        Page<Manufacturer> m = null;
        if (language != null) {
            m = manufacturerService.listByStore(store, language, criteria.getName(), page, count);
        } else {
            m = manufacturerService.listByStore(store, criteria.getName(), page, count);
        }
        manufacturers = m.getContent();
        readableList.setTotalPages(m.getTotalPages());
        readableList.setRecordsTotal(m.getTotalElements());
        readableList.setNumber(m.getNumber());
        ReadableManufacturerPopulator populator = new ReadableManufacturerPopulator();
        List<ReadableManufacturer> returnList = new ArrayList<ReadableManufacturer>();
        for (Manufacturer mf : manufacturers) {
            ReadableManufacturer readableManufacturer = new ReadableManufacturer();
            populator.populate(mf, readableManufacturer, store, language);
            returnList.add(readableManufacturer);
        }
        readableList.setManufacturers(returnList);
        return readableList;
    } catch (Exception e) {
        throw new ServiceRuntimeException("Error while get manufacturers", e);
    }
}
Also used : ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) PersistableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.PersistableManufacturer) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) ReadableManufacturerPopulator(com.salesmanager.shop.populator.manufacturer.ReadableManufacturerPopulator) ArrayList(java.util.ArrayList) ReadableManufacturerList(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturerList) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 8 with Manufacturer

use of com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer in project shopizer by shopizer-ecommerce.

the class ManufacturerFacadeImpl method getAllManufacturers.

@Override
public ReadableManufacturerList getAllManufacturers(MerchantStore store, Language language, ListCriteria criteria, int page, int count) {
    ReadableManufacturerList readableList = new ReadableManufacturerList();
    try {
        /**
         * Is this a pageable request
         */
        List<Manufacturer> manufacturers = null;
        if (page == 0 && count == 0) {
            // need total count
            int total = manufacturerService.count(store);
            if (language != null) {
                manufacturers = manufacturerService.listByStore(store, language);
            } else {
                manufacturers = manufacturerService.listByStore(store);
            }
            readableList.setRecordsTotal(total);
            readableList.setNumber(manufacturers.size());
        } else {
            Page<Manufacturer> m = null;
            if (language != null) {
                m = manufacturerService.listByStore(store, language, criteria.getName(), page, count);
            } else {
                m = manufacturerService.listByStore(store, criteria.getName(), page, count);
            }
            manufacturers = m.getContent();
            readableList.setTotalPages(m.getTotalPages());
            readableList.setRecordsTotal(m.getTotalElements());
            readableList.setNumber(m.getNumber());
        }
        ReadableManufacturerPopulator populator = new ReadableManufacturerPopulator();
        List<ReadableManufacturer> returnList = new ArrayList<ReadableManufacturer>();
        for (Manufacturer m : manufacturers) {
            ReadableManufacturer readableManufacturer = new ReadableManufacturer();
            populator.populate(m, readableManufacturer, store, language);
            returnList.add(readableManufacturer);
        }
        readableList.setManufacturers(returnList);
        return readableList;
    } catch (Exception e) {
        throw new ServiceRuntimeException("Error while get manufacturers", e);
    }
}
Also used : ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) PersistableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.PersistableManufacturer) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) ReadableManufacturerPopulator(com.salesmanager.shop.populator.manufacturer.ReadableManufacturerPopulator) ArrayList(java.util.ArrayList) ReadableManufacturerList(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturerList) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 9 with Manufacturer

use of com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer in project shopizer by shopizer-ecommerce.

the class ManufacturerFacadeImpl method getManufacturer.

@Override
public ReadableManufacturer getManufacturer(Long id, MerchantStore store, Language language) throws Exception {
    Manufacturer manufacturer = manufacturerService.getById(id);
    if (manufacturer == null) {
        throw new ResourceNotFoundException("Manufacturer [" + id + "] not found");
    }
    if (manufacturer.getMerchantStore().getId() != store.getId()) {
        throw new ResourceNotFoundException("Manufacturer [" + id + "] not found for store [" + store.getId() + "]");
    }
    ReadableManufacturer readableManufacturer = new ReadableManufacturer();
    ReadableManufacturerPopulator populator = new ReadableManufacturerPopulator();
    readableManufacturer = populator.populate(manufacturer, readableManufacturer, store, language);
    return readableManufacturer;
}
Also used : ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) PersistableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.PersistableManufacturer) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) ReadableManufacturerPopulator(com.salesmanager.shop.populator.manufacturer.ReadableManufacturerPopulator) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException)

Example 10 with Manufacturer

use of com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer in project shopizer by shopizer-ecommerce.

the class ManufacturerFacadeImpl method saveOrUpdateManufacturer.

@Override
public void saveOrUpdateManufacturer(PersistableManufacturer manufacturer, MerchantStore store, Language language) throws Exception {
    PersistableManufacturerPopulator populator = new PersistableManufacturerPopulator();
    populator.setLanguageService(languageService);
    Manufacturer manuf = new Manufacturer();
    if (manufacturer.getId() != null && manufacturer.getId().longValue() > 0) {
        manuf = manufacturerService.getById(manufacturer.getId());
        if (manuf == null) {
            throw new ResourceNotFoundException("Manufacturer with id [" + manufacturer.getId() + "] not found");
        }
        if (manuf.getMerchantStore().getId().intValue() != store.getId().intValue()) {
            throw new ResourceNotFoundException("Manufacturer with id [" + manufacturer.getId() + "] not found for store [" + store.getId() + "]");
        }
    }
    populator.populate(manufacturer, manuf, store, language);
    manufacturerService.saveOrUpdate(manuf);
    manufacturer.setId(manuf.getId());
}
Also used : PersistableManufacturerPopulator(com.salesmanager.shop.populator.manufacturer.PersistableManufacturerPopulator) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) PersistableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.PersistableManufacturer) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException)

Aggregations

Manufacturer (com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer)17 Language (com.salesmanager.core.model.reference.language.Language)12 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)10 Category (com.salesmanager.core.model.catalog.category.Category)9 ProductAvailability (com.salesmanager.core.model.catalog.product.availability.ProductAvailability)8 ProductDescription (com.salesmanager.core.model.catalog.product.description.ProductDescription)8 ProductType (com.salesmanager.core.model.catalog.product.type.ProductType)8 ArrayList (java.util.ArrayList)8 ProductPrice (com.salesmanager.core.model.catalog.product.price.ProductPrice)7 ProductPriceDescription (com.salesmanager.core.model.catalog.product.price.ProductPriceDescription)7 ReadableManufacturer (com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer)7 BigDecimal (java.math.BigDecimal)7 HashSet (java.util.HashSet)7 Product (com.salesmanager.core.model.catalog.product.Product)6 ProductAttribute (com.salesmanager.core.model.catalog.product.attribute.ProductAttribute)6 ManufacturerDescription (com.salesmanager.core.model.catalog.product.manufacturer.ManufacturerDescription)6 PersistableManufacturer (com.salesmanager.shop.model.catalog.manufacturer.PersistableManufacturer)5 ReadableManufacturerPopulator (com.salesmanager.shop.populator.manufacturer.ReadableManufacturerPopulator)5 Date (java.util.Date)5 Test (org.junit.Test)5