Gets values from Aspects

869 views
Skip to first unread message

Chad S

unread,
Jul 13, 2011, 7:39:28 PM7/13/11
to Alfresco OpenCMIS Extension
Hello,

WARNING: I'm a newbie. That has been trying/Googling to get data out
of aspects. Using the AlfrescoDocument. Has fixed the problem of
seeing the aspects. But I still can't seem to get data out of them.

What I am trying to do is use Apache Chemistry's OpenCMIS to get data
out of Alfresco.

I created a standard HTML content document. (Which I have the object
Id specified in my query String below.) Added aspects, namely the
Taggable. And added a tag.

I've been trying different things for the past week. And am completely
stuck. Any help, guidance, assistance is greatly appreciated!

Here is my code:
<code>
package org.apache.chemistry.opencmis.doc;

import java.util.HashMap;
import java.util.Map;
import org.alfresco.cmis.client.AlfrescoDocument;
import org.apache.chemistry.opencmis.client.api.ItemIterable;
import org.apache.chemistry.opencmis.client.api.ObjectType;
import org.apache.chemistry.opencmis.client.api.Property;
import org.apache.chemistry.opencmis.client.api.QueryResult;
import org.apache.chemistry.opencmis.client.api.Session;
import org.apache.chemistry.opencmis.client.api.SessionFactory;
import
org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.enums.BindingType;

/**
*
* @author g3rd
*/
public class AlfrescoCMISConnector {

public static void main(String args[]) {
Map<String, String> parameter = new HashMap<String, String>();

// user credentials
parameter.put(SessionParameter.USER, "cshryock");
parameter.put(SessionParameter.PASSWORD, "dRnkc0k3");

// connection settings
parameter.put(SessionParameter.ATOMPUB_URL, "http://
app.g3rdmedia.com:8080/alfresco/service/cmis");
parameter.put(SessionParameter.BINDING_TYPE,
BindingType.ATOMPUB.value());

// set the object factory
parameter.put(SessionParameter.OBJECT_FACTORY_CLASS,
"org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");

// create session
SessionFactory factory = SessionFactoryImpl.newInstance();
Session session =
factory.getRepositories(parameter).get(0).createSession();

String query = "SELECT d.* FROM cmis:document AS d WHERE
d.cmis:objectTypeId = 'D:pdl:person'";

query = "SELECT d.* FROM cmis:document AS d WHERE
d.cmis:objectId = 'workspace://SpacesStore/7b68ff5b-7a80-43cc-
ba75-256191c7654c'";

ItemIterable<QueryResult> result = session.query(query,
false);

print("Quering for: " + query);
print("Found: " + result.getTotalNumItems() + " Items");

printSeperator();

for(QueryResult item : result) {

// Load document
AlfrescoDocument doc = (AlfrescoDocument)
session.getObject(item.getPropertyByQueryName("d.cmis:objectId").getFirstValue().toString());

print("PROPERTIES:");
for (Property<?> prop : doc.getProperties()) {
print(" " + prop.getDisplayName() + " (" +
prop.getId() + "): " + prop.getFirstValue());
}

print("");
print("TRY TO GET TAGGABLE DATA:");
Property<Object> p = doc.getProperty("cm:taggable");
print(doc.getProperty("cm:taggable").toString());

System.out.println(session.getObject(p.getFirstValue().toString()));

print("");
print("ASPECTS:");
for (ObjectType aspect : doc.getAspects()) {
print(" " + aspect.getDisplayName() + "(" +
aspect.getId() + ")");
for (ObjectType ac : aspect.getChildren()) {
print(" > " + ac.getDisplayName() + "(" +
ac.getId() + ")");
}
}

printSeperator();
}
}

private static void print(String s) {
System.out.println(s);
}

private static void printSeperator() {
System.out.println("");
System.out.println("-----");
System.out.println("");
}
}
</code>



This is the exception I get in the console:
<exception>
Exception in thread "main"
org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException:
Internal Server Error
at
org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.convertStatusCode(AbstractAtomPubService.java:
450)
at
org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.read(AbstractAtomPubService.java:
552)
at
org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.getObjectInternal(AbstractAtomPubService.java:
777)
at
org.apache.chemistry.opencmis.client.bindings.spi.atompub.ObjectServiceImpl.getObject(ObjectServiceImpl.java:
433)
at
org.apache.chemistry.opencmis.client.runtime.SessionImpl.getObject(SessionImpl.java:
393)
at
org.apache.chemistry.opencmis.client.runtime.SessionImpl.getObject(SessionImpl.java:
371)
at
org.apache.chemistry.opencmis.doc.AlfrescoCMISConnector.main(AlfrescoCMISConnector.java:
80)
</exception>

This is the exception I get in the catalina.out / alfresco.log:
<exception>
23:35:48,140 User:cshryock ERROR [freemarker.runtime] Error executing
macro: typeuri
required parameter: typedef is not specified.

Error executing macro: typeuri
required parameter: typedef is not specified.
The problematic instruction:
----------
==> macro typeuri [on line 187, column 1 in org/alfresco/cmis/lib/
links.lib.atom.ftl]
in user-directive typeuri [on line 94, column 82 in org/alfresco/cmis/
lib/links.lib.atom.ftl]
in user-directive linksLib.linktype [on line 160, column 1 in org/
alfresco/cmis/lib/atomentry.lib.atom.ftl]
in user-directive folderCMISLinks [on line 109, column 1 in org/
alfresco/cmis/lib/atomentry.lib.atom.ftl]
in user-directive entry [on line 103, column 1 in org/alfresco/cmis/
lib/atomentry.lib.atom.ftl]
in user-directive entryLib.folder [on line 13, column 3 in org/
alfresco/cmis/item.get.atomentry.ftl]
----------

Java backtrace for programmers:
----------
freemarker.template.TemplateException: Error executing macro: typeuri
required parameter: typedef is not specified.
at freemarker.core.Macro$Context.sanityCheck(Macro.java:211)
at freemarker.core.Macro$Context.runMacro(Macro.java:169)
at freemarker.core.Environment.visit(Environment.java:603)
at freemarker.core.UnifiedCall.accept(UnifiedCall.java:106)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.Macro$Context.runMacro(Macro.java:172)
at freemarker.core.Environment.visit(Environment.java:603)
at freemarker.core.UnifiedCall.accept(UnifiedCall.java:106)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.Macro$Context.runMacro(Macro.java:172)
at freemarker.core.Environment.visit(Environment.java:603)
at freemarker.core.UnifiedCall.accept(UnifiedCall.java:106)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.Environment.visit(Environment.java:395)
at freemarker.core.BodyInstruction.accept(BodyInstruction.java:93)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.Macro$Context.runMacro(Macro.java:172)
at freemarker.core.Environment.visit(Environment.java:603)
at freemarker.core.UnifiedCall.accept(UnifiedCall.java:106)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.Macro$Context.runMacro(Macro.java:172)
at freemarker.core.Environment.visit(Environment.java:603)
at freemarker.core.UnifiedCall.accept(UnifiedCall.java:106)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.IfBlock.accept(IfBlock.java:82)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.Environment.visit(Environment.java:299)
at freemarker.core.CompressedBlock.accept(CompressedBlock.java:73)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.Environment.process(Environment.java:190)
at freemarker.template.Template.process(Template.java:237)
at
org.alfresco.repo.template.FreeMarkerProcessor.process(FreeMarkerProcessor.java:
197)
at
org.springframework.extensions.webscripts.AbstractWebScript.renderTemplate(AbstractWebScript.java:
589)
at
org.springframework.extensions.webscripts.DeclarativeWebScript.renderFormatTemplate(DeclarativeWebScript.java:
267)
at
org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:
147)
at org.alfresco.repo.web.scripts.RepositoryContainer
$2.execute(RepositoryContainer.java:377)
at
org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:
381)
at
org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:
436)
at
org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:
466)
at
org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:
304)
at
org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:
333)
at
org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:
189)
at
org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:
118)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:
206)
at
org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:
58)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
235)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:
206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:
233)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:
191)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:
127)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:
102)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:
109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:
298)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:
859)
at org.apache.coyote.http11.Http11Protocol
$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:
489)
at java.lang.Thread.run(Thread.java:619)
23:35:48,143 User:cshryock ERROR
[extensions.webscripts.AbstractRuntime] Exception from executeScript -
redirecting to status template error: 06130015 Wrapped Exception (with
status template): 06130141 Error during processing of the template
'Error executing macro: typeuri
required parameter: typedef is not specified.'. Please contact your
system administrator.
org.springframework.extensions.webscripts.WebScriptException: 06130015
Wrapped Exception (with status template): 06130141 Error during
processing of the template 'Error executing macro: typeuri
required parameter: typedef is not specified.'. Please contact your
system administrator.
at
org.springframework.extensions.webscripts.AbstractWebScript.createStatusException(AbstractWebScript.java:
758)
at
org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:
171)
at org.alfresco.repo.web.scripts.RepositoryContainer
$2.execute(RepositoryContainer.java:377)
at
org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:
381)
at
org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:
436)
at
org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:
466)
at
org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:
304)
at
org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:
333)
at
org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:
189)
at
org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:
118)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:
206)
at
org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:
58)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
235)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:
206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:
233)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:
191)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:
127)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:
102)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:
109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:
298)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:
859)
at org.apache.coyote.http11.Http11Protocol
$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:
489)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.alfresco.service.cmr.repository.TemplateException:
06130141 Error during processing of the template 'Error executing
macro: typeuri
required parameter: typedef is not specified.'. Please contact your
system administrator.
at
org.alfresco.repo.template.FreeMarkerProcessor.process(FreeMarkerProcessor.java:
201)
at
org.springframework.extensions.webscripts.AbstractWebScript.renderTemplate(AbstractWebScript.java:
589)
at
org.springframework.extensions.webscripts.DeclarativeWebScript.renderFormatTemplate(DeclarativeWebScript.java:
267)
at
org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:
147)
... 24 more
Caused by: freemarker.template.TemplateException: Error executing
macro: typeuri
required parameter: typedef is not specified.
at freemarker.core.Macro$Context.sanityCheck(Macro.java:211)
at freemarker.core.Macro$Context.runMacro(Macro.java:169)
at freemarker.core.Environment.visit(Environment.java:603)
at freemarker.core.UnifiedCall.accept(UnifiedCall.java:106)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.Macro$Context.runMacro(Macro.java:172)
at freemarker.core.Environment.visit(Environment.java:603)
at freemarker.core.UnifiedCall.accept(UnifiedCall.java:106)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.Macro$Context.runMacro(Macro.java:172)
at freemarker.core.Environment.visit(Environment.java:603)
at freemarker.core.UnifiedCall.accept(UnifiedCall.java:106)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.Environment.visit(Environment.java:395)
at freemarker.core.BodyInstruction.accept(BodyInstruction.java:93)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.Macro$Context.runMacro(Macro.java:172)
at freemarker.core.Environment.visit(Environment.java:603)
at freemarker.core.UnifiedCall.accept(UnifiedCall.java:106)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.Macro$Context.runMacro(Macro.java:172)
at freemarker.core.Environment.visit(Environment.java:603)
at freemarker.core.UnifiedCall.accept(UnifiedCall.java:106)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.IfBlock.accept(IfBlock.java:82)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.Environment.visit(Environment.java:299)
at freemarker.core.CompressedBlock.accept(CompressedBlock.java:73)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.Environment.process(Environment.java:190)
at freemarker.template.Template.process(Template.java:237)
at
org.alfresco.repo.template.FreeMarkerProcessor.process(FreeMarkerProcessor.java:
197)
... 27 more
</exception>

Again thanks for your assistance.
-Chad.

Florian Müller

unread,
Jul 14, 2011, 6:03:37 AM7/14/11
to alfresco-open...@googlegroups.com
Hi Chad,

The cause of the exception you are seeing is that tag objects are not exposed through CMIS. When you call getObject() with a tag NodeRef, it can't find a matching CMIS type and throws this exception.

Alfresco 3.4.3 supports querying for tags [1]. You can also get, set and remove tags via the cm:taggable aspect but you have to provide tag NodeRefs. Unfortunately, there is currently no way through CMIS to get hold of the names of the tags. 


- Florian



Andy Ingham

unread,
Mar 13, 2013, 7:30:37 AM3/13/13
to alfresco-open...@googlegroups.com
Hi Florian,

Do you know if CMIS (Alfresco) is now capable of allowing the retrieval of tag names? Hopefully things have moved on in those 2 years!

Many thanks,

Andy
Reply all
Reply to author
Forward
0 new messages