pb pour enregistrer un custom model dans le Repository

cancel
Showing results for 
Search instead for 
Did you mean: 
ethan
Member II

pb pour enregistrer un custom model dans le Repository

Bonsoir Smiley Happy

En m'inspirant des exemples fournis dans le SDK 3.3 de Alfresco, j'ai essayé d'écrire ma propre classe pour me connecter au repository et ajouter des noeuds de contenu.

Voici l'architecture de mon projet sous Eclipse :

ExportJcrToAlfresco
      – src
           –> com.test.exportJCR
                   –> XmlToJcrImporter.java

      – mds-model-context.xml

Et voici le début de ma classe :

ApplicationContext context = new ClassPathXmlApplicationContext("classpath:mds-model-context.xml");
Repository repository = (Repository)context.getBean("JCR.Repository");
SimpleCredentials credentials = new SimpleCredentials("admin",   "admin".toCharArray());      
session = repository.login(credentials);

Quand je teste mon application, j'ai le message d'erreur suivant :

log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'extension.dictionaryBootstrap' defined in class path resource [mds-model-context.xml]: Could not resolve parent bean definition 'dictionaryModelBootstrap'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'dictionaryModelBootstrap' is defined
   at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedBeanDefinition(AbstractBeanFactory.java:1110)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedBeanDefinition(AbstractBeanFactory.java:1055)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1041)
   at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:537)
   at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:842)
   at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:416)
   at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
   at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
   at com.test.exportJCR.XmlToJcrImporter.connectToRepository(XmlToJcrImporter.java:75)
   at com.test.exportJCR.XmlToJcrImporter.importXMLToRepository(XmlToJcrImporter.java:52)
   at com.test.exportJCR.ImportJCR.main(ImportJCR.java:16)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'dictionaryModelBootstrap' is defined
   at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:504)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1041)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedBeanDefinition(AbstractBeanFactory.java:827)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedBeanDefinition(AbstractBeanFactory.java:1096)
   … 10 more

Il doit y avoir quelque chose de mal configuré mais je ne sais pas vraiment quoi  Smiley Sad

Ah oui, le contenu de mon fichier mds-model-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="extension.dictionaryBootstrap" parent="dictionaryModelBootstrap" depends-on="dictionaryBootstrap">
        <property name="models">
            <list>
                <value>alfresco/extension/mdsModel.xml</value>
            </list>
        </property>
    </bean>        
</beans>

Merci par avance Smiley Happy
4 Replies
ethan
Member II

Re: pb pour enregistrer un custom model dans le Repository

Bonjour Smiley Happy

J'ai pu avancer un poil dans mon enregistrement de modèle personnalisé. J'ai ajouté des définitions de beans dans mon fichier de contexte pour que la bean dictionnaryBootstrap soit reconnue mais j'ai maintenant un autre problème. Voici l'erreur en question :

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'custom.dictionaryBootstrap' defined in class path resource [com/test/exportJCR/custom-model-context.xml]: Invocation of init method failed; nested exception is org.alfresco.service.cmr.dictionary.DictionaryException: 06260001 Could not import bootstrap model com/test/exportJCR/myCustomModel.xml
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1401)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:512)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
   at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
   at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
   at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
   at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:557)
   at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:842)
   at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:416)
   at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
   at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
   at com.test.exportJCR.XmlToJcrImporter.connectToRepository(XmlToJcrImporter.java:75)
   at com.test.exportJCR.XmlToJcrImporter.importXMLToRepository(XmlToJcrImporter.java:52)
   at com.test.exportJCR.ImportJCR.main(ImportJCR.java:16)
Caused by: org.alfresco.service.cmr.dictionary.DictionaryException: 06260001 Could not import bootstrap model com/test/exportJCR/myCustomModel.xml
   at org.alfresco.repo.dictionary.DictionaryBootstrap.onDictionaryInit(DictionaryBootstrap.java:157)
   at org.alfresco.repo.dictionary.DictionaryBootstrap.bootstrap(DictionaryBootstrap.java:104)
   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.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1529)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1468)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1398)
   … 14 more
Caused by: org.alfresco.service.cmr.dictionary.DictionaryException: 06260000 Failed to compile model custom:contentmodel
   at org.alfresco.repo.dictionary.CompiledModel.<init>(CompiledModel.java:106)
   at org.alfresco.repo.dictionary.M2Model.compile(M2Model.java:128)
   at org.alfresco.repo.dictionary.DictionaryDAOImpl.putModel(DictionaryDAOImpl.java:277)
   at org.alfresco.repo.dictionary.DictionaryBootstrap.onDictionaryInit(DictionaryBootstrap.java:153)
   … 22 more
Caused by: org.alfresco.service.namespace.NamespaceException: URI http://www.alfresco.org/model/content/1.0 cannot be imported as it is not defined (with prefix cm
   at org.alfresco.repo.dictionary.CompiledModel.createLocalPrefixResolver(CompiledModel.java:203)
   at org.alfresco.repo.dictionary.CompiledModel.constructDefinitions(CompiledModel.java:128)
   at org.alfresco.repo.dictionary.CompiledModel.<init>(CompiledModel.java:88)
   … 25 more
ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2
JDWP exit error AGENT_ERROR_NO_JNI_ENV(183):  [../../../src/share/back/util.c:820]

D'après ce que j'ai pu lire sur internet, il y aurait une erreur dans mon modèle xml qui empêcherait sa compilation et son enregistrement dans Alfresco. Cependant, je n'arrive pas à trouver cette erreur. Voici mon modèle :

<?xml version="1.0" encoding="UTF-8"?>
<!– Definition of new model –>
<model name="custom:contentmodel" xmlns="http://www.alfresco.org/model/dictionary/1.0">

   <!– Optional meta-data about the model –>  
   <description>Custom Document Content Model</description>
   <author>My Company</author>
   <version>1.0</version>

   <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"/>
     <import uri="http://www.jcp.org/jcr/nt/1.0" prefix="nt"/>
   </imports>

   <!– Introduction of new namespaces defined by this model –>
   <namespaces>
      <namespace uri="http://www.mycompany.com/model/content/1.0" prefix="mnt"/>
   </namespaces>
  
   <types>
      <type name="mnt:resource">
         <title>Document</title>
         <parent>nt:resource</parent>
         <properties>
            <property name="jcr:name">
               <title>Filename</title>
               <description>name of the document</description>
               <type>d:text</type>
            </property>
            <property name="jcr:createdDate">
               <title>Created</title>
               <description>date of creation</description>
               <type>d:date</type>
            </property>
            <property name="jcr:lastModifiedDate">
               <title>Last Modified</title>
               <description>last time a modification has been made</description>
               <type>d:date</type>
            </property>
            <property name="jcr:type">
               <title>Type</title>
               <description>type of the document</description>
               <type>d:text</type>
            </property>
            <property name="jcr:extension">
               <title>Extension</title>
               <description>extension of the document</description>
               <type>d:text</type>
            </property>
            <property name="jcr:owner">
               <title>Owner</title>
               <description>owner of the document</description>
               <type>d:text</type>
            </property>
            <property name="jcr:ownerMail">
               <title>Owner E-mail</title>
               <description>e-mail of the owner of the document</description>
               <type>d:text</type>
            </property>
            <property name="jcr:title">
               <title>Title</title>
               <description>title of the document</description>
               <type>d:text</type>
            </property>
            <property name="jcr:from">
               <title>From</title>
               <description>sender of the document</description>
               <type>d:text</type>
            </property>
            <property name="jcr:fromMail">
               <title>From</title>
               <description>e-mail of the sender of the document</description>
               <type>d:text</type>
            </property>
            <property name="jcr:to">
               <title>To</title>
               <description>recipient of the document</description>
               <type>d:text</type>
            </property>
            <property name="jcr:toMail">
               <title>To</title>
               <description>e-mail of the recipient of the document</description>
               <type>d:text</type>
            </property>
            <property name="jcr:text">
               <title>Text</title>
               <description>content of the document</description>
               <type>d:text</type>
            </property>
            <property name="jcr:xPath">
               <title>Xpath</title>
               <description>xpath of the document</description>
               <type>d:text</type>
            </property>
            <property name="jcr:timeStamp">
               <title>Timestamp</title>
               <description>JCR-managed timestamp of the document</description>
               <type>d:text</type>
            </property>
            <property name="jcr:flag">
               <title>Flag</title>
               <description>JCR-managed flag of the document</description>
               <type>d:text</type>
            </property>
            <property name="jcr:path">
               <title>Location</title>
               <description>Absolute path of the document</description>
               <type>d:text</type>
            </property>
            <property name="jcr:indexable">
               <title>Indexable</title>
               <description>specify if the content can be indexed</description>
               <type>d:text</type>
            </property>
            <property name="jcr:documentation">
               <title>Documentation</title>
               <description>the content of the documentation file</description>
               <type>d:any</type>
            </property>
            <property name="jcr:thar">
               <title>Thar file</title>
               <description>the content of the thar file</description>
               <type>d:any</type>
            </property>
         </properties>
      </type>
      
      <type name="mnt:file">
         <title>File</title>
         <parent>nt:file</parent>
         <associations>
            <child-association name="cm:containsFiles">
               <source>
                 <mandatory>false</mandatory>
                 <many>false</many>
               </source>
               <target>
                 <class>nt:file</class>
                 <mandatory>false</mandatory>
                 <many>true</many>
               </target>
               <duplicate>true</duplicate>
               <propagateTimestamps>true</propagateTimestamps>
            </child-association>
            <child-association name="cm:containsAttachment">
               <source>
                 <mandatory>false</mandatory>
                 <many>false</many>
               </source>
               <target>
                 <class>mnt:fileP</class>
                 <mandatory>false</mandatory>
                 <many>true</many>
               </target>
               <duplicate>false</duplicate>
               <propagateTimestamps>true</propagateTimestamps>
            </child-association>         
         </associations>
      </type>
      
      <type name="mnt:folder">
         <title>Folder</title>
         <parent>nt:folder</parent>
         <associations>
            <child-association name="cm:containsCustomFiles">
               <source>
                 <mandatory>false</mandatory>
                 <many>false</many>
               </source>
               <target>
                 <class>mnt:file</class>
                 <mandatory>false</mandatory>
                 <many>true</many>
               </target>
               <duplicate>false</duplicate>
               <propagateTimestamps>true</propagateTimestamps>
            </child-association>
            <child-association name="cm:containsAttachment">
               <source>
                 <mandatory>false</mandatory>
                 <many>false</many>
               </source>
               <target>
                 <class>mnt:fileP</class>
                 <mandatory>false</mandatory>
                 <many>true</many>
               </target>
               <duplicate>false</duplicate>
               <propagateTimestamps>true</propagateTimestamps>
            </child-association>
            <child-association name="cm:containsResources">
               <source>
                 <mandatory>false</mandatory>
                 <many>false</many>
               </source>
               <target>
                 <class>mnt:resource</class>
                 <mandatory>false</mandatory>
                 <many>true</many>
               </target>
               <duplicate>false</duplicate>
               <propagateTimestamps>true</propagateTimestamps>
            </child-association>
         </associations>
      </type>
      
      <type name="mnt:folderExchange">
         <title>Folder</title>
         <parent>nt:folder</parent>
         <associations>
            <child-association name="cm:containsMntFiles">
               <source>
                 <mandatory>false</mandatory>
                 <many>false</many>
               </source>
               <target>
                 <class>mnt:file</class>
                 <mandatory>false</mandatory>
                 <many>true</many>
               </target>
               <duplicate>false</duplicate>
               <propagateTimestamps>true</propagateTimestamps>
            </child-association>
            <child-association name="cm:containsAttachment">
               <source>
                 <mandatory>false</mandatory>
                 <many>false</many>
               </source>
               <target>
                 <class>mnt:fileP</class>
                 <mandatory>false</mandatory>
                 <many>true</many>
               </target>
               <duplicate>false</duplicate>
               <propagateTimestamps>true</propagateTimestamps>
            </child-association>
            <child-association name="cm:containsResources">
               <source>
                 <mandatory>false</mandatory>
                 <many>false</many>
               </source>
               <target>
                 <class>mnt:resource</class>
                 <mandatory>false</mandatory>
                 <many>true</many>
               </target>
               <duplicate>false</duplicate>
               <propagateTimestamps>true</propagateTimestamps>
            </child-association>
         </associations>
      </type>
      
      <type name="mnt:folderDirectory">
         <title>Folder</title>
         <parent>nt:folder</parent>
         <associations>
            <child-association name="cm:containsMntFiles">
               <source>
                 <mandatory>false</mandatory>
                 <many>false</many>
               </source>
               <target>
                 <class>mnt:file</class>
                 <mandatory>false</mandatory>
                 <many>true</many>
               </target>
               <duplicate>false</duplicate>
               <propagateTimestamps>true</propagateTimestamps>
            </child-association>
            <child-association name="cm:containsAttachment">
               <source>
                 <mandatory>false</mandatory>
                 <many>false</many>
               </source>
               <target>
                 <class>mnt:fileP</class>
                 <mandatory>false</mandatory>
                 <many>true</many>
               </target>
               <duplicate>false</duplicate>
               <propagateTimestamps>true</propagateTimestamps>
            </child-association>
            <child-association name="cm:containsResources">
               <source>
                 <mandatory>false</mandatory>
                 <many>false</many>
               </source>
               <target>
                 <class>mnt:resource</class>
                 <mandatory>false</mandatory>
                 <many>true</many>
               </target>
               <duplicate>false</duplicate>
               <propagateTimestamps>true</propagateTimestamps>
            </child-association>
            <child-association name="cm:containsFolderExchange">
               <source>
                 <mandatory>false</mandatory>
                 <many>false</many>
               </source>
               <target>
                 <class>mnt:folderExchange</class>
                 <mandatory>false</mandatory>
                 <many>true</many>
               </target>
               <duplicate>false</duplicate>
               <propagateTimestamps>true</propagateTimestamps>
            </child-association>
            <child-association name="cm:containsCustomFolders">
               <source>
                 <mandatory>false</mandatory>
                 <many>false</many>
               </source>
               <target>
                 <class>mnt:folder</class>
                 <mandatory>false</mandatory>
                 <many>true</many>
               </target>
               <duplicate>false</duplicate>
               <propagateTimestamps>true</propagateTimestamps>
            </child-association>
         </associations>
      </type>
      
      <type name="mnt:fileP">
         <title>Attachment</title>
         <parent>nt:file</parent>
         <associations>
            <child-association name="cm:containsFiles">
               <source>
                 <mandatory>false</mandatory>
                 <many>false</many>
               </source>
               <target>
                 <class>nt:file</class>
                 <mandatory>false</mandatory>
                 <many>true</many>
               </target>
               <duplicate>true</duplicate>
               <propagateTimestamps>true</propagateTimestamps>
            </child-association>
            <child-association name="cm:containsAttachment">
               <source>
                 <mandatory>false</mandatory>
                 <many>false</many>
               </source>
               <target>
                 <class>mnt:fileP</class>
                 <mandatory>false</mandatory>
                 <many>true</many>
               </target>
               <duplicate>false</duplicate>
               <propagateTimestamps>true</propagateTimestamps>
            </child-association>         
         </associations>
      </type>      
   </types>
</model>

J'ai une question supplémentaire concernant le modèle. A quoi correspondent les groupes source et target ainsi que leurs options respectives dans les associations? Est-ce qu'il existe une documentation contenant le détail de toutes les options possibles ?

Merci Smiley Happy
ethan
Member II

Re: pb pour enregistrer un custom model dans le Repository

Salut

J'ai fini par résoudre mon problème. J'ai repris la structure exacte du projet SDK FirstJCRClient ainsi que le contenu des fichiers de modèle et de context et cette fois c'est passé. D'autre part, il semble qu'Alfresco ne prenne pas en charge certains modèles pré-conçus par la norme JSR-170 tels que nt:file ou nt:folder. Du coup mon modèle ne pouvait pas fonctionner.
arkantos
Member II

Re: pb pour enregistrer un custom model dans le Repository

Bonjour,

  Je me demande pourquoi vous avez utilisé  <import uri="http://www.jcp.org/jcr/nt/1.0" prefix="nt"/> dans votre Model de données pour exploiter les propriétés telles que   <property name="jcr:lastModifiedDate">   ou  <property name="jcr:createdDate">, puisque ce genre de traitement est géré  intuitivement par le biais des Aspects, en l'occurrence l'aspect auditable ???  :?:

Bonne continuation
ethan
Member II

Re: pb pour enregistrer un custom model dans le Repository

Je les ai intégrées à mon modèle parce que je voulais copier un modèle utilisé dans une autre application. Mon but était de transférer le contenu d'un repository Jackrabbit dans le repository Alfresco. J'ai essayé de reproduire le même modèle à l'identique. Mais je me suis arrangé autrement Smiley Happy J'ai crée un nouveau modèle et je copie les propriétés des noeuds de mon repository jackrabbit une par une dans des noeuds basés sur ce nouveau modèle et je les insère dans alfresco.

Le problème avec l'aspect cm:auditable, c'est que les dates sont fixées par le système et sont définies à la date du jour de l'import dans Alfresco. Elle ne sont pas modifiables. Moi j'ai besoin d'afficher la vraie date de création des fichiers. Donc j'ai ajouté dans mon modèle mon propre aspect auditable, avec des dates modifiables Smiley Happy