Package com.day.cq.dam.api

Examples of com.day.cq.dam.api.Asset


public class DAMFunctionsTest {

    @Test
    public void testGetTitleOrName() {
        Asset assetWithTitle = mock(Asset.class);
        String title = RandomStringUtils.randomAlphanumeric(10);
        when(assetWithTitle.getMetadataValue(DamConstants.DC_TITLE)).thenReturn(title);
        assertEquals(title, DAMFunctions.getTitleOrName(assetWithTitle));

        Asset assetWithoutTitle = mock(Asset.class);
        String name = RandomStringUtils.randomAlphanumeric(10);
        when(assetWithoutTitle.getName()).thenReturn(name);
        assertEquals(name, DAMFunctions.getTitleOrName(assetWithoutTitle));

        verify(assetWithTitle, only()).getMetadataValue(DamConstants.DC_TITLE);
        verify(assetWithoutTitle).getMetadataValue(DamConstants.DC_TITLE);
        verify(assetWithoutTitle).getName();
View Full Code Here


        when(workItem.getWorkflowData()).thenReturn(data);
        when(data.getPayloadType()).thenReturn(AbstractAssetWorkflowProcess.TYPE_JCR_PATH);
        when(data.getPayload()).thenReturn(path);

        Resource resource = mock(Resource.class);
        Asset asset = mock(Asset.class);
        when(resource.adaptTo(Asset.class)).thenReturn(asset);
        when(resource.getResourceType()).thenReturn(DamConstants.NT_DAM_ASSET);

        when(resourceResolver.getResource(path)).thenReturn(resource);
View Full Code Here

        when(workItem.getWorkflowData()).thenReturn(data);
        when(data.getPayloadType()).thenReturn(AbstractAssetWorkflowProcess.TYPE_JCR_PATH);
        when(data.getPayload()).thenReturn(path);

        Resource resource = mock(Resource.class);
        Asset asset = mock(Asset.class);
        Rendition rendition = mock(Rendition.class);
        when(resource.adaptTo(Asset.class)).thenReturn(asset);
        when(resource.getResourceType()).thenReturn(DamConstants.NT_DAM_ASSET);
        when(resourceResolver.getResource(path)).thenReturn(resource);
        when(asset.getRendition(isA(RenditionPicker.class))).thenReturn(rendition);

        when(rendition.getStream()).then(new Answer<InputStream>() {

            @Override
            public InputStream answer(InvocationOnMock invocation) throws Throwable {
View Full Code Here

        if (renditionName == null) {
            log.warn("Rendition name was not configured in arguments. Skipping.");
            return;
        }

        final Asset asset = getAssetFromPayload(workItem, workflowSession.getSession());
        final Rendition rendition = asset.getRendition(new PrefixRenditionPicker(renditionName));

        if (rendition == null) {
            log.warn("Rendition name {} was not available for asset {}. Skipping.", renditionName, asset);
            return;
        }
View Full Code Here

    @SuppressWarnings("PMD.CollapsibleIfStatements")
    public final void execute(WorkItem workItem, WorkflowSession wfSession, MetaDataMap metaData)
            throws WorkflowException {

        final Asset asset = getAssetFromPayload(workItem, wfSession.getSession());

        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) {
View Full Code Here

    public static Map<String, Object> buildGenericResult(final Hit hit) throws RepositoryException {
        Map<String, Object> map = new LinkedHashMap<String, Object>();

        final Resource resource = hit.getResource();

        /**
         * Apply custom properties based on the "type"
         */

        // Assets
        final Asset asset = DamUtil.resolveToAsset(resource);
View Full Code Here

        if (DamUtil.isAsset(resource)) {
            // For assets, pick the configured rendition if it exists
            // If rendition does not exist, use original

            final Asset asset = DamUtil.resolveToAsset(resource);
            Rendition rendition = asset.getRendition(renditionPatternPicker);

            if (rendition == null) {
                log.warn("Could not find rendition [ {} ] for [ {} ]", renditionPatternPicker.toString(),
                        resource.getPath());
                rendition = asset.getOriginal();
            }

            final Resource renditionResource = request.getResourceResolver().getResource(rendition.getPath());

            final Image image = new Image(resource);
View Full Code Here

            for (final String path : paths) {
                // For each item in the WF Package, or if not a WF Package, path = payloadPath

                final Page page = pageManager.getContainingPage(path);
                final Asset asset = DamUtil.resolveToAsset(resourceResolver.getResource(path));

                Resource resource;

                if (page != null) {
                    // Page
                    resource = page.getContentResource();
                    log.trace("Candidate Page for setting replicateBy is [ {} ]", resource.getPath());
                } else if (asset != null) {
                    // DAM Asset
                    final Resource assetResource = resourceResolver.getResource(asset.getPath());
                    resource = assetResource.getChild(JcrConstants.JCR_CONTENT);
                    log.trace("Candidate Asset for setting replicateBy is [ {} ]", resource.getPath());
                } else {
                    // Some other resource
                    resource = resourceResolver.getResource(path);
View Full Code Here

TOP

Related Classes of com.day.cq.dam.api.Asset

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.