Search in sources :

Example 6 with Content

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

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

the class ContentFacadeImpl method updateContentPage.

@Override
public void updateContentPage(Long id, PersistableContentPage page, MerchantStore merchantStore, Language language) {
    Validate.notNull(page);
    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("Page with id [" + id + "] does not exist for store [" + merchantStore.getCode() + "]");
        }
        page.setId(id);
        content = convertContentPageToContent(merchantStore, content, page);
        contentService.saveOrUpdate(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)

Example 8 with Content

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

the class ContentFacadeImpl method getContent.

@Override
public ReadableContentFull getContent(String code, MerchantStore store, Language language) {
    Validate.notNull(store, "MerchantStore not null");
    Validate.notNull(code, "Content code must not be null");
    try {
        Content content = contentService.getByCode(code, store);
        if (content == null) {
            throw new ResourceNotFoundException("No content found with code [" + code + "] for store [" + store.getCode() + "]");
        }
        return this.convertContentToReadableContentFull(store, language, content);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Error while getting content [" + code + "]", e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) Content(com.salesmanager.core.model.content.Content) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 9 with Content

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

the class ContentFacadeImpl method saveContentPage.

@Override
public Long saveContentPage(PersistableContentPage page, MerchantStore merchantStore, Language language) {
    Validate.notNull(page);
    Validate.notNull(page.getCode(), "Content code must not be null");
    Validate.notNull(merchantStore);
    try {
        Content content = null;
        content = contentService.getByCode(page.getCode(), merchantStore);
        if (content != null) {
            throw new ConstraintException("Page with code [" + page.getCode() + "] already exist for store [" + merchantStore.getCode() + "]");
        }
        content = convertContentPageToContent(merchantStore, content, page);
        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 10 with Content

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

the class ContentFacadeImpl method delete.

@Override
public void delete(MerchantStore store, Long id) {
    Validate.notNull(store, "MerchantStore not null");
    Validate.notNull(id, "Content id must not be null");
    // select content first
    Content content = contentService.getById(id);
    if (content != null) {
        if (content.getMerchantStore().getId().intValue() != store.getId().intValue()) {
            throw new ResourceNotFoundException("No content found with id [" + id + "] for store [" + store.getCode() + "]");
        }
    }
    try {
        contentService.delete(content);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Exception while deleting content " + e.getMessage(), e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) Content(com.salesmanager.core.model.content.Content) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) 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