Category Archives: Java

SVN Log To CSV Converter

One of the many things that you may need to become accustomed to using is some type of versioning system.  One type that I use on a regular basis is SVN.  Last month, due to an audit, we had to get a spreadsheet or CSV file that contained all of the records of what was changed in an SVN repository.  Fortunately, SVN by default does provide a way of outputting all of the log entries but it is not in a CSV format.  Therefore, I wrote a simple SVN Log To CSV converter which can be used to export SVN log files as CSV files from the command line. Here is the SVN Log To CSV Converter as a ZIP file that contains the Java program, Java source code, readme file, and example CSV output.

As the readme file says, this program is really easy to use.  You can use one of the following statements in the command-line on a Unix, Linux or a Mac:

  • java svnLogToCSV {path_to_log}
  • cat {path_to_log} | java svnLogToCSV --stdin
  • svn log {url}[@{rev_num}] | java svnLogToCSV --stdin

For example, in order to produce the CSV file that is in the ZIP file, I used the following statement:

svn log http://jasperapiclient.googlecode.com/svn/trunk | java svnLogToCSV --stdin > svnLog.csv

As far as getting this to work on a PC, I will have to do a bit of research because I never deal with SVN on Windows. Let me know if you can come up with the equivalent in Windows terms. On the other hand, before creating this Java program, I actually wrote an online converter which can be found here at JSBin. Enjoy! 8)

OpenKM Scripting – Creating Folders

We recently had the need to create hundreds of folders but didn’t want to do so manually. Unfortunately, this wasn’t as easy as simply going into the database and adding them. Fortunately, it was as easy as using the following script:

import com.openkm.api.OKMFolder;
import com.openkm.core.JcrSessionManager;
import com.openkm.bean.Folder;

String token = JcrSessionManager.getInstance().getSystemToken();

String[] arrDepts = {"A","B","C","D1","D2","E"};
String path;
Folder folder;

for(String dept : arrDepts) {
  try {
    (folder = new Folder()).setPath(path = "/okm:root/Department " + dept);
    OKMFolder okmFolder = OKMFolder.getInstance();
    okmFolder.create(
      JcrSessionManager.getInstance().getSystemToken(),
      folder
    );
    print("\"" + path + "\" created
");
  }
  catch(Exception e) {
    print("\"" + path + "\" failed
");
  }
}

That script creates the following folders with the same access that the /okm:root folder has:

  • /okm:root/A
  • /okm:root/B
  • /okm:root/C
  • /okm:root/D1
  • /okm:root/D2
  • /okm:root/E

The output that will be shown will indicate which folders were successfully created.  As usual, play around with the script and make it your own!  If you think you have something really cool to add, let me know because I am always willing to do follow-up posts, of course giving FULL credit to contributors.

OpenKM Scripting – Adding UserRole

A while back, when I first starting working with OpenKM, I accidentally removed the UserRole role from the root directory. For the longest time, I had know clue how to add the UserRole role back to that folder, or any other folder for that matter. Today, after playing around with the example scripts, I developed the following script that can be run from the Administrators tab:

import com.openkm.api.OKMAuth;
import com.openkm.core.JcrSessionManager;
import com.openkm.bean.Permission;
 
String token = JcrSessionManager.getInstance().getSystemToken();
OKMAuth.getInstance().grantRole(token, "/okm:root", "UserRole", Permission.READ, false);