KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > calipso > reportgenerator > client > ReportManagerService


1 package com.calipso.reportgenerator.client;
2
3 import com.calipso.reportgenerator.common.CalipsoException;
4 import com.calipso.reportgenerator.common.InfoException;
5 import org.apache.commons.configuration.Configuration;
6 import org.apache.commons.logging.Log;
7 import org.apache.commons.logging.LogFactory;
8 import com.calipso.reportgenerator.common.*;
9 import com.calipso.reportgenerator.client.ReportManagerFactory;
10 import com.calipso.reportgenerator.reportdefinitions.ReportView;
11 import com.calipso.reportgenerator.reportdefinitions.ReportDefinition;
12 import com.calipso.reportgenerator.reportdefinitions.ReportSourceDefinition;
13 import com.calipso.reportgenerator.reportcalculator.Matrix;
14
15 import java.util.*;
16
17 /**
18  *
19  */

20 public class ReportManagerService implements IReportManager {
21   private IReportManager reportManager;
22   private IReportManager reportManagerPersist;
23   private static ReportGeneratorConfiguration reportGeneratorConfiguration;
24   private boolean initialized=false;
25   private String JavaDoc distributedHost;
26
27   private IReportManager getReportManager(){
28     return reportManager;
29   }
30
31   public void init(Configuration conf, String JavaDoc distributedHost) throws CalipsoException {
32     this.distributedHost = distributedHost;
33     reportGeneratorConfiguration = new ReportGeneratorConfiguration(conf);
34     ReportManagerFactory factory = new ReportManagerFactory();
35     reportManager = factory.newReportManager(reportGeneratorConfiguration,false,distributedHost);
36     LanguageTraslator.newLocaleFrom(reportGeneratorConfiguration.getLocaleLanguage(),reportGeneratorConfiguration.getCountry(),reportGeneratorConfiguration.getLanguagesPath());
37     initialized = true;
38   }
39
40   public void shutdown() {
41     if (reportManagerPersist!= null){
42       reportManagerPersist = null;
43     }
44     if (reportManager!= null){
45       reportManager = null;
46     }
47     initialized = false;
48   }
49
50   public boolean isInitialized() {
51     return initialized;
52   }
53
54   public void setLogger(Log logger) {
55     ReportManagerLogger.setLog(logger);
56   }
57
58   public IReportManager getReportManagerPersist() throws InfoException {
59     if (reportManagerPersist== null){
60       ReportManagerFactory factory = new ReportManagerFactory();
61       reportManagerPersist = factory.newReportManager(reportGeneratorConfiguration,true, distributedHost);
62     }
63     return reportManagerPersist;
64   }
65
66
67
68   public int PrepareReport(String JavaDoc reportDefID) throws InfoException{
69     return getReportManagerPersist().PrepareReport(reportDefID);
70   }
71
72   public int PrepareReport(String JavaDoc reportDefId, Map paramValues) throws InfoException {
73     return getReportManagerPersist().PrepareReport(reportDefId, paramValues);
74   }
75
76   public void ReleaseReport(int handle) throws InfoException {
77     getReportManagerPersist().ReleaseReport(handle);
78   }
79
80   public void prepareReportSource(String JavaDoc reportSourceDefinitionId) throws InfoException {
81     getReportManager().prepareReportSource(reportSourceDefinitionId);
82   }
83
84   public Map getReportDefinitions() throws InfoException {
85     return getReportManager().getReportDefinitions();
86   }
87
88   public Map getReportSourceDefinitions() throws InfoException {
89     return getReportManager().getReportSourceDefinitions();
90   }
91
92   public Map getReportsForEntity(String JavaDoc entityID) throws InfoException {
93     return getReportManager().getReportsForEntity(entityID);
94   }
95
96   public void ExecuteAction(int handle, String JavaDoc actionName, Object JavaDoc params) throws InfoException {
97     getReportManagerPersist().ExecuteAction(handle, actionName, params);
98   }
99
100   public void saveReportDefinition(ReportDefinition reportDefinition) throws InfoException {
101     getReportManager().saveReportDefinition(reportDefinition);
102   }
103
104   public void saveReportSourceDefinition(ReportSourceDefinition reportSourceDefinition) throws InfoException {
105     getReportManager().saveReportSourceDefinition(reportSourceDefinition);
106   }
107
108   public void invalidateReportSource(String JavaDoc reportSourceDefinitionId) throws InfoException{
109     getReportManager().invalidateReportSource(reportSourceDefinitionId);
110   }
111
112   public ReportQuery getReportQuery(int handle) throws InfoException {
113     return getReportManagerPersist().getReportQuery(handle);
114   }
115
116   public ReportQuery getDefaultReportQuery(int handle) throws InfoException {
117     return getReportManagerPersist().getDefaultReportQuery(handle);
118   }
119
120   public ReportQuery getReportQuery(String JavaDoc reportDefinitionId) throws InfoException {
121     return getReportManager().getReportQuery(reportDefinitionId);
122   }
123
124   public ReportQuery getDefaultReportQuery(String JavaDoc reportDefinitionId) throws InfoException{
125     return getReportManager().getDefaultReportQuery(reportDefinitionId);
126   }
127
128   public ReportResult ExecReportQuery(int handle, Map paramValues) throws InfoException {
129     return getReportManagerPersist().ExecReportQuery(handle, paramValues);
130   }
131
132   public ReportResult ExecReportQuery(int handle, ReportQuery query) throws InfoException{
133     return getReportManagerPersist().ExecReportQuery(handle, query);
134   }
135
136   public ReportResult ExecReportQuery(String JavaDoc reportDefinitionID, Map paramValues) throws InfoException {
137     return getReportManager().ExecReportQuery(reportDefinitionID, paramValues);
138   }
139
140   public ReportResult ExecReportQuery(String JavaDoc reportDefinitionID, ReportQuery query) throws InfoException{
141     return getReportManager().ExecReportQuery(reportDefinitionID, query);
142   }
143
144   public Log getLogger() {
145     return ReportManagerLogger.getLog();
146   }
147
148   public ReportQuery getDefaultReportQuery(int handle,String JavaDoc userID) throws InfoException{
149     return getReportManagerPersist().getDefaultReportQuery(handle,userID);
150   };
151
152   public Map getReportViews(String JavaDoc reportDefinitionID, String JavaDoc userID) throws InfoException{
153     return getReportManager().getReportViews(reportDefinitionID,userID);
154   };
155
156   public Map getReportViews(String JavaDoc reportDefinitionID) throws InfoException{
157     return getReportManager().getReportViews(reportDefinitionID);
158   };
159
160   public ReportResult ExecReportQuery(int handle, String JavaDoc reportViewId) throws InfoException{
161     return getReportManagerPersist().ExecReportQuery(handle,reportViewId);
162   };
163
164   public String JavaDoc getDefaultReportViewId(String JavaDoc reportDefinitionId, String JavaDoc userId) throws InfoException {
165     return getReportManager().getDefaultReportViewId(reportDefinitionId,userId);
166   }
167   ;
168
169   public ReportSpec getReportSpec(String JavaDoc reportDefinitionId, String JavaDoc reportSourceDefId) throws InfoException {
170     return getReportManager().getReportSpec(reportDefinitionId, reportSourceDefId);
171   }
172
173   public ReportSpec getReportSpec(ReportDefinition reportDefinition, ReportSourceDefinition reportSourceDef) throws InfoException {
174     return getReportManager().getReportSpec(reportDefinition, reportSourceDef);
175   }
176
177   public ReportSpec getReportSpec(String JavaDoc reportDefinitionId) throws InfoException {
178     return getReportManager().getReportSpec(reportDefinitionId);
179   }
180
181   public ReportView getReportView(String JavaDoc reportViewId) throws InfoException {
182     return getReportManager().getReportView(reportViewId);
183   }
184
185   public void saveReportView(ReportView reportView) throws InfoException {
186     getReportManager().saveReportView(reportView);
187   }
188
189   public ReportView getReportViewFromID(String JavaDoc id, String JavaDoc reportDefinitionId, String JavaDoc userId) throws InfoException {
190     return getReportManager().getReportViewFromID(id, reportDefinitionId, userId);
191   }
192
193   public ReportResult ExecReportQuery(int handle, ReportView reportView) throws InfoException {
194     return getReportManagerPersist().ExecReportQuery(handle, reportView);
195   }
196
197   public void registerDefinitions() throws InfoException {
198     getReportManager().registerDefinitions();
199   }
200
201   public Vector registerReportSourceDefinitions(Vector vector) throws InfoException {
202     return getReportManager().registerReportSourceDefinitions(vector);
203   }
204
205   public Vector registerReportDefinitions(Vector vector) throws InfoException {
206     return getReportManager().registerReportDefinitions(vector);
207   }
208
209   public Vector registerReportViews(Vector vector) throws InfoException {
210     return getReportManager().registerReportViews(vector);
211   }
212
213   public void deleteAllRepositories() throws InfoException {
214     getReportManager().deleteAllRepositories();
215   }
216
217   public void deleteAllDefinitions() throws InfoException {
218     getReportManager().deleteAllDefinitions();
219   }
220
221   public void deleteReportSourceRepository() throws InfoException {
222     getReportManager().deleteReportSourceRepository();
223   }
224
225   public void deleteReportSourceDefinitionRepository() throws InfoException {
226     getReportManager().deleteReportSourceDefinitionRepository();
227   }
228
229   public void deleteReportDefinitionRepository() throws InfoException {
230     getReportManager().deleteReportDefinitionRepository();
231   }
232
233   public void deleteReportViewRepository() throws InfoException {
234     getReportManager().deleteReportViewRepository();
235   }
236
237   public void deleteReportView(String JavaDoc id, String JavaDoc reportDefinitionId, String JavaDoc userId) throws InfoException {
238     getReportManager().deleteReportView(id,reportDefinitionId,userId);
239   }
240
241   public void deleteReportSource(String JavaDoc reportSourceDefinitionId) throws InfoException {
242     getReportManager().deleteReportSource(reportSourceDefinitionId);
243   }
244
245   public void deleteReportSourceDefinition(String JavaDoc reportSourceDefinitionID) throws InfoException {
246     getReportManager().deleteReportSourceDefinition(reportSourceDefinitionID);
247   }
248
249   public void deleteReportDefinition(String JavaDoc reportDefinitionID) throws InfoException {
250     getReportManager().deleteReportDefinition(reportDefinitionID);
251   }
252
253   public void assingDefaultView(String JavaDoc id, String JavaDoc reportDefinitionId, String JavaDoc userId) throws InfoException {
254     getReportManager().assingDefaultView(id,reportDefinitionId,userId);
255   }
256
257   public ReportResult ExecReportQuery(MicroReport microReport) throws InfoException {
258     ReportManagerFactory reportManagerFactory = new ReportManagerFactory();
259     boolean isDistributed = reportGeneratorConfiguration.getIsDistributed();
260     if (isDistributed){
261       reportGeneratorConfiguration.getValues().put("IsDistributed","false");
262     }
263     reportManager = reportManagerFactory.newReportManager(reportGeneratorConfiguration,false, distributedHost);
264     if (isDistributed){
265       reportGeneratorConfiguration.getValues().put("IsDistributed","true");
266     }
267     return reportManager.ExecReportQuery(microReport);
268   }
269
270   public int PrepareReport(MicroReport microReport) throws InfoException {
271     return getReportManagerPersist().PrepareReport(microReport);
272   }
273
274 /* public ZipOutputStream getMicroReport(int reportHandle, ReportView reportView, String userID, String fileName) throws InfoException {
275     return getReportManager().getMicroReport(reportHandle, reportView, userID, fileName);
276   }
277   */

278
279
280   public String JavaDoc getXML(int handle) throws InfoException {
281     return getReportManagerPersist().getXML(handle);
282   }
283
284   public String JavaDoc getXML(String JavaDoc reportDefinitionID, Map paramValues) throws InfoException {
285     return getReportManager().getXML(reportDefinitionID, paramValues);
286   }
287
288   public Set getDimensionValues(int handle, String JavaDoc name) throws InfoException {
289     return getReportManagerPersist().getDimensionValues(handle,name);
290   }
291
292   public Set getDimensionValues(String JavaDoc reportDefinitionID, Map paramValues, String JavaDoc name) throws InfoException {
293     return getReportManager().getDimensionValues(reportDefinitionID, paramValues, name);
294   }
295
296   public Vector getUpdatedDataModel(int handle, int mode, int row, int col, boolean isDistributed) throws InfoException {
297     return getReportManagerPersist().getUpdatedDataModel(handle, mode, row, col, isDistributed);
298   }
299
300   public boolean validateUser(String JavaDoc userName, String JavaDoc password, String JavaDoc userRepositoryPath) throws InfoException {
301     return getReportManagerPersist().validateUser( userName, password, userRepositoryPath);
302   }
303
304   public boolean validateRol(String JavaDoc[] roles, String JavaDoc userName, String JavaDoc rolRepositoryPath) throws InfoException {
305     return getReportManager().validateRol(roles, userName, rolRepositoryPath);
306   }
307
308   public void exportReport(String JavaDoc userName, String JavaDoc password,String JavaDoc userRepositoryPath, String JavaDoc reportDefinitionId, Map paramValues, boolean isLandscape, int type, String JavaDoc destinationPath, String JavaDoc name) throws InfoException {
309     getReportManager().exportReport(userName, password,userRepositoryPath, reportDefinitionId, paramValues, isLandscape, type, destinationPath, name);
310   }
311
312   public byte[] exportReport(Map params) throws InfoException {
313     return getReportManager().exportReport(params);
314   }
315
316   public boolean addNewUser(String JavaDoc rootPasswd, String JavaDoc userName, String JavaDoc userPassword, String JavaDoc userRepositoryPath) throws InfoException {
317     return getReportManager().addNewUser(rootPasswd, userName, userPassword, userRepositoryPath);
318   }
319
320   public void addUserData(String JavaDoc userName, String JavaDoc name, String JavaDoc company, String JavaDoc userDataRepositoryPath) throws InfoException {
321     getReportManager().addUserData(userName, name, company, userDataRepositoryPath);
322   }
323
324   public void addUserRol(String JavaDoc userName, String JavaDoc rol, String JavaDoc rolsRepositoryPath) throws InfoException {
325     getReportManager().addUserRol(userName, rol, rolsRepositoryPath);
326   }
327
328   public boolean isAcceptedLicence() throws InfoException {
329     return getReportManager().isAcceptedLicence();
330   }
331
332   public void acceptedLicence(boolean value) throws InfoException {
333     getReportManager().acceptedLicence(value);
334   }
335
336   public MicroReport getMicroReport(String JavaDoc fileName) throws InfoException {
337     return getReportManager().getMicroReport(fileName);
338   }
339
340   public MicroReport getMicroReport(String JavaDoc reportDefinitionId, Map param) throws InfoException {
341     return getReportManager().getMicroReport(reportDefinitionId,param);
342   }
343
344   public Collection getUserData(String JavaDoc userId, String JavaDoc userDataRepositoryPath) throws InfoException {
345     return getReportManager().getUserData(userId, userDataRepositoryPath);
346   }
347
348   public void logClientData(String JavaDoc clientData) throws InfoException{
349     getReportManager().logClientData(clientData);
350   }
351
352   public Matrix getMatrix(int handle) throws InfoException {
353     return getReportManagerPersist().getMatrix(handle);
354   }
355
356   public ReportDefinition getReportDefinitionFromID(String JavaDoc reportDefinitionId) throws InfoException {
357     return getReportManager().getReportDefinitionFromID(reportDefinitionId);
358   }
359
360   public ReportSourceDefinition getReportSourceDefinitionFromID(String JavaDoc reportSourceDefinitionId) throws InfoException {
361     return getReportManager().getReportSourceDefinitionFromID(reportSourceDefinitionId);
362   }
363
364   public void init(ReportGeneratorConfiguration reportGeneratorConfiguration) throws InfoException {
365   }
366
367   /**
368    * Instancia un report manager service
369    * @param propertiesPath
370    * @param log
371    * @return
372    * @throws com.calipso.reportgenerator.common.InfoException
373    */

374
375   public static IReportManager getReportManagerService(String JavaDoc propertiesPath,Log log, String JavaDoc distributedHost) throws InfoException {
376     ReportManagerService reportManagerService = new ReportManagerService();
377     try{
378       reportManagerService.init(ReportGeneratorConfiguration.getConfiguration(propertiesPath), distributedHost);
379     }catch(Exception JavaDoc e){
380       throw new InfoException("Archivo no encontrado: ReportGeneratorConfiguration.properties, "+ReportGeneratorConfiguration.getConfigurationPath(propertiesPath),e);
381     }
382     reportManagerService.setLogger(getLog(log));
383     return reportManagerService;
384   }
385
386
387   /**
388    * Obtiene un log
389    * @param log
390    * @return
391    */

392   private static Log getLog(Log log){
393     if (log == null){
394       Properties props = new Properties();
395       props.setProperty("log4j.rootLogger", "DEBUG, A1");
396       props.setProperty("log4j.appender.A1", "org.apache.log4j.ConsoleAppender");
397       props.setProperty("log4j.appender.A1.layout", "org.apache.log4j.PatternLayout");
398       props.setProperty("log4j.appender.A1.layout", "org.apache.log4j.PatternLayout");
399       props.setProperty("log4j.logger.test.reportmanager", "ALL");
400       Log localLog = LogFactory.getLog("ReportManager");
401       org.apache.log4j.PropertyConfigurator.configure(props);
402       return localLog;
403     } else {
404       return log;
405     }
406   }
407
408   public static ReportGeneratorConfiguration getConfiguration() {
409     return reportGeneratorConfiguration;
410   }
411 }
412
Popular Tags