Re: Using Beanshell to move Mails
PostPosted:Tue Nov 22, 2011 3:07 pm
Because information matters
https://forum.openkm.com/
import com.openkm.module.direct.*;
...
DirectDocumentModule.move(token, Document.getPath(), okmroot.getPath() + "/Manuals/");
...
Sourced file: inline evaluation of: ``import javax.jcr.*; import com.openkm.core.*; import com.openkm.bean.*; import c . . . '' : Error in method invocation: Static method move( java.lang.String, java.lang.String, java.lang.String ) not found in class'com.openkm.module.direct.DirectDocumentModule' : at Line: 28 : in file: inline evaluation of: ``import javax.jcr.*; import com.openkm.core.*; import com.openkm.bean.*; import c . . . '' : DirectDocumentModule .move ( token , Document .getPath ( ) , okmroot .getPath ( ) + "/Manuals/" )I guess static is the problem. But even if I remove the " + "/Manuals/" " (the only static thing in the parameter), it still gives me the same error message...
import javax.jcr.*;
import com.openkm.core.*;
import com.openkm.bean.*;
import com.openkm.module.*;
import com.openkm.module.direct.*;
import com.openkm.api.*;
String token = JcrSessionManager.getInstance().getSystemToken();
Session session = JcrSessionManager.getInstance().get(token);
Node okmmail = session.getRootNode().getNode(Repository.MAIL);
Node okmroot = session.getRootNode().getNode(Repository.ROOT);
DirectDocumentModule.move(token, "/okm:mail/Docs", okmroot.getPath() + "/Anleitungen/");
public void move(String token, String docPath, String dstPath) throws PathNotFoundException,
ItemExistsException, AccessDeniedException, RepositoryException, DatabaseException,
ExtensionException {
new DirectDocumentModule().move( token, docPath, dstPath)
import javax.jcr.*;
import java.lang.String;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import com.openkm.core.*;
import com.openkm.bean.*;
import com.openkm.module.*;
import com.openkm.module.direct.*;
import com.openkm.api.*;
String token = JcrSessionManager.getInstance().getSystemToken();
Session session = JcrSessionManager.getInstance().get(token);
Node okmmail = session.getRootNode().getNode(Repository.MAIL);
Node okmroot = session.getRootNode().getNode(Repository.ROOT);
String DirectoryPath;
String DocumentName;
String DocumentDate;
Boolean DateOk;
DateFormat dateFormat;
Date date;
Boolean done = false;
for (NodeIterator it = okmmail.getNodes(); it.hasNext(); ) {
Node userMailFolder = it.nextNode();
if(userMailFolder.getPath().equals("/okm:mail/Docs") ) {
//Check the mails in the doc Folder
for (NodeIterator itut = userMailFolder.getNodes(); itut.hasNext(); ) {
//aktuelles Mail aufbereiten
Node mail = itut.nextNode();
Mail actMail = OKMMail.getInstance().getProperties(null, mail.getPath());
List attach = actMail.getAttachments();
//get the subject from the mail
String mailSubject = actMail.getSubject();
//get the keyword from the subject
String Keyword = mailSubject.replaceAll(" ", "");
Keyword = Keyword.replaceAll("[0-9-,.]", "");
Keyword = Keyword.toLowerCase();
//Path to the right TaxDirectory and Document name
if(Keyword.equals("pro")){
DirectoryPath = "/Calculations/";
DocumentName = "Prodega";
}
else if(Keyword.equals("oth")){
DirectoryPath = "/Others/";
DocumentName = "Prodega";
}
//check if date is typed in. Else date is today
if(mailSubject.matches(".*[0-9-].*")){
DateOk = true;
//create string just with the date
DocumentDate = mailSubject.replaceAll(" ", "");
DocumentDate = DocumentDate.replaceAll("[aA-zZ,+-]", "");
DocumentName = DocumentName + " " + DocumentDate;
}else{
DateOk = false;
//get ready for date today
dateFormat = new SimpleDateFormat("yyyyMMdd");
date = new Date();
}
//Move the attachments to the right TaxDirectory and rename it
for(Document:attach){
new DirectDocumentModule().copy(token, Document.getPath(), okmroot.getPath() + DirectoryPath);
if(DateOk == true){
new DirectDocumentModule().rename(token, okmroot.getPath() + DirectoryPath + "Untitled .pdf", DocumentName);
done = true;
}else{
new DirectDocumentModule().rename(token, okmroot.getPath() + DirectoryPath + "Untitled .pdf", DocumentName +" "+ dateFormat.format(date));
done = true;
}
}
//Delete mail, if attachment movement is successful.
if(done == true){
new DirectDocumentModule().delete(token, actMail.getPath());
print("Verschieben nach " + DirectoryPath +" erfolgreich. Mail wurde gelöscht");
}
session.save();
}
userMailFolder.save();
}
}
Sourced file: inline evaluation of: ``import javax.jcr.*; import java.lang.String; import java.text.DateFormat; import . . . '' : Typed variable declaration : target exception : at Line: 34 : in file: inline evaluation of: ``import javax.jcr.*; import java.lang.String; import java.text.DateFormat; import . . . '' : .getProperties ( null , mail .getPath ( ) ) Target exception: com.openkm.core.RepositoryException: CallbackHandler does not support: javax.security.auth.callback.NameCallback@1e311e31: CallbackHandler does not support: javax.security.auth.callback.NameCallback@1e311e31Can anyone give me a hint how to handle this problem? Is there a problem with the security?
String sysToken = JcrSessionManager.getInstance().getSystemToken()
...
import com.openkm.api.*;
String token = JcrSessionManager.getInstance().getSystemToken();
Session session = JcrSessionManager.getInstance().get(token);
...
Session session = JcrSessionManager.getInstance().getSystemSession();
Mail actMail = OKMMail.getInstance().getProperties(null, mail.getPath());
Node mail = itut.nextNode();
Target exception: com.openkm.core.RepositoryException: CallbackHandler does not support: javax.security.auth.callback.NameCallback@68086808: CallbackHandler does not support: javax.security.auth.callback.NameCallback@68086808Is there a special import needed?
DocumentModule.getInstace().move(XXXX
new DirectDocumentModule().copy(XXXX
DirectDocumentModule().getInstance().copy(XXXX
Mail actMail = OKMMail.getInstance().getProperties(null, mail.getPath());