OKMNode
Basics
In almost all methods you'll see a parameter named "nodeId". The value of this parameter can be a valid node UUID.
Example of docId:
- Using UUID -> "c41f9ea0-0d6c-45da-bae4-d72b66f42d0f";
For the parameter named "fldId", the value of this parameter can be a valid folder UUID or a record node.
Example of fldId:
- Using UUID -> "c6785440-0d6c-45da-1234-d9874563d0f";
For the parameter named "dstId", the value of this parameter can be a valid folder UUID or a record node.
Example of dstId:
- Using UUID -> "c4455667-0d6c-45da-1234-d98564323e0";
Also, in all methods you'll see a parameter named "token". Because Cron Tasks are executed in the background without authentication, the 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
getNodeByUuid
Description:
| Method | Return values | Description |
|---|---|---|
|
getNodeByUuid(String token, String uuid) |
Node |
Get a node by UUID. |
Example:
package com.openkm;
import com.openkm.api.OKMNode;
import com.openkm.bean.Node;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMNode okmNode = ContextWrapper.getContext().getBean("okmNode", OKMNode.class);
Node node = okmNode.getNodeByUuid(null, "78f9c377-e557-48c7-804e-35c0ca284739");
System.out.println(node);
} catch (Exception e) {
e.printStackTrace();
}
}
}
getVersionHistory
Description:
| Method | Return values | Description |
|---|---|---|
|
getVersionHistory(String token, String nodeId) |
List<Version> |
Returns the version history list of a node. |
Example:
package com.openkm;
import java.util.List;
import com.openkm.api.OKMNode;
import com.openkm.bean.Version;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMNode okmNode = ContextWrapper.getContext().getBean("okmNode", OKMNode.class);
List<Version> versions = okmNode.getVersionHistory(null, "78f9c377-e557-48c7-804e-35c0ca284739");
for (Version version : versions) {
System.out.println(version);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
restoreVersion
Description:
| Method | Return values | Description |
|---|---|---|
|
restoreVersion(String token, String nodeId, String versionId) |
void |
Restore the version of a node. |
Example:
package com.openkm;
import com.openkm.api.OKMNode;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMNode okmNode = ContextWrapper.getContext().getBean("okmNode", OKMNode.class);
okmNode.restoreVersion(null, "78f9c377-e557-48c7-804e-35c0ca284739", "1.2");
} catch (Exception e) {
e.printStackTrace();
}
}
}
renameVersion
Description:
| Method | Return values | Description |
|---|---|---|
|
renameVersion(String token, String nodeId, String versionId, String newName) |
void |
Rename the version of a node. |
Example:
package com.openkm;
import com.openkm.api.OKMNode;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMNode okmNode = ContextWrapper.getContext().getBean("okmNode", OKMNode.class);
okmNode.renameVersion(null, "78f9c377-e557-48c7-804e-35c0ca284739", "1.2", "newName");
} catch (Exception e) {
e.printStackTrace();
}
}
}
purgeVersionHistory
Description:
| Method | Return values | Description |
|---|---|---|
|
purgeVersionHistory(String token, String nodeId) |
void |
Purge the version history of a node. |
Example:
package com.openkm;
import com.openkm.api.OKMNode;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMNode okmNode = ContextWrapper.getContext().getBean("okmNode", OKMNode.class);
okmNode.purgeVersionHistory(null, "3767deb4-21e7-4272-82be-fece5384fbab");
} catch (Exception e) {
e.printStackTrace();
}
}
}
getChildrenPaginated
Description:
| Method | Return values | Description |
|---|---|---|
|
getChildrenPaginated(String token, String nodeId, int offset, int limit, String filter, String orderByField, boolean orderAsc, List<Class<? extends NodeBase>> filteredByNodeTypeList) |
PageInfo |
Get children nodes paginated. |
|
The parameters "limit" and "offset" allow you to retrieve just a portion of the results of a query.
The parameter "orderByFilter" can have the following values: name or created. For example, if your query has 1000 results, but you only want to return the first 10, you should use these values:
Now suppose you want to show the results from 11-20, you should use these values:
|
||
Example:
package com.openkm;
import java.util.ArrayList;
import java.util.List;
import com.openkm.api.OKMNode;
import com.openkm.bean.PageInfo;
import com.openkm.db.bean.NodeBase;
import com.openkm.db.bean.NodeDocument;
import com.openkm.db.bean.NodeFolder;
import com.openkm.db.bean.NodeMail;
import com.openkm.db.bean.NodeRecord;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMNode okmNode = ContextWrapper.getContext().getBean("okmNode", OKMNode.class);
List<Class<? extends NodeBase>> filteredByNodeTypeList = new ArrayList<>();
filteredByNodeTypeList.add(NodeDocument.class);
filteredByNodeTypeList.add(NodeFolder.class);
filteredByNodeTypeList.add(NodeMail.class);
filteredByNodeTypeList.add(NodeRecord.class);
// nodeId Folder and Record UUID or Path
String nodeId = "39479efe-de5e-468e-91a7-24d2aa3f8837";
String orderByField = "created";
boolean orderAsc = true;
PageInfo pageInfo = okmNode.getChildrenPaginated(null, nodeId, 0, 10, "", orderByField, orderAsc,
filteredByNodeTypeList);
System.out.println("Filtered Elements: " + pageInfo.getFilteredElements());
System.out.println("Total Elements: " + pageInfo.getTotalElements());
for (Object object : pageInfo.getObjects()) {
NodeBase nodeBase = (NodeBase) object;
System.out.println(nodeBase.getPath());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
getChildrenByCategoryPaginated
Description:
| Method | Return values | Description |
|---|---|---|
|
getChildrenByCategoryPaginated(String token, String nodeId, int offset, int limit, String filter, String orderByField, boolean orderAsc, List<Class<? extends NodeBase>> filteredByNodeTypeList) |
PageInfo |
Get children nodes by category paginated. |
|
The parameters "limit" and "offset" allow you to retrieve just a portion of the results of a query.
The parameter "orderByFilter" can have the following values: name or created. For example, if your query has 1000 results, but you only want to return the first 10, you should use these values:
Now suppose you want to show the results from 11-20, you should use these values:
|
||
Example:
package com.openkm;
import java.util.ArrayList;
import java.util.List;
import com.openkm.api.OKMNode;
import com.openkm.bean.PageInfo;
import com.openkm.db.bean.NodeBase;
import com.openkm.db.bean.NodeDocument;
import com.openkm.db.bean.NodeFolder;
import com.openkm.db.bean.NodeMail;
import com.openkm.db.bean.NodeRecord;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMNode okmNode = ContextWrapper.getContext().getBean("okmNode", OKMNode.class);
List<Class<? extends NodeBase>> filteredByNodeTypeList = new ArrayList<>();
filteredByNodeTypeList.add(NodeDocument.class);
filteredByNodeTypeList.add(NodeFolder.class);
filteredByNodeTypeList.add(NodeMail.class);
filteredByNodeTypeList.add(NodeRecord.class);
// nodeId Folder and Record UUID or Path
String nodeId = "39479efe-de5e-468e-91a7-24d2aa3f8837";
String orderByField = "created";
boolean orderAsc = true;
PageInfo pageInfo = okmNode.getChildrenByCategoryPaginated(null, nodeId, 0, 10, "", orderByField, orderAsc,
filteredByNodeTypeList);
System.out.println("Filtered Elements: " + pageInfo.getFilteredElements());
System.out.println("Total Elements: " + pageInfo.getTotalElements());
for (Object object : pageInfo.getObjects()) {
NodeBase nodeBase = (NodeBase) object;
System.out.println(nodeBase.getPath());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
getBreadcrumb
Description:
| Method | Return values | Description |
|---|---|---|
|
getBreadcrumb(String token, String fldId) |
List<BreadCrumbItem> |
Get breadcrumb. |
Example:
package com.openkm;
import java.util.List;
import com.openkm.api.OKMNode;
import com.openkm.bean.BreadCrumbItem;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMNode okmNode = ContextWrapper.getContext().getBean("okmNode", OKMNode.class);
List<BreadCrumbItem> list = okmNode.getBreadcrumb(null, "39479efe-de5e-468e-91a7-24d2aa3f8837");
for (BreadCrumbItem item : list) {
System.out.println(item.getPath());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
subscribe
Description:
| Method | Return values | Description |
|---|---|---|
|
subscribe(String token, String nodeId) |
void |
Adds a subscription to a node. |
Example:
package com.openkm;
import com.openkm.api.OKMNode;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMNode okmNode = ContextWrapper.getContext().getBean("okmNode", OKMNode.class);
okmNode.subscribe(null, "39479efe-de5e-468e-91a7-24d2aa3f8837");
} catch (Exception e) {
e.printStackTrace();
}
}
}
unsubscribe
Description:
| Method | Return values | Description |
|---|---|---|
|
unsubscribe(String token, String nodeId) |
void |
Deletes a subscription to a node. |
Example:
package com.openkm;
import com.openkm.api.OKMNode;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMNode okmNode = ContextWrapper.getContext().getBean("okmNode", OKMNode.class);
okmNode.unsubscribe(null, "39479efe-de5e-468e-91a7-24d2aa3f8837");
} catch (Exception e) {
e.printStackTrace();
}
}
}
importZip
Description:
| Method | Return values | Description |
|---|---|---|
|
importZip(String token, String fldUuid, InputStream inputStream) |
void |
Import a zip file. |
Example:
package com.openkm;
import java.io.FileInputStream;
import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import com.openkm.api.OKMNode;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMNode okmNode = ContextWrapper.getContext().getBean("okmNode", OKMNode.class);
InputStream is = new FileInputStream("/home/gnujavasergio/okm/import.zip");
okmNode.importZip(null, "212e7c1f-443d-4aac-a12c-0b818ca03419", is);
IOUtils.closeQuietly(is);
} catch (Exception e) {
e.printStackTrace();
}
}
}
unzip
Description:
| Method | Return values | Description |
|---|---|---|
|
unzip(String token, String uuid, String destinationPath) |
void |
Unzips a file. |
Example:
package com.openkm;
import com.openkm.api.OKMNode;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMNode okmNode = ContextWrapper.getContext().getBean("okmNode", OKMNode.class);
String uuid = "82555dd1-bcc2-4e64-81cb-5f7c2b0d7801"; // zip File
String destinationPath = "/okm:root/test"; // destination path
okmNode.unzip(null, uuid, destinationPath);
} catch (Exception e) {
e.printStackTrace();
}
}
}
exportZip
Description:
| Method | Return values | Description |
|---|---|---|
|
exportZip(List<String> paths, boolean withPath, boolean background, boolean excludeProperties) |
ByteArrayInputStream |
Export as a zip file. |
Example:
package com.openkm;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.IOUtils;
import com.openkm.api.OKMNode;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMNode okmNode = ContextWrapper.getContext().getBean("okmNode", OKMNode.class);
List<String> uuids = new ArrayList<>();
uuids.add("/okm:root/test/logo.png");
uuids.add("/okm:root/test/invoice.pdf");
OutputStream fos = new FileOutputStream("/home/openkm/import.zip");
InputStream is = okmNode.exportZip(uuids, true, true, true);
IOUtils.copy(is, fos);
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(fos);
} catch (Exception e) {
e.printStackTrace();
}
}
}
getNodesFromUuids
Description:
| Method | Return values | Description |
|---|---|---|
|
getNodesFromUuids(String token, String[] uuids) |
List<Node> |
Returns a list of nodes. |
Example:
package com.openkm;
import java.util.List;
import com.openkm.api.OKMNode;
import com.openkm.bean.Node;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMNode okmNode = ContextWrapper.getContext().getBean("okmNode", OKMNode.class);
String[] uuids = {"0f6463f3-4d36-4091-b518-4fe7c353ee70", "d386cff8-1d4d-472f-9c6d-f21955ec499a"};
List<Node> nodes = okmNode.getNodesFromUuids(null, uuids);
for (Node node : nodes) {
System.out.println(node);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
evaluateZipDownload
Description:
| Method | Return values | Description |
|---|---|---|
|
evaluateZipDownload(String token, List<String> uuids) |
ZipDownloadEvaluationResult |
Evaluates whether a zip file can be downloaded in real time or in the background. |
|
Related configuration parameters:
More information at Performance configuration parameters
|
||
Example:
package com.openkm;
import java.util.ArrayList;
import java.util.List;
import com.openkm.api.OKMNode;
import com.openkm.bean.ZipDownloadEvaluationResult;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMNode okmNode = ContextWrapper.getContext().getBean("okmNode", OKMNode.class);
List<String> uuids = new ArrayList<>();
uuids.add("0f6463f3-4d36-4091-b518-4fe7c353ee70");
uuids.add("d386cff8-1d4d-472f-9c6d-f21955ec499a");
ZipDownloadEvaluationResult result = okmNode.evaluateZipDownload(null, uuids);
System.out.println(result);
} catch (Exception e) {
e.printStackTrace();
}
}
}
restore
Description:
| Method | Return values | Description |
|---|---|---|
|
restore(String token, String nodeId) |
Node |
Restore a node from the trash. |
|
When a node is moved to the trash, the application keeps the origin. When possible, the application will try to restore it to the same origin (sometimes this is not possible because the origin no longer exists or security has changed in the origin, etc.).
|
||
Example:
package com.openkm;
import com.openkm.api.OKMNode;
import com.openkm.bean.Node;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMNode okmNode = ContextWrapper.getContext().getBean("okmNode", OKMNode.class);
Node node = okmNode.restore(null, "0f6463f3-4d36-4091-b518-4fe7c353ee70");
System.out.println(node);
} catch (Exception e) {
e.printStackTrace();
}
}
}
hasNodesLockedByOtherUser
Description:
| Method | Return values | Description |
|---|---|---|
|
hasNodesLockedByOtherUser(String token, String nodeId) |
boolean |
Check if the node and descendants have been locked by other users. |
|
This method is used to evaluate if it is possible to lock a hierarchy. For example, in the case of a record, the lock affects all the nodes it contains, which will also be locked.
|
||
Example:
package com.openkm;
import com.openkm.api.OKMNode;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMNode okmNode = ContextWrapper.getContext().getBean("okmNode", OKMNode.class);
if (okmNode.hasNodesLockedByOtherUser(null, "0f6463f3-4d36-4091-b518-4fe7c353ee70")) {
System.out.println("Is blocked");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
lock
Description:
| Method | Return values | Description |
|---|---|---|
|
lock(String token, String nodeId) |
LockInfo |
Locks a node and returns an object with the Lock information. |
|
Only the user who locked the document is allowed to unlock it. A locked document cannot be modified by other users. |
||
Example:
package com.openkm;
import com.openkm.api.OKMNode;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMNode okmNode = ContextWrapper.getContext().getBean("okmNode", OKMNode.class);
okmNode.lock(null, "1ec49da9-1746-4875-ae32-9281d7303a62");
} catch (Exception e) {
e.printStackTrace();
}
}
}
forceLock
Description:
| Method | Return values | Description |
|---|---|---|
|
forceLock(String token, String nodeId) |
void |
Locks a locked node. |
|
This method allows locking any locked node. This action can only be done by users with administrator privileges. |
||
Example:
package com.openkm;
import com.openkm.api.OKMNode;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMNode okmNode = ContextWrapper.getContext().getBean("okmNode", OKMNode.class);
okmNode.forceLock(null, "1ec49da9-1746-4875-ae32-9281d7303a62");
} catch (Exception e) {
e.printStackTrace();
}
}
}
unlock
Description:
| Method | Return values | Description |
|---|---|---|
|
unlock(String token, String nodeId) |
void |
Unlocks a locked node. |
|
Only the user who locked the document is allowed to unlock it. |
||
Example:
package com.openkm;
import com.openkm.api.OKMNode;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMNode okmNode = ContextWrapper.getContext().getBean("okmNode", OKMNode.class);
okmNode.unlock(null, "1ec49da9-1746-4875-ae32-9281d7303a62");
} catch (Exception e) {
e.printStackTrace();
}
}
}
forceUnlock
Description:
| Method | Return values | Description |
|---|---|---|
|
forceUnlock(String token, String nodeId) |
void |
Unlocks a locked node. |
|
This method allows to unlock any locked node. It is not mandatory that the same user who previously executed the checkout lock action perform this action. This action can only be done by a user with administrator privileges. |
||
Example:
package com.openkm;
import com.openkm.api.OKMNode;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMNode okmNode = ContextWrapper.getContext().getBean("okmNode", OKMNode.class);
okmNode.forceUnlock(null, "1ec49da9-1746-4875-ae32-9281d7303a62");
} catch (Exception e) {
e.printStackTrace();
}
}
}
isLocked
Description:
| Method | Return values | Description |
|---|---|---|
|
isLocked(String token, String nodeId) |
Boolean |
Returns a boolean indicating whether the node is locked. |
Example:
package com.openkm;
import com.openkm.api.OKMNode;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMNode okmNode = ContextWrapper.getContext().getBean("okmNode", OKMNode.class);
System.out.println(okmNode.getLockInfo(null, "1ec49da9-1746-4875-ae32-9281d7303a62"));
} catch (Exception e) {
e.printStackTrace();
}
}
}
getLockInfo
Description:
| Method | Return values | Description |
|---|---|---|
|
getLockInfo(String token, String nodeId) |
LockInfo |
Returns an object with the Lock information. |
Example:
package com.openkm;
import com.openkm.api.OKMNode;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMNode okmNode = ContextWrapper.getContext().getBean("okmNode", OKMNode.class);
System.out.println(okmNode.getLockInfo(null, "1ec49da9-1746-4875-ae32-9281d7303a62"));
} catch (Exception e) {
e.printStackTrace();
}
}
}
setComment
Description:
| Method | Return values | Description |
|---|---|---|
|
setComment(String token, String nodeId, String versionName, String comment) |
void |
Sets the comment for a specific node version. |
Example:
package com.openkm;
import com.openkm.api.OKMNode;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMNode okmNode = ContextWrapper.getContext().getBean("okmNode", OKMNode.class);
okmNode.setComment(null, "1ec49da9-1746-4875-ae32-9281d7303a62", "1.14", "Update comment");
} catch (Exception e) {
e.printStackTrace();
}
}
}