Search in sources :

Example 11 with InputContentFile

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

the class StaticContentTest method createImage.

@Test
public void createImage() throws ServiceException, FileNotFoundException, IOException {
    MerchantStore store = merchantService.getByCode(MerchantStore.DEFAULT_STORE);
    final File file1 = new File(IMAGE_FILE);
    if (!file1.exists() || !file1.canRead()) {
        throw new ServiceException("Can't read" + file1.getAbsolutePath());
    }
    final byte[] is = IOUtils.toByteArray(new FileInputStream(file1));
    final ByteArrayInputStream inputStream = new ByteArrayInputStream(is);
    final InputContentFile cmsContentImage = new InputContentFile();
    cmsContentImage.setFileName(file1.getName());
    cmsContentImage.setFile(inputStream);
    cmsContentImage.setFileContentType(FileContentType.IMAGE);
    // Add image
    contentService.addContentFile(store.getCode(), cmsContentImage);
    // get image
    OutputContentFile image = contentService.getContentFile(store.getCode(), FileContentType.IMAGE, file1.getName());
    // print image
    OutputStream outputStream = new FileOutputStream(OUTPUT_FOLDER + image.getFileName());
    ByteArrayOutputStream baos = image.getFile();
    baos.writeTo(outputStream);
    // remove image
    contentService.removeFile(store.getCode(), FileContentType.IMAGE, file1.getName());
}
Also used : InputContentFile(com.salesmanager.core.model.content.InputContentFile) ServiceException(com.salesmanager.core.business.exception.ServiceException) ByteArrayInputStream(java.io.ByteArrayInputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) OutputContentFile(com.salesmanager.core.model.content.OutputContentFile) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) OutputContentFile(com.salesmanager.core.model.content.OutputContentFile) InputContentFile(com.salesmanager.core.model.content.InputContentFile) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Aggregations

InputContentFile (com.salesmanager.core.model.content.InputContentFile)11 ServiceException (com.salesmanager.core.business.exception.ServiceException)9 ByteArrayInputStream (java.io.ByteArrayInputStream)5 InputStream (java.io.InputStream)5 OutputContentFile (com.salesmanager.core.model.content.OutputContentFile)3 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)2 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)2 RestApiException (com.salesmanager.shop.store.api.exception.RestApiException)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 ProductOptionValue (com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue)1 ProductInstanceGroup (com.salesmanager.core.model.catalog.product.instance.ProductInstanceGroup)1 ProductInstanceImage (com.salesmanager.core.model.catalog.product.instance.ProductInstanceImage)1 FileContentType (com.salesmanager.core.model.content.FileContentType)1 PersistableProductOptionValue (com.salesmanager.shop.model.catalog.product.attribute.PersistableProductOptionValue)1