Bonjour à tous,

Voilà en ce moment j'essaye de modifier un rapport qui existe déjà en ajoutant une data, data set et table, en se basant sur le code suivant:


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
 
 
import java.io.IOException;
import java.util.ArrayList; 
import java.util.List;
 
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.model.api.CellHandle;
import org.eclipse.birt.report.model.api.DataItemHandle;
import org.eclipse.birt.report.model.api.DesignConfig; 
import org.eclipse.birt.report.model.api.ElementFactory;
import org.eclipse.birt.report.model.api.IDesignEngine;
import org.eclipse.birt.report.model.api.IDesignEngineFactory;
import org.eclipse.birt.report.model.api.LabelHandle;
import org.eclipse.birt.report.model.api.OdaDataSetHandle;
import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
import org.eclipse.birt.report.model.api.PropertyHandle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.RowHandle;
import org.eclipse.birt.report.model.api.SessionHandle;
import org.eclipse.birt.report.model.api.StructureFactory;
import org.eclipse.birt.report.model.api.TableHandle;
import org.eclipse.birt.report.model.api.activity.SemanticException;
import org.eclipse.birt.report.model.api.elements.structures.ComputedColumn;
 
import com.ibm.icu.util.ULocale;
import com.sun.xml.internal.ws.client.SenderException;
import com.sun.xml.internal.ws.org.objectweb.asm.Label;
 
 
public class DECreateDynamicTable {
 
    /**
     * @param args
     */
    org.eclipse.birt.report.model.api.elements.structures.ComputedColumn cs1 = null;
    ReportDesignHandle designHandle = null;
    ElementFactory designFactory = null;
    StructureFactory structFactory = null;
 
    public static void main(String[] args) {
         try
           {
             DECreateDynamicTable de = new DECreateDynamicTable();
               ArrayList al = new ArrayList();
               al.add("campagne");
               al.add("rem");
               de.buildReport(al, "FROM  `DataBase`.REMUNERATION" );
           }
         catch(IOException e)
         {
             e.printStackTrace();
         }
         catch( SemanticException e)
         {
             e.printStackTrace();
         }
 
    }
    //Construire la DataSource
    void buildDataSource( ) throws SemanticException
       {
        OdaDataSourceHandle dsHandle = designFactory.newOdaDataSource( "Data Source", "org.eclipse.birt.report.data.oda.jdbc" );
        dsHandle.setProperty( "odaDriverClass","com.mysql.jdbc.Driver");
        dsHandle.setProperty( "odaURL", "jdbc:mysql://localhost:3306/DataBase" );
        dsHandle.setProperty( "odaUser", "root" );
        dsHandle.setProperty( "odaPassword", "" );
 
           designHandle.getDataSources( ).add( dsHandle );
       }
 
    //Construire la DataSet
    void buildDataSet(ArrayList cols, String fromClause ) throws SemanticException
       {
        OdaDataSetHandle dsHandle = designFactory.newOdaDataSet("ds",
                "org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet");
           dsHandle.setDataSource( "Data Source" );
           String qry = "SELECT `campagne`,  `rem` FROM  `DataBase`.REMUNERATION ";
           for( int i=0; i < cols.size(); i++)
           {
               qry += " " + cols.get(i);
 
               if( i != (cols.size() -1) )
               {
                   qry += ",";
               }        
           }
 
           qry += " " + fromClause;        
           dsHandle.setQueryText( qry );
 
           designHandle.getDataSets( ).add( dsHandle );    
       }
 
 
     //Fonction permettant la contruction du rapport
 
     void buildReport(ArrayList cols, String fromClause ) throws IOException, SemanticException
     {
         //Configure the Engine and start the Platform
         DesignConfig config = new DesignConfig();
 
         config.setProperty("BIRT_HOME", "C:/Users/..../Downloads/birt-runtime-4_2_2/birt-runtime-4_2_2/ReportEngine");
         IDesignEngine engine = null;
 
         try
         {
             Platform.startup(config);
             IDesignEngineFactory factory = (IDesignEngineFactory) Platform.createFactoryObject(IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY);
             engine = factory.createDesignEngine(config);
         }
         catch(Exception ex)
         {
             ex.printStackTrace();
         }
 
         //Open session engine
 
         SessionHandle session = engine.newSessionHandle(ULocale.ENGLISH);
 
         try
         {
 
             //open a design or a template
 
             designHandle = session.openDesign("C:/Tomcat7/apache-tomcat-6.0.37/webapps/report/CA.rptdesign");
 
             designFactory = designHandle.getElementFactory();
 
             buildDataSource();
             buildDataSet(cols, fromClause);
 
             TableHandle table = designFactory.newTableItem("table", cols.size());
             table.setWidth("100%");
             table.setDataSet(designHandle.findDataSet("ds"));
 
             PropertyHandle computedSet = table.getColumnBindings();
             ComputedColumn cs1 = null;
 
            //Parametrages des colonnes data set
            for(int i=0; i<cols.size(); i++)
            {
                cs1 = StructureFactory.createComputedColumn();
                cs1.setName((String) cols.get(i));
                cs1.setExpression("dataSetRow[\""+ (String)cols.get(i)+"\"]");
                computedSet.addItem(cs1);    
 
            }
 
            //table header
            RowHandle tableheader = (RowHandle) table.getHeader().get(0);
 
            for (int i=0; i<cols.size(); i++)
            {
 
            LabelHandle label1 = designFactory.newLabel( (String) cols.get(i));
            label1.setText((String)cols.get(i));
            CellHandle cell = (CellHandle) tableheader.getCells().get(i);
            cell.getContent().add(label1);
 
            }
 
            //table detail
            RowHandle tabledetail = (RowHandle) table.getDetail().get(0);
 
            for(int i=0; i< cols.size(); i++)
            {
                CellHandle cell = (CellHandle) tabledetail.getCells().get(i);
                DataItemHandle data = designFactory.newDataItem("data_"+(String)cols.get(i));
                data.setResultSetColumn((String)cols.get(i));
                cell.getContent().add(data);    
 
            }
 
            designHandle.getBody().add(table);
 
            //Save the design and close it
 
            designHandle.saveAs("C:/Tomcat7/apache-tomcat-6.0.37/webapps/report/DynamicReport.rptdesign");
            designHandle.close();
            System.out.println("Finished");     
 
         }
         catch (Exception e)
         {
             e.printStackTrace();
         }
 
 
     }
}
Mon code s'execute sans aucun problème mais lorsque je l'execute sur mon serveur Tomcat, il génére l'erreur suivante:



Multiple exceptions occurred

rg.eclipse.birt.report.engine.api.EngineException: Failed to find out data source of data set "ds".
at org.eclipse.birt.report.engine.executor.ExecutionContext.addException(ExecutionContext.java:1239)
at org.eclipse.birt.report.engine.data.dte.AbstractDataEngine.prepare(AbstractDataEngine.java:154)
at org.eclipse.birt.report.engine.executor.ReportExecutor.execute(ReportExecutor.java:122)
at org.eclipse.birt.report.engine.internal.executor.wrap.WrappedReportExecutor.execute(WrappedReportExecutor.java:60)
at org.eclipse.birt.report.engine.internal.executor.emitter.ReportEmitterExecutor.execute(ReportEmitterExecutor.java:71)
at org.eclipse.birt.report.engine.internal.executor.wrap.WrappedReportExecutor.execute(WrappedReportExecutor.java:60)
at org.eclipse.birt.report.engine.internal.executor.dup.SuppressDuplciateReportExecutor.execute(SuppressDuplciateReportExecutor.java:42)
at org.eclipse.birt.report.engine.presentation.ReportDocumentBuilder.build(ReportDocumentBuilder.java:234)
at org.eclipse.birt.report.engine.api.impl.RunTask.doRun(RunTask.java:269)
at org.eclipse.birt.report.engine.api.impl.RunTask.run(RunTask.java:86)
Merci d'avance pour votre aide.

Bonne journée à tous