Page 1 of 1

OKMNotification - notify

PostPosted:Fri May 24, 2013 2:53 pm
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");
}

Re: OKMNotification - notify

PostPosted:Sun May 26, 2013 4:47 pm
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/.

Re: OKMNotification - notify

PostPosted:Mon May 27, 2013 6:47 am
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");
}

Re: OKMNotification - notify

PostPosted:Tue May 28, 2013 6:07 pm
by pavila
The error message is quite verbose: Can't send notification because 'from' or 'to' is empty.