use of com.salesmanager.shop.model.entity.ReadableEntityList in project shopizer by shopizer-ecommerce.
the class ProductInstanceFacadeImpl method list.
@Override
public ReadableEntityList<ReadableProductInstance> list(Long productId, MerchantStore store, Language language, int page, int count) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(productId, "Product id cannot be null");
Product product = productFacade.getProduct(productId, store);
if (product == null) {
throw new ResourceNotFoundException("Product with id [" + productId + "] not found for store [" + store.getCode() + "]");
}
Page<ProductInstance> instances = productInstanceService.getByProductId(store, product, language, page, count);
List<ReadableProductInstance> readableInstances = instances.stream().map(rp -> this.readableProductInstanceMapper.convert(rp, store, language)).collect(Collectors.toList());
return createReadableList(instances, readableInstances);
}
use of com.salesmanager.shop.model.entity.ReadableEntityList in project shopizer by shopizer-ecommerce.
the class TaxFacadeImpl method taxClasses.
@Override
public ReadableEntityList<ReadableTaxClass> taxClasses(MerchantStore store, Language language) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
try {
List<TaxClass> models = taxClassService.listByStore(store);
List<ReadableTaxClass> taxClasses = models.stream().map(t -> convertToReadableTaxClass(t, store, language)).collect(Collectors.toList());
ReadableEntityList<ReadableTaxClass> list = new ReadableEntityList<ReadableTaxClass>();
list.setItems(taxClasses);
list.setNumber(taxClasses.size());
list.setTotalPages(1);
list.setRecordsTotal(taxClasses.size());
return list;
} catch (ServiceException e) {
LOGGER.error("Error while getting taxClasses for store [" + store.getCode() + "]", e);
throw new ServiceRuntimeException("Error while getting taxClasses for store [" + store.getCode() + "]", e);
}
}
use of com.salesmanager.shop.model.entity.ReadableEntityList in project shopizer by shopizer-ecommerce.
the class TaxFacadeImpl method taxRates.
@Override
public ReadableEntityList<ReadableTaxRate> taxRates(MerchantStore store, Language language) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
try {
List<TaxRate> rates = taxRateService.listByStore(store, language);
List<ReadableTaxRate> readableRates = rates.stream().map(r -> readableTaxRateMapper.convert(r, store, language)).collect(Collectors.toList());
ReadableEntityList<ReadableTaxRate> returnRates = new ReadableEntityList<ReadableTaxRate>();
returnRates.setItems(readableRates);
returnRates.setTotalPages(1);
returnRates.setNumber(readableRates.size());
returnRates.setRecordsTotal(readableRates.size());
return returnRates;
} catch (ServiceException e) {
LOGGER.error("Error while getting taxRates for store [" + store.getCode() + "]", e);
throw new ServiceRuntimeException("Error while getting taxRates for store [" + store.getCode() + "]", e);
}
}
use of com.salesmanager.shop.model.entity.ReadableEntityList in project shopizer by shopizer-ecommerce.
the class ContentFacadeImpl method getContentPages.
@SuppressWarnings("unchecked")
@Override
public ReadableEntityList<ReadableContentPage> getContentPages(MerchantStore store, Language language, int page, int count) {
Validate.notNull(store, "MerchantStore cannot be null");
@SuppressWarnings("rawtypes") ReadableEntityList items = new ReadableEntityList();
Page<Content> contentPages;
try {
contentPages = contentService.listByType(ContentType.PAGE, store, page, count);
items.setTotalPages(contentPages.getTotalPages());
items.setNumber(contentPages.getContent().size());
items.setRecordsTotal(contentPages.getNumberOfElements());
List<ReadableContentBox> boxes = contentPages.getContent().stream().map(content -> convertContentToReadableContentBox(store, language, content)).collect(Collectors.toList());
items.setItems(boxes);
return items;
} catch (ServiceException e) {
throw new ServiceRuntimeException("Exception while getting content ", e);
}
}
use of com.salesmanager.shop.model.entity.ReadableEntityList in project shopizer by shopizer-ecommerce.
the class CatalogFacadeImpl method listCatalogEntry.
@Override
public ReadableEntityList<ReadableCatalogCategoryEntry> listCatalogEntry(Optional<String> product, Long id, MerchantStore store, Language language, int page, int count) {
Validate.notNull(store, "MerchantStore cannot be null");
String productCode = product.orElse(null);
Catalog catalog = catalogService.getById(id, store).orElseThrow(() -> new ResourceNotFoundException("Catalog with id [" + id + "] not found for store [" + store.getCode() + "]"));
Page<CatalogCategoryEntry> entries = catalogEntryService.list(catalog, store, language, productCode, page, count);
if (entries.isEmpty()) {
return new ReadableEntityList<>();
}
List<ReadableCatalogCategoryEntry> readableList = entries.getContent().stream().map(cat -> readableCatalogEntryMapper.convert(cat, store, language)).collect(Collectors.toList());
return createReadableList(entries, readableList);
}
Aggregations