Page 1 of 1

Folder Create Macro

PostPosted:Wed Jan 15, 2014 6:50 pm
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);

Re: Folder Create Macro

PostPosted:Fri Jan 17, 2014 10:34 pm
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.

Re: Folder Create Macro

PostPosted:Sat Jan 18, 2014 10:32 am
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
}

Re: Folder Create Macro

PostPosted:Mon Jan 20, 2014 9:48 pm
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.

Re: Folder Create Macro

PostPosted:Thu Jan 23, 2014 10:39 am
by jllort
I suggest do three conditionals for folder path creation.

Re: Folder Create Macro

PostPosted:Fri Jan 24, 2014 3:33 pm
by chartermfg
Thank you