OKMNotification
Basics
Section titled “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.
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”.
Methods
Section titled “Methods”subscribe
Section titled “subscribe”Description:
| Method | Return values | Description |
|---|---|---|
| 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
Section titled “unsubscribe”Description:
| Method | Return values | Description |
|---|---|---|
| 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
Section titled “getSubscriptors”Description:
| Method | Return values | Description |
|---|---|---|
| getSubscriptors(String token, String nodeId) | Set |
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
Section titled “notify”Description:
| Method | Return values | Description |
|---|---|---|
| notify(String token, String nodeId, List |
void | Sends a mail notification. |
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(); } }}