OKMNode
Esta página aún no está disponible en tu idioma.
Basics
Section titled “Basics”In almost all methods you’ll see a parameter named “nodeId”. The value of this parameter can be a valid node UUID.
For the parameter named “fldId”, the value of this parameter can be a valid folder UUID or a record node.
For the parameter named “dstId”, the value of this parameter can be a valid folder UUID or a record node.
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”.
Methods
Section titled “Methods”getNodeByUuid
Section titled “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
Section titled “getVersionHistory”Description:
| Method | Return values | Description |
|---|---|---|
| getVersionHistory(String token, String nodeId) | List |
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
Section titled “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
Section titled “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
Section titled “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
Section titled “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. |
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
Section titled “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. |
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
Section titled “getBreadcrumb”Description:
| Method | Return values | Description |
|---|---|---|
| getBreadcrumb(String token, String fldId) | List |
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
Section titled “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
Section titled “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
Section titled “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(); } }}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
Section titled “exportZip”Description:
| Method | Return values | Description |
|---|---|---|
| exportZip(List |
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
Section titled “getNodesFromUuids”Description:
| Method | Return values | Description |
|---|---|---|
| getNodesFromUuids(String token, String[] uuids) | List |
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
Section titled “evaluateZipDownload”Description:
| Method | Return values | Description |
|---|---|---|
| evaluateZipDownload(String token, List |
ZipDownloadEvaluationResult | Evaluates whether a zip file can be downloaded in real time or in the background. |
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
Section titled “restore”Description:
| Method | Return values | Description |
|---|---|---|
| restore(String token, String nodeId) | Node | Restore a node from the trash. |
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
Section titled “hasNodesLockedByOtherUser”Description:
| Method | Return values | Description |
|---|---|---|
| hasNodesLockedByOtherUser(String token, String nodeId) | boolean | Check if the node and descendants have been locked 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); if (okmNode.hasNodesLockedByOtherUser(null, "0f6463f3-4d36-4091-b518-4fe7c353ee70")) { System.out.println("Is blocked"); } } catch (Exception e) { e.printStackTrace(); } }}Description:
| Method | Return values | Description |
|---|---|---|
| lock(String token, String nodeId) | LockInfo | Locks a node and 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); okmNode.lock(null, "1ec49da9-1746-4875-ae32-9281d7303a62"); } catch (Exception e) { e.printStackTrace(); } }}forceLock
Section titled “forceLock”Description:
| Method | Return values | Description |
|---|---|---|
| forceLock(String token, String nodeId) | void | Locks a locked node. |
- This method allows locking any locked 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.forceLock(null, "1ec49da9-1746-4875-ae32-9281d7303a62"); } catch (Exception e) { e.printStackTrace(); } }}unlock
Section titled “unlock”Description:
| Method | Return values | Description |
|---|---|---|
| unlock(String token, String nodeId) | void | Unlocks a locked 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.unlock(null, "1ec49da9-1746-4875-ae32-9281d7303a62"); } catch (Exception e) { e.printStackTrace(); } }}forceUnlock
Section titled “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.
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
Section titled “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
Section titled “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
Section titled “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(); } }}