cancel
Showing results for 
Search instead for 
Did you mean: 

Namespace prefix by is not mapped to a namespace URI

st1ll
Champ in-the-making
Champ in-the-making
Hello.
When I try to run simple code to add a node (custom model type), I get stacktrace:
org.alfresco.service.namespace.NamespaceException: Namespace prefix by is not mapped to a namespace URI
   at org.alfresco.service.namespace.QName.createQName(QName.java:99)
   at org.alfresco.service.namespace.QName.createQName(QName.java:121)
   at org.alfresco.jcr.item.JCRPath$SimpleElement.<init>(JCRPath.java:114)
   at org.alfresco.jcr.item.JCRPath.<init>(JCRPath.java:66)
   at org.alfresco.jcr.item.NodeImpl.addNode(NodeImpl.java:146)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.alfresco.jcr.util.JCRProxyFactory$SessionContextInvocationHandler.invoke(JCRProxyFactory.java:132)
   at $Proxy154.addNode(Unknown Source)
   at org.alfresco.sample.FirstJCRClient.main(FirstJCRClient.java:76)

Code of client:

ApplicationContext context = new ClassPathXmlApplicationContext("classpath:alfresco/application-context.xml");
       Repository repository = (Repository)context.getBean("JCR.Repository");   
       Session session = repository.login(new SimpleCredentials("admin", "123".toCharArray()));
   
       try
       {
           // first, access the company home
           Node rootNode = session.getRootNode();
           Node companyHome = rootNode.getNode("app:company_home");
   
           // create the content node
           String name = "JCR sample (" + System.currentTimeMillis() + ")";
           Node content = companyHome.addNode("by:" + name, "by:log");
               …

On last line a get an exception.

My model code:

<model name="by:logmodel" xmlns="http://www.alfresco.org/model/dictionary/1.0">
   
   
    <imports>
        <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"></import>
        <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"></import>
    </imports> 
    <namespaces>
        <namespace uri="http://www.blabla.com/model/log/1.1" prefix="by" />
    </namespaces>

    <types>
      <type name="by:log">
         <title>Log</title>
         <parent>cm:content</parent>        
         <properties>
            <property name="by:id">
               <title>id</title>
               <type>d:text</type>
               <protected>false</protected>
               <mandatory>true</mandatory>
               <multiple>false</multiple>
            </property>
            <property name="by:sender">
               <title>sender</title>
               <type>d:text</type>
               <protected>false</protected>
               <mandatory>true</mandatory>
               <multiple>false</multiple>
            </property>
            <property name="by:recipient">
               <title>recipient</title>
               <type>d:text</type>
               <protected>false</protected>
               <mandatory>true</mandatory>
               <multiple>false</multiple>
            </property>
            <property name="by:senddate">
               <title>senddate</title>
               <type>d:datetime</type>
               <protected>false</protected>
               <mandatory>true</mandatory>
               <multiple>false</multiple>
            </property>
            <property name="by:signature">
               <title>signature</title>
               <type>d:text</type>
               <protected>false</protected>
               <mandatory>true</mandatory>
               <multiple>false</multiple>
            </property>
            <property name="by:finishdate">
               <title>finishdate</title>
               <type>d:datetime</type>
               <protected>false</protected>
               <mandatory>true</mandatory>
               <multiple>false</multiple>
            </property>
            <property name="by:resultprocess">
               <title>resultprocess</title>
               <type>d:text</type>
               <protected>false</protected>
               <mandatory>true</mandatory>
               <multiple>false</multiple>
            </property>
         </properties>
         
         <associations>
            <association name="by:response">
            <title>response</title>
            <source>
               <mandatory>false</mandatory>
               <many>false</many>
            </source>
            <target>
               <class>cm:content</class>
               <mandatory>false</mandatory>
               <many>false</many>
            </target>
            </association>
         </associations>
      </type>
    </types>
   
</model>

And file request-context.xml

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>


<beans>
  <bean id="requestModel" parent="dictionaryModelBootstrap" depends-on="JCR.DictionaryBootstrap">
    <property name="models">
      <list>
        <value>alfresco/extension/request.xml</value>
      </list>
    </property>
  </bean>
</beans>
In UI all work fine, I can add, edit documents with this model. But not work, when I try to programmaticly add content.

Excuse me for my bad English
1 REPLY 1

afaust
Legendary Innovator
Legendary Innovator
Hello,

Are you running your FirstJCRClient application in the same application context as the repository you deployed your model in? As far as I know the FirstJCRClient locally starts an embedded repository and I assume your model is not deployed in that one, causing the error from your stacktrace.

Regards
Axel