001/* 002 * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Miguel Nixo 018 */ 019package org.nuxeo.ecm.platform.picture.convert; 020 021import java.io.Serializable; 022import java.util.ArrayList; 023import java.util.List; 024import java.util.Map; 025 026import org.apache.commons.logging.Log; 027import org.apache.commons.logging.LogFactory; 028import org.nuxeo.ecm.core.api.Blob; 029import org.nuxeo.ecm.core.api.blobholder.BlobHolder; 030import org.nuxeo.ecm.core.convert.api.ConversionException; 031import org.nuxeo.ecm.core.convert.cache.SimpleCachableBlobHolder; 032import org.nuxeo.ecm.core.convert.extension.Converter; 033import org.nuxeo.ecm.core.convert.extension.ConverterDescriptor; 034import org.nuxeo.ecm.platform.picture.api.ImagingService; 035import org.nuxeo.runtime.api.Framework; 036 037/** 038 * @since 8.4 039 */ 040public class ConvertToPDFPictureConverter implements Converter { 041 042 private static final Log log = LogFactory.getLog(ConvertToPDFPictureConverter.class); 043 044 @Override 045 public BlobHolder convert(BlobHolder blobHolder, Map<String, Serializable> parameters) throws ConversionException { 046 ImagingService service = Framework.getService(ImagingService.class); 047 List<Blob> sources = blobHolder.getBlobs(); 048 List<Blob> results = new ArrayList<>(sources.size()); 049 sources.stream().filter(source -> source != null).forEach(source -> { 050 Blob result = service.convertToPDF(source); 051 if (result != null) { 052 results.add(result); 053 } 054 }); 055 return new SimpleCachableBlobHolder(results); 056 } 057 058 @Override 059 public void init(ConverterDescriptor descriptor) { 060 } 061 062}