AnsweredAssumed Answered

Custom Action

Question asked by fougnawa on Jun 2, 2009
Latest reply on Jun 4, 2009 by landry_2530
Bonjour ,
Je suis entrain de développer une action qui vise à générer un PDF qui contient des donnés d'une base que j'ai déjà créée. c'est donnés sont identifié par un ID que je récupère depuis un fichier html que je crée pour faire le test dans le meme espace. En fait la création du fichier HTML c'est elle qui declanche l'action.
donc j'ai généré le jar depuis mon projet et je l'ai mis dans "WEB-INF\lib" , en plus j'ai créé un XML que j'ai placé dans C:\Alfresco\tomcat\shared\classes\alfresco\extension. Mais lors ce que je lance ALFRESCO le msg d'erreur survient:
Etat HTTP 404 -

type Rapport d'�tat

message

description La ressource demand�e () n'est pas disponible.
Apache Tomcat/6.0.18

Le code de ma classe JAVA est  ActionApogee.java:
package org.teggoinfo.alfresco.bdintegration.action;

import java.awt.Color;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.sql.ResultSet;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.cmr.security.AuthenticationService;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.TempFileProvider;
import org.apache.axis.security.AuthenticatedUser;
import org.teggoinfo.alfresco.bdintegration.BDConnection;

import com.lowagie.text.BadElementException;
import com.lowagie.text.Cell;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.HeaderFooter;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.Table;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;

import de.schlichtherle.io.FileOutputStream;

public class ActionApogee extends ActionExecuterAbstractBase
{
   private ContentService contentService;
   private SearchService searchService;
   private NodeService nodeService;
   
   




   public static HeaderFooter createHeader() {
      Paragraph para = new Paragraph();
      para.add("Facture");
      HeaderFooter header = new HeaderFooter(para,false);
      header.setAlignment(HeaderFooter.ALIGN_CENTER);
      return header;
   }
   


   
   public static Cell ajoutEnseignement(String cours,String prof, String salle, int type, int heure) {
      Cell cell = new Cell("");
      Paragraph p = new Paragraph();
      p.add(cours +"\n"+prof+"\n"+salle);
      cell.add(p);
      cell.setColspan(type);
      cell.setRowspan(heure/2);
      cell.setHorizontalAlignment(Cell.ALIGN_CENTER);
      cell.setVerticalAlignment(Cell.ALIGN_CENTER);
      return cell;
   }
   
   public static Table createTable(int debut) throws BadElementException {
      String sFin = Integer.toString(debut+4);
      Table table = new Table(11);
      table.setBorderWidth(2);
      table.setBorderColor(new Color(0, 0, 255));
      table.setPadding(5);
      table.setSpacing(3);
      Cell cell = createCell("Semaine du "+debut+" au "+ sFin +" décembre",11);
      table.addCell(cell);
      cell = createCell("Jours\n/\nHeure",1);       
      table.addCell(cell);
      cell=createCell("Lundi "+Integer.toString(debut),2);
      table.addCell(cell);
      cell=createCell("Mardi "+Integer.toString(debut+1),2);
      table.addCell(cell);
      cell=createCell("Mercredi "+Integer.toString(debut+2),2);
      table.addCell(cell);
      cell=createCell("Jeudi "+Integer.toString(debut+3),2);
      table.addCell(cell);
      cell= createCell("Vendredi "+Integer.toString(debut+4),2);
      table.addCell(cell);
      return table;
   }

   private static Cell createCell(String sCell, int colspan) {
      Cell cell = new Cell(sCell);
      cell.setColspan(colspan);
      cell.setHorizontalAlignment(Cell.ALIGN_CENTER);
      cell.setVerticalAlignment(Cell.ALIGN_CENTER);
      return cell;
   }

   private File genererFacture(ResultSet res, ResultSet res_client,String id)
   {   Document document = new Document(PageSize.A4);
      File tmp = TempFileProvider.createTempFile("fact_", ".pdf");
        try
        {   PdfWriter.getInstance(document, new FileOutputStream(tmp));
            document.open();
           
            float[] colsWidth1 = {1f,2f};
          PdfPTable table1 = new PdfPTable(colsWidth1);
          table1.setWidthPercentage(60);
           
          /*PdfPCell c11 = new PdfPCell(new Paragraph("Client"));
          table1.addCell(c11);
          
          res_client.next();
           
          table1.addCell(res.getString(1));
            c11 = new PdfPCell(new Paragraph("Adresse Client"));
            table1.addCell(c11);
            table1.addCell(res.getString(2));
            c11 = new PdfPCell(new Paragraph("Facture"));
            table1.addCell(c11);
            table1.addCell(res.getString(3));
            c11 = new PdfPCell(new Paragraph("Date de la facture"));
            table1.addCell(c11);
            table1.addCell(res.getString(4));
           
            */
          
            float[] colsWidth = {4f,1f,1f,1f};
          PdfPTable table = new PdfPTable(colsWidth);
          table.setWidthPercentage(90);
          table.setHorizontalAlignment(Element.ALIGN_LEFT);

          PdfPCell c = new PdfPCell(new Paragraph("Désignation"));
          c.setBackgroundColor(new Color(210,210,210));
            table.addCell©;
           
            PdfPCell c1 = new PdfPCell(new Paragraph("Quantité"));
          c1.setBackgroundColor(new Color(210,210,210));
            table.addCell(c1);
           
            PdfPCell c2 = new PdfPCell(new Paragraph("Prix Unitaire"));
          c2.setBackgroundColor(new Color(210,210,210));
            table.addCell(c2);
           
            PdfPCell c3 = new PdfPCell(new Paragraph("Montant"));
          c3.setBackgroundColor(new Color(210,210,210));
            table.addCell(c3);
            int total=0;
            while(res.next())
            {   table.addCell(res.getString(1));
                table.addCell(res.getString(2));
                table.addCell(res.getString(3));
                table.addCell(res.getString(4));
                total = total + res.getInt(4);
            }
           
            PdfPCell c4 = new PdfPCell(new Paragraph("Total"));
          c4.setBackgroundColor(new Color(210,210,210));
          c4.setHorizontalAlignment(Cell.ALIGN_RIGHT);
          c4.setColspan(3);
            table.addCell(c4);
           
            c3 = new PdfPCell(new Paragraph(""+total));
            table.addCell(c3);

            document.add(table1);
            document.add(table);
        }
        catch(DocumentException de) {
            System.err.println(de.getMessage());
        }
        catch(IOException ioe) {
            System.err.println(ioe.getMessage());
        }
        catch (Exception e) {

      }

        document.close();
        System.out.println("Document  generated");
        return tmp;

   }
   public static void main(String[] args) {
      
      Document document = new Document(PageSize.A4);
             
         try {   File tmp = TempFileProvider.createTempFile("fact_", ".pdf");
                  PdfWriter.getInstance(document, new FileOutputStream(tmp));
                               
                  document.open();
                
                  document.add(new Phrase("Hello World"));
                
              }
              catch(DocumentException de) {
                  System.err.println(de.getMessage());
              }
              catch(IOException ioe) {
                  System.err.println(ioe.getMessage());
              }
              // etape 5: Fermeture du document
              document.close();
              System.out.println("Document  generated");
         }
      
   
   protected void executeImpl(Action action, NodeRef actionedUponNodeRef)
   {   
      
      
      
      
      ContentReader cr = contentService.getReader(actionedUponNodeRef,ContentModel.TYPE_CONTENT );
      String contenu = cr.getContentString();
      
      String req = "select * "+
                  " from indi "+
                  " where       id ="+contenu+
                  ;
      
      String req_client = "select *"+
                     " from indi "+
                     " where id ="+contenu+
                     " and nom='ayoub'";
      
      File pdf = null;
      Connection con= null;
      Statement st= null;
      
      try
      {   
         String url = "jdbc:mysql://127.0.0.1:3306/rvn";
               String user = "root";
               String password = "";
               String driver = "com.mysql.jdbc.Driver";
              
               //Charger le driver
               Class.forName(driver).newInstance();
               //se connecter
               conn = DriverManager.getConnection(url,user,password);
              
         ResultSet res = dbc.selectReq(req);
         ResultSet res_client = dbc.selectReq(req_client);
         pdf = genererFacture(res, res_client,contenu);
      }
      catch (Exception e) {
      }
      
      StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
      org.alfresco.service.cmr.search.ResultSet resultSet = searchService.query(storeRef, SearchService.LANGUAGE_LUCENE, "PATH:\"/app:company_home/cm:CFAO\"");
      
      System.out.println(resultSet.getNodeRef(0));
      
        NodeRef companyHome = resultSet.getNodeRef(0);
       
       
        String name_pdf = "RVN_"+contenu+".pdf";
       
        Map<QName, Serializable> contentProps1 = new HashMap<QName, Serializable>();
       
        contentProps1.put(ContentModel.PROP_NAME, name_pdf);
       
       
        ChildAssociationRef association1 = nodeService.createNode(companyHome,
              ContentModel.ASSOC_CONTAINS,
              QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, name_pdf),
                ContentModel.TYPE_CONTENT,
                contentProps1);
        NodeRef content1 = association1.getChildRef();
       
        ContentWriter writer1 = contentService.getWriter(content1, ContentModel.PROP_CONTENT, true);
        writer1.setMimetype(MimetypeMap.MIMETYPE_PDF);
        writer1.setEncoding("UTF-8");
        writer1.putContent(pdf);
       
       
      
   }
   
   protected void addParameterDefinitions(List<ParameterDefinition> paramList)
   {
   }

   public void setContentService(ContentService contentService) {
      this.contentService = contentService;
   }

   public void setSearchService(SearchService searchService) {
      this.searchService = searchService;
   }

   public void setNodeService(NodeService nodeService) {
      this.nodeService = nodeService;
   }
   
}

Le XML bdintergration-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="bd_integration" class="org.alfresco.sample.ActionApogee" parent="action-executer" >
      <property name="nodeService">
         <ref bean="nodeService" />
      </property>
      <property name="contentService">
         <ref bean="contentService" />
      </property>
      <property name="searchService">
         <ref bean="searchService" />
      </property>
   </bean>
   
</beans>

Je ne sais pas d'où vient l'erreur . Votre aide est vivement convoité.
                             Merci d'avance.

Outcomes