Search in sources :

Example 1 with Content

use of com.salesmanager.core.model.content.Content in project shopizer by shopizer-ecommerce.

the class LandingController method displayLanding.

@RequestMapping(value = { Constants.SHOP_URI + "/home.html", Constants.SHOP_URI + "/", Constants.SHOP_URI }, method = RequestMethod.GET)
public String displayLanding(Model model, HttpServletRequest request, HttpServletResponse response, Locale locale) throws Exception {
    Language language = (Language) request.getAttribute(Constants.LANGUAGE);
    MerchantStore store = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
    request.setAttribute(Constants.LINK_CODE, HOME_LINK_CODE);
    Content content = contentService.getByCode(LANDING_PAGE, store, language);
    /**
     * Rebuild breadcrumb *
     */
    BreadcrumbItem item = new BreadcrumbItem();
    item.setItemType(BreadcrumbItemType.HOME);
    item.setLabel(messages.getMessage(Constants.HOME_MENU_KEY, locale));
    item.setUrl(Constants.HOME_URL);
    Breadcrumb breadCrumb = new Breadcrumb();
    breadCrumb.setLanguage(language);
    List<BreadcrumbItem> items = new ArrayList<BreadcrumbItem>();
    items.add(item);
    breadCrumb.setBreadCrumbs(items);
    request.getSession().setAttribute(Constants.BREADCRUMB, breadCrumb);
    request.setAttribute(Constants.BREADCRUMB, breadCrumb);
    if (content != null) {
        ContentDescription description = content.getDescription();
        model.addAttribute("page", description);
        PageInformation pageInformation = new PageInformation();
        pageInformation.setPageTitle(description.getName());
        pageInformation.setPageDescription(description.getMetatagDescription());
        pageInformation.setPageKeywords(description.getMetatagKeywords());
        request.setAttribute(Constants.REQUEST_PAGE_INFORMATION, pageInformation);
    }
    ReadableProductPopulator populator = new ReadableProductPopulator();
    populator.setPricingService(pricingService);
    populator.setimageUtils(imageUtils);
    // featured items
    List<ProductRelationship> relationships = productRelationshipService.getByType(store, ProductRelationshipType.FEATURED_ITEM, language);
    List<ReadableProduct> featuredItems = new ArrayList<ReadableProduct>();
    Date today = new Date();
    for (ProductRelationship relationship : relationships) {
        Product product = relationship.getRelatedProduct();
        if (product.isAvailable() && DateUtil.dateBeforeEqualsDate(product.getDateAvailable(), today)) {
            ReadableProduct proxyProduct = populator.populate(product, new ReadableProduct(), store, language);
            featuredItems.add(proxyProduct);
        }
    }
    String tmpl = store.getStoreTemplate();
    if (StringUtils.isBlank(tmpl)) {
        tmpl = "generic";
    }
    model.addAttribute("featuredItems", featuredItems);
    /**
     * template *
     */
    StringBuilder template = new StringBuilder().append("landing.").append(tmpl);
    return template.toString();
}
Also used : BreadcrumbItem(com.salesmanager.shop.model.shop.BreadcrumbItem) ArrayList(java.util.ArrayList) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) Breadcrumb(com.salesmanager.shop.model.shop.Breadcrumb) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Date(java.util.Date) Language(com.salesmanager.core.model.reference.language.Language) PageInformation(com.salesmanager.shop.model.shop.PageInformation) ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator) ProductRelationship(com.salesmanager.core.model.catalog.product.relationship.ProductRelationship) Content(com.salesmanager.core.model.content.Content) ContentDescription(com.salesmanager.core.model.content.ContentDescription) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with Content

use of com.salesmanager.core.model.content.Content in project shopizer by shopizer-ecommerce.

the class StoreFilter method getContent.

private Map<String, List<Content>> getContent(MerchantStore store, Language language) throws Exception {
    Map<String, List<Content>> contents = new ConcurrentHashMap<String, List<Content>>();
    // Get boxes and sections from the database
    List<ContentType> contentTypes = new ArrayList<ContentType>();
    contentTypes.add(ContentType.BOX);
    contentTypes.add(ContentType.SECTION);
    List<Content> contentPages = contentService.listByType(contentTypes, store, language);
    if (contentPages != null && contentPages.size() > 0) {
        // create a Map<String,List<Content>
        for (Content content : contentPages) {
            if (content.isVisible()) {
                List<ContentDescription> descriptions = content.getDescriptions();
                for (ContentDescription contentDescription : descriptions) {
                    Language lang = contentDescription.getLanguage();
                    String key = new StringBuilder().append(store.getId()).append("_").append(Constants.CONTENT_CACHE_KEY).append("-").append(lang.getCode()).toString();
                    List<Content> contentList = null;
                    if (contents == null || contents.size() == 0) {
                        contents = new HashMap<String, List<Content>>();
                    }
                    if (!contents.containsKey(key)) {
                        contentList = new ArrayList<Content>();
                        contents.put(key, contentList);
                    } else {
                        // get from key
                        contentList = contents.get(key);
                        if (contentList == null) {
                            LOGGER.error("Cannot find content key in cache " + key);
                            continue;
                        }
                    }
                    contentList.add(content);
                }
            }
        }
    }
    return contents;
}
Also used : ContentType(com.salesmanager.core.model.content.ContentType) Language(com.salesmanager.core.model.reference.language.Language) Content(com.salesmanager.core.model.content.Content) ContentDescription(com.salesmanager.core.model.content.ContentDescription) ReadableCategoryList(com.salesmanager.shop.model.catalog.category.ReadableCategoryList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 3 with Content

use of com.salesmanager.core.model.content.Content in project shopizer by shopizer-ecommerce.

the class ContentFacadeImpl method convertContentBoxToContent.

private Content convertContentBoxToContent(MerchantStore store, Content model, PersistableContentBox content) throws Exception {
    Content contentModel = new Content();
    if (model != null) {
        contentModel = model;
    }
    List<ContentDescription> descriptions = buildDescriptions(contentModel, content.getDescriptions());
    for (ContentDescription cd : descriptions) {
        cd.setContent(contentModel);
    }
    contentModel.setCode(content.getCode());
    contentModel.setContentType(ContentType.BOX);
    contentModel.setMerchantStore(store);
    contentModel.setVisible(content.isVisible());
    contentModel.setDescriptions(descriptions);
    contentModel.setId(content.getId());
    return contentModel;
}
Also used : Content(com.salesmanager.core.model.content.Content) ContentDescription(com.salesmanager.core.model.content.ContentDescription)

Example 4 with Content

use of com.salesmanager.core.model.content.Content 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);
    }
}
Also used : ContentDescription(com.salesmanager.core.model.content.ContentDescription) ContentFacade(com.salesmanager.shop.store.controller.content.facade.ContentFacade) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) LanguageService(com.salesmanager.core.business.services.reference.language.LanguageService) ContentDescriptionEntity(com.salesmanager.shop.model.content.ContentDescriptionEntity) ArrayList(java.util.ArrayList) ServiceException(com.salesmanager.core.business.exception.ServiceException) PersistableContentBox(com.salesmanager.shop.model.content.box.PersistableContentBox) PersistableContentPage(com.salesmanager.shop.model.content.page.PersistableContentPage) Inject(javax.inject.Inject) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ContentFile(com.salesmanager.shop.model.content.ContentFile) ReadableContentPageFull(com.salesmanager.shop.model.content.page.ReadableContentPageFull) ReadableContentPage(com.salesmanager.shop.model.content.page.ReadableContentPage) ByteArrayInputStream(java.io.ByteArrayInputStream) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Content(com.salesmanager.core.model.content.Content) ReadableContentFull(com.salesmanager.shop.model.content.ReadableContentFull) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ContentType(com.salesmanager.core.model.content.ContentType) FileContentType(com.salesmanager.core.model.content.FileContentType) ReadableContentBox(com.salesmanager.shop.model.content.box.ReadableContentBox) Validate(org.jsoup.helper.Validate) OutputContentFile(com.salesmanager.core.model.content.OutputContentFile) Logger(org.slf4j.Logger) ConstraintException(com.salesmanager.shop.store.api.exception.ConstraintException) IOException(java.io.IOException) ImageFilePath(com.salesmanager.shop.utils.ImageFilePath) Page(org.springframework.data.domain.Page) InputContentFile(com.salesmanager.core.model.content.InputContentFile) Collectors(java.util.stream.Collectors) ContentService(com.salesmanager.core.business.services.content.ContentService) ContentFolder(com.salesmanager.shop.model.content.ContentFolder) ReadableContentBoxFull(com.salesmanager.shop.model.content.box.ReadableContentBoxFull) URLEncoder(java.net.URLEncoder) List(java.util.List) Component(org.springframework.stereotype.Component) ContentImage(com.salesmanager.shop.model.content.ContentImage) CollectionUtils(org.springframework.util.CollectionUtils) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) Optional(java.util.Optional) ReadableContentEntity(com.salesmanager.shop.model.content.ReadableContentEntity) FilePathUtils(com.salesmanager.shop.utils.FilePathUtils) InputStream(java.io.InputStream) ReadableEntityList(com.salesmanager.shop.model.entity.ReadableEntityList) ReadableEntityList(com.salesmanager.shop.model.entity.ReadableEntityList) ServiceException(com.salesmanager.core.business.exception.ServiceException) Content(com.salesmanager.core.model.content.Content) ReadableContentBox(com.salesmanager.shop.model.content.box.ReadableContentBox) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 5 with Content

use of com.salesmanager.core.model.content.Content in project shopizer by shopizer-ecommerce.

the class ContentFacadeImpl method deleteContent.

@Override
public void deleteContent(Long id, MerchantStore merchantStore) {
    Validate.notNull(id, "Content id must not be null");
    Validate.notNull(merchantStore);
    try {
        Content content = null;
        content = contentService.getById(id, merchantStore);
        if (content == null) {
            throw new ConstraintException("Content with id [" + id + "] does not exist for store [" + merchantStore.getCode() + "]");
        }
        contentService.delete(content);
    } catch (Exception e) {
        throw new ServiceRuntimeException(e);
    }
}
Also used : Content(com.salesmanager.core.model.content.Content) ConstraintException(com.salesmanager.shop.store.api.exception.ConstraintException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ConstraintException(com.salesmanager.shop.store.api.exception.ConstraintException) IOException(java.io.IOException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Aggregations

Content (com.salesmanager.core.model.content.Content)25 ServiceException (com.salesmanager.core.business.exception.ServiceException)14 ContentDescription (com.salesmanager.core.model.content.ContentDescription)14 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)14 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)14 ConstraintException (com.salesmanager.shop.store.api.exception.ConstraintException)11 IOException (java.io.IOException)11 Language (com.salesmanager.core.model.reference.language.Language)10 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)9 ArrayList (java.util.ArrayList)8 ContentType (com.salesmanager.core.model.content.ContentType)7 ContentService (com.salesmanager.core.business.services.content.ContentService)6 LanguageService (com.salesmanager.core.business.services.reference.language.LanguageService)6 FileContentType (com.salesmanager.core.model.content.FileContentType)6 InputContentFile (com.salesmanager.core.model.content.InputContentFile)6 OutputContentFile (com.salesmanager.core.model.content.OutputContentFile)6 ContentDescriptionEntity (com.salesmanager.shop.model.content.ContentDescriptionEntity)6 ContentFile (com.salesmanager.shop.model.content.ContentFile)6 ContentFolder (com.salesmanager.shop.model.content.ContentFolder)6 ContentImage (com.salesmanager.shop.model.content.ContentImage)6