SOLVED Download Document with Revision in Filename

We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
Forum rules
Please, before asking something see the documentation wiki or use the search feature of the forum. And remember we don't have a crystal ball or mental readers, so if you post about an issue tell us which OpenKM are you using and also the browser and operating system version. For more info read How to Report Bugs Effectively.
alexwgordon
Gold Boarder
Gold Boarder
Posts: 182
Joined: Fri Sep 05, 2014 6:24 pm

SOLVED Download Document with Revision in Filename

Post 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! :D
Last edited by alexwgordon on Mon Mar 16, 2015 11:02 pm, edited 1 time in total.

jllort
Moderator
Moderator
Posts: 11151
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: Download Document with Revision in Filename

Post 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 ).

alexwgordon
Gold Boarder
Gold Boarder
Posts: 182
Joined: Fri Sep 05, 2014 6:24 pm

Re: Download Document with Revision in Filename

Post 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!

jllort
Moderator
Moderator
Posts: 11151
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: Download Document with Revision in Filename

Post 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 all

String fileName = PathUtils.getName(doc.getPath());
WebUtils.sendFile(request, response, fileName, doc.getMimeType(), inline, is);
You should do a call to

Code: Select all

String versionToAppend = OKMDocument.getInstance().getProperties().getActualVersion().getName();

alexwgordon
Gold Boarder
Gold Boarder
Posts: 182
Joined: Fri Sep 05, 2014 6:24 pm

Re: Download Document with Revision in Filename

Post 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 all

error: 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!

jllort
Moderator
Moderator
Posts: 11151
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: Download Document with Revision in Filename

Post 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.

alexwgordon
Gold Boarder
Gold Boarder
Posts: 182
Joined: Fri Sep 05, 2014 6:24 pm

Re: Download Document with Revision in Filename

Post by alexwgordon »

Hi jllort,

Alright, so my lines now look like

Code: Select all

String 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 all

Note: 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!

jllort
Moderator
Moderator
Posts: 11151
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: Download Document with Revision in Filename

Post by jllort »

I've got idea about what could be wrong, are you compiling with jdk 1.7 ?

alexwgordon
Gold Boarder
Gold Boarder
Posts: 182
Joined: Fri Sep 05, 2014 6:24 pm

Re: Download Document with Revision in Filename

Post 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.

jllort
Moderator
Moderator
Posts: 11151
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: Download Document with Revision in Filename

Post by jllort »

Yes you should compile with jdk 1.7 and also execute with same jdk version

alexwgordon
Gold Boarder
Gold Boarder
Posts: 182
Joined: Fri Sep 05, 2014 6:24 pm

Re: Download Document with Revision in Filename

Post 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.

alexwgordon
Gold Boarder
Gold Boarder
Posts: 182
Joined: Fri Sep 05, 2014 6:24 pm

Re: Download Document with Revision in Filename

Post 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!

jllort
Moderator
Moderator
Posts: 11151
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: Download Document with Revision in Filename

Post 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.

alexwgordon
Gold Boarder
Gold Boarder
Posts: 182
Joined: Fri Sep 05, 2014 6:24 pm

Re: Download Document with Revision in Filename

Post 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 all

String 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 :)

jllort
Moderator
Moderator
Posts: 11151
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: Download Document with Revision in Filename

Post 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.

Post Reply