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.

Categories: BlogJava

2 Comments

Renato · February 26, 2013 at 2:48 PM

hello, come here for this question http://stackoverflow.com/questions/9844549/determine-the-user-who-starts-a-jbpm-workflow-for-openkm

wanted to know if you find any solution to capture the value of the initiator (the actor who started it) thanks.

    Chris West · February 26, 2013 at 3:15 PM

    Unfortunately I don’t use jBPM anymore, but I believe the answer that I put on that Stack Overflow page was sufficient for what you are looking for.

Leave a Reply

Your email address will not be published. Required fields are marked *