Programmatically retrieve all versions of a document from jcr-runner

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Programmatically retrieve all versions of a document from jcr-runner

sharath
This post was updated on .
Hello,

I want to programmatically retrieve all versions of a document from JCR runner, here is my first stab:

<code>

@Override
    public void visit(Node node) {
        try {
            ClientServicingXASession session = (ClientServicingXASession) node.getSession();
            Workspace ws = session.getWorkspace();
            VersionHistory vh = ws.getVersionManager().getVersionHistory(node.getPath());
            VersionIterator vi = vh.getAllVersions();
            while (vi.hasNext()) {
                Version version = vi.nextVersion();
                NodeIterator ni = version.getNodes();
                while (ni.hasNext()) {                    
                     Node currentNode = ni.nextNode();
                     // how do i retrieve the version of document from currentNode?

                }
            }
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
    }

</code>

Given the code above, looks like currentNode refers to a frozen version node, how can i retrieve the corresponding document from currentNode?

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Programmatically retrieve all versions of a document from jcr-runner

marijan milicevic
Hi Sharath,
On 01/15/2013 10:14 PM, sharath wrote:
Hello,

I want to programmatically retrieve all "versioned node" corresponding to a
document from JCR runner, here is my first stab:

<code>

@Override
    public void visit(Node node) {
        try {
            ClientServicingXASession session = (ClientServicingXASession)
node.getSession();
            Workspace ws = session.getWorkspace();
            VersionHistory vh =
ws.getVersionManager().getVersionHistory(node.getPath());
            VersionIterator vi = vh.getAllVersions();
            while (vi.hasNext()) {
                Version version = vi.nextVersion();
                NodeIterator ni = version.getNodes();
                while (ni.hasNext()) {                    
                     Node currentNode = ni.nextNode();
                     // how do i retrieve the version of document from
currentNode?

                }
            }
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
    }

</code>

Given the code above, looks like currentNode refers to a frozen version
node, how can i retrieve the corresponding document from currentNode?

this may help:

http://svn.onehippo.org/repos/hippo/hippo-cms7/tools/versions-cleaner/trunk/src/main/java/org/onehippo/forge/jcrrunner/plugins/versions/HippoVersionsDeleteRunner.java


cheers
marijan



Thanks




--
View this message in context: http://hippo.2275632.n2.nabble.com/Programmatically-retrieve-all-versions-of-a-document-from-jcr-runner-tp7580188.html
Sent from the Hippo CMS 7 mailing list archive at Nabble.com.
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html


-- 
best regards,
marijan milicevic
 
| || ||| || onehippo.com, amsterdam
Oosteinde 11
1017 WT Amsterdam
+31 (0) 20 522 4466 /T

_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html
Reply | Threaded
Open this post in threaded view
|

Re: Programmatically retrieve all versions of a document from jcr-runner

sharath
Hello marijan,

thanks for the information.

- sharath
Reply | Threaded
Open this post in threaded view
|

Re: Programmatically retrieve all versions of a document from jcr-runner

sharath
In reply to this post by marijan milicevic
Hello marijan,

I looked at the HippoVersionsDeleteRunner, the information was insightful, however I was unable to figure out how a  node (corresponding to a document) can be retrieved from a corresponding Version object.  

Is there a way to retrieve the node representation from Version object?

Thanks,
Reply | Threaded
Open this post in threaded view
|

Re: Programmatically retrieve all versions of a document from jcr-runner

sharath
In reply to this post by marijan milicevic
Hello Marijan,

Could you please provide some insight?

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Programmatically retrieve all versions of a document from jcr-runner

Frank van Lankvelt
In reply to this post by sharath
a Version is a Node, so you can just use JCR on it.

cheers, Frank

On Wed, Jan 16, 2013 at 4:58 PM, sharath <[hidden email]> wrote:

> Hello marijan,
>
> I looked at the HippoVersionsDeleteRunner, the information was insightful,
> however I was unable to figure out how a  node (corresponding to a document)
> can be retrieved from a corresponding Version object.
>
> Is there a way to retrieve the node representation from Version object?
>
> Thanks,
>
>
>
> --
> View this message in context: http://hippo.2275632.n2.nabble.com/Programmatically-retrieve-all-versions-of-a-document-from-jcr-runner-tp7580188p7580196.html
> Sent from the Hippo CMS 7 mailing list archive at Nabble.com.
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/forums.html



--
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
Boston - 1 Broadway, Cambridge, MA 02142

US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
www.onehippo.com
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html
Reply | Threaded
Open this post in threaded view
|

Re: Programmatically retrieve all versions of a document from jcr-runner

marijan milicevic
In reply to this post by sharath
Hi Sharath
On 01/17/2013 10:07 PM, sharath wrote:
> Hello Marijan,
>
> Could you please provide some insight?


If you are using  above  mentioned code version.getParent().getName()
will return you handle uuid.

cheers
marijan

> Thanks
>
>
>
> --
> View this message in context: http://hippo.2275632.n2.nabble.com/Programmatically-retrieve-all-versions-of-a-document-from-jcr-runner-tp7580188p7580211.html
> Sent from the Hippo CMS 7 mailing list archive at Nabble.com.
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/forums.html


--
best regards,
marijan milicevic
 
| || ||| || onehippo.com, amsterdam
Oosteinde 11
1017 WT Amsterdam
+31 (0) 20 522 4466 /T

_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html
Reply | Threaded
Open this post in threaded view
|

Re: Programmatically retrieve all versions of a document from jcr-runner

Minos Chatzidakis-2
This may also help:

http://svn.onehippo.org/viewvc/hippo-cms7/repository/trunk/engine/src/main/java/org/hippoecm/repository/standardworkflow/VersionWorkflowImpl.java

I'm not sure this code is still in use however, or some things are getting deprecated. But I guess it can provided some more insight.
By the way, the questions you're asking us could very well be targeted to jackrabbits' mailing lists. Or any implementer of the JCR 2 api.

Minos

--


On Fri, Jan 18, 2013 at 10:45 AM, marijan milicevic <[hidden email]> wrote:
Hi Sharath

On 01/17/2013 10:07 PM, sharath wrote:
Hello Marijan,

Could you please provide some insight?


If you are using  above  mentioned code version.getParent().getName() will return you handle uuid.

cheers
marijan


Thanks



--
View this message in context: http://hippo.2275632.n2.nabble.com/Programmatically-retrieve-all-versions-of-a-document-from-jcr-runner-tp7580188p7580211.html
Sent from the Hippo CMS 7 mailing list archive at Nabble.com.
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html


--
best regards,
marijan milicevic
 | || ||| || onehippo.com, amsterdam
Oosteinde 11
1017 WT Amsterdam
<a href="tel:%2B31%20%280%29%2020%20522%204466" value="+31205224466" target="_blank">+31 (0) 20 522 4466 /T

_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html



--
With kind regards/Met vriendelijke groet,
Minos Chatzidakis

Amsterdam - Oosteinde 11, 1017 WT Amsterdam
Boston - 1 Broadway, Cambridge, MA 02142

US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
www.onehippo.com

_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html
Reply | Threaded
Open this post in threaded view
|

Re: Programmatically retrieve all versions of a document from jcr-runner

Frank van Lankvelt
On Fri, Jan 18, 2013 at 10:56 AM, Minos Chatzidakis
<[hidden email]> wrote:
> This may also help:
>
> http://svn.onehippo.org/viewvc/hippo-cms7/repository/trunk/engine/src/main/java/org/hippoecm/repository/standardworkflow/VersionWorkflowImpl.java
>
> I'm not sure this code is still in use however, or some things are getting
> deprecated. But I guess it can provided some more insight.

it is still in use.  When a document is published, or taken offline, a
new version is created with this workflow.
(there are many more version histories initiated though; each edit
cycle will create a versionable variant, implicitly also creating a
version history)

Since the handle and the document are both versionable, traversing the
version history is not trivial.  The jcr runner, the cms version
history dialog and the version workflow should all have some variant
of the algorithm.

cheers, Frank

> By the way, the questions you're asking us could very well be targeted to
> jackrabbits' mailing lists. Or any implementer of the JCR 2 api.
>
> Minos
>
> --
>
>
> On Fri, Jan 18, 2013 at 10:45 AM, marijan milicevic
> <[hidden email]> wrote:
>>
>> Hi Sharath
>>
>> On 01/17/2013 10:07 PM, sharath wrote:
>>>
>>> Hello Marijan,
>>>
>>> Could you please provide some insight?
>>
>>
>>
>> If you are using  above  mentioned code version.getParent().getName() will
>> return you handle uuid.
>>
>> cheers
>> marijan
>>
>>
>>> Thanks
>>>
>>>
>>>
>>> --
>>> View this message in context:
>>> http://hippo.2275632.n2.nabble.com/Programmatically-retrieve-all-versions-of-a-document-from-jcr-runner-tp7580188p7580211.html
>>> Sent from the Hippo CMS 7 mailing list archive at Nabble.com.
>>> _______________________________________________
>>> Hippo-cms7-user mailing list and forums
>>> http://www.onehippo.org/cms7/support/forums.html
>>
>>
>>
>> --
>> best regards,
>> marijan milicevic
>>  | || ||| || onehippo.com, amsterdam
>> Oosteinde 11
>> 1017 WT Amsterdam
>> +31 (0) 20 522 4466 /T
>>
>> _______________________________________________
>> Hippo-cms7-user mailing list and forums
>> http://www.onehippo.org/cms7/support/forums.html
>
>
>
>
> --
> With kind regards/Met vriendelijke groet,
> Minos Chatzidakis
>
> Amsterdam - Oosteinde 11, 1017 WT Amsterdam
> Boston - 1 Broadway, Cambridge, MA 02142
>
> US +1 877 414 4776 (toll free)
> Europe +31(0)20 522 4466
> www.onehippo.com
>
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/forums.html



--
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
Boston - 1 Broadway, Cambridge, MA 02142

US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
www.onehippo.com
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html
Reply | Threaded
Open this post in threaded view
|

Re: Programmatically retrieve all versions of a document from jcr-runner

sharath
This post was updated on .
Thanks all for your responses.

Actually, I am able to get to a point where I get access to "nt:frozenNode" via "nt:versionedChild" node and see properties of the document.  

However, I am unable to convert the "nt:frozenNode" node to the content-type of the original node.  

(As Minos and Frank suggested) I looked up in VersionWorkflowImpl, HistoryView and related artifacts but still cannot figure out how to do the conversion.  

One alternative I could think of is restore the "nt:frozenNode" to a temporary location(node) and delete the temporary node once done with the retrieving the information from the restored node.  Is there another way to retrieve the "old" node without restoring to a temporary location?

Thanks,
Reply | Threaded
Open this post in threaded view
|

Re: Programmatically retrieve all versions of a document from jcr-runner

Frank van Lankvelt
On Fri, Jan 18, 2013 at 5:34 PM, sharath <[hidden email]> wrote:

> Thanks all for your responses.
>
> Actually, I am able to get to a point where I get access to "nt:frozenNode"
> via "nt:versionedChild" node and see properties of the document.
>
> However, I am unable to convert the "nt:frozenNode" node to the content-type
> the actual node.
>
> (As Minos and Frank suggested) I looked up in VersionWorkflowImpl,
> HistoryView and related artifacts but still cannot figure out how to do the
> conversion.
>
> One alternative I could think of is restore the "nt:frozenNode" to a
> temporary location(node) and delete the temporary node once done with the
> retrieving the information from the restored node.  Is there another way to
> retrieve the "old" node without restoring to a temporary location?
>
once you've found the correct version, you can just read it's
properties.  The primaryType will indeed be nt:frozenNode, but it will
have all the properties of the versioned node.
Some JCR defined properties are stored under different names, e.g. the
original primary type is stored in the jcr:frozenPrimaryType.

Why do you want to restore the version to a temporary location?
To be able to do some mapping based on primary type?  If that's the
case, it's probably easier to make the mapping a bit more flexible, so
that it looks for the jcr:frozenPrimaryType when necessary.

cheers, Frank

> Thanks,
>
>
>
> --
> View this message in context: http://hippo.2275632.n2.nabble.com/Programmatically-retrieve-all-versions-of-a-document-from-jcr-runner-tp7580188p7580233.html
> Sent from the Hippo CMS 7 mailing list archive at Nabble.com.
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/forums.html



--
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
Boston - 1 Broadway, Cambridge, MA 02142

US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
www.onehippo.com
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html
Reply | Threaded
Open this post in threaded view
|

Re: Programmatically retrieve all versions of a document from jcr-runner

Jeroen Reijn
Administrator
If you want to get it as a Bean then you could annotate a bean with
"nt:frozenNode". It wil not be specific probably with your specific
document type, but it might help you using in it in a REST service of
HST component.

On Sun, Jan 20, 2013 at 12:20 PM, Frank van Lankvelt
<[hidden email]> wrote:

> On Fri, Jan 18, 2013 at 5:34 PM, sharath <[hidden email]> wrote:
>> Thanks all for your responses.
>>
>> Actually, I am able to get to a point where I get access to "nt:frozenNode"
>> via "nt:versionedChild" node and see properties of the document.
>>
>> However, I am unable to convert the "nt:frozenNode" node to the content-type
>> the actual node.
>>
>> (As Minos and Frank suggested) I looked up in VersionWorkflowImpl,
>> HistoryView and related artifacts but still cannot figure out how to do the
>> conversion.
>>
>> One alternative I could think of is restore the "nt:frozenNode" to a
>> temporary location(node) and delete the temporary node once done with the
>> retrieving the information from the restored node.  Is there another way to
>> retrieve the "old" node without restoring to a temporary location?
>>
> once you've found the correct version, you can just read it's
> properties.  The primaryType will indeed be nt:frozenNode, but it will
> have all the properties of the versioned node.
> Some JCR defined properties are stored under different names, e.g. the
> original primary type is stored in the jcr:frozenPrimaryType.
>
> Why do you want to restore the version to a temporary location?
> To be able to do some mapping based on primary type?  If that's the
> case, it's probably easier to make the mapping a bit more flexible, so
> that it looks for the jcr:frozenPrimaryType when necessary.
>
> cheers, Frank
>
>> Thanks,
>>
>>
>>
>> --
>> View this message in context: http://hippo.2275632.n2.nabble.com/Programmatically-retrieve-all-versions-of-a-document-from-jcr-runner-tp7580188p7580233.html
>> Sent from the Hippo CMS 7 mailing list archive at Nabble.com.
>> _______________________________________________
>> Hippo-cms7-user mailing list and forums
>> http://www.onehippo.org/cms7/support/forums.html
>
>
>
> --
> Amsterdam - Oosteinde 11, 1017 WT Amsterdam
> Boston - 1 Broadway, Cambridge, MA 02142
>
> US +1 877 414 4776 (toll free)
> Europe +31(0)20 522 4466
> www.onehippo.com
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/forums.html



--
Jeroen Reijn
Solution Architect
Hippo

Amsterdam - Oosteinde 11, 1017 WT Amsterdam
Boston - 1 Broadway, Cambridge, MA 02142

US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
www.onehippo.com

http://about.me/jeroenreijn
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html
Reply | Threaded
Open this post in threaded view
|

Re: Programmatically retrieve all versions of a document from jcr-runner

sharath
Hello Jeroen & Frank,

Thanks for the information.  For my use-case, I want to export the XML representation of the versioned documents,  So, one way to accomplish that is to first convert the "nt:frozenNode" to an equivalent document type node and then export the resulting node as XML.  Could you let me know if there any alternatives? (Use XSLT on the xml representation of the nt:frozenNode etc..)

Thanks,
Sharath