Page 1 of 1

setting Lock during Document Create not working in script

PostPosted:Fri Nov 18, 2011 1:13 am
by ngovinda
I would like to set all documents to "Lock" setting when users upload a document.

So I created a script at the respective folder where I use the following lines:
Code: Select all
import javax.jcr.*;
import com.openkm.core.*;
import com.openkm.bean.*;
import com.openkm.module.base.*;
import com.openkm.bean.Document;


if (eventType.equals("CREATE_DOCUMENT")) {
        String token = JcrSessionManager.getInstance().getSystemToken();
        Session session = JcrSessionManager.getInstance().get(token);
        Node rootNode = session.getRootNode().getNode(Repository.ROOT);
        String docName = com.openkm.util.FileUtils.getName(eventNode.getPath());
       String parentDir = com.openkm.util.FileUtils.getParent(eventNode.getPath());
        Node myNode = session.getNode(parentDir + "/" + docName);
 
        Document doc = BaseDocumentModule.getProperties(session, myNode);
        doc.setLocked(true);
        myNode.setProperty(Document.NAME, "Name1.xls");

         String[] keywords = {"one", "two"};
         myNode.setProperty(Property.KEYWORDS, keywords);
        myNode.save();
        rootNode.save();
}

The Document Name change works and the Keywords work,

BUT the doc.setLocked(true); does not work.

Why is this? and How can I set Locked to true by default when uploading documents?

Thanks in advance - Govinda

Re: setting Lock during Document Create not working in scrip

PostPosted:Sun Nov 20, 2011 9:05 pm
by jllort
The problem is that you're changing a property of object document, that has no relevance. Really you should execute lock method ( I suggest take a look at DocumentServlet.java ), you must execute something like :
Code: Select all
OKMDocument.getInstance().lock(null, docPath);

Re: setting Lock during Document Create not working in scrip

PostPosted:Wed Nov 23, 2011 7:28 am
by ngovinda
Wonderful ! It worked very well.

Thanks

Govinda