Repository samples

Methods

getRootFolder

Description:

MethodReturn valuesDescription

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:

MethodReturn valuesDescription

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(); } } }

getTemplatesFolder

Description:

MethodReturn valuesDescription

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:

MethodReturn valuesDescription

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(); } } }

getMailFolder

Description:

MethodReturn valuesDescription

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(); } } }

getThesaurusFolder

Description:

MethodReturn valuesDescription

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:

MethodReturn valuesDescription

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:

MethodReturn valuesDescription

purgeTrash()

void

Definitively purge all nodes into "/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 only will 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:

MethodReturn valuesDescription

getUpdateMessage()

String

Retrieves a message in case there is a newer 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:

MethodReturn valuesDescription

getRepositoryUuid()

String

Retrieves 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:

MethodReturn valuesDescription

hasNode(String nodeId)

Boolean

Check node exists. Returns true when the node exists.
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:

MethodReturn valuesDescription

getNodePath(String uuid)

String Converts node UUID to a 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:

MethodReturn valuesDescription

getNodeUuid(String path)

String

Converts 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:

MethodReturn valuesDescription

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();
        }
    }
}

 

getTrashFolderBase

Description:

MethodReturn valuesDescription

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(); } } }

getPersonalFolderBase

Description:

MethodReturn valuesDescription

getPersonalFolderBase()

Folder

Returns the object Folder of node "/okm:personal"

For example, if the method is executed by the user "okmAdmin", then the purged trash 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.getPersonalFolderBase()); } catch (Exception e) { e.printStackTrace(); } } }

getMailFolderBase

Description:

MethodReturn valuesDescription

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(); } } }

copyAttributes

Description:

MethodReturn valuesDescription

copyAttributes(String nodeId, String dstId, boolean categories, boolean keywords, boolean propertyGroups, boolean notes, boolean wiki)

void

Copy attributes from a node to another.

The values of the dstId parameter should be a node UUID or path.

  • When the category parameter is true the original values of the categories will be copied.
  • When the keywords parameter is true the original values of the keywords will be copied.
  • When the property Groups parameter is true the original values of the metadata groups will be copied.
  • When the notes parameter is true the original values of the notes will be copied.
  • When the wiki parameter is true the original values of the wiki will be copied.

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:

MethodReturn valuesDescription

executeScript(InputStream is)

ScriptExecutionResult

Executes a 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 string return "some result";

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:

MethodReturn valuesDescription

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;

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:

MethodReturn valuesDescription

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';

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"));

getConfiguration

Description:

MethodReturn valuesDescription

getConfiguration(String key)

Configuration

Retrieve the value of a configuration parameter.

If your OpenKM version have the configuration parameter named "webservices.visible.properties", will be restricted for non Administrator users what parameters are accessible. That means any non Administrator use who will try accessing across the webservices to configuration parameters not set into the list of values of "webservices.visible.properties" will get an access denied exception.

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(); } } }