Page 1 of 1

Inline evaluation error in OpenKM 6.3.0 script

PostPosted:Tue Jul 07, 2015 12:33 pm
by hariharan.gopal
Hi,

I am trying to run a script in OpenKM 6.3.0. But I am getting errors as below.
Code: Select all
Sourced file: inline evaluation of: ``import javax.jcr.*; import com.openkm.core.*; import com.openkm.bean.*; impor . . . '' : Typed variable declaration : Attempt to resolve method: getUserID() on undefined variable or class name: session : at Line: 6 : in file: inline evaluation of: ``import javax.jcr.*; import com.openkm.core.*; import com.openkm.bean.*; impor . . . '' : session .getUserID ( )
The script as follows:
Code: Select all
import javax.jcr.*;
import com.openkm.core.*;
import com.openkm.bean.*;
import com.openkm.api.OKMDocument;

String userID = session.getUserID();
if (userID.equals("okmAdmin"))
    return;                     // RRRRRRRRRRRRRRRRRRRRRRReturn

String startPrefix = "2012AP";
int lengthOfPrefix = startPrefix.length(); 
int lengthOfDocPrefix = 10; // 2012APnnnn

String parentDir = com.openkm.util.FileUtils.getParent(eventNode.getPath());
if ( (parentDir.indexOf ("Native Format Documents") >= 0) || (parentDir.indexOf ("Invoices") >= 0) || (parentDir.indexOf ("Source") >= 0) || (parentDir.indexOf ("Former Numbering") >= 0) || (parentDir.indexOf ("References") >= 0) || (parentDir.indexOf ("Obselete Documents") >= 0)  ){
//    String shellCmd = "sh /home/abcd/debug.sh" + " = Special Directory " + parentDir;
//    java.lang.Process p = java.lang.Runtime.getRuntime().exec(shellCmd);
    return;                     // RRRRRRRRRRRRRRRRRRRRRRReturn
}

String parentName = parentDir.substring(10); // length of /okm:root/
String docName = com.openkm.util.FileUtils.getName(eventNode.getPath());

String parentFolderName = com.openkm.util.FileUtils.getName(parentDir);
String parentStartPrefix = parentFolderName;
if (parentFolderName.length() > lengthOfPrefix){
    parentStartPrefix = parentFolderName.substring(0,lengthOfPrefix);
}

String docNamePrefix = docName;
String parentFolderPrefix = parentFolderName;

if ((docName.length() > lengthOfDocPrefix) && (parentFolderName.length() > lengthOfDocPrefix)) {
    docNamePrefix = docName.substring(0,lengthOfDocPrefix);
    parentFolderPrefix = parentFolderName.substring(0, lengthOfDocPrefix);
}

if (eventType.equals("CREATE_FOLDER")) {
   // Prevent creation of a new document directory within another docuemnt directory
    if (parentStartPrefix.equals(startPrefix)){
        String token = JcrSessionManager.getInstance().getSystemToken();
        Session session = JcrSessionManager.getInstance().get(token);
        Node rootNode = session.getRootNode().getNode(Repository.ROOT);
    
        Node myNode = session.getNode(parentDir + "/" + docName);
        myNode.remove();
        rootNode.save();
        return;              // RRRRRRRRRRRRRRRRRRRRRRReturn
    }
    
    String userID = session.getUserID();
    String parentStr = parentName.replace(' ', '_');
    String docStr = docName.replace(' ', '_');
    String shellCmd = "sh /home/abcd/APnextDoc.sh" + " " + userID + " " + parentStr + " " + docStr;
    String docNumber;
    java.lang.Process p = java.lang.Runtime.getRuntime().exec(shellCmd);
    BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
    docNumber = stdInput.readLine();
    
    // Checlk if a new document number has been created in the XXnextdoc.sh script on the server
    if (docNumber.length() < 0){
        String token = JcrSessionManager.getInstance().getSystemToken();
        Session session = JcrSessionManager.getInstance().get(token);
        Node rootNode = session.getRootNode().getNode(Repository.ROOT);
        Node myNode = session.getNode(parentDir + "/" + docName);
        myNode.remove();
        rootNode.save();
    } else {
        session.move(eventNode.getPath(), parentDir + "/" +  docNumber + " " + docName);
        session.save();
    }
}

if (eventType.equals("CREATE_DOCUMENT")) {
    String token = JcrSessionManager.getInstance().getSystemToken();
    Session session = JcrSessionManager.getInstance().get(token);
    Node rootNode = session.getRootNode().getNode(Repository.ROOT);
    Node myNode = session.getNode(parentDir + "/" + docName);
    if (( parentFolderPrefix.length() < lengthOfDocPrefix) || (docNamePrefix.length()  < lengthOfDocPrefix) || !(parentFolderPrefix.equals(docNamePrefix))){
        myNode.remove();
        rootNode.save();
    } else if ( (parentDir.indexOf ("Decisions List") >= 0) || (parentDir.indexOf ("Follow Up Items") >= 0)  ) {
       return;
    } else {
       try { OKMDocument.getInstance().lock(null, myNode.getPath()); } 
       catch (Exception Ex) {;}
    }
}

Re: Inline evaluation error in OpenKM 6.3.0 script

PostPosted:Thu Jul 09, 2015 6:35 am
by jllort
First of all, create an script step by step.

Into the scripting are injected these variables:
systemToken
node
uuid
userId

You can see there's no session var, that was injected on older openkm version but not on 6.3.X, that's the reason why you get this error. You can use directly the var userId
print(userId);

Also I see eventNode varible, I suspect the same, you will get error on this line.

Sorry, because our actual documentation it's a big messi, we know and we're working these month ( july and august ) to finish rebuilding a new one. Our expectation is at the end of august have it.

Re: Inline evaluation error in OpenKM 6.3.0 script

PostPosted:Thu Jul 09, 2015 12:57 pm
by hariharan.gopal
Hi,

I tried as below, but got the following errors.

Error Message:
Code: Select all
Sourced file: inline evaluation of: ``import javax.jcr.*; import com.openkm.core.*; import com.openkm.bean.*; impor . . . '' : Undefined argument: userId : at Line: 6 : in file: inline evaluation of: ``import javax.jcr.*; import com.openkm.core.*; import com.openkm.bean.*; impor . . . '' : ( userId )
Script:
Code: Select all
import javax.jcr.*;
import com.openkm.core.*;
import com.openkm.bean.*;
import com.openkm.api.OKMDocument;

print(userId);

Re: Inline evaluation error in OpenKM 6.3.0 script

PostPosted:Mon Jul 13, 2015 10:15 am
by jllort
userId is only embedded from automation view, not from scripting one. Did you executed from scripting view ?

Re: Inline evaluation error in OpenKM 6.3.0 script

PostPosted:Mon Jul 13, 2015 11:23 am
by hariharan.gopal
Yes, I executed from scripting view. How should I execute in automated view.

Re: Inline evaluation error in OpenKM 6.3.0 script

PostPosted:Thu Jul 16, 2015 3:57 pm
by jllort
At automation view only can be executed when is fired by some event.