• OKMNotification - notify

  • We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
Forum rules: Please, before asking something see the documentation wiki or use the search feature of the forum. And remember we don't have a crystal ball or mental readers, so if you post about an issue tell us which OpenKM are you using and also the browser and operating system version. For more info read How to Report Bugs Effectively.
 #23184  by Rudolf21
 
Hey there,

I'm having some trouble using the OKMNotification class in a script with the API.

Can somebody please give me an example of how to use the "notify" function correctly or tell me where I got my script wrong?

I especially got problems with the definition of "List<String> users":

If I try to set the users variable like so: "List<String> = {"okmAdmin"};" I get a Pars error: "Parse error at line XX, column YY. Encountered: ="

If I try to convert the variable from a simple String Array ("String[] users = {"okmAdmin"};") to a "List<String>" like so: "new List<String>(Arrays.asList(users))" I again get a Pars error: "Parse error at line XX, column YY. Encountered: <"

I've also tried converting it from a simple String Array ("String[] users = {"okmAdmin"};") to some similar Java data types which haven't worked either:

Converting the variable to a Array List with the String template like so: "new ArrayList<String>(Arrays.asList(users))" I again get a Pars error: "Parse error at line XX, column YY. Encountered: <"

If I try to convert the users variable to a ArrayList like so: "Arrays.asList(users)" I get a weird error: "Error: com.openkm.principal.PrincipalAdapterException: Can't send notification because 'from' or 'to' is empty"

I have following script:
Code: Select all
import com.openkm.api.*;
import com.openkm.bean.*;
import com.openkm.dao.*;
import com.openkm.module.db.stuff.*;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import com.openkm.module.jcr.stuff.*;

try{
    String token =  DbSessionManager.getInstance().getSystemToken();
    String nodePath = "";
    List<String> users = {"okmAdmin"};    
    String msg = "A Notification";
    boolean attachment = false;
    
    OKMNotification.getInstance().notify(token, nodePath, users, msg, attachment);
} catch(Exception e) {
    UserActivity.log("okmAdmin", "TCC_NOTIFICATION", null, null, "ERROR: " + e);
    print("-> Error: " + e + "\n");
}
 #23218  by jllort
 
When you're executing scring you're not in java sun, you're in bean shell scripting and is not 100% pure java. Initialize array in a more normal way:
Code: Select all
List array = new ArrayList();
arrray.add("some string");
Generics are not allowed in bean shell scripting. For more information about what you got in your hands take a look at http://www.beanshell.org/.
 #23226  by Rudolf21
 
Sorry, forgot to mention that: I'm using OpenKM v6.2.3 on a Linux (Kernel 3.0) SLES 11 SP2 x86_64

Thanks a lot, this got me rid of the "Pars Error"!

But I still can't send any notifications:
Code: Select all
Error: com.openkm.principal.PrincipalAdapterException: Can't send notification because 'from' or 'to' is empty 
My Script (changed the "users" definition):
Code: Select all
import com.openkm.api.*;
import com.openkm.bean.*;
import com.openkm.dao.*;
import com.openkm.util.*;
import com.openkm.module.db.stuff.*;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import com.openkm.module.jcr.stuff.*;

try{
    String token =  DbSessionManager.getInstance().getSystemToken();
    print("-> Token: " + token + "\n");
    String nodePath = "";
    List users = new ArrayList();
    users.add("okmAdmin");
    String msg = "A Notification";
    boolean attachment = false;
    
    OKMNotification.getInstance().notify(token, nodePath, users, msg, attachment);
} catch(Exception e) {
    UserActivity.log("okmAdmin", "TCC_NOTIFICATION", null, null, "ERROR: " + e);
    print("-> Error: " + e + "\n");
}
 #23240  by pavila
 
The error message is quite verbose: Can't send notification because 'from' or 'to' is empty.

About Us

OpenKM is part of the management software. A management software is a program that facilitates the accomplishment of administrative tasks. OpenKM is a document management system that allows you to manage business content and workflow in a more efficient way. Document managers guarantee data protection by establishing information security for business content.