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 "okmAdmin" user 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 "okmAdmin" user 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 "okmAdmin" user 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 removes from repository all nodes into "/okm:trash/{userId}"

For example if the method is executed by "okmAdmin" user 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 remove 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

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:

MethodReturn valuesDescription

getNodePath(String uuid)

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

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

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

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