Search in sources :

Example 1 with ContentType

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

the class StoreFilter method getContentPagesNames.

private Map<String, List<ContentDescription>> getContentPagesNames(MerchantStore store, Language language) throws Exception {
    Map<String, List<ContentDescription>> contents = new ConcurrentHashMap<String, List<ContentDescription>>();
    // Get boxes and sections from the database
    List<ContentType> contentTypes = new ArrayList<ContentType>();
    contentTypes.add(ContentType.PAGE);
    List<ContentDescription> contentPages = contentService.listNameByType(contentTypes, store, language);
    if (contentPages != null && contentPages.size() > 0) {
        // create a Map<String,List<Content>
        for (ContentDescription content : contentPages) {
            Language lang = language;
            String key = new StringBuilder().append(store.getId()).append("_").append(Constants.CONTENT_PAGE_CACHE_KEY).append("-").append(lang.getCode()).toString();
            List<ContentDescription> contentList = null;
            if (contents == null || contents.size() == 0) {
                contents = new HashMap<String, List<ContentDescription>>();
            }
            if (!contents.containsKey(key)) {
                contentList = new ArrayList<ContentDescription>();
                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) ContentDescription(com.salesmanager.core.model.content.ContentDescription) ReadableCategoryList(com.salesmanager.shop.model.catalog.category.ReadableCategoryList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 2 with ContentType

use of com.salesmanager.core.model.content.ContentType 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 ContentType

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

the class ContentFacadeImpl method getContents.

@Override
public List<ReadableContentEntity> getContents(Optional<String> type, MerchantStore store, Language language) {
    /**
     * get all types
     */
    List<ContentType> types = new ArrayList<ContentType>();
    types.add(ContentType.BOX);
    types.add(ContentType.PAGE);
    types.add(ContentType.SECTION);
    try {
        return contentService.listByType(types, store, language).stream().map(content -> convertContentToReadableContentEntity(store, language, content)).collect(Collectors.toList());
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Exception while getting contents", 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) ContentType(com.salesmanager.core.model.content.ContentType) FileContentType(com.salesmanager.core.model.content.FileContentType) ServiceException(com.salesmanager.core.business.exception.ServiceException) ArrayList(java.util.ArrayList) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 4 with ContentType

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

the class ContentFacadeImpl method getContentBoxes.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public ReadableEntityList<ReadableContentBox> getContentBoxes(ContentType type, MerchantStore store, Language language, int page, int count) {
    Validate.notNull(store, "MerchantStore cannot be null");
    ReadableEntityList items = new ReadableEntityList();
    Page<Content> contentBoxes;
    try {
        contentBoxes = contentService.listByType(type, store, page, count);
        items.setTotalPages(contentBoxes.getTotalPages());
        items.setNumber(contentBoxes.getContent().size());
        items.setRecordsTotal(contentBoxes.getNumberOfElements());
        List<ReadableContentBox> boxes = contentBoxes.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)

Aggregations

ContentDescription (com.salesmanager.core.model.content.ContentDescription)4 ContentType (com.salesmanager.core.model.content.ContentType)4 Language (com.salesmanager.core.model.reference.language.Language)4 Content (com.salesmanager.core.model.content.Content)3 ServiceException (com.salesmanager.core.business.exception.ServiceException)2 ContentService (com.salesmanager.core.business.services.content.ContentService)2 LanguageService (com.salesmanager.core.business.services.reference.language.LanguageService)2 FileContentType (com.salesmanager.core.model.content.FileContentType)2 InputContentFile (com.salesmanager.core.model.content.InputContentFile)2 OutputContentFile (com.salesmanager.core.model.content.OutputContentFile)2 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)2 ReadableCategoryList (com.salesmanager.shop.model.catalog.category.ReadableCategoryList)2 ContentDescriptionEntity (com.salesmanager.shop.model.content.ContentDescriptionEntity)2 ContentFile (com.salesmanager.shop.model.content.ContentFile)2 ContentFolder (com.salesmanager.shop.model.content.ContentFolder)2 ContentImage (com.salesmanager.shop.model.content.ContentImage)2 ReadableContentEntity (com.salesmanager.shop.model.content.ReadableContentEntity)2 ReadableContentFull (com.salesmanager.shop.model.content.ReadableContentFull)2 PersistableContentBox (com.salesmanager.shop.model.content.box.PersistableContentBox)2 ReadableContentBox (com.salesmanager.shop.model.content.box.ReadableContentBox)2