如何在工作流程过程中访问资产 [英] How to access the asset in workflow process step

查看:174
本文介绍了如何在工作流程过程中访问资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为 DAM更新资产编写工作流流程步骤,以便上传的资产将是发送到将修改资产的外部服务,然后可以将修改后的资产发送到元数据提取步骤。所以我已将我的流程步骤添加到DAM更新资产中,如下所示:

I am trying to write a workflow process step for the DAM update asset such that the uploaded asset will be sent to an external service that will modify the asset and then the modified asset can be sent to the Metadata extraction step. So I've added my process step to the DAM update asset like this:

到目前为止,我的代码看起来像这样:

And my code looks like this so far:

public void execute(WorkItem item, WorkflowSession wfsession,MetaDataMap args) throws WorkflowException {
    try
    {
        log.info("Here2 in execute method");    //ensure that the execute method is invoked

        final Map<String, Object> map = new HashMap<String, Object>();
        map.put( "user.jcr.session", wfsession.getSession());

        ResourceResolver rr = resolverFactory.getResourceResolver(map);
        String path = item.getWorkflowData().getPayload().toString();
        log.info("Here2 path: " + path);
        Resource resource = rr.getResource(path);
        log.info("Here2 resource: " + resource);
        InputStream is = resource.adaptTo(InputStream.class);
        log.info("Here2 assets IS: " + is);
    }

    catch (Exception e)
    {
        log.info("Here Error");
        e.printStackTrace();
    }
}

这是我上传时在日志中看到的内容资产:

This is what I see in the logs when I upload an asset:

执行方法中的Here2
Here2路径:/content/dam/photo1.JPG/jcr:content/renditions/original
Here2资产:null

Here2 in execute method Here2 path: /content/dam/photo1.JPG/jcr:content/renditions/original Here2 asset: null

问题


  • 我的外部service具有通过HTTP接受请求的API。我应该如何将资产发送到外部服务?

  • 一旦外部服务修改资产,我应该怎样做才能让元数据提取步骤读取修改后的资产而不是原始资产?

推荐答案

要通过HTTP访问外部服务,您必须编写客户端。 CQ提供 commons-httpclient 捆绑,您可以使用它来访问该服务。可以在此处找到该库的文档。我不知道服务是否期望使用PUT或POST发送文件,但httpclient提供了所有这些方法。您所要做的就是提供适当的 InputStream 。使您的资源适应 Rendition 并使用 getStream()方法获取 InputStream

In order to access your external service via HTTP, you have to write a client. CQ provides commons-httpclient bundle and you may use it to access the service. Documentation for the library can be found here. I don't know if the service expects that the file will be send using PUT or POST, but httpclient provides all these methods. All you have to do is to provide appropriate InputStream. Adapt your resource to Rendition and use getStream() method to get the InputStream.

当您从网络服务获得修改后的资产时,您需要替换原来的资产:

When you'll get the modified asset from the webservice, you need to replace the original one:

// rendition = ...;      // original rendition object created as above
// newInputStream = ...; // new asset received from your webservice
Asset asset = rendition.getAsset();
asset.addRendition("original", newInputStream, rendition.getMimeType());

这篇关于如何在工作流程过程中访问资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆