OKMNotification

Basics

On most methods you'll see 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 on all methods you'll see parameter named "token". Because the Cron Task are executed in background without authentication, the methods used in this scenario might use the token parameter. From default application execution context you must use "null" value what indicates to the application must use the "user session".

On 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

Delete 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 subscriptors 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

Send a mail notification.

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

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

The parameter message is the content body of the mail.

When attachment value is true the node is attached into 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();
        }
    }
}