Repository samples
Methods
Section titled “Methods”getRootFolder
Section titled “getRootFolder”Description:
| Method | Return values | Description |
|---|---|---|
| getRootFolder() | Folder | Returns the object Folder of node “/okm:root” |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try { System.out.println(ws.getRootFolder()); } catch (Exception e) { e.printStackTrace(); } }}getTrashFolder
Section titled “getTrashFolder”Description:
| Method | Return values | Description |
|---|---|---|
| getTrashFolder() | Folder | Returns the object Folder of node “/okm:trash/{userId}” |
The returned folder will be the user trash folder.
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try { System.out.println(ws.getTrashFolder()); } catch (Exception e) { e.printStackTrace(); } }}getTrashFolderBase
Section titled “getTrashFolderBase”Description:
| Method | Return values | Description |
|---|---|---|
| getTrashFolderBase() | Folder | Returns the object Folder of node “/okm:trash” |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try { System.out.println(ws.getTrashFolderBase()); } catch (Exception e) { e.printStackTrace(); } }}getTemplatesFolder
Section titled “getTemplatesFolder”Description:
| Method | Return values | Description |
|---|---|---|
| getTemplatesFolder() | Folder | Returns the object Folder of node “/okm:templates” |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try { System.out.println(ws.getTemplatesFolder()); } catch (Exception e) { e.printStackTrace(); } }}getPersonalFolder
Section titled “getPersonalFolder”Description:
| Method | Return values | Description |
|---|---|---|
| getPersonalFolder() | Folder | Returns the object Folder of node “/okm:personal/{userId}” |
The returned folder will be the user personal folder.
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try { System.out.println(ws.getPersonalFolder()); } catch (Exception e) { e.printStackTrace(); } }}getPersonalFolderBase
Section titled “getPersonalFolderBase”Description:
| Method | Return values | Description |
|---|---|---|
| getPersonalFolderBase() | Folder | Returns the object Folder of node “/okm:personal” |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try { System.out.println(ws.getPersonalFolderBase()); } catch (Exception e) { e.printStackTrace(); } }}getMailFolder
Section titled “getMailFolder”Description:
| Method | Return values | Description |
|---|---|---|
| getMailFolder() | Folder | Returns the object Folder of node “/okm:mail/{userId}” |
The returned folder will be the user mail folder.
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try { System.out.println(ws.getMailFolder()); } catch (Exception e) { e.printStackTrace(); } }}getMailFolderBase
Section titled “getMailFolderBase”Description:
| Method | Return values | Description |
|---|---|---|
| getMailFolderBase() | Folder | Returns the object Folder of node “/okm:mail” |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try { System.out.println(ws.getMailFolderBase()); } catch (Exception e) { e.printStackTrace(); } }}getThesaurusFolder
Section titled “getThesaurusFolder”Description:
| Method | Return values | Description |
|---|---|---|
| getThesaurusFolder() | Folder | Returns the object Folder of node “/okm:thesaurus” |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try { System.out.println(ws.getThesaurusFolder()); } catch (Exception e) { e.printStackTrace(); } }}getCategoriesFolder
Section titled “getCategoriesFolder”Description:
| Method | Return values | Description |
|---|---|---|
| getCategoriesFolder() | Folder | Returns the object Folder of node “/okm:categories” |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try { System.out.println(ws.getCategoriesFolder()); } catch (Exception e) { e.printStackTrace(); } }}purgeTrash
Section titled “purgeTrash”Description:
| Method | Return values | Description |
|---|---|---|
| purgeTrash() | void | Definitively removes from repository all nodes to “/okm:trash/{userId}” |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try { ws.purgeTrash(); } catch (Exception e) { e.printStackTrace(); } }}getUpdateMessage
Section titled “getUpdateMessage”Description:
| Method | Return values | Description |
|---|---|---|
| getUpdateMessage() | String | Retrieves a message when there is a new OpenKM release. |
There’s an official OpenKM update message service available which is based on your local OpenKM version.
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try { System.out.println(ws.getUpdateMessage()); } catch (Exception e) { e.printStackTrace(); } }}getRepositoryUuid
Section titled “getRepositoryUuid”Description:
| Method | Return values | Description |
|---|---|---|
| getRepositoryUuid() | String | Retrieves the installation unique identifier. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try { System.out.println(ws.getRepositoryUuid()); } catch (Exception e) { e.printStackTrace(); } }}hasNode
Section titled “hasNode”Description:
| Method | Return values | Description |
|---|---|---|
| hasNode(String nodeId) | Boolean | Returns a node that indicate if a node exists or not. |
The value of the parameter nodeId can be a valid UUID or path.
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try { System.out.println("Exists node:" + ws.hasNode("064ff51a-b815-4f48-a096-b4946876784f")); } catch (Exception e) { e.printStackTrace(); } }}getNodePath
Section titled “getNodePath”Description:
| Method | Return values | Description |
|---|---|---|
| getNodePath(String uuid) | String | Converts a node UUID to path. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try { System.out.println(ws.getNodePath("064ff51a-b815-4f48-a096-b4946876784f")); } catch (Exception e) { e.printStackTrace(); } }}getNodeUuid
Section titled “getNodeUuid”Description:
| Method | Return values | Description |
|---|---|---|
| getNodeUuid(String path) | String | Converts a node path to UUID. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try { System.out.println(ws.getNodeUuid("/okm:root/tmp")); } catch (Exception e) { e.printStackTrace(); } }}getAppVersion
Section titled “getAppVersion”Description:
| Method | Return values | Description |
|---|---|---|
| getAppVersion() | AppVersion | Returns information about OpenKM version. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try { System.out.println(ws.getAppVersion()); } catch (Exception e) { e.printStackTrace(); } }}copyAttributes
Section titled “copyAttributes”Description:
| Method | Return values | Description |
|---|---|---|
| copyAttributes(String nodeId, String dstId, boolean categories, boolean keywords, boolean propertyGroups, boolean notes, boolean wiki) |
void | Copy attributes from a node to other. |
The values of the dstId parameter should be a node UUID or path.
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try { ws.copyAttributes("/okm:root/invoice.pdf", "/okm:root/cloned_invoice.pdf", true, true, true, true, true); } catch (Exception e) { e.printStackTrace(); } }}executeScript
Section titled “executeScript”Description:
| Method | Return values | Description |
|---|---|---|
| executeScript(InputStream is) | ScriptExecutionResult | Executes an script. |
The local script - test.bsh - used in the sample below:
import com.openkm.bean.*;import com.openkm.api.*;
for (Folder fld : OKMFolder.getInstance().getChildren(null,"/okm:root")) { print(fld + "\n");}
// Some value can also be returned as stringreturn "some result";Example:
package com.openkm;
import java.io.FileInputStream;import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;import com.openkm.sdk4j.bean.ScriptExecutionResult;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try { InputStream is = new FileInputStream("/opt/files/test.bsh"); ScriptExecutionResult result = ws.executeScript(is); System.out.println(result.getResult()); System.out.println(result.getStdout());
if (!result.getStderr().isEmpty()) { System.out.println("Error happened"); System.out.println(result.getStderr()); }
IOUtils.closeQuietly(is); } catch (Exception e) { e.printStackTrace(); } }}executeSqlQuery
Section titled “executeSqlQuery”Description:
| Method | Return values | Description |
|---|---|---|
| executeSqlQuery(InputStream is) | SqlQueryResults | Executes SQL sentences. |
The test.sql script used in the sample below:
SELECT NBS_UUID, NBS_NAME FROM OKM_NODE_BASE LIMIT 10;Example:
package com.openkm;
import java.io.FileInputStream;import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;import com.openkm.sdk4j.bean.SqlQueryResultColumns;import com.openkm.sdk4j.bean.SqlQueryResults;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try { InputStream is = new FileInputStream("/opt/files/test.sql"); SqlQueryResults result = ws.executeSqlQuery(is);
for (SqlQueryResultColumns row : result.getResults()) { System.out.println("uuid" + row.getColumns().get(0) + ", name:" + row.getColumns().get(1)); }
IOUtils.closeQuietly(is); } catch (Exception e) { e.printStackTrace(); } }}Also the InputStream can be set as:
String sql = "SELECT NBS_UUID, NBS_NAME FROM OKM_NODE_BASE LIMIT 10;";InputStream is = new ByteArrayInputStream(sql.getBytes("UTF-8"));executeHqlQuery
Section titled “executeHqlQuery”Description:
| Method | Return values | Description |
|---|---|---|
| executeHqlQuery(InputStream is) | HqlQueryResults | Executes HQL sentences. |
The test.sql script used in the sample below:
SELECT uuid, name from NodeBase where name = 'okm:root';Example:
package com.openkm;
import java.io.FileInputStream;import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;import com.openkm.sdk4j.bean.HqlQueryResults;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try { InputStream is = new FileInputStream("/opt/files/test.sql"); HqlQueryResults result = ws.executeHqlQuery(is);
for (String column : result.getResults()) { System.out.println(column); }
IOUtils.closeQuietly(is); } catch (Exception e) { e.printStackTrace(); } }}Also the InputStream can be set as:
String sql = "SELECT uuid, name from NodeBase where name = 'okm:root';";InputStream is = new ByteArrayInputStream(sql.getBytes("UTF-8"));getTranslations
Section titled “getTranslations”Description:
| Method | Return values | Description |
|---|---|---|
| getTranslations(String lang, String module) | Map<String, String> | Retrieve the translations of a module into a Map of values. |
Example:
package com.openkm;
import java.util.Map;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8180/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try { Map<String, String> translations = ws.getTranslations("en-GB", "frontend"); for (String key : translations.keySet()) { System.out.println("key:'" + key + "', with translation:'" + translations.get(key) + "'"); } } catch (Exception e) { e.printStackTrace(); } }}getConfiguration
Section titled “getConfiguration”Description:
| Method | Return values | Description |
|---|---|---|
| getConfiguration(String key) | Configuration | Retrieve the value of a configuration parameter. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;import com.openkm.sdk4j.bean.Configuration;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try { Configuration configuration = ws.getConfiguration("system.ocr"); System.out.println(configuration); } catch (Exception e) { e.printStackTrace(); } }}executePlugin
Section titled “executePlugin”Description:
| Method | Return values | Description |
|---|---|---|
| executePlugin(String className, Map<String, String> parameters, Class<?> clazz, InputStream is) This method is deprecated in favour of “executePostPlugin”. We encourage use it rather exeutePlugin. For more information take a look at Plugin samples. |
Object | Return the Object value of execution of a class which implements RestPlugin. |
Example:
package com.openkm;
import java.util.HashMap;import java.util.Map;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); try { Map<String, String> parameters = new HashMap<>(); parameters.put("param1", "value1"); parameters.put("param2", "value2"); String value = (String) ws.executePlugin("com.openkm.plugin.rest.TestRestPlugin", parameters, String.class, null); System.out.println(value); } catch (Exception e) { e.printStackTrace(); } }}getChangeLog
Section titled “getChangeLog”Description:
| Method | Return values | Description |
|---|---|---|
| getChangeLog(String nodePath, Calendar modificationsFrom) | List |
Return the list of changes in some path and subfolders. |
Example:
package com.openkm;
import java.util.Calendar;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;import com.openkm.sdk4j.bean.ChangeLogged;
public class Test2 { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); try { Calendar now = Calendar.getInstance(); for (ChangeLogged cl : ws.getChangeLog("/okm:root/synchronized", now)) { System.out.println(cl); } } catch (Exception e) { e.printStackTrace(); } }}getServerTime()
Section titled “getServerTime()”Description:
| Method | Return values | Description |
|---|---|---|
| getServerTime() | String | Return the current server time. |
Example:
package com.openkm;
import java.util.Calendar;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;import com.openkm.sdk4j.bean.ChangeLogged;
public class Test2 { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); try { System.out.println(ws.getServerTime()); } catch (Exception e) { e.printStackTrace(); } }}