Repository samples
Methods
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
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. For example if the method is executed by the user "okmAdmin" then the folder returned will be "/okm:trash/okmAdmin". |
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
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
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
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. For example if the method is executed by the user "okmAdmin" then the folder returned will be "/okm:personal/okmAdmin". |
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
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
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. For example if the method is executed by the user "okmAdmin" then the folder returned will be "/okm:mail/okmAdmin". |
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
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
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
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
Description:
Method | Return values | Description |
---|---|---|
purgeTrash() |
void |
Definitively removes from repository all nodes to "/okm:trash/{userId}" |
For example if the method is executed by the user "okmAdmin" then the purged trash will be "/okm:trash/okmAdmin". When a node is purged it will only be able to be restored from a previously repository backup. The purge action removes the node definitely from the repository.
|
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
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. The most common message is that a new OpenKM version has been released. |
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
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
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
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
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
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
Description:
Method | Return values | Description |
---|---|---|
copyAttributes(String nodeId, String dstId, boolean categories, boolean keywords, boolean propertyGroups, boolean notes, |
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
Description:
Method | Return values | Description |
---|---|---|
executeScript(InputStream is) |
ScriptExecutionResult |
Executes an script. |
The local script - test.bsh - used in the sample below:
This action can only be done by a super user ( user with ROLE_ADMIN ). |
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
Description:
Method | Return values | Description |
---|---|---|
executeSqlQuery(InputStream is) |
SqlQueryResults |
Executes SQL sentences. |
The test.sql script used in the sample below:
The SQL script can only contains a single SQL sentence. This action can only be done by a super user ( user with ROLE_ADMIN ). |
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
Description:
Method | Return values | Description |
---|---|---|
executeHqlQuery(InputStream is) |
HqlQueryResults |
Executes HQL sentences. |
The test.sql script used in the sample below:
The HQL script can only contains a single HQL sentence. This action can only be done by a super user ( user with ROLE_ADMIN ). |
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
Description:
Method | Return values | Description |
---|---|---|
getTranslations(String lang, String module) |
Map<String, String> |
Retrieve the translations of a module into a Map of values |
The OpenKM translations tables can be used to retrieve actually OpenKM translations or create your own translations ( insert values into new module ). By default modules values are :
Example to add a new Translation module : SQL values to be executed from Database query view:
The code then should be:
|
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();
}
}
}