Just married: Alfresco & VTiger
Very well. On my work some people are in fraud with its business-contacts that must be managed twice: VTiger (a CRM-TOOL) as well as in Alfresco. We´ve had looking for a cool solution that brings together all those peaces to get rid of the management-overhead. And we found… nothing… realy strange i guess as i guess that both tools will be used more frequently and in some cases together. Why there exists no free-solution to fetch data from vTiger into Alfresco and vice-versa(okay first way is unidirectional towards Alfresco)
Okay, i´ve enough spoked and flamed regarding that outstanding-issue.
What can we do to get marriaged both worlds? Well we using Alfresco´s nice connector-api to solve the whole problem. The way to achieve an one-way synchronisation descripes only the way from vtiger towards alfresco. So Alfresco posses after a synchronisation more data than before ;-D
I´ve tested my basic-authentication as well as fetching of data with Alfresco 3.2 as well as vTiger-CRM Version 5.1.0
Steps i want to introduce:
1. Defining of the vTiger-Authenticator
2. Authentication with vTiger
3. fetching of Leads/Contacts
At first, we have to setup the connector, thus knows alfresco which location must be taken to connect with a particular (Web-)Service. Therefor we add following lines to the file tomcat/shared/classes/alfresco/web-extension/webscript-framework-config-custom.xml following lines:
<config evaluator="string-compare" condition="Remote"> <remote> <endpoint> <id>vTiger</id> <name>vTiger</name> <description>vTiger vTiger vTiger</description> <connector-id>http</connector-id> <endpoint-url>http://localhost:82</endpoint-url> <identity>none</identity> </endpoint> </remote> </config>
Next step descripes the setup for the spring-context. If you have sucesfully done this step you are able to retrive informations about vTiger in your whole application. In my case i adding a quite other way on implementing a webscript (but that doesnt matter at all):
<bean id="webscript.de.dmc.VTiger.get" class="de.dmc.alfresco.VTigerWebScript" parent="webscript"> <property name="scriptRemote" ref="webscripts.script.remote" /> </bean>
Now its time to implement most important functionality.
Firstly, i obtain the vTiger-Connector being defined in the file webscript-framework-config-custom.xml:
ScriptRemoteConnector vTigerConnector = scriptRemote.connect("vTiger");
Next we have to get a valid sessionId, so we can start quering the database of vTiger. As you have to know that vTiger-Authentication is using a chalange-response-mechanism to avoiding password-sending. But its nothing to worring about: its quite simple. What for ingredients we must own:
A valid Access Key: that key will be encrypted with an computed-number (token) from serversite. You can find this key in you user-account in vTiger.
A username: surely you need this part ;-D
You have to know about vTiger that the WebService-Protocoll is based on REST and simple HTTP-mechanism. The returned value from vTiger is in every case a JSON-Object. Oh did i had say in every case? In some circumstances you get nothing back if you got made some errors … really bad.
String key = "wJAsUpRC6Bp5qKm3";Response response = connector.call("/webservice.php?operation=getchallenge&username=admin");
JSONObject resultObject = new JSONObject(response.getResponse());
resultObject = resultObject.getJSONObject("result");Map<String, String> data = new HashMap<String, String>();
data.put("operation", "login");
data.put("username", "admin");
data.put("accessKey", md5(resultObject.get("token").toString() + key));
String postBody = "";
boolean isFirst=true;
for(Map.Entry<String, String> entry : data.entrySet()){
if(!isFirst)
postBody+="&";
postBody+=entry.getKey()+"="+entry.getValue();
isFirst = false;
}
response = connector.post("/webservice.php", postBody, "application/x-www-form-urlencoded");
resultObject = new JSONObject(response.getResponse());
//returns the sessionKey
return (String)resultObject.getJSONObject("result").get("sessionName");
public String md5(Object obj){
String toEnc = new String(obj.toString());
MessageDigest mdEnc = null;
try {
mdEnc = MessageDigest.getInstance("MD5");
}
catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
mdEnc.update(toEnc.getBytes(), 0, toEnc.length());
return new BigInteger(1, mdEnc.digest()).toString(16);
}
In my depicted example i want to get a valid authenticaten with an admin-account so i take use of the user “admin”.
The returned value is nothing less than the sessionId. Ever preceeding call must posses this sessionId on adding this part as a param/value-pair upon the url.
Last step we have to go is to retrieving - for instance - the list of contacts in vTiger.
org.alfresco.connector.Response response = connector.call("/webservice.php?operation=query&query=" + org.alfresco.util.URLEncoder.encode("select * from Contacts;") + "&sessionName=" + sessionKey);return new JSONObject(response.getResult());
We are done… the next steps are quite simple as you got the data already. Subsequent doings on adding persons based on Leads/Contacts being stored in vTiger are the easiest part.
Comments
Leave a Reply

Sebastian Wenzky works since october 09 as a ecm-consultant at Westernacher in Stuttgart. Alfresco, Spring, Hibernate, JBPM and - to much - coffee are now his companions. The corresponding company the right way to go.