Common repository

As a Content Management Product, Alfresco has two different modules, DM and WCM.

In this section, we will see how we can use Alfresco with the combination of DM and WCM both as a single repository. Consider a use case of a company where they are using Alfresco WCM for managing their website but at the same time they have an Intranet application, which is more for managing documents and other assets. For this Intranet, they are using the Alfresco DM. Now suppose some of the documents/assets need to be managed in DM but are basically part of the website and need to be deployed. In this scenario, we can get the advantage of both the DM and WCM in the same repository.

Let's take the example of the Cignex company. As we have already seen in the earlier chapter, the website for Cignex is managed by Alfresco WCM. But in this website, some of the images, videos, and so on are being used, which are managed in DM. There are some departments such as Marketing, Sales, HR, IT, and many more available that are using this Intranet application. Now if a Marketing person is uploading a video, then he or she may have some requirements such as it should be transformed into different formats like 3GP (for cell phones), MPEG4 (for iPod), and Flash (the default format for the website). Alfresco can be integrated with FFMPEG, using which we can easily transform the videos to other formats.

Integrating Alfresco with the FFMPEG Video Transcoder

FFMPEG is a very popular high performance video and audio transcoder. It has various widely used commercial tools to convert audio and video files from one format to another. It is basically a command-line interface. We can easily integrate any such command-line applications with Alfresco.

You need to download the FFMPEG binary version for Microsoft Windows and put it into the<alfresco_install>/bin directory. The command used for transformation is:

ffmpeg.exe -i [input_file.extension] [options] [output_file.extension]

Various options for video transcoding

Following are the various options for video transcoding:

  • -b bitrate

    Set the video bitrate in bit/s (default = 200 kb/s).

    =>512 k

  • -r fps

    Set frame rate (Hz value, fraction, or abbreviation), (default = 25).

    =>15.02

  • -s size

    Set frame size. The format is 'wxh' (ffserver default = 160x128, ffmpeg default = same as source).

    =>320x240

  • -aspect aspect

    Set aspect ratio (4:3, 16:9 or 1.3333, 1.7777).

    =>4:3

Various options for audio transcoding

Following are the various options for audio transcoding:

  • -ar freq

    Set the audio sampling frequency (default = 44100 Hz).

    => 44100

  • -ab bitrate

    Set the audio bitrate in bit/s (default = 64 k).

    => 64 k

  • -ac channels

    Set the number of audio channels (default = 1 Mono; 2 = stereo).

    => 2

For further details and all options, you can refer to http://www.ffmpeg.org/ffmpeg-doc.html.

Integrating transformation as an Action in Alfresco

In this section, we will see how we can use FFMPEG transformations as a custom action in Alfresco. From there we can trigger some business rules on the spaces, which will execute this custom action to perform transformation of all video files. Follow these steps to execute the transformation:

  1. We need to configure the extra mime types that we want to use. Here in our case, we are using 3GP, MP2, MP4, AVI, MOV, and many more. All others are already supported by Alfresco and are defined in the mimetype-map.xml file in Alfresco (except 3GP). So we need to add 3GP as a mimetype supported by Alfresco in the mimetype-map file, as follows:
    <config evaluator="string-compare" condition="Mimetype Map">
    <mimetypes>
    <mimetype mimetype="video/3gp" display="Mobile video">
    <extension>3gp</extension>
    </mimetype>
    </mimetypes>
    </config>
    
  2. The next step is, as FFMPEG is a command-line interface, we can use Alfresco's org.alfresco.util.exec.RuntimeExec class to execute this command. For that we need to configure it as a bean, which will be referred by our custom action executer. We can make these bean entries in the custom-services-context.xml file.
    <bean id="transformer.ffmpegVideo" class="com.cignex.alfresco.repo.content.transform. FfmpegVideoContentTransformer"
    parent="baseContentTransformer"
    init-method="init">
    <property name="executer">
    <bean name="transformer.ffmpegVideo.Command" class="org.alfresco.util.exec.RuntimeExec">
    <property name="commandMap">
    <map>
    <entry key="Windows.*">
    <value>ffmpeg -i "${source}" ${options} "${target}"</value>
    </entry>
    </map>
    </property>
    <property name="defaultProperties">
    <props>
    <prop key="options"></prop>
    </props>
    </property>
    </bean>
    </property>
    </bean>
    <bean id="transform-video" class="com.cignex.alfresco.repo.action.executer. FfmpegVideoTransformActionExecuter"
    parent="transform">
    <property name="videoContentTransformer">
    <ref bean="transformer.ffmpegVideo" />
    </property>
    </bean>
    
  3. In the web-client-config-custom.xml file, add the following:
    <config evaluator="string-compare" condition="Action Wizards">
    <video-transformers>
    <transformer name="video/x-msvideo"/>
    <transformer name="video/mp4"/>
    <transformer name="video/3gp"/>
    <transformer name="video/x-ms-wmv"/>
    </video-transformers>
    <action-handlers>
    <handler name="transform-video" class="com.cignex.alfresco.web.bean.actions.handlers. FfmpegTransformVideoHandler" />
    </action-handlers>
    </config>
    
  4. Here you can specify all transformer names, and the formats you want to support in the transform action from the Alfresco UI as:
    <transformer name="video/mp4"/>
    
  5. You can add more if you want; here we have configured four different formats.
  6. Once this is done, you need to create custom Action Executer classes and do the configurations for this.

    Note

    You can also refer to the following Wikis for more detail on these: http://wiki.alfresco.com/wiki/Custom_Actions

    http://wiki.alfresco.com/wiki/Wizard_Framework

  7. After finishing creation and configuration of the Action Executer, you are ready with the example code. Now start the Alfresco server and we will see how you can configure the rule for transformation.
  8. We will create the folder structure such as Company Home | Cignex | videos. Inside the videos space, create spaces for all different types of formats (for video) that you want to support (that is, MPEG4, 3GP, and so on).

Configuring FFMPEG transformation as a business rule

Alfresco DM provides the business rule; you can configure a business rule for a particular type of content or for all the content in a particular space. Here we will configure a business rule on the videos space to transform the videos we upload in this space to convert into other formats.

  1. Browse to Company Home | Cignex | videos and click on More Actions | Manage Content Rules. On the next screen, click on the Create Rule link. In the first step of the Create Rule Wizard, select All Items and click on Add to List. Click on Next.
  2. In the next step, you can see the action created by us in the Select Action combo box. Select the action Transform video using FFMPEG and copy, as shown in the following screenshot. Click on Next:
    Configuring FFMPEG transformation as a business rule
  3. In the next step, you need to select the proper value for the required format (the target format for transformation). As we have configured 3GP, MP4, AVI, and WMV in the configuration file, we will have all these four options available to us for transforming the video. After that, provide the proper options for a particular video transformation selection based on source- and target-type of video file. Also, you need to provide the destination space to copy the transformed video. Here we have created the 3GP space inside the videos folder, so provide it as a destination folder. Click on OK.
    Configuring FFMPEG transformation as a business rule
  4. In the next step, choose Type as Inbound; also provide Title and Description. Check the option Apply rule to sub spaces as shown in the following screenshot. Click on Finish:
    Configuring FFMPEG transformation as a business rule

Now whenever you upload any video in videos space, it will be transformed into the 3GP video format. It will also be copied to the 3GP space inside the videos space as shown in the next screenshot:

Configuring FFMPEG transformation as a business rule

You can create as many rules and transformations as you want to perform for different video types.

Note

Download the sample code files from the Packt website.

Copying videos from DM to WCM

In this section, we will discuss the different ways to copy the content—here videos from DM to WCM. One is with the help of business rule and the other one is using JavaScript. Both of these are described in the following sections.

DM to WCM using business rule

We have videos available in all required formats under Company Home | Cignex | videos and the respective folders for the video formats. Now we need to move these videos in WCM in the proper web project and to the proper folder.

There is one more rule available in DM, which will copy the DM content to WCM. For this, you need to configure that rule. Use the following steps:

  1. Browse to Company Home | Cignex | videos and click on More Actions | Manage Content Rules. In the next screen, click on the Create Rule link. In the first step of the Create Rule Wizard, select All Items and click on Add to List. Click on Next.
  2. In the next step, you can see the action created by us in the Select Action combo box. Select the Copy item to a folder in a web project action, as shown in the following screenshot. Click on Next:
    DM to WCM using business rule
  3. In the next screen, select the web project and the specific folder in that web project as Destination folder and click on OK as shown in the following screenshot:
    DM to WCM using business rule
  4. Then click on Next. In the next screen, choose Type as Inbound and provide the Title and the Description. Also select Apply rule to sub spaces as shown in the next screenshot. Click on Finish:
    DM to WCM using business rule

DM to WCM using JavaScript

There is one API available in Alfresco JavaScript, which allows you to copy content from one repository to another. Using this API, you can copy the content from DM to WCM. Here we will copy all the videos, which we transformed previously to a specific folder in the web project.

Alfresco JavaScript has crossRepoCopy as one of the root objects, using which we can copy nodes or content between the different repositories (Document Management and Web Content Management).

copy(ScriptNode source, ScriptNode destination, String name): This will copy a source node to the specified destination node and return the new node. In the parameter name, you can specify the new name for that content, which is being copied to some other location.

Using this API, we can copy all of the transformed video from the DM repository to the WCM repository, as follows:

  1. Create new JavaScript file, copy_wcm.js, with the following content:
    logger.log("Document :: " + document.name);
    var l_cignex_root=avm.lookupStore("wwwcignex--admin");
    l_video_path="/ROOT/videos";
    if(l_cignex_root != null) {
    l_videoNode = l_cignex_root.lookupNode(l_video_path + "/");
    if(l_videoNode != null){
    crossRepoCopy.copy(document,l_videoNode,document.name);
    logger.log(document.name + " is copied");
    }
    }
    
  2. Upload this JavaScript file to the Company Home | Data Dictionary | Scripts space in Alfresco.
    DM to WCM using JavaScript
  3. Now, with the help of Run Action, you can execute this script. Go to the View Details page of the video content, which you want to copy to the WCM. Click on Run Action from the available actions, as shown in the following screenshot:
    DM to WCM using JavaScript
  4. Choose Execute a script from the available list of actions and click on the Set Values and Add button. Select copy_wcm.js from the list of available JavaScript files to execute and click on OK.
    DM to WCM using JavaScript
  5. Click on Finish. This will execute the copy_wcm.js JavaScript and copy the content to the WCM in a specified web project and a specified folder, as shown in the following screenshot:
    DM to WCM using JavaScript

Note

You can also configure this 'Execute Script' as a rule on the videos folder. For configuring it as a business rule, you can follow the same steps as mentioned in the DM to WCM Using Business Rule section. Just choose the Execute a Script action during configuration and copy_wcm.js as a value.

If you configure this rule for Inbound Documents, it will automatically copy the videos file to the corresponding destination folder in WCM.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset