OKMNotification

Basics

In most methods you'll see a parameter named "nodeId". The value of this parameter can be a valid document, folder, mail, or record UUID.

Example of nodeId:

  • Using UUID -> "b153c4b7-3d1c-4589-bd42-0ed0f34fd338"

Also, in all methods you'll see a parameter named "token". Because cron tasks are executed in the background without authentication, the methods used in this scenario might use the token parameter. From the default application execution context you must use the "null" value, which indicates that the application must use the "user session".

In special cases you might be "promoted as Administrator" using the "administrator token".

String systemToken = DbSessionManager.getInstance().getSystemToken();

Methods

subscribe

Description:

MethodReturn valuesDescription

subscribe(String token, String nodeId)

void

Adds a subscription to a node.

Example:

package com.openkm;

import com.openkm.api.OKMNotification;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMNotification okmNotification = ContextWrapper.getContext().getBean(OKMNotification.class);

            okmNotification.subscribe(null, "b153c4b7-3d1c-4589-bd42-0ed0f34fd338");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

unsubscribe

Description:

MethodReturn valuesDescription

unsubscribe(String token, String nodeId)

void

Deletes a subscription to a node.

Example:

package com.openkm;

import com.openkm.api.OKMNotification;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMNotification okmNotification = ContextWrapper.getContext().getBean(OKMNotification.class);
            okmNotification.unsubscribe(null, "b153c4b7-3d1c-4589-bd42-0ed0f34fd338");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getSubscriptors

Description:

MethodReturn valuesDescription

getSubscriptors(String token, String nodeId)

Set<String>

Retrieves a list of all the subscribers of a node.

Example:

package com.openkm;

import com.openkm.api.OKMNotification;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMNotification okmNotification = ContextWrapper.getContext().getBean(OKMNotification.class);
            for (String subscriptor : okmNotification.getSubscriptors(null, "b153c4b7-3d1c-4589-bd42-0ed0f34fd338")) {
                System.out.println(subscriptor);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

notify

Description:

MethodReturn valuesDescription

notify(String token, String nodeId, List<String> users, List<String> mails, String message, boolean attachment)

void

Sends a mail notification.

The parameter users is a set of OpenKM users to be notified.

The parameter mails is a set of mails - usually external mails - to be notified.

The parameter message is the body of the mail.

When the attachment value is true, the node is attached to the mail.

Example:

package com.openkm;

import java.util.ArrayList;
import java.util.List;

import com.openkm.api.OKMNotification;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMNotification okmNotification = ContextWrapper.getContext().getBean(OKMNotification.class);
            List<String> users = new ArrayList<>();
            users.add("sochoa");
            List<String> mails = new ArrayList<>();
            String body = "Body of the message";
            okmNotification.notify(null, "b153c4b7-3d1c-4589-bd42-0ed0f34fd338", users, mails, body, false);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}