Search code examples
javaalfrescocmisopencmis

Alfresco CMIS query return objectId that contains semi-colon and version


I'm using alfresco 4.2 with OpenCMIS java client library CMIS 1.1.

    String serviceUrl = "http://URL/alfresco/api/-default-/public/cmis/versions/1.1/atom"; // Uncomment for Web Services binding

    // default factory implementation
    SessionFactory factory = SessionFactoryImpl.newInstance();
    Map<String, String> parameter = new HashMap<String, String>();
    // user credentials
    parameter.put(SessionParameter.USER, "admin");
    parameter.put(SessionParameter.PASSWORD, "admin");
    // connection settings
    parameter.put(SessionParameter.ATOMPUB_URL, serviceUrl); // Uncomment for Atom Pub binding
    parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value()); // Uncomment for Atom Pub binding

    // Set the alfresco object factory
    // Used when using the CMIS extension for Alfresco for working with aspects
    List<Repository> repositories = factory.getRepositories(parameter);
    Session session = repositories.get(0).createSession();

    // Get some repository info
    System.out.println("Repository Name: "+session.getRepositoryInfo().getName());
    System.out.println("Repository ID: "+session.getRepositoryInfo().getId());
    System.out.println("CMIS Version: "+session.getRepositoryInfo().getCmisVersion());

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

    StringBuilder sb = new StringBuilder();
    sb.append("select * from ged:document m");

    // execute query
    ItemIterable<QueryResult> results = session.query(sb.toString(), false);

    for (QueryResult qResult : results) {

        PropertyData<?> propData = qResult.getPropertyById("cmis:objectId");
        String objectId = (String) propData.getFirstValue();
        cmisObjectId.add(objectId);
        System.out.println(objectId);
    }

The result is :

e8137d5d-cf50-41c4-844a-ec98a44ee73a;1.0
f86557af-89c3-4287-85c4-381e47896c1a;1.0
d56b4e1e-e1dc-4514-9bd2-24080b7879a8;1.0
59a0a9a8-8309-43b6-8040-bb3e9e448171;1.0

But I would like the id of the node without the version number, to use it for REST API Call.

Thanks.


Solution

  • The CMIS Object ID is defined as being an opaque string. The format will differ between repository implementations, and may differ between versions of a repository.

    If you want the Alfresco NodeRef, and you're sure you're talking to an Alfresco server, then the property you'll want is alfcmis:nodeRef

    If you connect to your repository with the Apache Chemistry CMIS Workbench, you can see the properties it reports, and from there see things like this

    Workbench showing it