AnsweredAssumed Answered

get content for older versions [solved]

Question asked by thierensbart on Oct 15, 2009
Latest reply on Oct 15, 2009 by thierensbart
i found an example/solution on this forums on how to download content from older versions but it throws exceptions in my face.

the suggested solution:

1. create a versionStore
private static Store _versionStore = new Store("versionStore", "lightWeightVersionStore");

2. follow this code
VersionHistory versionHistory =  WebServiceFactory.getAuthoringService().getVersionHistory(ReferenceFactory.newReference(uuid, nodePath));
Version[] versions = versionHistory.getVersions();
  for(Version nodeVersion : versions) {
    if(nodeVersion.getLabel().equals(version)) {
        InputStream result = null;
    Reference reference = new Reference(versionStore, nodeVersion.getId().getUuid(), nodeVersion.getId().getPath());
    Predicate predicate = new Predicate(new Reference[] { reference }, versionStore, null);
    Content[] contents = WebServiceFactory.getContentService().read(predicate, Constants.TYPE_CONTENT);
    result = ContentUtils.getContentAsInputStream(contents[0]);
    return result;
  }
}

How i did it:
1. made the version store and created a getter-method
private static Store _versionStore = new Store("versionStore", "lightWeightVersionStore");

private static Store getVersionStore(){
   return _versionStore;
}

2.  wrote this code (based on the example but slightly different
//i didn't use the ReferenceFactory, but created my own reference to the document (document = the one from which i want all the old versions)
//getStore() returns the normal store, not the versionStore
Reference docRef = new Reference(getStore(), document.getUuid(), null);

//like in the sample code
VersionHistory versionHistory = authService.getVersionHistory(docRef);
Version[] versions = versionHistory.getVersions();

//check if it's not null or empty (which it isn't, it gets all the versions)
   if((versions != null) && (versions.length > 0)){

//for every version, get the content, like in the example-code
      for(Version version : versions) {
         Reference reference = new Reference(getVersionStore(), version.getId().getUuid(), version.getId().getPath());
         Predicate predicate = new Predicate(new Reference[] { reference }, getStore(), null);
         Content[] contents = contentService.read(predicate, Constants.TYPE_CONTENT);

BUT i get this error on the last line:
AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.generalException
faultSubcode:
faultString:
faultActor:
faultNode:
faultDetail:
   {http://www.alfresco.org/ws/service/content/1.0}ContentFault:<ns1:errorCode>0</ns1:errorCode><ns1:message>Node does not exist: workspace://lightWeightVersionStore/39e90565-836c-41bc-b033-259d209b9615</ns1:message>
   {http://xml.apache.org/axis/}exceptionName:org.alfresco.repo.webservice.content.ContentFault
   {http://xml.apache.org/axis/}stackTrace:
   at org.alfresco.repo.webservice.content.ContentWebService.read(ContentWebService.java:106)
   at sun.reflect.GeneratedMethodAccessor1290.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397)
   at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186)
   at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323)
   at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
   at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
   at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
   at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:454)
   at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)
   at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
   at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:568)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
   at java.lang.Thread.run(Thread.java:595)

   {http://xml.apache.org/axis/}hostname:docbyte-manu


   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
   at java.lang.reflect.Constructor.newInstance(Unknown Source)
   at java.lang.Class.newInstance0(Unknown Source)
   at java.lang.Class.newInstance(Unknown Source)
   at org.apache.axis.encoding.ser.BeanDeserializer.<init>(BeanDeserializer.java:104)
   at org.apache.axis.encoding.ser.BeanDeserializer.<init>(BeanDeserializer.java:90)
   at org.alfresco.webservice.content.ContentFault.getDeserializer(ContentFault.java:146)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.apache.axis.encoding.ser.BaseDeserializerFactory.getSpecialized(BaseDeserializerFactory.java:154)
   at org.apache.axis.encoding.ser.BaseDeserializerFactory.getDeserializerAs(BaseDeserializerFactory.java:84)
   at org.apache.axis.encoding.DeserializationContext.getDeserializer(DeserializationContext.java:464)
   at org.apache.axis.encoding.DeserializationContext.getDeserializerForType(DeserializationContext.java:547)
   at org.apache.axis.message.SOAPFaultDetailsBuilder.onStartChild(SOAPFaultDetailsBuilder.java:157)
   at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1035)
   at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
   at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
   at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
   at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
   at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
   at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
   at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
   at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
   at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
   at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source)
   at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
   at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
   at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
   at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
   at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
   at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
   at org.apache.axis.client.Call.invoke(Call.java:2767)
   at org.apache.axis.client.Call.invoke(Call.java:2443)
   at org.apache.axis.client.Call.invoke(Call.java:2366)
   at org.apache.axis.client.Call.invoke(Call.java:1812)
   at org.alfresco.webservice.content.ContentServiceSoapBindingStub.read(ContentServiceSoapBindingStub.java:421)
   at com.docbyte.migrate.util.AlfrescoDA.manageVersions(AlfrescoDA.java:294)
   at com.docbyte.migrate.util.AlfrescoDA.doExport(AlfrescoDA.java:271)
   at com.docbyte.migrate.action.Migrate.go(Migrate.java:31)
   at com.docbyte.migrate.action.Migrate.main(Migrate.java:18)

does anyone have an idea why i get this error?

Outcomes