Md Noorshid
Md Noorshid

Reputation: 107

Alfresco using opencmis apache chemistry to create a link to a Folder

Hi guys i am doing alfresco using opencmis apache chemistry. I have done many services such as creating folder,subfolder,uploading,downloading with version updates. Now i am trying to generate link of folder/document whatever the link is in dashboard of alfresco. Somebody is there who can help me to genrate the link using openCmis(java)?? Thanks in advance

public  String dowloadingDocument(String docuementID){
	  Session cmisSession=new CreateSession().getSession();
	  Document document=(Document) cmisSession.getObject(docuementID);
     String link=null;
      try {
	        Method loadLink = AbstractAtomPubService.class.getDeclaredMethod("loadLink", 

	            new Class[] { String.class, String.class, String.class, String.class });

		try {
			
			link=(String) loadLink.invoke(cmisSession.getBinding().getObjectService(),cmisSession.getRepositoryInfo().getId(),document.getId(),AtomPubParser.LINK_REL_CONTENT,null);
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
		
	} catch (NoSuchMethodException e) {
		e.printStackTrace();
	} catch (SecurityException e) {
		e.printStackTrace();
	}
      return link;
      
}

Upvotes: 0

Views: 420

Answers (1)

Florian Müller
Florian Müller

Reputation: 3235

This snippet gives you a download link for the document:

Document document= (Document)cmisSession.getObject(docuementID);
String link = document.getContentUrl();

This is not same link you'll find the Alfresco dashboard, but it also lets the user download the document. Please note, that depending on the authentication setup the user has to authenticate again before the download starts.

Upvotes: 1

Related Questions