[ 
https://issues.apache.org/jira/browse/OAK-4911?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15562053#comment-15562053
 ] 

amin zamani commented on OAK-4911:
----------------------------------

Here some information of implementation of the method for updating the node - 
but as mentioned before, it is doing nothing different but is only called in a 
thread - it only writes an input stream of a file into the preview node in oak, 
nothing more and then returns deep inside of it some properties of the node :
void updateDocumentPreview(String originalDocumentId){
//Get inputstream  of the preview (preview file is in local directory of OS)
//Now save the preview file content into oak:
        //Call of content update method:
        updateDocumentContent(previewNodeIdToUpdate, InputStream);

}

And this is the implementation of the method with the input stream of the 
preview file:

 public Document updateDocumentContent(String documentId, InputStream 
fileContents) {
        try {
            Binary binary = 
jcrSession.getValueFactory().createBinary(fileContents);
            try {
                Node file = jcrSession.getNodeByIdentifier(documentId);
                Version updatedVersion = versionFile(file, binary);

                return toDocument(updatedVersion);
            } finally {
                binary.dispose();
            }
        } catch (Exception e) {
            throw new RuntimeItemNotFoundException(e);
        } 
    }


 => The exception is thrown in the method toDocument(updatedVersion)

First, This is the implementation of the "versionFile(file, binary)" method:

 private Version versionFile(Node file, Binary fileContent) {
        try {
            VersionManager versionManager = 
file.getSession().getWorkspace().getVersionManager();

            versionManager.checkout(file.getPath());
            
file.getNode(Property.JCR_CONTENT).setProperty(Property.JCR_LAST_MODIFIED, 
Calendar.getInstance());
            
file.getNode(Property.JCR_CONTENT).setProperty(Property.JCR_LAST_MODIFIED_BY, 
SecurityUtil.getCurrentUserLogin());
            file.getNode(Property.JCR_CONTENT).setProperty(Property.JCR_DATA, 
fileContent);

            jcrSession.save();
            Version version = versionManager.checkin(file.getPath());

            
versionManager.getVersionHistory(file.getPath()).addVersionLabel(version.getName(),
 NOAH_LAST_VERSION_LABEL, DO_MOVE_LABEL);

            return version;
        } catch (RepositoryException e) {
            throw new RuntimeRepositoryException(e);
        }
    }

    



> Can not read node Property in a Thread (Java)
> ---------------------------------------------
>
>                 Key: OAK-4911
>                 URL: https://issues.apache.org/jira/browse/OAK-4911
>             Project: Jackrabbit Oak
>          Issue Type: Bug
>    Affects Versions: 1.3.10
>         Environment: MAC OS X
>            Reporter: amin zamani
>
> Hallo,
> we develop an application and everything is working as it should. We upload 
> documents and for each document a new preview file (node) should be 
> generated. It works well when we execute the code synchron. But because of 
> the fact that the generation of a preview file (like PDF format) can take 
> very long time we decided to move the preview generation code into a usual 
> java thread so that after the user is upload a document the website is 
> responding very quick and does not wait till the preview file is generated 
> but the preview file is generated parallel. 
> No the problem: As soon as I move the same code regarding to the preview file 
> generation into a usual thread (no modifications to the logic, only a thread 
> is bordered to it) suddenly the node path does not exist, this is the error:
> -----------------
> Caused by: javax.jcr.PathNotFoundException: jcr:lastModifiedBy not found on 
> /jcr:system/jcr:versionStorage/7e/f8/5b/7ef85b25-4598-4476-82df-446eb3a08a90/1.0/jcr:frozenNode/jcr:content
>       at 
> org.apache.jackrabbit.oak.jcr.session.NodeImpl$11.perform(NodeImpl.java:631)
>       at 
> org.apache.jackrabbit.oak.jcr.session.NodeImpl$11.perform(NodeImpl.java:625)
>       at 
> org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.perform(SessionDelegate.java:207)
>       at 
> org.apache.jackrabbit.oak.jcr.session.ItemImpl.perform(ItemImpl.java:112)
>       at 
> org.apache.jackrabbit.oak.jcr.session.NodeImpl.getProperty(NodeImpl.java:625)
>       at 
> com.westernacher.noah.util.content_repository.JcrUtil.getStringProperty(JcrUtil.java:35)
> ---------------------------
> In my point of view this is a bug. This is the code that works:
> Example:
> /// 1) User Upload document through browser in our web app..
> // 2) ... document uploaded and saved in OAK CR
> // 3) Now generate the preview:
> updateDocumentPreview(documentId);
> --------------------------------
> Now the same in a thread that does not work:
> => I have only moved the method "updateDocumentPreview(documentId);" in a 
> Thread (Java 8):
> //Same code as before except the last line replaced by following lines:
> Runnable run = ()-> {updateDocumentPreview(documentId);}
> new Thread(run).start(); //Start the thread to generate a document preview
> --------------------------



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to