Search in sources :

Example 6 with ContentDescription

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

the class ContentFacadeImpl method contentDescriptionToReadableContent.

private ReadableContentPage contentDescriptionToReadableContent(MerchantStore store, Content content, ContentDescription contentDescription) {
    ReadableContentPage page = new ReadableContentPage();
    ContentDescription desc = new ContentDescription();
    desc.setName(contentDescription.getName());
    desc.setDescription(contentDescription.getDescription());
    page.setId(content.getId());
    desc.setSeUrl(contentDescription.getSeUrl());
    page.setLinkToMenu(content.isLinkToMenu());
    desc.setTitle(contentDescription.getTitle());
    desc.setMetatagDescription(contentDescription.getMetatagDescription());
    page.setContentType(ContentType.PAGE.name());
    page.setCode(content.getCode());
    page.setPath(fileUtils.buildStaticFilePath(store.getCode(), contentDescription.getSeUrl()));
    return page;
}
Also used : ContentDescription(com.salesmanager.core.model.content.ContentDescription) ReadableContentPage(com.salesmanager.shop.model.content.page.ReadableContentPage)

Example 7 with ContentDescription

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

the class ContentFacadeImpl method getContentBox.

@Override
public ReadableContentBox getContentBox(String code, MerchantStore store, Language language) {
    Validate.notNull(code, "Content code cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    try {
        Content content = null;
        ReadableContentBox box = new ReadableContentBox();
        if (language != null) {
            content = Optional.ofNullable(contentService.getByCode(code, store, language)).orElseThrow(() -> new ResourceNotFoundException("Resource not found [" + code + "] for store [" + store.getCode() + "]"));
            Optional<ContentDescription> contentDescription = findAppropriateContentDescription(content.getDescriptions(), language);
            if (contentDescription.isPresent()) {
                com.salesmanager.shop.model.content.common.ContentDescription desc = this.contentDescription(// return cdata description
                contentDescription.get());
                desc.setDescription(this.fixContentDescription(desc.getDescription()));
                box.setDescription(desc);
            }
            return box;
        } else {
            content = Optional.ofNullable(contentService.getByCode(code, store)).orElseThrow(() -> new ResourceNotFoundException("Resource not found [" + code + "] for store [" + store.getCode() + "]"));
            // all languages
            ReadableContentBoxFull full = new ReadableContentBoxFull();
            List<com.salesmanager.shop.model.content.common.ContentDescription> descriptions = content.getDescriptions().stream().map(d -> this.contentDescription(d)).collect(Collectors.toList());
            /**
             *				Optional<ContentDescription> contentDescription = findAppropriateContentDescription(
             *						content.getDescriptions(), store.getDefaultLanguage());
             *
             *				if(contentDescription.isPresent()) {
             *					com.salesmanager.shop.model.content.common.ContentDescription desc = this
             *							.contentDescription(contentDescription.get());
             *					full.setDescription(desc);
             *				}
             */
            full.setDescriptions(descriptions);
            full.setCode(content.getCode());
            full.setId(content.getId());
            full.setVisible(content.isVisible());
            return full;
        }
    } catch (ServiceException e) {
        throw new ServiceRuntimeException(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) ReadableContentBoxFull(com.salesmanager.shop.model.content.box.ReadableContentBoxFull) ReadableContentBox(com.salesmanager.shop.model.content.box.ReadableContentBox) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceException(com.salesmanager.core.business.exception.ServiceException) Content(com.salesmanager.core.model.content.Content) ContentDescription(com.salesmanager.core.model.content.ContentDescription) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException)

Example 8 with ContentDescription

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

the class ContentFacadeImpl method getContentPageByName.

@Override
public ReadableContentPage getContentPageByName(String name, MerchantStore store, Language language) {
    Validate.notNull(name, "Content name cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(language, "Language cannot be null");
    try {
        ContentDescription contentDescription = Optional.ofNullable(contentService.getBySeUrl(store, name)).orElseThrow(() -> new ResourceNotFoundException("No page found : " + name));
        return this.contentDescriptionToReadableContent(store, contentDescription.getContent(), contentDescription);
    } catch (Exception e) {
        throw new ServiceRuntimeException("Error while getting page " + e.getMessage(), e);
    }
}
Also used : ContentDescription(com.salesmanager.core.model.content.ContentDescription) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) 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)

Example 9 with ContentDescription

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

the class ContentFacadeImpl method createContentDescriptionEntitys.

/*
	 * private Content convertContentPageToContent(MerchantStore store, Language
	 * language, Content content, PersistableContentEntity contentPage) throws
	 * ServiceException {
	 * 
	 * ContentType contentType =
	 * ContentType.valueOf(contentPage.getContentType()); if (contentType ==
	 * null) { throw new
	 * ServiceRuntimeException("Invalid specified contentType [" +
	 * contentPage.getContentType() + "]"); }
	 * 
	 * List<ContentDescription> descriptions = createContentDescription(store,
	 * content, contentPage); descriptions.stream().forEach(c ->
	 * c.setContent(content));
	 * 
	 * content.setDescriptions(descriptions);
	 * 
	 * // ContentDescription contentDescription = //
	 * createContentDescription(store, contentPage, language); //
	 * setContentDescriptionToContentModel(content,contentDescription,language);
	 * 
	 * // contentDescription.setContent(content);
	 * 
	 * if (contentPage.getId() != null && contentPage.getId().longValue() > 0) {
	 * content.setId(contentPage.getId()); }
	 * content.setVisible(contentPage.isVisible());
	 * content.setLinkToMenu(contentPage.isDisplayedInMenu());
	 * content.setContentType(ContentType.valueOf(contentPage.getContentType()))
	 * ; content.setMerchantStore(store);
	 * 
	 * return content; }
	 */
@Deprecated
private List<ContentDescriptionEntity> createContentDescriptionEntitys(MerchantStore store, Content contentModel, Language language) throws ServiceException {
    List<ContentDescriptionEntity> descriptions = new ArrayList<ContentDescriptionEntity>();
    if (!CollectionUtils.isEmpty(contentModel.getDescriptions())) {
        for (ContentDescription description : contentModel.getDescriptions()) {
            if (language != null && !language.getId().equals(description.getLanguage().getId())) {
                continue;
            }
            ContentDescriptionEntity contentDescription = create(description);
            descriptions.add(contentDescription);
        }
    }
    return descriptions;
}
Also used : ArrayList(java.util.ArrayList) ContentDescription(com.salesmanager.core.model.content.ContentDescription) ContentDescriptionEntity(com.salesmanager.shop.model.content.ContentDescriptionEntity)

Example 10 with ContentDescription

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

the class ContentFacadeImpl method convertContentPageToContent.

private Content convertContentPageToContent(MerchantStore store, Content model, PersistableContentPage content) throws Exception {
    Content contentModel = new Content();
    if (model != null) {
        contentModel = model;
    }
    List<ContentDescription> descriptions = buildDescriptions(contentModel, content.getDescriptions());
    contentModel.setCode(content.getCode());
    contentModel.setContentType(ContentType.PAGE);
    contentModel.setMerchantStore(store);
    contentModel.setLinkToMenu(content.isLinkToMenu());
    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)

Aggregations

ContentDescription (com.salesmanager.core.model.content.ContentDescription)16 Content (com.salesmanager.core.model.content.Content)10 Language (com.salesmanager.core.model.reference.language.Language)8 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)6 ArrayList (java.util.ArrayList)6 ContentType (com.salesmanager.core.model.content.ContentType)4 PageInformation (com.salesmanager.shop.model.shop.PageInformation)4 ServiceException (com.salesmanager.core.business.exception.ServiceException)3 ReadableCategoryList (com.salesmanager.shop.model.catalog.category.ReadableCategoryList)3 ContentDescriptionEntity (com.salesmanager.shop.model.content.ContentDescriptionEntity)3 ReadableContentPage (com.salesmanager.shop.model.content.page.ReadableContentPage)3 ConstraintException (com.salesmanager.shop.store.api.exception.ConstraintException)3 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)3 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)3 IOException (java.io.IOException)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 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