05-31-2011 09:56 AM
public class AddNodeWithJCR {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
// access the Alfresco JCR Repository (here it's via programmatic approach, but it could also be injected)
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:alfresco/application-context.xml");
Repository repository = (Repository)context.getBean("JCR.Repository");
// login to workspace (here we rely on the default workspace defined by JCR.Repository bean)
Session session = repository.login(new SimpleCredentials("admin", "alfrescoadmin".toCharArray()));
// TODO Auto-generated method stub
try
{
// first, access the company home
Node rootNode = session.getRootNode();
Node companyHome = rootNode.getNode("app:company_home");
// create the content node
String name = "RM4";
Node content = companyHome.addNode("cm:" + name, "cm:content");
content.setProperty("cm:name", name);
// add titled aspect (for Web Client display)
content.addMixin("cm:titled");
content.setProperty("cm:title", name);
content.setProperty("cm:description", name);
//
// write some content to new node
//
ClassPathResource resource = new ClassPathResource("org/alfresco/sample/jcr/wikiModel.xml");
content.setProperty("cm:content", resource.getInputStream());
//
// To set the content mime type, we need to use an Alfresco native service
// as there isn't an equivalent call in JCR
//
// setMimeType(context, content, MimetypeMap.MIMETYPE_TEXT_PLAIN);
// save changes
session.save();
}
finally
{
session.logout();
//System.exit(0);
}
try {
// login to workspace (here we rely on the default workspace defined by JCR.Repository bean)
session = repository.login(new SimpleCredentials("admin", "alfrescoadmin".toCharArray()));
// access a RM node directly from root node (by path and by UUID)
Node rootNode = session.getRootNode();
Node section = rootNode.getNode("app:company_home/cm:RM4");
// create the section node
String name = "Section";
Node sectionNode = section.addNode("cm:" + name, "cm:content");
sectionNode.setProperty("cm:name", name);
// add titled aspect (for Web Client display)
sectionNode.addMixin("cm:titled");
sectionNode.setProperty("cm:title", name);
sectionNode.setProperty("cm:description", name);
// write some content to new node
//
ClassPathResource resource = new ClassPathResource("org/alfresco/sample/jcr/wiki-context.xml");
sectionNode.setProperty("cm:content", resource.getInputStream());
}
finally
{
session.logout();
}
}
}
Exception in thread "main" javax.jcr.RepositoryException: 04310001 Cannot determine child association for node type '{http://www.alfresco.org/model/content/1.0}content within parent workspace://SpacesStore/b1c0521a-0cca-4303-a810-47cd59c2a299: 04310001 Cannot determine child association for node type '{http://www.alfresco.org/model/content/1.0}content within parent workspace://SpacesStore/b1c0521a-0cca-4303-a810-47cd59c2a299
at org.alfresco.jcr.util.JCRProxyFactory$SessionContextInvocationHandler.invoke(JCRProxyFactory.java:169)
at $Proxy131.addNode(Unknown Source)
at org.alfresco.sample.jcr.AddNodeWithJCR.main(AddNodeWithJCR.java:121)
Caused by: org.alfresco.error.AlfrescoRuntimeException: 04310001 Cannot determine child association for node type '{http://www.alfresco.org/model/content/1.0}content within parent workspace://SpacesStore/b1c0521a-0cca-4303-a810-47cd59c2a299
at org.alfresco.jcr.item.NodeImpl.getNodeTypeChildAssocDefForParent(NodeImpl.java:277)
at org.alfresco.jcr.item.NodeImpl.addNode(NodeImpl.java:183)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.alfresco.jcr.util.JCRProxyFactory$SessionContextInvocationHandler.invoke(JCRProxyFactory.java:132)
… 2 more
org.alfresco.error.AlfrescoRuntimeException: 04310001 Cannot determine child association for node type '{http://www.alfresco.org/model/content/1.0}content within parent workspace://SpacesStore/b1c0521a-0cca-4303-a810-47cd59c2a299
at org.alfresco.jcr.item.NodeImpl.getNodeTypeChildAssocDefForParent(NodeImpl.java:277)
at org.alfresco.jcr.item.NodeImpl.addNode(NodeImpl.java:183)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.alfresco.jcr.util.JCRProxyFactory$SessionContextInvocationHandler.invoke(JCRProxyFactory.java:132)
at $Proxy131.addNode(Unknown Source)
at org.alfresco.sample.jcr.AddNodeWithJCR.main(AddNodeWithJCR.java:121)
05-31-2011 10:38 AM
Cannot determine child association
05-31-2011 10:52 AM
<model name="wiki:wikimodel" xmlns="http://www.alfresco.org/model/dictionary/1.0">
<imports>
<import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d" />
<import uri="http://www.alfresco.org/model/content/1.0" prefix="cm" />
</imports>
<namespaces>
<namespace uri="http://www.alfresco.org/model/jcr/example/wiki/1.0" prefix="wiki" />
</namespaces>
<types>
<type name="wiki:page">
<title>WIKI Page</title>
<parent>cm:content</parent>
<properties>
<property name="wiki:restrict">
<type>d:boolean</type>
<default>false</default>
</property>
<property name="wiki:category">
<type>d:text</type>
<multiple>true</multiple>
</property>
</properties>
<mandatory-aspects>
<aspect>cm:titled</aspect>
</mandatory-aspects>
</type>
</types>
</model>
05-31-2011 10:59 AM
05-31-2011 11:56 AM
05-31-2011 12:21 PM
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.