cancel
Showing results for 
Search instead for 
Did you mean: 

Bonjour à Tous et à Toutes,J'utilise actuellement...

xantrax
Champ in-the-making
Champ in-the-making
Bonjour à Tous et à Toutes,

J'utilise actuellement Alfresco 2.0 sous windows avec Mysql,Tomcat 5.5 et le JDK 1.5

J'ai créé une nouvelle classe qui hérite de la classe
org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint
Cette classe me permet d'aller chercher dans une nouvelle instance mysql les données contenues dans une table, mettre ces données dans une ArrayList et de passer cette liste à la méthode
setAllowedValues
de la classe héritée. De cette manière je peux bénéficier d'une contrainte de type LIST dynamique. Voici le code de ma classe

package be.test.alfresco.constraint;

import java.sql.Connection;
import java.util.ArrayList;

import org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint;
import org.apache.commons.logging.Log;[quote]import org.apache.commons.logging.LogFactory;

import be.test.alfresco.utility.db.DbUtils;
import be.test.alfresco.utility.db.SqlHelper;

public class ListCiviliteConstraint extends ListOfValuesConstraint {
   private static Log logger = LogFactory.getLog("be.nsi.alfresco.constraint.DbUtils");
   
   public ListCiviliteConstraint() {
      super();
      super.setAllowedValues(getCivilite());
   }
   
   /**
    * Va rechercher la liste des Civilites dans la base de donnée
    * @return la liste des Civilites
    */
   private ArrayList getCivilite(){
      ArrayList civilites=null;
      Connection conn=null;
      
      try {
         conn = DbUtils.getDbConnection();
         civilites = SqlHelper.getAllCivilitesType(conn);
          DbUtils.closeDbConnection(conn);
      } catch (Exception e) {
         logger.error(e.getMessage());
      }[/quote]
return civilites;
   }

}
Aprés avoir testé (avec une classe test) cette classe tout fonctionne correctement.

C'est maintenant que cela ce complique Smiley Happy

J'ai un fichier customModel.xml dans lequel :

Je défini ma contrainte comme ceci

<constraints>
      [b]<constraint name="Identification:ctrCivilite" type="be.test.alfresco.constraint.ListCiviliteConstraint">
      </constraint>[/b]
   </constraints>
J’applique cette contrainte sur un custom aspect
<aspect name="Identification:Personne">
         <title>Identification Personne</title>

         <properties>
            <property name="Identification:Civilite">
               <title>Civilite</title>

               <type>d:text</type>

               <constraints>
                  [b]<constraint ref="Identification:ctrCivilite" />[/b]
               </constraints>
                ………
            </property>
Je génère un jar avec mes nouvelles classes que je place dans le répertoire
webappsalfrescoWEB-INFlib
de tomcat

Je démarre Alfresco et la j'obtiens le message suivant dans le log file
org.alfresco.service.cmr.dictionary.DictionaryException: Constraint type 'be.test.alfresco.constraint.ListCiviliteConstraint' on constraint 'Identification:ctrCivilite' is not a well-known type or a valid Constraint implementation
   at org.alfresco.repo.dictionary.M2ConstraintDefinition.resolveInternal(M2ConstraintDefinition.java:176)
   at org.alfresco.repo.dictionary.M2ConstraintDefinition.resolveDependencies(M2ConstraintDefinition.java:117)
   at org.alfresco.repo.dictionary.CompiledModel.<init>(CompiledModel.java:107)
On dirait que ma nouvelle classe n'a pas été correctement déployée.

Si quelqu'un à une idée il est le bien venu Smiley Wink

Merci d'avance
12 REPLIES 12

kbonnet
Champ in-the-making
Champ in-the-making
Svp excusez moi pour ne pas parler Francais.

Dear French Alfresco users,

I run into the same error message as the one above:


Constraint type 'org.contezza.customConstraints.ListOfValuesQueryConstraint' on constraint 'test:CodeLabel' is not a well-known type or a valid Constraint implementation

This is the only place on the internet on which this error is discussed. I also would like a custom constraint like you are making here.

I was able to get the java code compiled with javac against the Alfresco SDK. The result was a compiled .class file. I was not sure where to put it, so i put it in a new "classes" directory in my extensions root.

Next i created a test model, again based on the example i found, and i set the "type" parameter to my package name in the java code, extended with the name of the public class in the java code. In my case "org.contezza.customConstraints.ListOfValuesQueryConstraint".

Of course it did something wrong. When i try to deploy the model (it's a dynamic model in the data dictionary/models folder) i get the error message in the logging "Constraint type 'org.contezza.customConstraints.ListOfValuesQueryConstraint' on constraint 'test:CodeLabel' is not a well-known type or a valid Constraint implementation".

Because i was able to compile the java code against the SDK without error, i think this error has to do with the place i put the class file in. Can anyone give me a push into the right direction?

My environment is:
- Ubuntu 7.04
- Tomcat 5.5
- JDK 1.5
- MySQL 5

My (example) java code is as follows:


package org.contezza.customConstraints;

import java.util.ArrayList;
import java.util.List;
import java.sql.*;
//import org.alfresco.i18n.I18NUtil;
import org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint;
import org.alfresco.web.bean.generator.BaseComponentGenerator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.Serializable;
import javax.faces.model.SelectItem;

public class ListOfValuesQueryConstraint extends ListOfValuesConstraint implements Serializable {

   private static Log logger = LogFactory.getLog(BaseComponentGenerator.class);

   private static final long serialVersionUID=1;

   private List<String> allowedLabels;

   public void setAllowedValues(List allowedValues) {}
   public void setCaseSensitive(boolean caseSensitive) {}

   public void initialize() {
       super.setCaseSensitive(false);
       this.loadDB();
    }

   public List<String> getAllowedLabels() {
      return this.allowedLabels;
   }

   public void setAllowedLabels(List<String> allowedLabels) {
      this.allowedLabels=allowedLabels;
   }

    public List<SelectItem> getSelectItemList() {
      List<SelectItem> result = new ArrayList<SelectItem>(this.getAllowedValues().size());
      for(int i=0;i<this.getAllowedValues().size();i++) {
         result.add(new SelectItem((Object)this.getAllowedValues().get(i),this.allowedLabels.get(i)));
      }
      return result;
   }

    protected void loadDB() {

       String driverName = "org.gjt.mm.mysql.Driver";
        String serverName = "localhost";
        String mydatabase = "alfresco";
        String username = "alfresco";
        String password = "alfresco";

        List<String> av = new ArrayList<String>();
        List<String> al=new ArrayList<String>();


        try {
           Connection connection = null;
            Class.forName(driverName);
            String url = "jdbc:mysql://" + serverName +  "/" + mydatabase;
            connection = DriverManager.getConnection(url, username, password);
            Statement stmt = connection.createStatement();
            ResultSet rs = stmt.executeQuery("select code,label from codelabel");
            while (rs.next()) {
                av.add(rs.getString("code"));
                al.add(rs.getString("label"));
            }
        }
        catch (Exception e) {}

      super.setAllowedValues(av);
      this.setAllowedLabels(al);
   }
}

My example model is as follows:

<?xml version="1.0" encoding="UTF-8"?>

<model name="test:test" xmlns="http://www.alfresco.org/model/dictionary/1.0">
   <description></description>
   <author>Contezza InformatieManagement</author>
   <version>0.1</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" />
   </imports>
   <namespaces>
      <namespace uri="http://www.contezza.nl/model/test/1.0" prefix="test" />
   </namespaces>


<constraints>
   <constraint name="test:CodeLabel" type="org.contezza.customConstraints.ListOfValuesQueryConstraint">
      <parameter name="allowedValues">
         <list>
         </list>
      </parameter>
   <parameter name="caseSensitive"><value>true</value></parameter>
</constraint>
   </constraints>
  
   <types>
      <type name="test:codecontent">
         <title>Contenu étendu</title>
         <parent>cm:content</parent>
         <properties>
            <property name="test:codestr">
               <title>Code str</title>
               <type>d:text</type>
               <constraints>
                  <constraint ref="test:CodeLabel" />
               </constraints>
            </property>
         </properties>
      </type>
   </types>
</model>

Could you please give me a push into the right direction? If you prefer to answer in French, i think i will be able to read or translate it!

Merci beaucoup!

Koen Bonnet
Pays-Bas

kbonnet
Champ in-the-making
Champ in-the-making
Salut France,

I posted my question also on the english speaking forum. The problem is solved. You can read the replies at the english forum:
http://forums.alfresco.com/viewtopic.php?f=4&t=11687&p=38710#p38710

Merci beaucoup!

Koen Bonnet

michaelh
Champ on-the-rise
Champ on-the-rise
Hi Koen,

Since we did absolutely nothing on the French side, don't mention it Smiley Happy
Anyway, it's good to see that your problem is now solved. Thanks for the feedback !

Cheers,
Getting started

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.