OKMFolder
Basics
Section titled “Basics”In almost all methods you’ll see a parameter named “fldId”. The value of this parameter can be a valid folder UUID.
Also, in all methods you’ll see a parameter named “token”. Because Cron tasks are executed in the background without authentication, methods used in this scenario might use the token parameter. From the default application execution context you must use the “null” value, which indicates the application must use the “user session”.
Methods
Section titled “Methods”create
Section titled “create”Description:
| Method | Return values | Description |
|---|---|---|
| create(String token, Folder fld) | Folder | Creates a new folder and returns a Folder object. |
- The variable path in the parameter fld must be initialized. It indicates the folder path in OpenKM.
Example:
package com.openkm;
import com.openkm.api.OKMFolder;import com.openkm.bean.Folder;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class); Folder fld = new Folder(); fld.setPath("/okm:root/test"); okmFolder.create(null, fld); } catch (Exception e) { e.printStackTrace(); } }}createSimple
Section titled “createSimple”Description:
| Method | Return values | Description |
|---|---|---|
| createSimple(String token, String fldPath) | Folder | Creates a new folder and returns a Folder object. |
Example:
package com.openkm;
import com.openkm.api.OKMFolder;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class); String fldPath = "/okm:root/test"; okmFolder.createSimple(null, fldPath); } catch (Exception e) { e.printStackTrace(); } }}getProperties
Section titled “getProperties”Description:
| Method | Return values | Description |
|---|---|---|
| getProperties(String token, String fldId) | Folder | Returns the folder properties. |
Example:
package com.openkm;
import com.openkm.api.OKMFolder;import com.openkm.bean.Folder;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class); Folder fld = okmFolder.getProperties(null, "9f64248c-e049-4706-b89e-6d725842c7f7"); System.out.println(fld); } catch (Exception e) { e.printStackTrace(); } }}delete
Section titled “delete”Description:
| Method | Return values | Description |
|---|---|---|
| delete(String token, String fldId) | void | Deletes a folder. |
Example:
package com.openkm;
import com.openkm.api.OKMFolder;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class); okmFolder.delete(null, "9f64248c-e049-4706-b89e-6d725842c7f7"); } catch (Exception e) { e.printStackTrace(); } }}Description:
| Method | Return values | Description |
|---|---|---|
| purge(String token, String fldId) | void | The folder is permanently removed from the repository. |
- Usually you will purge folders in /okm:trash/userId - the personal trash user locations - but it is possible to directly purge any folder from the repository.
Example:
package com.openkm;
import com.openkm.api.OKMFolder;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class); okmFolder.delete(null, "9f64248c-e049-4706-b89e-6d725842c7f7"); } catch (Exception e) { e.printStackTrace(); } }}rename
Section titled “rename”Description:
| Method | Return values | Description |
|---|---|---|
| rename(String token, String fldId, String newName) | Folder | Renames a folder. |
Example:
package com.openkm;
import com.openkm.api.OKMFolder;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class); okmFolder.rename(null, "7aceb86c-1dc8-4551-aebd-b7bd73d01263", "newname"); } catch (Exception e) { e.printStackTrace(); } }}Description:
| Method | Return values | Description |
|---|---|---|
| move(String token, String fldId, String dstId) | void | Moves a folder into another folder or record. |
- The values of the dstId parameter should be a folder or record UUID.
Example:
package com.openkm;import com.openkm.api.OKMFolder;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class); okmFolder.move(null, "7aceb86c-1dc8-4551-aebd-b7bd73d01263", "b67fe3ae-bcca-4947-b8ea-0cc7aedd4474"); } catch (Exception e) { e.printStackTrace(); } }}Description:
| Method | Return values | Description |
|---|---|---|
| copy(String token, String fldId, String dstId) | void | Copies a folder into another folder or record. |
- The values of the dstId parameter should be a folder or record UUID.
Example:
package com.openkm;
import com.openkm.api.OKMFolder;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class); okmFolder.copy(null, "7aceb86c-1dc8-4551-aebd-b7bd73d01263", "b67fe3ae-bcca-4947-b8ea-0cc7aedd4474"); } catch (Exception e) { e.printStackTrace(); } }}Description:
| Method | Return values | Description |
|---|---|---|
| copy(String token, String fldId, String dstId, String newName) | void | Copies a folder into a folder or record. |
- The values of the dstId parameter should be a folder or record UUID.
- When the newName parameter value is null, the folder will preserve the same name.
Example:
package com.openkm;
import com.openkm.api.OKMFolder;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class); okmFolder.copy(null, "7aceb86c-1dc8-4551-aebd-b7bd73d01263", "b67fe3ae-bcca-4947-b8ea-0cc7aedd4474", "newname"); } catch (Exception e) { e.printStackTrace(); } }}extendedCopy
Section titled “extendedCopy”Description:
| Method | Return values | Description |
|---|---|---|
| extendedCopy(String token, String fldId, String dstId, ExtendedAttributes extAttr) | void | Copies a folder with the associated data into another folder or record. |
- The values of the dstId parameter should be a folder or record UUID.
Example:
package com.openkm;
import com.openkm.api.OKMFolder;import com.openkm.bean.ExtendedAttributes;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class);
ExtendedAttributes extAttr = new ExtendedAttributes(); extAttr.setKeywords(true); extAttr.setNotes(true); extAttr.setCategories(true); extAttr.setPropertyGroups(true);
okmFolder.extendedCopy(null, "7aceb86c-1dc8-4551-aebd-b7bd73d01263", "b67fe3ae-bcca-4947-b8ea-0cc7aedd4474", extAttr); } catch (Exception e) { e.printStackTrace(); } }}extendedCopy
Section titled “extendedCopy”Description:
| Method | Return values | Description |
|---|---|---|
| extendedCopy(String token, String fldId, String dstId, ExtendedAttributes extAttr, String newName) | void | Copies a folder with the associated data into some folder or record. |
- The values of the dstId parameter should be a folder or record UUID.
- When the newName parameter value is null, the folder will preserve the same name.
Example:
package com.openkm;
import com.openkm.api.OKMFolder;import com.openkm.bean.ExtendedAttributes;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class);
ExtendedAttributes extAttr = new ExtendedAttributes(); extAttr.setKeywords(true); extAttr.setNotes(true); extAttr.setCategories(true); extAttr.setPropertyGroups(true);
okmFolder.extendedCopy(null, "7aceb86c-1dc8-4551-aebd-b7bd73d01263", "b67fe3ae-bcca-4947-b8ea-0cc7aedd4474", extAttr, "newname"); } catch (Exception e) { e.printStackTrace(); } }}getChildren
Section titled “getChildren”Description:
| Method | Return values | Description |
|---|---|---|
| getChildren(String token, String fldId) | List |
Returns a list of all folders whose parent is fldId. |
- The parameter fldId can be a folder or a record node.
Example:
package com.openkm;
import com.openkm.api.OKMFolder;import com.openkm.bean.Folder;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class); for (Folder fld : okmFolder.getChildren(null, "b67fe3ae-bcca-4947-b8ea-0cc7aedd4474")) { System.out.println(fld); } } catch (Exception e) { e.printStackTrace(); } }}getContentInfo
Section titled “getContentInfo”Description:
| Method | Return values | Description |
|---|---|---|
| getContentInfo(String token, String fldId) | ContentInfo | Returns a ContentInfo object with information about the folder. |
- The ContentInfo object retrives information about:
Example:
package com.openkm;
import com.openkm.api.OKMFolder;import com.openkm.bean.ContentInfo;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class); ContentInfo ci = okmFolder.getContentInfo(null, "b67fe3ae-bcca-4947-b8ea-0cc7aedd4474"); System.out.println(ci); } catch (Exception e) { e.printStackTrace(); } }}isValid
Section titled “isValid”Description:
| Method | Return values | Description |
|---|---|---|
| isValid(String token, String fldId) | boolean | Returns a boolean that indicates whether the node is a folder. |
Example:
package com.openkm;
import com.openkm.api.OKMFolder;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class); boolean valid = okmFolder.isValid(null, "7aceb86c-1dc8-4551-aebd-b7bd73d01263"); System.out.println(valid); } catch (Exception e) { e.printStackTrace(); } }}getPath
Section titled “getPath”Description:
| Method | Return values | Description |
|---|---|---|
| getPath(String token, String uuid) | String | Converts a folder UUID to a folder path. |
Example:
package com.openkm;
import com.openkm.api.OKMFolder;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class); String path = okmFolder.getPath(null, "7aceb86c-1dc8-4551-aebd-b7bd73d01263"); System.out.println(path); } catch (Exception e) { e.printStackTrace(); } }}setStyle
Section titled “setStyle”Description:
| Method | Return values | Description |
|---|---|---|
| setStyle(String token, String fldId, long styleId) | void | Sets the folder style. |
Example:
package com.openkm;
import com.openkm.api.OKMFolder;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class); okmFolder.setStyle(null, "/okm:root/test", 1); } catch (Exception e) { e.printStackTrace(); } }}createMissingFolders
Section titled “createMissingFolders”Description:
| Method | Return values | Description |
|---|---|---|
| createMissingFolders(String token, String fldPath) | void | Creates missing folders based on all the path nodes. |
Example:
package com.openkm;
import com.openkm.api.OKMFolder;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class); okmFolder.createMissingFolders(null, "/okm:root/test/missing/from/here"); } catch (Exception e) { e.printStackTrace(); } }}addNodeClassChildren
Section titled “addNodeClassChildren”Description:
| Method | Return values | Description |
|---|---|---|
| addNodeClassChildren(String token, String fldId, long ncId) | void | Adds the NodeClass. |
Example:
package com.openkm;
import com.openkm.api.OKMFolder;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class); long ncId = 2; okmFolder.addNodeClassChildren(null, "7ce1b4a8-4ade-4dce-8d7d-4e99a6cd368b", ncId); } catch (Exception e) { e.printStackTrace(); } }}setDescription
Section titled “setDescription”Description:
| Method | Return values | Description |
|---|---|---|
| setDescription(String token, String uuid, String description) | void | Sets a description. |
Example:
package com.openkm;
import com.openkm.api.OKMFolder;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class); okmFolder.setDescription(null, "7ce1b4a8-4ade-4dce-8d7d-4e99a6cd368b", "some description"); } catch (Exception e) { e.printStackTrace(); } }}