views:

43

answers:

1

[Solved, it seems that there was some bug affecting Alfresco 3.3.0, which is no longer present on Alfresco 3.3.0g]

Hi,

I'm using OpenCMIS to retrieve data from Alfresco 3.3, but it's having a very weird behaviour on CMISQL queries. I've googled somebody else with the same problems, but it seems I'm the first one all over the world :), so I guess it's my fault, not OpenCMIS'.

This is how I'm querying Alfresco:

public Class CmisTest {
    private static Session sesion;

    private static final String QUERY = "select cmis:objectid, cmis:name from cmis:folder where cmis:name='MyFolder'";

    public static void main(String[] args) {
        // Open a CMIS session with Alfresco
        Map<String, String> params = new HashMap<String, String>();
        params.put(SessionParameter.USER, "admin");
        params.put(SessionParameter.PASSWORD, "admin");
        params.put(SessionParameter.ATOMPUB_URL, "http://localhost:8080/alfresco/s/api/cmis");
        params.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
        params.put(SessionParameter.REPOSITORY_ID, "fa9d2553-1e4d-491b-87fd-3de894dc7ca9");
        sesion = SessionFactoryImpl.newInstance().createSession(params);

        // Ugly bug in Alfresco which raises an exception if we request more data than it's available
        // See https://issues.alfresco.com/jira/browse/ALF-2859
        sesion.getDefaultContext().setMaxItemsPerPage(1);

        // We repeat the same query 20 times and count the number of elements retrieved each time
        for (int i = 0; i < 20; i++) {
            List<QueryResult> result = doQuery();
            System.out.println(result.size() + " folders retrieved");
        }
    }

    public static List<QueryResult> doQuery() {
        List<QueryResult> result = new LinkedList<QueryResult>();
        try {
            int page = 0;
            while (true) {
                ItemIterable<QueryResult> iterable = sesion.query(QUERY, false).skipTo(page);
                page++;
                for (QueryResult qr : iterable) {
                    result.add(qr);
                }
            }
        } catch (Exception e) {
            // We will always get an exception when Alfresco has no more data to retrieve... :(
            // See https://issues.alfresco.com/jira/browse/ALF-2859
        }
        return result;
    }

}

As you can see, we just execute the same query, up to 20 times in a row. You would expect the same result each time, wouldn't you? Unfortunately, this is a sample of what we get:

1 folders retrieved
1 folders retrieved
1 folders retrieved
0 folders retrieved
0 folders retrieved
0 folders retrieved
0 folders retrieved
0 folders retrieved
1 folders retrieved
1 folders retrieved

Sometimes we get 20 1 in a row, sometimes it's all 0. We have never get a "mix" of 1 and 0, though; we always get "a run" of them.

It does not matter if we create the session before each query, we still have the random issue. We have tried against two different Alfresco servers (both of them 3.3 Community), clean installation, and they both fail randomly. We also tried to measure the time for each query, but it doesn't seem to have any relation with the result being wrong (0 folders retrieved) or right (1 folders retrieved).

Alfresco seems to be working fine: if we go to "Administration --> Node browser" and launch the CMISQL query from there, it always retrieves one folder, which is right. So, it must be our code, or an OpenCMIS bug...

Any ideas?

+1  A: 

Hi AJPerez,

I can't reproduce this behavior. It's running fine against http://cmis.alfresco.com . The issue https://issues.alfresco.com/jira/browse/ALF-2859 states that there have been bug fixes. Are you running the latest Alfresco version?

Florian

Florian Müller
Hi Florian, thanks for your answer.I'm using Alfresco 3.3.0 (build 2765), I didn't notice that Alfresco 3.3g was already released. I'll update it and hopefully the ALF-2859 issue will be gone.As for the test, I'm testing now against http://cmis.alfresco.com and I'm unable to reproduce it. Maybe there was another bug in my version of Alfresco, I'll have to retry after updating it.
AJPerez
After upgrading from 3.3.0 to 3.3.0g it seems that the "random behaviour" is solved. Now I get always 0 results (apparently, querying the cmis:name property doesn't work)... but, at least, it fails always. Thanks again for your help :)
AJPerez