OKMDocument
Basics
Section titled “Basics”On almost methods you’ll see parameter named “docId”. The value of this parameter can be some valid document UUID or path node.
When you’ll see parameter named “fldId”. The value of this parameter can be some valid folder UUID or path node.
About the parameter named “dstId”, the value of this parameter can be some valid folder UUID or path node.
Also on all methods you’ll see parameter named “token”. When accessing application across SOAP the login process returns a token, what is used to identify the user on all the exposed methods. From default application execution context you must use “null” value what indicates to the application must use the “user session”.
Methods
Section titled “Methods”create
Section titled “create”Description:
| Method | Return values | Description |
|---|---|---|
| create(String token, Document doc, InputStream is) | Document | Create a new document. |
- The parameter doc must be initialized with the OpenKM path value into the repository. Optionally you can also set keywords and title values.
Example:
package com.openkm;
import java.io.FileInputStream;import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import com.openkm.api.OKMDocument;import com.openkm.bean.Document;
public class Test { public static void main(String[] args) { InputStream is = null; try { is = new FileInputStream("/home/user/sample.pdf"); Document doc = new Document(); doc.setPath("/okm:root/sample.pdf"); // Optional doc.setTitle("sample document"); doc.getKeywords().add("key1"); doc.getKeywords().add("key2"); // Create document doc = OKMDocument.getInstance().create(null, doc, is); System.out.println(doc); } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(is); } }}createSimple
Section titled “createSimple”Description:
| Method | Return values | Description |
|---|---|---|
| createSimple(String token, String docPath, InputStream is) | Document | Create a new document. |
Example:
package com.openkm;
import java.io.FileInputStream;import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import com.openkm.api.OKMDocument;import com.openkm.bean.Document;
public class Test { public static void main(String[] args) { InputStream is = null; try { is = new FileInputStream("/home/user/sample.pdf"); String docPath = "/okm:root/sample.pdf"; Document doc = OKMDocument.getInstance().createSimple(null, docPath, is); System.out.println(doc); } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(is); } }}delete
Section titled “delete”Description:
| Method | Return values | Description |
|---|---|---|
| delete(String token, String docId) | void | Delete a document. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;
public class Test { public static void main(String[] args) { try { // Delete document by path OKMDocument.getInstance().delete(null, "/okm:root/sample.pdf"); // Delete document by uuid OKMDocument.getInstance().delete(null, "adc048d7-3791-4540-ae32-680629f73875"); } catch (Exception e) { e.printStackTrace(); } }}getProperties
Section titled “getProperties”Description:
| Method | Return values | Description |
|---|---|---|
| getProperties(String token, String docId) | Document | Return a document properties. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.bean.Document;
public class Test { public static void main(String[] args) { try { Document doc = OKMDocument.getInstance().getProperties(null, "adc048d7-3791-4540-ae32-680629f73875"); System.out.println(doc); } catch (Exception e) { e.printStackTrace(); } }}getContent
Section titled “getContent”Description:
| Method | Return values | Description |
|---|---|---|
| getContent(String token, String docId, boolean checkout) | InputStream | Return the document content. |
- When paramer checkout is true, the document is marked for edition.
Example:
package com.openkm;
import java.io.File;import java.io.FileOutputStream;import java.io.InputStream;import java.io.OutputStream;
import org.apache.commons.io.IOUtils;
import com.openkm.api.OKMDocument;
public class Test { public static void main(String[] args) { InputStream is = null; OutputStream fos = null; try { is = OKMDocument.getInstance().getContent(null, "adc048d7-3791-4540-ae32-680629f73875", false); File tmp = new File("/home/user/sample.pdf"); fos = new FileOutputStream(tmp); IOUtils.copy(is, fos); } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(fos); } }}getContentByVersion
Section titled “getContentByVersion”Description:
| Method | Return values | Description |
|---|---|---|
| getContentByVersion(String token, String docId, String versionId) | InputStream | Return the document content by version. |
- The parameter versionIs is the name of the document version.
Example:
package com.openkm;
import java.io.File;import java.io.FileOutputStream;import java.io.InputStream;import java.io.OutputStream;
import org.apache.commons.io.IOUtils;
import com.openkm.api.OKMDocument;
public class Test { public static void main(String[] args) { InputStream is = null; OutputStream fos = null; try { is = OKMDocument.getInstance().getContentByVersion(null, "adc048d7-3791-4540-ae32-680629f73875", "1.1"); File tmp = new File("/home/user/sample.pdf"); fos = new FileOutputStream(tmp); IOUtils.copy(is, fos); } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(fos); } }}getChilds
Section titled “getChilds”Description:
| Method | Return values | Description |
|---|---|---|
| getChilds(String token, String fldId) | List |
Returns a list of all documents which their parent is fldId. |
- The parameter fldId can be a folder node.
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.bean.Document;
public class Test { public static void main(String[] args) { try { for (Document doc : OKMDocument.getInstance().getChilds(null, "/okm:root/import")) {; System.out.println(doc); } } catch (Exception e) { e.printStackTrace(); } }}getChildren
Section titled “getChildren”Descripcion:
| Method | Return values | Description |
|---|---|---|
| getChildren(String token, String fldId) | List |
Returns a list of all documents which their parent is fldId. |
- The parameter fldId can be a folder node.
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.bean.Document;
public class Test { public static void main(String[] args) { try { for (Document doc : OKMDocument.getInstance().getChildren(null, "/okm:root/import")) {; System.out.println(doc); } } catch (Exception e) { e.printStackTrace(); } }}rename
Section titled “rename”Description:
| Method | Return values | Description |
|---|---|---|
| rename(String token, String docId, String newName) | Document | Changes the name of a document. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.bean.Document;
public class Test { public static void main(String[] args) { try { Document doc = OKMDocument.getInstance().rename(null, "/okm:root/samples.pdf","samples_renamed.pdf"); System.out.println(doc); } catch (Exception e) { e.printStackTrace(); } }}setProperties
Section titled “setProperties”Description:
| Method | Return values | Description |
|---|---|---|
| setProperties(String token, Document doc) | void | Changes some document properties. |
- Variables allowed to be changed:
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.bean.Document;
public class Test { public static void main(String[] args) { try { Document doc = OKMDocument.getInstance().getProperties(null, "/okm:root/samples.pdf"); doc.getKeywords().add("key1"); doc.setDescription("some description"); OKMDocument.getInstance().setProperties(null, doc); } catch (Exception e) { e.printStackTrace(); } }}checkout
Section titled “checkout”Description:
| Method | Return values | Description |
|---|---|---|
| checkout(String token, String docId) | void | Marks the document for edition. |
- Only one user can modify a document at a time.
- Before starting edition you must do a checkout action that locks the edition process for other users and allows edition only to the user who has executed the action.
Example:
package com.openkm;
import com.openkm.api.OKMDocument;
public class Test { public static void main(String[] args) { try { OKMDocument.getInstance().checkout(null, "/okm:root/samples.pdf"); } catch (Exception e) { e.printStackTrace(); } }}cancelCheckout
Section titled “cancelCheckout”Description:
| Method | Return values | Description |
|---|---|---|
| cancelCheckout(String token, String docId) | void | Cancels a document edition. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;
public class Test { public static void main(String[] args) { try { OKMDocument.getInstance().cancelCheckout(null, "/okm:root/samples.pdf"); } catch (Exception e) { e.printStackTrace(); } }}forceCancelCheckout
Section titled “forceCancelCheckout”Description:
| Method | Return values | Description |
|---|---|---|
| forceCancelCheckout(String token, String docId) | void | Cancels a document edition. |
- This method allows to cancel edition on any document.
- It is not mandatory to execute this action by the same user who previously executed the checkout action.
Example:
package com.openkm;
import com.openkm.api.OKMDocument;
public class Test { public static void main(String[] args) { try { OKMDocument.getInstance().forceCancelCheckout(null, "/okm:root/samples.pdf"); } catch (Exception e) { e.printStackTrace(); } }}isCheckedOut
Section titled “isCheckedOut”Description:
| Method | Return values | Description |
|---|---|---|
| isCheckedOut(String token, String docId) | void | Returns a boolean that indicates if the document is on edition or not. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;
public class Test { public static void main(String[] args) { try { System.out.println(OKMDocument.getInstance().isCheckedOut(null, "/okm:root/samples.pdf")); } catch (Exception e) { e.printStackTrace(); } }}checkin
Section titled “checkin”Description:
| Method | Return values | Description |
|---|---|---|
| checkin(String token, String docId, InputStream is, String comment) | Version | Updates a document with a new version and returns an object with new Version values. |
Example:
package com.openkm;
import java.io.FileInputStream;import java.io.InputStream;
import org.apache.poi.util.IOUtils;
import com.openkm.api.OKMDocument;
public class Test { public static void main(String[] args) { InputStream is = null; try { is = new FileInputStream("/home/user/sample.pdf"); OKMDocument.getInstance().checkin(null, "/okm:root/samples.pdf", is, "optional comment"); } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(is); } }}checkin
Section titled “checkin”Description:
| Method | Return values | Description |
|---|---|---|
| checkin(String token, String docId, InputStream is, String comment, int increment) | Version | Updates a document with a new version and returns an object with new Version values. |
- The increment value depends on VersionNumeration implementation.
Example:
package com.openkm;
import java.io.FileInputStream;import java.io.InputStream;
import org.apache.poi.util.IOUtils;
import com.openkm.api.OKMDocument;import com.openkm.vernum.VersionNumerationAdapter;
public class Test { public static void main(String[] args) { InputStream is = null; try { is = new FileInputStream("/home/user/sample.pdf"); OKMDocument.getInstance().checkin(null, "/okm:root/samples.pdf", is, "optional comment", VersionNumerationAdapter.INCREASE_MINOR); } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(is); } }}isCheckedOut
Section titled “isCheckedOut”Description:
| Method | Return values | Description |
|---|---|---|
| isCheckedOut(String token, String docId) | void | Returns a boolean that indicates if the document is on edition or not. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;
public class Test { public static void main(String[] args) { try { System.out.println(OKMDocument.getInstance().isCheckedOut(null, "/okm:root/samples.pdf")); } catch (Exception e) { e.printStackTrace(); } }}getVersionHistory
Section titled “getVersionHistory”Description:
| Method | Return values | Description |
|---|---|---|
| getVersionHistory(String token, String docId | List |
Returns a list of all document versions. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.bean.Version;
public class Test { public static void main(String[] args) { try { for (Version ver :OKMDocument.getInstance().getVersionHistory(null, "/okm:root/samples.pdf")) { System.out.println(ver); } } catch (Exception e) { e.printStackTrace(); } }}Description:
| Method | Return values | Description |
|---|---|---|
| lock(String token, String docId | LockInfo | Locks a document and returns an object with the Lock information. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.bean.LockInfo;
public class Test { public static void main(String[] args) { try { LockInfo lockInfo = OKMDocument.getInstance().lock(null, "/okm:root/samples.pdf")); System.out.println(lockInfo); } catch (Exception e) { e.printStackTrace(); } }}unlock
Section titled “unlock”Description:
| Method | Return values | Description |
|---|---|---|
| unlock(String token, String docId | LockInfo | Unlocks a locked document. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;
public class Test { public static void main(String[] args) { try { OKMDocument.getInstance().unlock(null, "/okm:root/samples.pdf")); } catch (Exception e) { e.printStackTrace(); } }}forceUnlock
Section titled “forceUnlock”Description:
| Method | Return values | Description |
|---|---|---|
| forceUnlock(String token, String docId | LockInfo | Unlocks a locked document. |
- This method allows to unlock any locked document.
- It is not mandatory execute this action by the same user who previously executed the checkout lock action.
Example:
package com.openkm;
import com.openkm.api.OKMDocument;
public class Test { public static void main(String[] args) { try { OKMDocument.getInstance().forceUnlock(null, "/okm:root/samples.pdf")); } catch (Exception e) { e.printStackTrace(); } }}isLocked
Section titled “isLocked”Description:
| Method | Return values | Description |
|---|---|---|
| isLocked(String token, String docId) | void | Returns a boolean that indicates if the document is locked or not. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;
public class Test { public static void main(String[] args) { try { System.out.println(OKMDocument.getInstance().isLocked(null, "/okm:root/samples.pdf")); } catch (Exception e) { e.printStackTrace(); } }}getLockInfo
Section titled “getLockInfo”Description:
| Method | Return values | Description |
|---|---|---|
| getLockInfo(String token, String docId) | LockInfo | Returns an object with the Lock information. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.bean.LockInfo;
public class Test { public static void main(String[] args) { try { LockInfo lockInfo = OKMDocument.getInstance().getLockInfo(null, "/okm:root/samples.pdf")); System.out.println(lockInfo); } catch (Exception e) { e.printStackTrace(); } }}Description:
| Method | Return values | Description |
|---|---|---|
| purge(String token, String docId) | void | The document is definitely removed from repository. |
- Usually you will purge documents into /okm:trash/userId - the personal trash user locations - but is possible to directly purge any document from the whole repository.
Example:
package com.openkm;
import com.openkm.api.OKMDocument;
public class Test { public static void main(String[] args) { try { OKMDocument.getInstance().purge(null, "/okm:root/samples.pdf")); } catch (Exception e) { e.printStackTrace(); } }}Description:
| Method | Return values | Description |
|---|---|---|
| move(String token, String docId, String dstId) | void | Move document into some folder. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;
public class Test { public static void main(String[] args) { try { OKMDocument.getInstance().move(null, "/okm:root/samples.pdf", "/okm/root/temp")); } catch (Exception e) { e.printStackTrace(); } }}Description:
| Method | Return values | Description |
|---|---|---|
| copy(String token, String docId, String dstId) | void | Copy a document into some folder. |
- The values of the dstId parameter should be a folder UUID or path.
Example:
package com.openkm;
import com.openkm.api.OKMDocument;
public class Test { public static void main(String[] args) { try { OKMDocument.getInstance().copy(null, "/okm:root/samples.pdf", "/okm/root/temp")); } catch (Exception e) { e.printStackTrace(); } }}extendedCopy
Section titled “extendedCopy”Description:
| Method | Return values | Description |
|---|---|---|
| extendedCopy(String token, String docId, String dstId, String docName, ExtendedAttributes extAttr) | void | Copies a document with associated data into some folder. |
- The values of the dstId parameter should be a folder UUID or path.
- When the parameter newName value is null, the document will preserve the same name.
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.bean.ExtendedAttributes;
public class Test { public static void main(String[] args) { try { ExtendedAttributes extAttr = new ExtendedAttributes(); // copy keywords extAttr.setKeywords(true); OKMDocument.getInstance().extendedCopy(null, "/okm:root/samples.pdf", "/okm:root/temp", "samples_renamed.pdf", extAttr); } catch (Exception e) { e.printStackTrace(); } }}restoreVersion
Section titled “restoreVersion”Description:
| Method | Return values | Description |
|---|---|---|
| restoreVersion(String token, String docId, String versionId) | void | Restores previously document version to actual version. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;
public class Test { public static void main(String[] args) { try { OKMDocument.getInstance().restoreVersion(null, "/okm:root/samples.pdf", "1.2"); } catch (Exception e) { e.printStackTrace(); } }}purgeVersionHistory
Section titled “purgeVersionHistory”Description:
| Method | Return values | Description |
|---|---|---|
| purgeVersionHistory(String token, String docId) | void | Purges all the previous document versions except the actual version. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;
public class Test { public static void main(String[] args) { try { OKMDocument.getInstance().purgeVersionHistory(null, "/okm:root/samples.pdf"); } catch (Exception e) { e.printStackTrace(); } }}getVersionHistorySize
Section titled “getVersionHistorySize”Description:
| Method | Return values | Description |
|---|---|---|
| getVersionHistorySize(String token, String docId) | long | Returns the sum in bytes of all documents into documents history. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;import com.openkm.util.FormatUtil;
public class Test { public static void main(String[] args) { try { System.out.println(FormatUtil.formatSize(OKMDocument.getInstance().getVersionHistorySize(null, "/okm:root/samples.pdf"))); } catch (Exception e) { e.printStackTrace(); } }}isValid
Section titled “isValid”Description:
| Method | Return values | Description |
|---|---|---|
| isValid(String token, String docId) | boolean | Returns a boolean that indicates if the node is a document or not. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;
public class Test { public static void main(String[] args) { try { boolean valid = OKMDocument.getInstance().isValid(null, "/okm:root/samples.pdf"); 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 document UUID to document path. |
Example:
package com.openkm;
import com.openkm.api.OKMDocument;
public class Test { public static void main(String[] args) { try { String docPath = OKMDocument.getInstance().getPath(null, "f123a950-0329-4d62-8328-0ff500fd42dbg"); System.out.println(docPath); } catch (Exception e) { e.printStackTrace(); } }}