best grammar app

Alfresco Document Management System and BPM Integration using custom code

Submitted by Abhishek on Sun, 2012-01-22 12:42
Alfresco

Alfresco document management system is gaining popularity these days due to the easy installation and user friendly interface. Often you could have a requirement to integrate your BPM Product so that it can check in and out documents from Alfresco. While tools like Progress Savvion, Bonita Soft etc providing out of the box adapters to do this, sometimes you might need to write custom code to check in. One such case could be if you need to decide the server path based on certain user preferences i.e. if you have, lets say, a Purchase Order request for Admin Department and you want to store the generated PDF in /po/po_1234.pdf then this method can be very useful for you.

For doing this simple integration we will be leveraging the built in FTP Server feature of Alfresco.

 

Step 1: Download and Install Alfresco

You can download the Alfresco community edition from the alfresco site http://alfresco.com. Installation is fairly simple. Just make sure you are noting down the following:

  • Name of the host or IP Address
  • FTP Port number
  • Admin username
  • Admin password

Step 2: Create a Site in Alfresco

After installation (assuming you have loaded alfresco on localhost port 8080), Open the admin console by typing http://localhost:8080/share. If you just started your server it could take a while for it to initialize and the console to be active. Once done, go ahead and create a site in Alfresco. Give it a name say PO  Site.

Step 3: Use an FTP Client to check your connection

Using an FTP client like say FileZilla, connect to the DMS Server and see if you can browse. You will need to provide the server name, port number, username and password to connect. If your connection is successful, you should see that based on your site name (which we assume is PO Site, a folder structure gets created as /Alfresco/po-site/documentLibrary.

Do check if you are able to upload and download files. Your uploaded files should also get reflected under “Documents” in your Alfresco Admin Console.

Step 4: Write code to connect using Java

Next we will need to write client libraries to connect our BPM Product to alfresco. You can use an adapter or may be some logic on your page depending on your requirement. The idea is that you should have a file which can be checked into Alfresco using Java.

Apache commons net project available from http://commons.apache.org/net provides a great way of connecting to FTP Servers. We will be using that for our operations. You will need the following classes:

 

import java.io.File;

import java.io.FileInputStream;

import java.io.IOException;

import java.io.PrintWriter;

import org.apache.commons.net.PrintCommandListener;

import org.apache.commons.net.ftp.FTP;

import org.apache.commons.net.ftp.FTPClient;

import org.apache.commons.net.ftp.FTPFile;

 

Step 5: Connecting to FTP Server

Apache commons has a utility class called FTPClient that can be used for all FTP Operations. The simplest way to connect to FTP Server is using the following code snippet:

 

FTPClient ftpClient = new FTPClient();

ftpClient.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));

ftpClient.connect(“192.168.1.2”,”21”);

ftpClient.login(“admin”,”password”);

ftpClient.setFileType(FTP.BINARY_FILE_TYPE);

 

The above code creates a ftpClient object  and adds a Command listeners. The benefit of adding System.out as a Command listener is that all FTP Commands and responses will now be printed when your program runs. Then we use the connect call with a servername and port number to connect to the server.

After connection the login call is made to authenticate the user.

Finally, the setFileType is set to Binary because we are uploading a Binary File.


Abhishek Mishra
Good experience in working with BPM technologies like Savvion, JBPM. Founder and Chief Editor of BPMGeek.com. Founder of Savvion Business Manager Mobility Framework Savmobify| View my BPMGeek Profile
|
best grammar app

About BPMGeek

BPMGeek is an initiative to collaborate and communicate with the growing Business process management community out there. The goal is to help developers connect with experts, ask questions, post their learning and get understanding of BPM Concepts. Often tool specific knowledge of niche areas end up developers perplexed and confused - especially when there are very less number of resources available. We will be coming up several several new features. Have a look at our Roadmap here

BPMGeek is an independent entity not associated with any Product. All BPM product professionals are invited to contribute. The Logos and Names used across the site belong to their respective owners. The viewpoints mentioned by Individual contributors are their own. BPMgeek cannot be held liable for any issues arising out of it.


BPMgeek is promoting the Nounshoun English Grammar App - developed by Constellation Software.