3 Replies Latest reply on Apr 26, 2012 12:50 AM by V B Sajjan

    How to get the Version History of a stored document?

    V B Sajjan Level 1

      Hi,

       

      I am trying to store and retrieve the content using Content Services features of ADEP 10.0.

       

      I am able to store and retrieve content where as I am not able to get the version of the document. I am trying to store same or different document, but I donot get the version history or version label. Please guide me how I can get  the version of a stored document.

       

      Also, please advise me if there are simple alternative to do the same in ADEP10.

       

      Please see below my sample code below:

       

      package test.sample;

      import java.io.File;
      import java.util.*;

      import com.adobe.idp.Document;
      import com.adobe.idp.dsc.clientsdk.ServiceClientFactory;
      import com.adobe.idp.dsc.clientsdk.ServiceClientFactoryProperties;
      import com.adobe.livecycle.contentservices.client.CRCResult;
      import com.adobe.livecycle.contentservices.client.impl.DocumentManagementServiceClientImpl;
      import com.adobe.livecycle.contentservices.client.impl.UpdateVersionType;

      public class AddContent {

          public static void main(String[] args) {
              
              try{
              
                  //Set connection properties required to invoke Document Services in EJB mode                                
                  Properties connectionProps = new Properties();
                  connectionProps.setProperty(ServiceClientFactoryProperties.DSC_DEFAULT_EJB_ENDPOINT, "jnp://localhost:1099");
                  connectionProps.setProperty(ServiceClientFactoryProperties.DSC_TRANSPORT_PROTOCOL,Service ClientFactoryProperties.DSC_EJB_PROTOCOL);          
                  connectionProps.setProperty(ServiceClientFactoryProperties.DSC_SERVER_TYPE, "JBoss");
                  connectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_USERNAME, "administrator");
                  connectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_PASSWORD, "password");
                              
                  //Create a ServiceClientFactory object
                  ServiceClientFactory myFactory = ServiceClientFactory.createInstance(connectionProps);

                  //Create a DocumentManagementServiceClientImpl object
                  DocumentManagementServiceClientImpl    docManager = new DocumentManagementServiceClientImpl(myFactory);
                  
                  //Specify the store and node name
                  String storeName ="SpacesStore"; 
                  String nodeName = "/Company Home/Test Directory";
                  
                  //Retrieve the document to store in /Company Home/Test Directory
                  Document contentA =  new Document(new File("C://Adobe/New files/Data-A.pdf"), false);
                  Document contentB =  new Document(new File("C://Adobe/New files/Data-B.txt"), false);
                  Document contentC =  new Document(new File("C://Adobe/New files/Data-C.xlsx"), false);
                 
                  //Create a MAP instance to store attributes
                  Map<String,Object> inputs = new HashMap<String,Object>();
                  
                  //Specify attributes that belong to the new content
                  String creator = "{http://www.alfresco.org/model/content/1.0}creator";
                  String description = "{http://www.alfresco.org/model/content/1.0}description"; 
                  
                  inputs.put(creator,"Veeraganteppa Sajjan");
                  inputs.put(description,"A sample application form");
                             
                  //Store MortgageForm.pdf in /Company Home/Test Directory
                  CRCResult resultA = docManager.storeContent(storeName, 
                           nodeName,
                          "dataA.pdf",
                          "{http://www.alfresco.org/model/content/1.0}content", 
                          contentA,
                          "UTF-8",
                          UpdateVersionType.INCREMENT_MAJOR_VERSION,
                          null,
                          inputs); 
                  CRCResult resultB = docManager.storeContent(storeName, 
                          nodeName,
                         "dataB.pdf",
                         "{http://www.alfresco.org/model/content/1.0}content", 
                         contentB,
                         "UTF-8",
                         UpdateVersionType.INCREMENT_MAJOR_VERSION,
                         null,
                         inputs);
                  CRCResult resultC = docManager.storeContent(storeName, 
                          nodeName,
                         "dataC",
                         "{http://www.alfresco.org/model/content/1.0}content", 
                         contentC,
                         "UTF-8",
                         UpdateVersionType.INCREMENT_MAJOR_VERSION,
                         null,
                         inputs);
                 
                  //Get the identifier value of the new resource
                  String idA = resultA.getNodeUuid();
                  String idB = resultB.getNodeUuid();
                  String idC = resultC.getNodeUuid();
                
                  System.out.println("A -The identifier value of the new content is "+idA);
                  System.out.println("B - The identifier value of the new content is "+idB);
                  System.out.println("C - The identifier value of the new content is "+idC);
                 
                 System.out.println("A - The Browse Link is "+resultA.getBrowseLink());
                  System.out.println("B - The Browse Link is "+resultB.getBrowseLink());
                  System.out.println("C - The Browse Link is "+resultC.getBrowseLink());
               
                System.out.println("A-The Version Label is "+resultA.getVersionLabel());
                System.out.println("B-The Version Label is "+resultB.getVersionLabel());
                System.out.println("C-The Version Label is "+resultC.getVersionLabel());
                System.out.println("The Version History is "+docManager.getVersionHistory(storeName,nodeName, true));
          }catch(Exception e)
          {
              e.printStackTrace();
          }
          }
      }

       

      Message was edited by: V B Sajjan

        • 1. Re: How to get the Version History of a stored document?
          V B Sajjan Level 1

          Sorry I did not attach the output and errors. Please find the same below.

           

          A -The identifier value of the new content is f5427f5b-c7c1-4c3c-b959-cb84e4e49a13

          B - The identifier value of the new content is b237d22c-5ff5-4628-a83a-23f5e49ae48e

          C - The identifier value of the new content is 34a9992c-3705-4488-bb55-6dd7ddfa0517

          A - The Browse Link is http://localhost:8080/contentspace/wcs/api/node/content/workspace/SpacesStore/f5427f5b-c7c 1-4c3c-b959-cb84e4e49a13/dataA.pdf

          B - The Browse Link is http://localhost:8080/contentspace/wcs/api/node/content/workspace/SpacesStore/b237d22c-5ff 5-4628-a83a-23f5e49ae48e/dataB.pdf

          C - The Browse Link is http://localhost:8080/contentspace/wcs/api/node/content/workspace/SpacesStore/34a9992c-370 5-4488-bb55-6dd7ddfa0517/dataC

          A-The Version Label is null

          B-The Version Label is null

          C-The Version Label is null

          ALC-CSV-30015-000: com.adobe.livecycle.contentservices.client.exceptions.CSInvocationException: ALC-CSV-030-015-The node [/Company Home/Test Directory] is not versioned.

          at com.adobe.contentservices.webscripts.impl.AbstractContentManager.doGetVersionHistory(Abst ractContentManager.java:1362)

          at com.adobe.contentservices.webscripts.impl.ContentManagerImpl.executeParams(ContentManager Impl.java:198)

          at com.adobe.contentservices.webscripts.impl.CSRetryingTransactionCallback.execute(CSRetryin gTransactionCallback.java:45)

          at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransacti onHelper.java:326)

          at com.adobe.contentservices.webscripts.impl.ContentManagerImpl.execute(ContentManagerImpl.j ava:114)

          at org.alfresco.repo.web.scripts.RepositoryContainer$2.execute(RepositoryContainer.java:333)

          at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransacti onHelper.java:326)

          at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContaine r.java:386)

          at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContai ner.java:404)

          at org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java: 246)

          at org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntime.java:294)

          at org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntime.java:172)

          at org.alfresco.web.scripts.servlet.WebScriptServlet.service(WebScriptServlet.java:122)

          at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.j ava:290)

          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

          at com.adobe.idp.um.auth.filter.CSRFFilter.doFilter(CSRFFilter.java:86)

          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.j ava:235)

          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

          at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.j ava:235)

          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)

          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

          at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.ja va:183)

          at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:95)

          at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEs tablishmentValve.java:126)

          at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEst ablishmentValve.java:70)

          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)

          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

          at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java: 158)

          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)

          at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)

          at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.ja va:598)

          at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:451)

          at java.lang.Thread.run(Thread.java:662)

          • 2. Re: How to get the Version History of a stored document?
            Sourabh S Level 1

            Here are a few points for your consideration : -

            1. Please note that  there are two ways of creating versions in Content Services (a) by using storeContent API and passing "Version Type parameter as Major or Minor as you have done. But in addtion to this, you also need to pass Aspect Versionable. The second last parameter is null here.  

            List<String> aspectList = new ArrayList<String>();

            aspectList.add(0,

            "{http://www.alfresco.org/model/content/1.0}versionable");  Passing this aspect will make sure that versionable node is created. But in this way, you may not be able to set your own version labels.

             

              b) An alternative is to use checkout, checkin APIs where you could set your own versions.

             

              After using either of these methods, the node wil be versionable and its version information can be obtained using the versionhistory API

             

              2.  To retrieve the actual content corresponding to node version, you need to use retrieveContent API.  Here you will need to supply the required versionLabel for which details are required.

             

            Please feel free to revert back in case of any doubts.

             

            Regards,

            Sourabh

            1 person found this helpful
            • 3. Re: How to get the Version History of a stored document?
              V B Sajjan Level 1

              Sourabh,

               

              Your ponits have worked to me. Thanks a lot.

               

              Regards,

              V B Sajjan.