• SOLVED Download Document with Revision in Filename

  • We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
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.
 #30916  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.
 #30932  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 ).
 #31061  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!
 #31087  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();
 #31093  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!
 #31110  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.
 #31230  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!
 #31283  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.
 #31322  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!
 #31351  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.
 #31365  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 :)
 #31380  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.

About Us

OpenKM is part of the management software. A management software is a program that facilitates the accomplishment of administrative tasks. OpenKM is a document management system that allows you to manage business content and workflow in a more efficient way. Document managers guarantee data protection by establishing information security for business content.