Page 2 of 3

Re: Download Document with Revision in Filename

PostPosted:Mon Feb 23, 2015 6:41 pm
by alexwgordon
Hi jllort,

Yeah that system check is why I was hoping to have 2 different methods. Turning off the system name check is nice for now, but I think for safety, it would be nice to not be able to upload a different file name and just when "editing" a file, download without the revision name.

Is there a way to have "edit" and "download" use two different Servlets potentially?

Thanks again jllort :)

Re: Download Document with Revision in Filename

PostPosted:Wed Feb 25, 2015 6:46 pm
by jllort
Should duplicate the code ( create other servlet ) and change the edit url

Re: Download Document with Revision in Filename

PostPosted:Fri Feb 27, 2015 7:51 pm
by alexwgordon
Sounds easy enough! My only question is what class calls the DownloadServlet for "Edit"? Thanks jllort!

Re: Download Document with Revision in Filename

PostPosted:Sun Mar 01, 2015 4:22 pm
by jllort
All is concentrated in ToolBar.java if you follow code from there you'll arrive to one call Util.downloadFileByUUID(getDocument().getUuid(), (checkout ? "checkout" : ""));

And this is the method involved on it, really after edit, you're doing a normal download at Util.java calling servlet defined into var RPCService.DownloadServlet -> public static String DownloadServlet = Main.CONTEXT + "/frontend/Download";.
Code: Select all
/**
 * Download file by UUID
 */
public static void downloadFileByUUID(String uuid, String params) {
	if (!params.equals("") && !params.endsWith("&")) {
		params += "&";
	}
	
	final Element downloadIframe = RootPanel.get("__download").getElement();
	String url = RPCService.DownloadServlet + "?" + params + "uuid=" + URL.encodeQueryString(uuid);
	DOM.setElementAttribute(downloadIframe, "src", url);
}
You could create other method for downloading from edit, or pass extra var indicating downloading is for edit purpose ( probably the most easy ). My suggestion is follow from Toolbar.java the method called executeCheckout().

Re: Download Document with Revision in Filename

PostPosted:Fri Mar 06, 2015 2:49 am
by alexwgordon
Hi Jllort,

Okay so I've been trying to parse through all this and i'm at a standstill. I can't figure out how the downloadFileByUUID calls the DownloadServlet. I think once I figure that out I can adjust the downloadservlet by passing the params TRUE or FALSE for checkout. Thanks for your help in advance :)

Re: Download Document with Revision in Filename

PostPosted:Sat Mar 07, 2015 5:11 pm
by jllort
With eclipse or other java ide you must have and option called "referenced" select the method, right click -> references -> workspace and you'll get who's calling the method etc... and you can follow back. Or if you want to follow from beggining -> Toolbar.java the executeDownload() normal download or executeCheckout() for checkout download.

Re: Download Document with Revision in Filename

PostPosted:Tue Mar 10, 2015 1:50 am
by alexwgordon
Thanks jllort!

Finally was able to solve it! Took me some digging and learning, but ended up figuring it out! All I did was add the code below to my DownloadServlet.java and all done :) Hope this helps someone else at some point!
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];
if (checkout == null)
	WebUtils.sendFile(request, response, newFileName, doc.getMimeType(), inline, is);
else 
	WebUtils.sendFile(request, response, fileName, doc.getMimeType(), inline, is);

Re: SOLVED Download Document with Revision in Filename

PostPosted:Mon Oct 12, 2015 7:19 am
by mountain73
Hi.

Thanks for this solution, it helped us a lot:
We used your solution for revision in filename and improved it a little: Revision filename is added in filename as in your case, but we also add it when downloading document version from history, and also when converting document to pdf.
You will find below the patch.
I think this is worth integrating in community version, what is your opinion about that?

Regards

Mountain73
Code: Select all
diff --git a/src/main/java/com/openkm/servlet/frontend/ConverterServlet.java b/src/main/java/com/openkm/servlet/frontend/ConverterServlet.java
index c4ba980..8b2e9cd 100644
--- a/src/main/java/com/openkm/servlet/frontend/ConverterServlet.java
+++ b/src/main/java/com/openkm/servlet/frontend/ConverterServlet.java
@@ -95,11 +95,12 @@ public class ConverterServlet extends OKMHttpServlet {
 				
 				String path = OKMRepository.getInstance().getNodePath(null, uuid);
 				Document doc = OKMDocument.getInstance().getProperties(null, path);
+				final String versionToAppend = OKMDocument.getInstance().getProperties(null,uuid).getActualVersion().getName();
 				String fileName = PathUtils.getName(doc.getPath());
-				
+				String[] nameParts = fileName.split("\\.(?=[^\\.]+$)");
+				String newFileName = nameParts[0] + " rev " + versionToAppend + "." + nameParts[1];
 				// Save content to temporary file
-				tmp = File.createTempFile("okm", "." + FileUtils.getFileExtension(fileName));
-				
+				tmp = new File(System.getProperty("java.io.tmpdir"),newFileName);
 				if (Config.REPOSITORY_NATIVE) {
 					// If is used to preview, it should workaround the DOWNLOAD extended permission.
 					is = new DbDocumentModule().getContent(null, path, false, !(toSwf));
@@ -124,7 +125,7 @@ public class ConverterServlet extends OKMHttpServlet {
 				// Prepare conversion
 				ConversionData cd = new ConversionData();
 				cd.uuid = uuid;
-				cd.fileName = fileName;
+				cd.fileName = newFileName;
 				cd.mimeType = doc.getMimeType();
 				cd.file = tmp;
 				
diff --git a/src/main/java/com/openkm/servlet/frontend/DownloadServlet.java b/src/main/java/com/openkm/servlet/frontend/DownloadServlet.java
index 309481a..ec4aa96 100644
--- a/src/main/java/com/openkm/servlet/frontend/DownloadServlet.java
+++ b/src/main/java/com/openkm/servlet/frontend/DownloadServlet.java
@@ -150,17 +150,21 @@ public class DownloadServlet extends OKMHttpServlet {
 				if (OKMDocument.getInstance().isValid(null, path)) {
 					// Get document
 					Document doc = OKMDocument.getInstance().getProperties(null, path);
-					
+					String versionToAppend = "";
 					if (ver != null && !ver.equals("")) {
 						is = OKMDocument.getInstance().getContentByVersion(null, path, ver);
+						versionToAppend = " rev " + ver;
 					} else {
 						is = OKMDocument.getInstance().getContent(null, path, checkout != null);
-					}
-					
+						if (checkout == null) {
+							versionToAppend = " rev " + OKMDocument.getInstance().getProperties(null,uuid).getActualVersion().getName();
+						}
+                    }
 					// Send document
 					String fileName = PathUtils.getName(doc.getPath());
-					WebUtils.sendFile(request, response, fileName, doc.getMimeType(), inline, is);
-				} else if (OKMMail.getInstance().isValid(null, path)) {
+					String[] nameParts = fileName.split("\\.(?=[^\\.]+$)");
+					String newFileName = nameParts[0] + versionToAppend + "." + nameParts[1];
+					WebUtils.sendFile(request, response, newFileName, doc.getMimeType(), inline, is);				} else if (OKMMail.getInstance().isValid(null, path)) {
 					// Get mail
 					Mail mail = OKMMail.getInstance().getProperties(null, path);

Re: SOLVED Download Document with Revision in Filename

PostPosted:Mon Oct 12, 2015 10:43 am
by jllort
Could you create an eclipse .patch ( team -> create patch ) file and send into this post attached into zip file ?

Re: SOLVED Download Document with Revision in Filename

PostPosted:Mon Oct 12, 2015 1:00 pm
by mountain73
Hi jjlort.

Here it is.
Regards.

Mountain73

Re: SOLVED Download Document with Revision in Filename

PostPosted:Tue Oct 13, 2015 11:53 am
by jllort
We will study it.

Re: SOLVED Download Document with Revision in Filename

PostPosted:Tue Oct 13, 2015 3:35 pm
by pavila
I've revised the patch but I don't know if this modification is needed by all users. Perhaps, adding a boolean configuration property which can be used to choose if OpenKM should make this change is a better approach.

Re: SOLVED Download Document with Revision in Filename

PostPosted:Thu Oct 15, 2015 8:31 am
by mountain73
Hi pavila.

According to me, this modification could be integrated for the following two reasons:

1- I doubt that this modification will not interest all users: when user download a document from openkm, he does not have any way to know which revision it was, unless he renames it or have implemented some code to write it within the file (quite tricky, and file format dependant...).

2- This modification also has no side effect as it does not affect the commit of new revisions: when performing "edit", original file name is kept so that it can be modified and updated to openkm server without any problem.

Still, if you do not agree, a boolean parameter sound also fine to me.

Thanks for your support.

Regards

Mountain73

Re: SOLVED Download Document with Revision in Filename

PostPosted:Wed Oct 21, 2015 1:46 pm
by alexwgordon
Hi mountain73,

That's exactly why I implemented my revision filename on download and not edit. It would also do the same if it is printed to PDF. Only when it is edited, do I not append the filename.

Re: SOLVED Download Document with Revision in Filename

PostPosted:Tue Nov 03, 2015 8:00 am
by mountain73
Hi all.

@pavila: what is finally your decision about potential patch integration?

@alexgordon: Yes, I understood and agreed ;-) By the way, did you see we haave added also the case of file download of previous version stored in history?

Thanks all of yoo.
Regards.
mountain73