Page 1 of 3
SOLVED Download Document with Revision in Filename
PostPosted:Thu Jan 15, 2015 12:10 am
by alexwgordon
Hi guys!
I'm running into an issue where once I download the file from within OpenKM, I lose the revision information attached to it, which can become confusing if I send these documents to other users. Is there a way to create some sort of automation or script that can run when I "download" a file to append the revision number to the end of the filename? Any and all advice is greatly appreciated! Thank you so much in advance!

Re: Download Document with Revision in Filename
PostPosted:Fri Jan 16, 2015 10:51 am
by jllort
Can be done, but actually only in professional version based on download event, which is not still present in community version. The idea is easy, each time you download any file ( event handler ), the file name is changed. In community without patching actual source code you can not get it. I can guide you on class you should take a look into, if you want to change ( will not be based on event, but also can go right ).
Re: Download Document with Revision in Filename
PostPosted:Mon Jan 26, 2015 6:57 pm
by alexwgordon
Hi Jllort,
Always coming to my rescue!
What would it be based on if we change the class? But either way, yes I would greatly appreciate being guided through the process of changing the class to allow for the rev to be attached to the name!
Re: Download Document with Revision in Filename
PostPosted:Thu Jan 29, 2015 4:42 pm
by jllort
The class you should be insterested is called Download.java into package com.openkm.servlet.frontend
You should be interested in lines from 158:
// Send document
Code: Select allString fileName = PathUtils.getName(doc.getPath());
WebUtils.sendFile(request, response, fileName, doc.getMimeType(), inline, is);
You should do a call to
Code: Select allString versionToAppend = OKMDocument.getInstance().getProperties().getActualVersion().getName();
Re: Download Document with Revision in Filename
PostPosted:Fri Jan 30, 2015 2:29 am
by alexwgordon
Hi jllort!
Thank you so much for the guidance! So I've started modifying the class and have inputted the line as you said and then done a concatenation on the filename to combine the filename and I get the following error:
Code: Select allerror: method getProperties in class OKMDocument cannot be applied to given types;
String versionToAppend = OKMDocument.getInstance().getProperties().getActualVersion().getName();
^
required: String,String
found: no arguments
Any advice? Thanks!
Re: Download Document with Revision in Filename
PostPosted:Fri Jan 30, 2015 10:58 am
by jllort
yes getProperties() method need two parameters, getProperties(null, uuid). Can be uuid or docPath but I think at that line of code you got always uuid.
Re: Download Document with Revision in Filename
PostPosted:Mon Feb 09, 2015 11:13 pm
by alexwgordon
Hi jllort,
Alright, so my lines now look like
Code: Select allString fileName = PathUtils.getName(doc.getPath());
String versionToAppend = OKMDocument.getInstance().getProperties(null,uuid).getActualVersion().getName();
String newFileName = fileName.concat(versionToAppend);
Everything compiles fine with this one note
Code: Select allNote: DownloadServlet.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
OpenKM loads fine, but getting no download functionality at the moment. Any ideas on what might cause the non-functionality at this point? Is there some sort of log file I can look at to aid in troubleshooting? Thanks!
Re: Download Document with Revision in Filename
PostPosted:Fri Feb 13, 2015 5:42 pm
by jllort
I've got idea about what could be wrong, are you compiling with jdk 1.7 ?
Re: Download Document with Revision in Filename
PostPosted:Fri Feb 13, 2015 7:15 pm
by alexwgordon
Ah, I'm actually compiling with jdk 1.8 I realize...
I should be compiling with 1.7, yeah?
I tried recompiling using
Code: Select all-Xbootclasspath $TOMCAT/java/jre/lib/rt.jar -source 1.7
in my compilation. No errors, but still no luck. Doesn't seem to be doing anything still.
Re: Download Document with Revision in Filename
PostPosted:Sat Feb 14, 2015 9:44 am
by jllort
Yes you should compile with jdk 1.7 and also execute with same jdk version
Re: Download Document with Revision in Filename
PostPosted:Mon Feb 16, 2015 3:39 pm
by alexwgordon
So as far as I know, I'm using the java that is packaged with the community nightly build, so I should be running with 1.7 as well.
Re: Download Document with Revision in Filename
PostPosted:Tue Feb 17, 2015 5:26 pm
by alexwgordon
Yes, I just checked and my JAVA_Home is $TOMCAT/java and still no functionality. The browser attempts to download, but no download occurs. Any other thoughts on what might be causing the issue? Thanks again for all your help jllort!
Re: Download Document with Revision in Filename
PostPosted:Thu Feb 19, 2015 2:58 pm
by jllort
You should debug the class with eclipse, because you've done some mistake or something strange happens, here you've only changed the download file name, nothing else, this is not a great change. Try to log the output too.
Re: Download Document with Revision in Filename
PostPosted:Fri Feb 20, 2015 6:48 pm
by alexwgordon
It works! I realize I was having the same problem that I did with my revision Letter class that I was working on. basically I needed to compile it in Eclipse (this was a huge help -
http://wiki.openkm.com/index.php/Developer_Guide) and now everything works. Here is my final code if anyone is interested!
Code: Select allString fileName = PathUtils.getName(doc.getPath());
String versionToAppend = OKMDocument.getInstance().getProperties(null,uuid).getActualVersion().getName();
String[] nameParts = fileName.split("\\.(?=[^\\.]+$)");
String newFileName = nameParts[0] + " rev " + versionToAppend + "." + nameParts[1];
WebUtils.sendFile(request, response, newFileName, doc.getMimeType(), inline, is);
I have another question though: can I have 2 different methods for downloading the file and renaming it? What I mean is, when I click "Download" it appends the revision to the filename and when I click "edit" it does not append the revision to the filename? Not sure if this is possible, but if it is, that's exactly what I'm looking for! Thanks, jllort! As always you've been super helpful

Re: Download Document with Revision in Filename
PostPosted:Sat Feb 21, 2015 12:14 pm
by jllort
Append revision filename on edition will cause a trouble, because when you checkin file openkm will raise error because filename are not equals ( can disable this feature from administration -> configuration -> system.document.name.mismatch.check).
About document name change on edition, OpenKM use the same /frontend/DownloadServlet ( try to debug it ).
Next week we will release a portable development environement, hope that will help developers community in some way.