Search in sources :

Example 11 with Content

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

Example 12 with Content

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

the class ContentRepositoryImpl method listNameByType.

@Override
public List<ContentDescription> listNameByType(List<ContentType> contentType, MerchantStore store, Language language) {
    StringBuilder qs = new StringBuilder();
    qs.append("select c from Content c ");
    qs.append("left join fetch c.descriptions cd join fetch c.merchantStore cm ");
    qs.append("where c.contentType in (:ct) ");
    qs.append("and cm.id =:cm ");
    qs.append("and cd.language.id =:cl ");
    qs.append("and c.visible=true ");
    qs.append("order by c.sortOrder");
    String hql = qs.toString();
    Query q = this.em.createQuery(hql);
    q.setParameter("ct", contentType);
    q.setParameter("cm", store.getId());
    q.setParameter("cl", language.getId());
    @SuppressWarnings("unchecked") List<Content> contents = q.getResultList();
    List<ContentDescription> descriptions = new ArrayList<ContentDescription>();
    for (Content c : contents) {
        String name = c.getDescription().getName();
        String url = c.getDescription().getSeUrl();
        ContentDescription contentDescription = new ContentDescription();
        contentDescription.setName(name);
        contentDescription.setSeUrl(url);
        contentDescription.setContent(c);
        descriptions.add(contentDescription);
    }
    return descriptions;
}
Also used : Query(javax.persistence.Query) Content(com.salesmanager.core.model.content.Content) ArrayList(java.util.ArrayList) ContentDescription(com.salesmanager.core.model.content.ContentDescription)

Example 13 with Content

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

the class ContentServiceImpl method delete.

@Override
public void delete(Content content) throws ServiceException {
    Content c = this.getById(content.getId());
    super.delete(c);
}
Also used : Content(com.salesmanager.core.model.content.Content)

Example 14 with Content

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

the class ContentFacadeImpl method saveContentBox.

@Override
public Long saveContentBox(PersistableContentBox box, MerchantStore merchantStore, Language language) {
    Validate.notNull(box);
    Validate.notNull(box.getCode(), "Content box must not be null");
    Validate.notNull(merchantStore);
    try {
        Content content = null;
        content = contentService.getByCode(box.getCode(), merchantStore);
        if (content != null) {
            throw new ConstraintException("Content box with code [" + box.getCode() + "] already exist for store [" + merchantStore.getCode() + "]");
        }
        content = convertContentBoxToContent(merchantStore, content, box);
        contentService.saveOrUpdate(content);
        return content.getId();
    } 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)

Example 15 with Content

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

the class ContentFacadeImpl method convertContentToReadableContentBox.

private ReadableContentBox convertContentToReadableContentBox(MerchantStore store, Language language, Content content) {
    if (language != null) {
        ReadableContentBox box = new ReadableContentBox();
        this.setDescription(content, box, language);
        box.setCode(content.getCode());
        box.setId(content.getId());
        box.setVisible(content.isVisible());
        return box;
    } else {
        ReadableContentBoxFull box = new ReadableContentBoxFull();
        List<com.salesmanager.shop.model.content.common.ContentDescription> descriptions = content.getDescriptions().stream().map(d -> this.contentDescription(d)).collect(Collectors.toList());
        this.setDescription(content, box, store.getDefaultLanguage());
        box.setDescriptions(descriptions);
        box.setCode(content.getCode());
        box.setId(content.getId());
        box.setVisible(content.isVisible());
        return box;
    }
// TODO revise this
// String staticImageFilePath = imageUtils.buildStaticImageUtils(store,
// content.getCode() + ".jpg");
// box.setImage(staticImageFilePath);
}
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) ContentDescription(com.salesmanager.core.model.content.ContentDescription) ReadableContentBox(com.salesmanager.shop.model.content.box.ReadableContentBox)

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