OKMFolder
Basics
In almost all methods you'll see a parameter named "fldId". The value of this parameter can be a valid folder UUID.
Example of fldId:
- Using UUID -> "b67fe3ae-bcca-4947-b8ea-0cc7aedd4474";
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".
In special cases you might be "promoted to Administrator" using the "administrator token".
String systemToken = DbSessionManager.getInstance().getSystemToken();
Methods
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.
The other variables of the Folder ( fld ) will not have any effect on the folder creation. We suggest using the method below to create the Folder rather than this one. |
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
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
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
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();
}
}
}
purge
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. When a folder is purged, it can only be restored from a previous repository backup. The purge action removes the folder permanently 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
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();
}
}
}
move
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();
}
}
}
copy
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. Only the security grants are copied to the destination; the metadata, keywords, etc. of the folder are not copied. See "extendedCopy" method for this feature. |
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();
}
}
}
copy
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. Only the security grants are copied to destination, the metadata, keywords, etc. of the folder are not copied. See "extendedCopy" method for this feature. |
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
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. By default only the binary data and the security grants are copied; the metadata, keywords, etc. of the folder are not copied. Additional extended attributes parameters:
|
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
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. By default only the binary data and the security grants are copied; the metadata, keywords, etc. of the folder are not copied. Additional extended attributes parameters:
|
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
Description:
Method | Return values | Description |
---|---|---|
getChildren(String token, String fldId) |
List<Folder> |
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
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
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
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
Description:
Method | Return values | Description |
---|---|---|
setStyle(String token, String fldId, long styleId) |
void |
Sets the folder style. |
More information at 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
Description:
Method | Return values | Description |
---|---|---|
createMissingFolders(String token, String fldPath) |
void |
Creates missing folders based on all the path nodes. |
The method checks all subfolders and when it detects that one is missing, it creates all missing subfolders from there. |
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
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
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();
}
}
}