• Folder Create Macro

  • 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.
 #27600  by chartermfg
 
I was able to locate the example for file moves using the macro extension. What is the syntax to create a folder in macros.actions?

What I would like to do is every time some one creates a new project folder in OpenKM 3 folders are generated beneath the new folder. I tried to use automation, but I am having an issue stopping it looping into the folder set. I tried to use the event of the Property Group add, but it was not working. I used the Folder Create event, but that creates a looping issue. I tried putting a conditional in the script not to create the folder if it had one of the 3 subfolders created by the script, but I am unsure which API to use to return the folder name (not UUID) of the current folder.

I am not sure what would be the best method to execute the folder creation; Automation and script or Macros.

Details Below.

Thank you for your time.

OpenKM Community Edition 6.2.5
Oracle Enterprise Linux x64

Working script for automated folder create:
Code: Select all
import com.openkm.api.OKMFolder;
import com.openkm.api.OKMRepository;
 
String path = OKMRepository.getInstance().getNodePath(null, uuid);

String subpathfun = path + "/Functional";
OKMFolder.getInstance().createSimple(null, subpathfun);

String subpathtech = path + "/Technical";
OKMFolder.getInstance().createSimple(null, subpathtech);

String subpathimp = path + "/Implementation";
OKMFolder.getInstance().createSimple(null, subpathimp);
 #27607  by chartermfg
 
I am getting close:

Using Automation, event - Folder Create.
Code: Select all
import com.openkm.api.OKMFolder;
import com.openkm.api.OKMRepository;
 
String parentpath = "/okm:root/EBASS/Projects/Oracle/folder/Functional";
 
if (!OKMRepository.getInstance().hasNode(null, parentpath)) {
String path = OKMRepository.getInstance().getNodePath(null, uuid);
String subpathfun = path + "/Functional";
OKMFolder.getInstance().createSimple(null, subpathfun);
}
My Issue is I want to pass the String parent path untilizing one of the API's, but I am unable to fgure out which one will return the path using name only or the parent path and I can add "/Functional" at the end.
 #27617  by jllort
 
I suggest scripting.

For what I understood you want to create subfolder structure, after some folder creation under this path /okm:root/EBASS/Projects/Oracle/folder/Functional no ?

You're using event "create folder" at "post". Be care with concurrence !!! because folder creation what calls folders into will make another folder event creation call ( should take it in mind ).

I suggest a simple conditional:
Code: Select all
String parentPath = "/okm:root/EBASS/Projects";
Folder fld = OKMFolder.getInstance.getProperties(null, uuid); // Here you got folder properties ( after folder creation )
// To ensure subfolder creation will not be considered
if (fld.getParent().equals(parentPaht)) {
  // create folders here
}
 #27631  by chartermfg
 
This is what I ended up doing via Automation on Folder Create - Post:
Code: Select all
import com.openkm.api.OKMFolder;
import com.openkm.api.OKMRepository;
import com.openkm.api.*;
import com.openkm.util.PathUtils;

String substrf = "/Functional";
String substrt = "/Technical";
String substri = "/Implementation";

String pathm = OKMRepository.getInstance().getNodePath(null, uuid);

String pathp = pathm.substring(0,pathm.lastIndexOf("/"));

String folderf = pathp  + substrf;
String foldert = pathp  + substrt;
String folderi = pathp  + substri;

 
if ((!OKMRepository.getInstance().hasNode(null, folderf)) && (!OKMRepository.getInstance().hasNode(null, foldert)) && (!OKMRepository.getInstance().hasNode(null, folderi)) && (!pathm.contains(substrf)) && (!pathm.contains(substrt)) && (!pathm.contains(substri))) {
String path = OKMRepository.getInstance().getNodePath(null, uuid);
String subpathfun = path + "/Functional";
String subpathtec = path + "/Technical";
String subpathimp = path + "/Implementation";
OKMFolder.getInstance().createSimple(null, subpathfun);
OKMFolder.getInstance().createSimple(null, subpathtec);
OKMFolder.getInstance().createSimple(null, subpathimp);
OKMPropertyGroup.getInstance().addGroup(null, path, "okg:projectstatus");
}
Based on automation rules any folder created under the Projects folder will have 3 sub folders created: Functional, Technical, and Implementation. The original folder will have the (Custom) Property Group ProjectStatus added. If any folders are created under the 3 sub folders the process will NOT create a additional 3 folders nor will it create and infinite set.

This appears to be working for me and I wanted to post the results and open it up for evaluation.

Thank you for replying to my post.
 #27649  by jllort
 
I suggest do three conditionals for folder path creation.

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.