cancel
Showing results for 
Search instead for 
Did you mean: 

revert content/versioning.

xerox
Champ in-the-making
Champ in-the-making
When there a several versions on the space, I want to make it possible to revert a previous version to be the default version.

I saw the versionservice
public void revert(NodeRef nodeRef, Version version);
So I made a link in documentdetails.jsp and linked an actionlistener documentdetailsbean.revert at it.
But I don't know what to programm in  public revert{}+
can someone help me?
9 REPLIES 9

xerox
Champ in-the-making
Champ in-the-making
So I made a link in document-details.jsp in the panel with version history.
So every version has the link

<a:column id="col6" style="text-align:left">
       <f:facet name="header">
              <hSmiley SurprisedutputText id="reverttekst" value="#{ourmsg.revert}" />
       </f:facet>
       <a:actionLink id="revertlink" value="Revert" ActionListener="#{DocumentDetailsBean.Revert}" >
        <fSmiley Tonguearam name="id" value="#{r.id}" />
              </a:actionLink>
</a:column>

I created the following code in the documentDetailBean


public void Revert(ActionEvent event)
   {
      UIActionLink link = (UIActionLink)event.getComponent();
      Map<String, String> params = link.getParameterMap();
      String id = params.get("id");
      NodeRef ref = new NodeRef(Repository.getStoreRef(), id);
    
     
       this.versionService.revert(ref);
      
     
   }

But now if I Click on such a link, it always gaves the following exception:
javax.faces.el.EvaluationException: Exception while invoking expression #{DocumentDetailsBean.Revert}

caused by:
org.alfresco.service.cmr.repository.InvalidNodeRefException: Node does not exist: workspace://SpacesStore/2c137b9f-bd92-11da-8af1-7f4265dd7452

Apparently, I don't ask the right nodereference or somethign like that.
Any comments?

xerox
Champ in-the-making
Champ in-the-making
I've changed this method

public void Revert(ActionEvent event)
   {
NodeRef ref = this.browseBean.getDocument().getNodeRef();
Version version = this.versionService.getCurrentVersion(ref);
     
     
     
this.versionService.revert(ref,version);
      
     
   }
But when I click on revert, is seems it doesn't do a thing.

xerox
Champ in-the-making
Champ in-the-making
I made a mistake
my public void revert shoud be

public void Revert(ActionEvent event)
   {UIActionLink link = (UIActionLink)event.getComponent();
Map<String, String> params = link.getParameterMap();
String id = params.get("id");

/*because I need the version store*/
NodeRef refold = new NodeRef(this.versionService.getVersionStoreReference(), id);

this.versionService.revert(refold);
}
But now it says, version is a mandatory parameter, it means in the object version in empty, how is this possible?

this.versionService.revert(refold) call the following service:
public void revert(NodeRef nodeRef)
    {
revert(nodeRef, getCurrentVersion(nodeRef), true);
}
So I really don't know why the object version is empty?

kevinr
Star Contributor
Star Contributor
Your StoreRef is incorrect for the NodeRef you are building. A repository has multiple stores, say for System, SpacesStore (the main one used by the web-client) and the Versioning Store. The previous versions of a document are stored in the Versioning Store.

So this line:
   NodeRef ref = new NodeRef(Repository.getStoreRef(), id); 

Should look something like this:
   NodeRef ref = new NodeRef(this.versionService.getVersionStoreReference(), id); 

Thanks,

Kevin

xerox
Champ in-the-making
Champ in-the-making
Yes I know, but this still doesn't work
check my previous reply.
it's really strange.

Nick

rwetherall
Confirmed Champ
Confirmed Champ
Hi Nick,

I think there may have been some confusion about how the revert method on the version service works so I'll try and clear things up a little.

The node reference passed to the method revert(NodeRef) should be a reference to the workspace node ref that you want to revert to a previously versioned state.  Not a reference directly to the versioned state in the VersionStore.

When this method is called the state of the node reference is reverted back to the state of the last version.  i.e. any changes made since the last version will be lost.

There are other overrides to this method which allow a specific version to be specified to which the node's state should be reverted.  In this case the Version object relating to the version should be passed along with the node reference.

Note that when a node is reverted to a particular version's state the version label of the node is not reverted also.  To revert a node simply means to revert the current node to a previously versioned state.  If a reverted node is later versioned the version history will carry on from the last version, branches are not created.

So if you want to revert a modified node back to its last versioned state then I would assume that your original code should work.  Why you where getting a problem with the node ref you where creating I am not sure.

Perhaps you could try looking in the node browser (found on the admin panel) to confirm that the node ref you are generating is indeed the node ref for the object you want.

Hope this helps to clear things up.  Let me know if you need any further assistance,

Cheers,
Roy

xerox
Champ in-the-making
Champ in-the-making
thx for your explanation, but I don't understand it whole.

I'll explain what I mean.

when you're viewing at  the details of a document, there's a version history panel with all the versions
Next to all those versions there a view link. Next to each view link I've placed a revert link..
e.g.
version1.0 view revert
version1.1 view revert
version1.2 view revert
version2.0 view revert.

Now when I clik on the revert link of version 1.1, this version should be the "Current version", so actually the newest version.

But my method isn't working.
any comment?

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

Ok,  this is becuase you may be expecting revert to be doing more than it is.

If, for exmaple, you have a node at version 1.3 and you ask it to be reverted to version 1.1 the state of the node will be reverted to its state as of 1.1 (ie: the property values and content) but the version label of the node will remain at 1.3.  If you then versioned the node again the reverted state would be commited to the version store and the version label would increment to version 1.4 .

Revert does not change the version label of the node, it simply modifes the state of the node to match a previous version.

Hope this helps,
Roy

xerox
Champ in-the-making
Champ in-the-making
thx, it helped…
Another question..
Can someone explain to me the difference of a deep and "not deep" revert?

Nick