GeneralUtils

GeneralUtils is a Spring bean that provides methods for sending in-application UI notifications to users.

GeneralUtils is a Spring bean ? access it via ContextWrapper.getContext().getBean(GeneralUtils.class) or inject it with @Autowired.

Methods

uiNotify (current user)

Description:

MethodReturn valuesDescription

uiNotify(String msg)

void

Sends an in-application UI notification to the currently authenticated user.

msg: The notification message text.

The user must be logged in before calling this method.

Example:

package com.openkm;

import com.openkm.util.ContextWrapper;
import com.openkm.util.GeneralUtils;

public class Test {

    public static void main(String[] args) {
        try {
            GeneralUtils generalUtils = ContextWrapper.getContext().getBean(GeneralUtils.class);
            generalUtils.uiNotify("Your export is ready.");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

uiNotify (set of users)

Description:

MethodReturn valuesDescription

uiNotify(String msg, Set<String> users)

void

Sends an in-application UI notification to a specific set of users.

msg: The notification message text.

users: The set of usernames to notify.

Example:

package com.openkm;

import com.openkm.util.ContextWrapper;
import com.openkm.util.GeneralUtils;

import java.util.HashSet;
import java.util.Set;

public class Test {

    public static void main(String[] args) {
        try {
            GeneralUtils generalUtils = ContextWrapper.getContext().getBean(GeneralUtils.class);
            Set<String> recipients = new HashSet<>();
            recipients.add("jsmith");
            recipients.add("mjones");
            generalUtils.uiNotify("Scheduled maintenance in 10 minutes.", recipients);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

uiNotifyAll

Description:

MethodReturn valuesDescription

uiNotifyAll(String msg)

void

Sends an in-application UI notification to all active users in the current tenant.

msg: The notification message text.

Example:

package com.openkm;

import com.openkm.util.ContextWrapper;
import com.openkm.util.GeneralUtils;

public class Test {

    public static void main(String[] args) {
        try {
            GeneralUtils generalUtils = ContextWrapper.getContext().getBean(GeneralUtils.class);
            generalUtils.uiNotifyAll("System will restart in 5 minutes. Please save your work.");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}