Question

I'm trying to use the Alfresco OpenCMIS Extension for aspects in a Groovy script.

I'd like to be able to set an aspect on a document, but when I try to cast a Document as AlfrescoDocument, it throws an error. I'm pointing Groovy to the Alfresco Chemistry jar files that ship with Alfresco 4.1.5

I can create a document and look at the properties of it, but when I try to convert it to an AlfrescoDocument, it throws an error.

import org.apache.chemistry.opencmis.commons.*
import org.apache.chemistry.opencmis.commons.data.*
import org.apache.chemistry.opencmis.client.api.*
import org.apache.chemistry.opencmis.client.runtime.*
import org.alfresco.cmis.client.*;
import org.alfresco.cmis.client.impl.*;

def doc = (Document) session.getObject(id);
def adoc = (AlfrescoDocument) doc;

.

Caught: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object   'org.apache.chemistry.opencmis.client.runtime.DocumentImpl@3e0339' with class  'org.apache.chemistry.opencmis.client.runtime.DocumentImpl' to class 'org.alfresco.cmis.client.AlfrescoDocument'
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object  'org.apache.chemistry.opencmis.client.runtime.DocumentImpl@3e0339' with class 'org.apache.chemistry.opencmis.client.runtime.DocumentImpl' to class 'org.alfresco.cmis.client.AlfrescoDocument'
Was it helpful?

Solution

Found the answer. The session needs to be wired to be able to use the Alfresco Extension:

parameter.put(SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top