cancel
Showing results for 
Search instead for 
Did you mean: 

CMIS Change Log Token problem using OpenCMIS

gregbpopstar
Champ on-the-rise
Champ on-the-rise
I'm successfully opening an OpenCMIS "Session" to Alfresco 3.4.b and getting a list of change log changes to support a sync operation.

The relevant code looks kinda like this:

ChangeEvents changes = session.getContentChanges(getLastToken(), true, 1000);
String newToken = changes.getLatestChangeLogToken();

saveAsLastToken(newToken);

Once I get the list of changes I'm trying keep the last change token and use it for the next getContentChanges call in order to get only new content changes.

My problem is that the changes.getLatestChangeLogToken() always returns null for me.

In order the get the change log stuff to work at all I have to turn it on in alfresco using the audit.cmischangelog.enabled=true option in the global config.

Has anyone had success getting a change log token?
3 REPLIES 3

fmui
Champ in-the-making
Champ in-the-making
You are probably using the AtomPub binding. It doesn't return a change log token. That's a binding limitation, not an Alfresco limitation.

You either have to switch to Web Services or you have to do something ugly like this:
RepositoryInfo ri = session.getBinding().getRepositoryService().getRepositoryInfo(session.getRepositoryInfo().getId(), null);
String latestChangeLogToken = ri.getLatestChangeLogToken();

- Florian

keesvanbemmel
Champ in-the-making
Champ in-the-making
Hi,

I've tried getting changes (iteratively) from the repository… but I think I fail to understand the logic behind it. I thought it would work like this:

1. Get the changes from the repo using "null" token
2. This returns the changes as well as a new token
3. Process the changes
4. Get new changes using new token (because I don't want to process the same changes again of course)
5. rinse and repeat from 2 Smiley Happy

However, the test code below shows that the returned change token in the changes is always the same as the one that was passed?? Any idea why and how I should process changes??

By the way, the tokens that are returned using webservice calls are identical to the ones gotten from atompub binding.

Regards,

Kees.

OUTPUT:
<blockquote>
token: null total numbers: 33
New changes token: null
token: 27 total numbers: 7
New changes token: 27
token: 28 total numbers: 5
New changes token: 29
token: 29 total numbers: 6
New changes token: 28
token: 33 total numbers: 1
New changes token: 33
</blockquote>

CODE:

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;

import org.apache.chemistry.opencmis.client.api.ChangeEvents;
import org.apache.chemistry.opencmis.client.api.Session;
import org.apache.chemistry.opencmis.client.api.SessionFactory;
import org.apache.chemistry.opencmis.client.bindings.CmisBindingFactory;
import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
import org.apache.chemistry.opencmis.commons.enums.BindingType;
import org.apache.chemistry.opencmis.commons.spi.CmisBinding;

public class TempTest {

   /**
    * @param args
    */
   public static void main(String[] args) {
      final CmisBinding binding;
      final Session session;
      final Session websession;
      String repositoryId;
      String url = "http://10.20.1.110:8080/alfresco/cmisatom";

      // holder for the parameters
      final Map<String, String> parameters = new HashMap<String, String>();

      // User credentials.
      parameters.put(SessionParameter.USER, "admin");
      parameters.put(SessionParameter.PASSWORD, "admin");
      // Connection settings.
      parameters.put(SessionParameter.ATOMPUB_URL, url);
      // type of binding
      parameters.put(SessionParameter.BINDING_TYPE,
            BindingType.ATOMPUB.value());
      try {
            // no repositoryId is set so first make a binding to fetch
            // the
            // first repository in the list
            binding = CmisBindingFactory.newInstance()
                  .createCmisAtomPubBinding(parameters);
            // if there is no binding no use to get on
            if (binding != null) {
               final List<RepositoryInfo> infos = binding
                     .getRepositoryService()
                     .getRepositoryInfos(null);
               if (!infos.isEmpty()) {
                  final RepositoryInfo repInfo = infos.get(0);
                  // now we have the repository and use it as a
                  // parameter
                  // to create the session
                  repositoryId = repInfo.getId();
                  parameters.put(SessionParameter.REPOSITORY_ID,
                        repositoryId);
               } else {
                  System.out.println("No repository found!");
               }
            } else {
               System.out.println("Given credentials are probably not correct!");
            }
         final SessionFactory sessionFactory = SessionFactoryImpl
               .newInstance();
         session = sessionFactory.createSession(parameters);
         
         RepositoryInfo ri = session.getBinding().getRepositoryService().getRepositoryInfo(session.getRepositoryInfo().getId(), null);
         String latestChangeLogToken = ri.getLatestChangeLogToken();
         ChangeEvents changes = session.getContentChanges(null, true, 1000);
         System.out.println("token: " + null + " total numbers: " +changes.getChangeEvents().size());
         System.out.println("New changes token: " + changes.getLatestChangeLogToken());
         changes = session.getContentChanges("27", true, 1000);
         System.out.println("token: " +"27" + " total numbers: " +changes.getChangeEvents().size());
         System.out.println("New changes token: " + changes.getLatestChangeLogToken());
         changes = session.getContentChanges("29", true, 1000);
         System.out.println("token: " +"28" + " total numbers: " +changes.getChangeEvents().size());
         System.out.println("New changes token: " + changes.getLatestChangeLogToken());
         changes = session.getContentChanges("28", true, 1000);
         System.out.println("token: " +"29" + " total numbers: " +changes.getChangeEvents().size());
         System.out.println("New changes token: " + changes.getLatestChangeLogToken());
         changes = session.getContentChanges(latestChangeLogToken, true, 1000);
         System.out.println("token: " +latestChangeLogToken + " total numbers: " +changes.getChangeEvents().size());
         System.out.println("New changes token: " + changes.getLatestChangeLogToken());
      } catch (final Exception e) {
         System.out.println("Given credentials are probably not correct! ");
         e.printStackTrace();
      }

   }

}

gregbpopstar
Champ on-the-rise
Champ on-the-rise
Thanks Florian. 

When I use your "ugly solution", I get a token which is not null.  That's progress!