cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with checkOut() using Apache Chemistry

mandarj
Champ in-the-making
Champ in-the-making
I am connecting to Alfresco 3.4.1 Enterprise using Apache Chemistry and trying to checkout a file from repository. I could get the ContentStream of object which I want to checkout but somehow it does not checkout document and create pwc.

Can anyone help me to figure out what could be the issue?

Piece of code I am trying with :

CmisObject testCmisObject = ….;
if (testCmisObject.getAllowableActions().getAllowableActions().contains(org.apache.chemistry.opencmis.commons.enums.Action.CAN_CHECK_OUT)) {
   testCmisObject.refresh();
   System.out.println("Object Refreshed");
   org.apache.chemistry.opencmis.client.api.Document documentToBeCheckedout = (org.apache.chemistry.opencmis.client.api.Document) testCmisObject;
   System.out.println("Creating a pwc document");
   String testName = documentToBeCheckedout.getContentStream().getFileName();
   System.out.println("File Name=" + testName);
   ObjectId idOfCheckedOutDocument = documentToBeCheckedout.checkOut();
   System.out.println("Got Object Id=" + idOfCheckedOutDocument.getId());
   org.apache.chemistry.opencmis.client.api.Document pwcOfDocumentCheckedOut = (org.apache.chemistry.opencmis.client.api.Document) session.getObject(idOfCheckedOutDocument);
   System.out.println("Object checked-out");
}

In this, I think, it gets stuck at
ObjectId idOfCheckedOutDocument = documentToBeCheckedout.checkOut();
and does not print the message after that.

Thanks,
Mandar
9 REPLIES 9

jpotts
World-Class Innovator
World-Class Innovator
Are there any error messages in the server log?

Jeff

mandarj
Champ in-the-making
Champ in-the-making
Not Really.

When I add following catch exception, it says -  "Error: OK"

catch(Exception exception) {
   System.out.println("Error: " + exception.getMessage());
}

jpotts
World-Class Innovator
World-Class Innovator
This code runs fine for me using Apache Chemistry 0.7.0 and Alfresco 3.4.1 Enterprise for both the SOAP and the AtomPub bindings.

How are you retrieving your testCmisObject? Maybe you aren't getting back what you expect?

Jeff

mandarj
Champ in-the-making
Champ in-the-making
Ok. Is there any way to check if the CmisObject I am getting is correct and can be checked-out?

Currently I'm checking this condition using:
testCmisObject.getAllowableActions().getAllowableActions().contains(org.apache.chemistry.opencmis.commons.enums.Action.CAN_CHECK_OUT)

Also, as I mentioned above, I could get the filename of CmisObject successfully as:
String testName = documentToBeCheckedout.getContentStream().getFileName();

Is there any other criteria that I can check if the CmisObject I'm getting is correct and checked-out.

I'm retrieving CmisObject by following:
SessionFactory factory = SessionFactoryImpl.newInstance();
IdentityHashMap<String, String> parameter = new IdentityHashMap<String, String>();
parameter.put(SessionParameter.USER, "ROLE_TICKET");
parameter.put(SessionParameter.PASSWORD, ticket);
parameter.put(SessionParameter.ATOMPUB_URL, url + "/s/cmis");
parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
parameter.put(SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");
List<Repository> repositories = factory.getRepositories(parameter);
Session session = repositories.get(0).createSession();
Folder rootFolder = session.getRootFolder();
ItemIterable<CmisObject> rootFolderChildren = rootFolder.getChildren();
Iterator<CmisObject> childrenItems = rootFolderChildren.iterator();
while(childrenItems.hasNext()) {
   CmisObject testCmisObject = childrenItems.next();
}

After this, I do some tests checking some conditions and if those conditions pass, then I store this CmisObject in a Hashmap and retrieve this hashmap later for check-out.

Will there be any other dependent libraries issue?

Thanks.

jpotts
World-Class Innovator
World-Class Innovator
I tested your code successfully as admin and a getObject call to retrieve the object. You are using ticket-based auth and iterating over getChildren to retrieve the test object. So those are two differences between mine and yours.

Just as a test, create a new document. Then, grab the ID of that document (let's say it is "workspace://SpacesStore/c3f34858-678e-49b7-b7b7-7821a76d5b54" and test your code with:

       CmisObject testCmisObject = getSession().getObject("workspace://SpacesStore/c3f34858-678e-49b7-b7b7-7821a76d5b54");

Also, if you log in to one of the web clients using the same credentials you are using for this test, are you able to checkout the doc?

Jeff

mandarj
Champ in-the-making
Champ in-the-making
Hi Jeff,

I tried creating a document using:
session.getRootFolder().createDocument(properties, contentStream, VersioningState.MAJOR)

But it gets stuck at this statement "session.getRootFolder().createDocument(….)" which is same behaviour as it gets stuck at checkOut() method above. The error message just says "OK" at:
                      
catch(Exception exception) {
            System.out.println("Error: " + exception.getMessage());
         }

Thanks,
Mandar

jpotts
World-Class Innovator
World-Class Innovator
Well, that's a clue. Can you create content by logging in and using either Alfresco Explorer or Alfresco Share? Maybe you don't have the proper credentials or maybe your repository has gone into a read-only state (for example, you're on an Enterprise trial and the license has expired).

Jeff

mandarj
Champ in-the-making
Champ in-the-making
Hi Jeff,

Finally, I figured out the issue. It was not issue regarding repository. Actually, my code was not using Sun's default connection protocol "sun.net.www.protocol.http.HttpURLConnection". When I set this protocol, It checks-out document.

Thanks,
Mandar

jpotts
World-Class Innovator
World-Class Innovator
Glad you got it working. And thanks for reporting back with the solution!

Jeff
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.