OKMNode
Basics
On almost methods you'll see parameter named "nodeId". The value of this parameter can be some valid UUID node.
Example of docId:
- Using UUID -> "c41f9ea0-0d6c-45da-bae4-d72b66f42d0f";
About the parameter named "fldId", the value of this parameter can be some valid folder UUID or record node.
Example of fldId:
- Using UUID -> "c6785440-0d6c-45da-1234-d9874563d0f";
About the parameter named "dstId", the value of this parameter can be some valid folder UUID or record node.
Example of dstId:
- Using UUID -> "c4455667-0d6c-45da-1234-d98564323e0";
Also on all methods you'll see parameter named "token". Because the Cron Task are executed in background without authentication, the methods used in this scenario might use the token parameter. From default application execution context you must use "null" value what indicates to the application must use the "user session".
On special cases you might be "promoted as 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();
}
}
}
mayBePromotedAsRecord
Description:
Method | Return values | Description |
---|---|---|
mayBePromotedAsRecord(String token, String nodeId, boolean fullEvaluation) |
PromoteAsRecordEvaluation |
Returns the result of the evaluation to promote a node to the "record" status. When the node can not be promoted to the "record" status, the result of the evaluation contains information about the reason why can not be promoted. |
Example:
package com.openkm;
import com.openkm.api.OKMNode;
import com.openkm.plugin.fileplan.record.bean.PromoteAsRecordEvaluation;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMNode okmNode = ContextWrapper.getContext().getBean("okmNode", OKMNode.class);
PromoteAsRecordEvaluation pre = okmNode.mayBePromotedAsRecord(null, "3767deb4-21e7-4272-82be-fece5384fbab", false);
System.out.println(pre);
} catch (Exception e) {
e.printStackTrace();
}
}
}
promoteAsRecord
Description:
Method | Return values | Description |
---|---|---|
promoteAsRecord(String token, String nodeId) |
void |
Promote the node to the "record" status. |
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.promoteAsRecord(null, "3767deb4-21e7-4272-82be-fece5384fbab");
} catch (Exception e) {
e.printStackTrace();
}
}
}
degradeRecord
Description:
Method | Return values | Description |
---|---|---|
degradeRecord(String token, String nodeId) |
void |
Degrade a node with "record" status. |
This action only can be done by administrators.
|
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.degradeRecord(null, "3767deb4-21e7-4272-82be-fece5384fbab");
} catch (Exception e) {
e.printStackTrace();
}
}
}
isElectronicRecordPath
Description:
Method | Return values | Description |
---|---|---|
isElectronicRecordPath(String token, String nodeId) |
boolean |
Returns true when the node is into an electronic record. |
Return true when one of the parents of the node is an electronic record. |
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.isElectronicRecordPath(null, "3767deb4-21e7-4272-82be-fece5384fbab"));
} catch (Exception e) {
e.printStackTrace();
}
}
}
getElectronicRecordInPath
Description:
Method | Return values | Description |
---|---|---|
getElectronicRecordInPath(String token, String nodeId) |
Record |
Get the electronic record in the path. |
Returns the first electronic record in the path of the node. |
Example:
package com.openkm;
import com.openkm.api.OKMNode;
import com.openkm.bean.Record;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMNode okmNode = ContextWrapper.getContext().getBean("okmNode", OKMNode.class);
Record record = okmNode.getElectronicRecordInPath(null, "3767deb4-21e7-4272-82be-fece5384fbab");
System.out.println(record);
} 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 parameter "limit" and "offset" allows 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 parameter "limit" and "offset" allows 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 |
Delete 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 |
Unzip 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> |
Return 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 |
Evaluate when a zip file can be downloaded in real-time or at 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 trash, the application keeps the origin. When possible the application will try to restore in the same origin ( sometimes is not possible because the origin no longer exist or security has been 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) |
booelan |
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 case of a record, the lock affects all the nodes into what also will 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. 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 to lock any locked node. This action can only be done by users with administrator grants. |
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. |
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 execute this action by the same user who previously executed the checkout lock action. This action can only be done by a user with administrator grants. |
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 that indicates if the node is locked or not. |
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();
}
}
}