All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.day.cq.dam.core.process.ThumbnailProcess Maven / Gradle / Ivy

There is a newer version: 6.5.21
Show newest version
/*************************************************************************
 *
 * ADOBE CONFIDENTIAL
 * __________________
 *
 *  Copyright 2014 Adobe Systems Incorporated
 *  All Rights Reserved.
 *
 * NOTICE:  All information contained herein is, and remains
 * the property of Adobe Systems Incorporated and its suppliers,
 * if any.  The intellectual and technical concepts contained
 * herein are proprietary to Adobe Systems Incorporated and its
 * suppliers and are protected by trade secret or copyright law.
 * Dissemination of this information or reproduction of this material
 * is strictly forbidden unless prior written permission is obtained
 * from Adobe Systems Incorporated.
 **************************************************************************/
package com.day.cq.dam.core.process;

import javax.jcr.Node;
import javax.jcr.RepositoryException;

import com.day.cq.dam.commons.util.AssetUpdate;
import com.day.cq.dam.commons.util.AssetUpdateMonitor;
import com.day.cq.dam.commons.util.DamUtil;
import com.day.cq.workflow.exec.WorkflowProcess;
import org.apache.commons.lang.StringUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.jackrabbit.JcrConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.day.cq.dam.api.Asset;
import com.day.cq.dam.api.renditions.RenditionMaker;
import com.day.cq.dam.commons.process.AbstractAssetWorkflowProcess;
import com.day.cq.dam.core.impl.process.CreateFPORenditionProcess;
import com.day.cq.dam.core.impl.ui.preview.FolderPreviewUpdater;
import com.day.cq.workflow.WorkflowException;
import com.day.cq.workflow.WorkflowSession;
import com.day.cq.workflow.exec.WorkItem;
import com.day.cq.workflow.metadata.MetaDataMap;

/**
 * The ThumbnailProcess is called in a Workflow process step. This process will create one or more Thumbnails for the Asset to
 * be procesed, create web enabled image and update folder thumbnail.
 */
@Component
@Service
@Property(name = "process.label", value = "Thumbnail Process")
public class ThumbnailProcess extends AbstractAssetWorkflowProcess {

    /**
     * Logger instance for this class.
     */
    private static final Logger log = LoggerFactory.getLogger(ThumbnailProcess.class);

    @Reference
    private RenditionMaker renditionMaker;

    @Reference
    private FolderPreviewUpdater folderPreviewUpdater;

    @Reference
    private AssetUpdateMonitor monitor;

    private CreateThumbnailProcess thumbnailCreator = new CreateThumbnailProcess();

    private CreateWebEnabledImageProcess webEnabledImageCreator = new CreateWebEnabledImageProcess();

    private UpdateFolderThumbnailProcess folderThumbnailUpdater = new UpdateFolderThumbnailProcess();
    private CreateFPORenditionProcess fpoCreator = new CreateFPORenditionProcess();

    private static final String DAM_SCENE7FILE = "dam:scene7File";

    public void execute(final WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaData) throws WorkflowException {
        final AssetUpdate update = monitor.startUpdate(workItem, getResourceResolver(workflowSession.getSession()), this);
        try {
            final Asset asset = update.getAsset(new AssetUpdate.Check() {
                @Override
                public boolean isNullAcceptable() throws WorkflowException {
                    String wfPayload = workItem.getWorkflowData().getPayload().toString();
                    String message = "execute: cannot process thumbnails, asset [{" + wfPayload + "}] in payload doesn't exist for " +
                            "workflow [{"
                            + workItem.getId() + "}].";
                    throw new WorkflowException(message);
                }
            });
            if (asset != null) {
                try {
                    Node assetNode = asset.adaptTo(Node.class);
                    Node contentNode = assetNode.getNode(JcrConstants.JCR_CONTENT);
                    String scene7File = asset.getMetadata(DAM_SCENE7FILE) != null? asset.getMetadata(DAM_SCENE7FILE).toString() : "";
                    boolean isScene7Video = DamUtil.isVideo(asset) && !StringUtils.isEmpty(scene7File);
                    // don't create static thumbnails/webImage for a scene7 processed video since it creates proxy thumbnails/webImage
                    if (!isScene7Video) {
                        // don't generate thumbnail if default thumbnail is set.
                        if(!(contentNode.hasProperty("dam:manualThumbnail") && contentNode.getProperty("dam:manualThumbnail").getBoolean() == true)){
                            final CreateThumbnailProcess.Config createThumbnailConfig = thumbnailCreator.parseConfig(metaData);
                            thumbnailCreator.createThumbnails(asset, createThumbnailConfig, renditionMaker);
                        }
                        final CreateWebEnabledImageProcess.Config createWebEnabledImageConfig = webEnabledImageCreator.parseConfig(metaData);
                        try {
                            webEnabledImageCreator.createWebEnabledImage(workItem, createWebEnabledImageConfig, asset, renditionMaker);
                        } catch (RepositoryException re){
                            throw new WorkflowException(re);
                        }
                        final CreateFPORenditionProcess.Config fpoConfig = fpoCreator.parseConfig(metaData);
                        fpoCreator.createFPO(workItem, fpoConfig, asset, renditionMaker);
                    } else {
                        log.info("Skip to create static thumbnails/webImage for a scene7 processed video.");
                    }

                    // don't generate thumbnail if default thumbnail is set.
                    if(!(contentNode.hasProperty("dam:manualThumbnail") && contentNode.getProperty("dam:manualThumbnail").getBoolean() == true)){
                        try {
                            folderThumbnailUpdater.updateFolderThumbnail(asset, assetNode, folderPreviewUpdater);
                        } catch (Exception e) {
                            update.error(e);
                            log.error("Error while updating folder thumbnail of asset ", asset.getPath(), e);
                        }
                    }
                } catch (RepositoryException re) {
                    throw new WorkflowException(re);
                }

            }
        } finally {
            update.done();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy