Search in sources :

Example 1 with ReadableProductTypeFull

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

the class ReadableProductTypeMapper method type.

private ReadableProductType type(ProductType type, Language language) {
    ReadableProductType readableType = null;
    if (language != null) {
        readableType = new ReadableProductType();
        if (!CollectionUtils.isEmpty(type.getDescriptions())) {
            Optional<ProductTypeDescription> desc = type.getDescriptions().stream().filter(t -> t.getLanguage().getCode().equals(language.getCode())).map(d -> typeDescription(d)).findFirst();
            if (desc.isPresent()) {
                readableType.setDescription(desc.get());
            }
        }
    } else {
        readableType = new ReadableProductTypeFull();
        List<ProductTypeDescription> descriptions = type.getDescriptions().stream().map(t -> this.typeDescription(t)).collect(Collectors.toList());
        ((ReadableProductTypeFull) readableType).setDescriptions(descriptions);
    }
    readableType.setCode(type.getCode());
    readableType.setId(type.getId());
    readableType.setVisible(type.getVisible() != null && type.getVisible().booleanValue() ? true : false);
    readableType.setAllowAddToCart(type.getAllowAddToCart() != null && type.getAllowAddToCart().booleanValue() ? true : false);
    return readableType;
}
Also used : Mapper(com.salesmanager.shop.mapper.Mapper) ReadableProductType(com.salesmanager.shop.model.catalog.product.type.ReadableProductType) Collectors(java.util.stream.Collectors) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Language(com.salesmanager.core.model.reference.language.Language) List(java.util.List) Component(org.springframework.stereotype.Component) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ReadableProductTypeFull(com.salesmanager.shop.model.catalog.product.type.ReadableProductTypeFull) Validate(org.apache.commons.lang3.Validate) Optional(java.util.Optional) ProductType(com.salesmanager.core.model.catalog.product.type.ProductType) ProductTypeDescription(com.salesmanager.shop.model.catalog.product.type.ProductTypeDescription) ProductTypeDescription(com.salesmanager.shop.model.catalog.product.type.ProductTypeDescription) ReadableProductTypeFull(com.salesmanager.shop.model.catalog.product.type.ReadableProductTypeFull) ReadableProductType(com.salesmanager.shop.model.catalog.product.type.ReadableProductType)

Aggregations

ProductType (com.salesmanager.core.model.catalog.product.type.ProductType)1 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)1 Language (com.salesmanager.core.model.reference.language.Language)1 Mapper (com.salesmanager.shop.mapper.Mapper)1 ProductTypeDescription (com.salesmanager.shop.model.catalog.product.type.ProductTypeDescription)1 ReadableProductType (com.salesmanager.shop.model.catalog.product.type.ReadableProductType)1 ReadableProductTypeFull (com.salesmanager.shop.model.catalog.product.type.ReadableProductTypeFull)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 CollectionUtils (org.apache.commons.collections4.CollectionUtils)1 Validate (org.apache.commons.lang3.Validate)1 Component (org.springframework.stereotype.Component)1