Search in sources :

Example 1 with WorkflowHelper

use of com.adobe.acs.commons.util.WorkflowHelper in project acs-aem-commons by Adobe-Consulting-Services.

the class AbstractRenditionModifyingProcess method execute.

public final void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaData, WorkflowHelper workflowHelper) throws WorkflowException {
    String[] args = workflowHelper.buildArguments(metaData);
    final String renditionName = workflowHelper.getValuesFromArgs(ARG_RENDITION_NAME, args).size() > 0 ? workflowHelper.getValuesFromArgs(ARG_RENDITION_NAME, args).get(0) : null;
    // image quality: from 0 t0 100%
    final String qualityStr = workflowHelper.getValuesFromArgs(ARG_QUALITY, args).size() > 0 ? workflowHelper.getValuesFromArgs(ARG_QUALITY, args).get(0) : DEFAULT_QUALITY;
    if (renditionName == null) {
        log.warn("Rendition name was not configured in arguments. Skipping.");
        return;
    }
    final WorkflowHelper.AssetResourceResolverPair pair = workflowHelper.getAssetFromPayload(workItem, workflowSession);
    if (pair == null) {
        return;
    }
    final Rendition rendition = pair.asset.getRendition(new PrefixRenditionPicker(renditionName));
    if (rendition == null) {
        log.warn("Rendition name {} was not available for asset {}. Skipping.", renditionName, pair.asset);
        return;
    }
    Layer layer = null;
    try {
        layer = new Layer(rendition.getStream());
        layer = processLayer(layer, rendition, workflowSession, args);
        String mimetype = layer.getMimeType();
        double quality = mimetype.equals("image/gif") ? workflowHelper.getQuality(MAX_GIF_QUALITY, qualityStr) : workflowHelper.getQuality(1.0, qualityStr);
        saveImage(pair.asset, rendition, layer, mimetype, quality, workflowHelper);
    } catch (IIOException e) {
        log.warn("Unable to load image layer from " + rendition.getPath(), e);
    } catch (IOException e) {
        log.warn("Unable to load image layer from " + rendition.getPath(), e);
    } finally {
        if (layer != null) {
            layer.dispose();
            layer = null;
        }
        pair.resourceResolver.close();
    }
}
Also used : Rendition(com.day.cq.dam.api.Rendition) WorkflowHelper(com.adobe.acs.commons.util.WorkflowHelper) IIOException(javax.imageio.IIOException) IOException(java.io.IOException) IIOException(javax.imageio.IIOException) PrefixRenditionPicker(com.day.cq.dam.commons.util.PrefixRenditionPicker) Layer(com.day.image.Layer)

Aggregations

WorkflowHelper (com.adobe.acs.commons.util.WorkflowHelper)1 Rendition (com.day.cq.dam.api.Rendition)1 PrefixRenditionPicker (com.day.cq.dam.commons.util.PrefixRenditionPicker)1 Layer (com.day.image.Layer)1 IOException (java.io.IOException)1 IIOException (javax.imageio.IIOException)1