AnsweredAssumed Answered

constraint error

Question asked by lazaro on Feb 18, 2013
Latest reply on Feb 18, 2013 by lazaro
Hi, I'm trying to create a list to access a table in a database and II have found that does not work.
Step as I have done everything step by step

First I have created a class and have exported. jar and put it in webapps/alfresco/WEB-INF/lib
in case you missed the access to the database I have done a simulation manually adding items to the list

package com.tecnausa.meconecto;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;

import java.util.List;
import javax.faces.model.SelectItem;
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;
public class ListOfValuesQueryConstraint extends ListOfValuesConstraint implements Serializable{

   @SuppressWarnings("unused")
   private static Log logger = LogFactory.getLog(BaseComponentGenerator.class);
   private static final long serialVersionUID=1;
   private List<String> allowedLabels;
   @SuppressWarnings("unchecked")
   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.postgresql.Driver";
        String serverName = "localhost";
        String mydatabase = "alfresco";
        String username = "alfresco";
        String password = "admin";
        String port = "5432";
        */
        List<String> av = new ArrayList<String>();
        List<String> al=new ArrayList<String>();
        av.add("av1");
        av.add("av2");
        av.add("av3");
        /*
        try {
           Connection connection = null;
            Class.forName(driverName);
            String url = "jdbcsmileyostgresql://" + serverName + ":"+ port + "/" + mydatabase;
            connection = DriverManager.getConnection(url, username, password);
            Statement stmt = connection.createStatement();
            ResultSet rs = stmt.executeQuery("select mi_id from t_equipos"smiley;
            while (rs.next()) {
                   av.add(rs.getString("JMBG"smiley);
               }
        }
        catch (Exception e) {}

        */
    }
}

later, I based in share-sample-DataLists for me here on my own I got it http://code.google.com/p/share-extras/wiki/DataLists
Basically what I have done is unzip the. jar and re-tune it compressed into jar, so that has been so

……
<constraints>
      <constraint name="dlexample:l01" type="LIST">
         <parameter name="allowedValues">
            <list>
               <value>Equipo de red</value>
               <value>Impresora</value>
               <value>Ordenador PC</value>
            </list>
         </parameter>
      </constraint>
      <constraint name="dlexample:l02" type="com.tecnausa.meconecto.ListOfValuesQueryConstraint"></constraint>
    </constraints>
   <types>

      <type name="dlexample:book">
          ….
            <property name="dlexample:lista1">
               <title>lista1</title>
               <type>d:text</type>
               <constraints>
           <constraint ref="dlexample:l01" />
               </constraints>
            </property>
        ….

when I change the line <constraint ref="dlexample:l01" /"> by <"constraint ref =" dlexample: l02 "/>
alfresco completely stops working

sorry for my english, is terribly wrong
Thanks

Outcomes