Package com.day.cq.workflow

Examples of com.day.cq.workflow.WorkflowException


        if (asset == null) {
            String wfPayload = workItem.getWorkflowData().getPayload().toString();
            String message = "execute: cannot process audio, asset [{" + wfPayload
                    + "}] in payload doesn't exist for workflow [{" + workItem.getId() + "}].";
            throw new WorkflowException(message);
        }

        final String assetMimeType = asset.getMimeType();
        if (assetMimeType == null || !assetMimeType.startsWith("audio/")) {
            if (!asset.getName().endsWith(".wav") || !asset.getName().endsWith(".mp3")
                    || !asset.getName().endsWith(".ogg")) {
                log.info("execute: asset [{}] is not of a audio mime type, asset ignored.", asset.getPath());
                return;
            }
        }

        File tmpDir = null;
        File tmpWorkingDir = null;
        FileOutputStream fos = null;
        InputStream is = null;
        FFMpegWrapper wrapper = null;
        try {
            // creating temp directory
            tmpDir = createTempDir(null);

            // creating temp working directory for ffmpeg
            tmpWorkingDir = createTempDir(getWorkingDir());

            // streaming file to temp directory
            final File tmpFile = new File(tmpDir, asset.getName().replace(' ', '_'));
            fos = new FileOutputStream(tmpFile);
            is = asset.getOriginal().getStream();
            IOUtils.copy(is, fos);

            processAudio(metaData, asset, tmpFile, wfSession);

            // get information about original audio file (size, video length,
            // ...)
            wrapper = new FFMpegWrapper(tmpFile, tmpWorkingDir);
            wrapper.setExecutableLocator(locator);

            final ResourceResolver resolver = getResourceResolver(wfSession.getSession());
            final Resource assetResource = asset.adaptTo(Resource.class);
            final Resource metadata = resolver.getResource(assetResource, JCR_CONTENT + "/" + METADATA_FOLDER);

            if (null != metadata) {

                final Node metadataNode = metadata.adaptTo(Node.class);
                metadataNode.setProperty(DC_EXTENT, wrapper.getInputDuration());

                metadataNode.getSession().save();
            } else {
                log.warn("execute: failed setting metdata for asset [{}] in workflow [{}], no metdata node found.",
                        asset.getPath(), workItem.getId());
            }

        } catch (IOException e) {
            throw new WorkflowException(e);
        } catch (RepositoryException e) {
            throw new WorkflowException(e);
        } catch (FfmpegNotFoundException e) {
            log.error(e.getMessage(), e);
        } finally {
            IOUtils.closeQuietly(is);
            IOUtils.closeQuietly(fos);
            try {
                // cleaning up temp directory
                if (tmpDir != null) {
                    FileUtils.deleteDirectory(tmpDir);
                }
            } catch (IOException e) {
                log.error("Could not delete temp directory: {}", tmpDir.getPath());
                throw new WorkflowException(e);

            }
            try {
                // cleaning up ffmpeg's temp working directory
                if (tmpWorkingDir != null) {
View Full Code Here

TOP

Related Classes of com.day.cq.workflow.WorkflowException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.