Search in sources :

Example 1 with ContentFolder

use of com.salesmanager.shop.model.content.ContentFolder in project shopizer by shopizer-ecommerce.

the class ContentFacadeImpl method getContentFolder.

@Override
public ContentFolder getContentFolder(String folder, MerchantStore store) throws Exception {
    try {
        List<String> imageNames = Optional.ofNullable(contentService.getContentFilesNames(store.getCode(), FileContentType.IMAGE)).orElseThrow(() -> new ResourceNotFoundException("No Folder found for path : " + folder));
        // images from CMS
        List<ContentImage> contentImages = imageNames.stream().map(name -> convertToContentImage(name, store)).collect(Collectors.toList());
        ContentFolder contentFolder = new ContentFolder();
        if (!StringUtils.isBlank(folder)) {
            contentFolder.setPath(URLEncoder.encode(folder, "UTF-8"));
        }
        contentFolder.getContent().addAll(contentImages);
        return contentFolder;
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Error while getting folder " + e.getMessage(), 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) ContentImage(com.salesmanager.shop.model.content.ContentImage) ContentFolder(com.salesmanager.shop.model.content.ContentFolder) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 2 with ContentFolder

use of com.salesmanager.shop.model.content.ContentFolder in project shopizer by shopizer-ecommerce.

the class ContentAdministrationApi method list.

/**
 * Works with ng-file-man client
 *
 * @param path
 * @param merchantStore
 * @param language
 * @return
 * @throws Exception
 */
@GetMapping(value = "/private/content/list", produces = MediaType.APPLICATION_JSON_VALUE)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public List<ImageFile> list(@RequestParam(value = "parentPath", required = false) String path, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) throws Exception {
    String decodedPath = decodeContentPath(path);
    ContentFolder folder = contentFacade.getContentFolder(decodedPath, merchantStore);
    List<ImageFile> files = folder.getContent().stream().map(x -> convertToImageFile(merchantStore, x)).collect(Collectors.toList());
    return files;
}
Also used : Content(com.salesmanager.shop.model.content.Content) RequestParam(org.springframework.web.bind.annotation.RequestParam) URLDecoder(java.net.URLDecoder) RestApiException(com.salesmanager.shop.store.api.exception.RestApiException) ContentFacade(com.salesmanager.shop.store.controller.content.facade.ContentFacade) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) StringUtils(org.apache.commons.lang3.StringUtils) CrossOrigin(org.springframework.web.bind.annotation.CrossOrigin) 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) Qualifier(org.springframework.beans.factory.annotation.Qualifier) GetMapping(org.springframework.web.bind.annotation.GetMapping) FileNameUtils(com.salesmanager.shop.utils.FileNameUtils) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) FileContentType(com.salesmanager.core.model.content.FileContentType) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) PostMapping(org.springframework.web.bind.annotation.PostMapping) Logger(org.slf4j.Logger) MediaType(org.springframework.http.MediaType) ApiImplicitParam(io.swagger.annotations.ApiImplicitParam) IOException(java.io.IOException) ImageFilePath(com.salesmanager.shop.utils.ImageFilePath) UUID(java.util.UUID) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) Serializable(java.io.Serializable) ApiIgnore(springfox.documentation.annotations.ApiIgnore) ContentFolder(com.salesmanager.shop.model.content.ContentFolder) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) MultipartFile(org.springframework.web.multipart.MultipartFile) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) UnsupportedEncodingException(java.io.UnsupportedEncodingException) FilenameUtils(org.apache.commons.io.FilenameUtils) ContentFolder(com.salesmanager.shop.model.content.ContentFolder) GetMapping(org.springframework.web.bind.annotation.GetMapping) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams)

Aggregations

FileContentType (com.salesmanager.core.model.content.FileContentType)2 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)2 Language (com.salesmanager.core.model.reference.language.Language)2 ContentFile (com.salesmanager.shop.model.content.ContentFile)2 ContentFolder (com.salesmanager.shop.model.content.ContentFolder)2 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)2 ContentFacade (com.salesmanager.shop.store.controller.content.facade.ContentFacade)2 ImageFilePath (com.salesmanager.shop.utils.ImageFilePath)2 IOException (java.io.IOException)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 StringUtils (org.apache.commons.lang3.StringUtils)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Qualifier (org.springframework.beans.factory.annotation.Qualifier)2 ServiceException (com.salesmanager.core.business.exception.ServiceException)1 ContentService (com.salesmanager.core.business.services.content.ContentService)1 LanguageService (com.salesmanager.core.business.services.reference.language.LanguageService)1 Content (com.salesmanager.core.model.content.Content)1