Hi,
I am trying to run a script in OpenKM 6.3.0. But I am getting errors as below.
I am trying to run a script in OpenKM 6.3.0. But I am getting errors as below.
Code: Select all
The script as follows: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 ( )
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) {;}
}
}