001: package com.calipso.reportgenerator.client;
002:
003: import com.calipso.reportgenerator.common.CalipsoException;
004: import com.calipso.reportgenerator.common.InfoException;
005: import org.apache.commons.configuration.Configuration;
006: import org.apache.commons.logging.Log;
007: import org.apache.commons.logging.LogFactory;
008: import com.calipso.reportgenerator.common.*;
009: import com.calipso.reportgenerator.client.ReportManagerFactory;
010: import com.calipso.reportgenerator.reportdefinitions.ReportView;
011: import com.calipso.reportgenerator.reportdefinitions.ReportDefinition;
012: import com.calipso.reportgenerator.reportdefinitions.ReportSourceDefinition;
013: import com.calipso.reportgenerator.reportcalculator.Matrix;
014:
015: import java.util.*;
016:
017: /**
018: *
019: */
020: public class ReportManagerService implements IReportManager {
021: private IReportManager reportManager;
022: private IReportManager reportManagerPersist;
023: private static ReportGeneratorConfiguration reportGeneratorConfiguration;
024: private boolean initialized = false;
025: private String distributedHost;
026:
027: private IReportManager getReportManager() {
028: return reportManager;
029: }
030:
031: public void init(Configuration conf, String distributedHost)
032: throws CalipsoException {
033: this .distributedHost = distributedHost;
034: reportGeneratorConfiguration = new ReportGeneratorConfiguration(
035: conf);
036: ReportManagerFactory factory = new ReportManagerFactory();
037: reportManager = factory.newReportManager(
038: reportGeneratorConfiguration, false, distributedHost);
039: LanguageTraslator.newLocaleFrom(reportGeneratorConfiguration
040: .getLocaleLanguage(), reportGeneratorConfiguration
041: .getCountry(), reportGeneratorConfiguration
042: .getLanguagesPath());
043: initialized = true;
044: }
045:
046: public void shutdown() {
047: if (reportManagerPersist != null) {
048: reportManagerPersist = null;
049: }
050: if (reportManager != null) {
051: reportManager = null;
052: }
053: initialized = false;
054: }
055:
056: public boolean isInitialized() {
057: return initialized;
058: }
059:
060: public void setLogger(Log logger) {
061: ReportManagerLogger.setLog(logger);
062: }
063:
064: public IReportManager getReportManagerPersist()
065: throws InfoException {
066: if (reportManagerPersist == null) {
067: ReportManagerFactory factory = new ReportManagerFactory();
068: reportManagerPersist = factory
069: .newReportManager(reportGeneratorConfiguration,
070: true, distributedHost);
071: }
072: return reportManagerPersist;
073: }
074:
075: public int PrepareReport(String reportDefID) throws InfoException {
076: return getReportManagerPersist().PrepareReport(reportDefID);
077: }
078:
079: public int PrepareReport(String reportDefId, Map paramValues)
080: throws InfoException {
081: return getReportManagerPersist().PrepareReport(reportDefId,
082: paramValues);
083: }
084:
085: public void ReleaseReport(int handle) throws InfoException {
086: getReportManagerPersist().ReleaseReport(handle);
087: }
088:
089: public void prepareReportSource(String reportSourceDefinitionId)
090: throws InfoException {
091: getReportManager()
092: .prepareReportSource(reportSourceDefinitionId);
093: }
094:
095: public Map getReportDefinitions() throws InfoException {
096: return getReportManager().getReportDefinitions();
097: }
098:
099: public Map getReportSourceDefinitions() throws InfoException {
100: return getReportManager().getReportSourceDefinitions();
101: }
102:
103: public Map getReportsForEntity(String entityID)
104: throws InfoException {
105: return getReportManager().getReportsForEntity(entityID);
106: }
107:
108: public void ExecuteAction(int handle, String actionName,
109: Object params) throws InfoException {
110: getReportManagerPersist().ExecuteAction(handle, actionName,
111: params);
112: }
113:
114: public void saveReportDefinition(ReportDefinition reportDefinition)
115: throws InfoException {
116: getReportManager().saveReportDefinition(reportDefinition);
117: }
118:
119: public void saveReportSourceDefinition(
120: ReportSourceDefinition reportSourceDefinition)
121: throws InfoException {
122: getReportManager().saveReportSourceDefinition(
123: reportSourceDefinition);
124: }
125:
126: public void invalidateReportSource(String reportSourceDefinitionId)
127: throws InfoException {
128: getReportManager().invalidateReportSource(
129: reportSourceDefinitionId);
130: }
131:
132: public ReportQuery getReportQuery(int handle) throws InfoException {
133: return getReportManagerPersist().getReportQuery(handle);
134: }
135:
136: public ReportQuery getDefaultReportQuery(int handle)
137: throws InfoException {
138: return getReportManagerPersist().getDefaultReportQuery(handle);
139: }
140:
141: public ReportQuery getReportQuery(String reportDefinitionId)
142: throws InfoException {
143: return getReportManager().getReportQuery(reportDefinitionId);
144: }
145:
146: public ReportQuery getDefaultReportQuery(String reportDefinitionId)
147: throws InfoException {
148: return getReportManager().getDefaultReportQuery(
149: reportDefinitionId);
150: }
151:
152: public ReportResult ExecReportQuery(int handle, Map paramValues)
153: throws InfoException {
154: return getReportManagerPersist().ExecReportQuery(handle,
155: paramValues);
156: }
157:
158: public ReportResult ExecReportQuery(int handle, ReportQuery query)
159: throws InfoException {
160: return getReportManagerPersist().ExecReportQuery(handle, query);
161: }
162:
163: public ReportResult ExecReportQuery(String reportDefinitionID,
164: Map paramValues) throws InfoException {
165: return getReportManager().ExecReportQuery(reportDefinitionID,
166: paramValues);
167: }
168:
169: public ReportResult ExecReportQuery(String reportDefinitionID,
170: ReportQuery query) throws InfoException {
171: return getReportManager().ExecReportQuery(reportDefinitionID,
172: query);
173: }
174:
175: public Log getLogger() {
176: return ReportManagerLogger.getLog();
177: }
178:
179: public ReportQuery getDefaultReportQuery(int handle, String userID)
180: throws InfoException {
181: return getReportManagerPersist().getDefaultReportQuery(handle,
182: userID);
183: };
184:
185: public Map getReportViews(String reportDefinitionID, String userID)
186: throws InfoException {
187: return getReportManager().getReportViews(reportDefinitionID,
188: userID);
189: };
190:
191: public Map getReportViews(String reportDefinitionID)
192: throws InfoException {
193: return getReportManager().getReportViews(reportDefinitionID);
194: };
195:
196: public ReportResult ExecReportQuery(int handle, String reportViewId)
197: throws InfoException {
198: return getReportManagerPersist().ExecReportQuery(handle,
199: reportViewId);
200: };
201:
202: public String getDefaultReportViewId(String reportDefinitionId,
203: String userId) throws InfoException {
204: return getReportManager().getDefaultReportViewId(
205: reportDefinitionId, userId);
206: };
207:
208: public ReportSpec getReportSpec(String reportDefinitionId,
209: String reportSourceDefId) throws InfoException {
210: return getReportManager().getReportSpec(reportDefinitionId,
211: reportSourceDefId);
212: }
213:
214: public ReportSpec getReportSpec(ReportDefinition reportDefinition,
215: ReportSourceDefinition reportSourceDef)
216: throws InfoException {
217: return getReportManager().getReportSpec(reportDefinition,
218: reportSourceDef);
219: }
220:
221: public ReportSpec getReportSpec(String reportDefinitionId)
222: throws InfoException {
223: return getReportManager().getReportSpec(reportDefinitionId);
224: }
225:
226: public ReportView getReportView(String reportViewId)
227: throws InfoException {
228: return getReportManager().getReportView(reportViewId);
229: }
230:
231: public void saveReportView(ReportView reportView)
232: throws InfoException {
233: getReportManager().saveReportView(reportView);
234: }
235:
236: public ReportView getReportViewFromID(String id,
237: String reportDefinitionId, String userId)
238: throws InfoException {
239: return getReportManager().getReportViewFromID(id,
240: reportDefinitionId, userId);
241: }
242:
243: public ReportResult ExecReportQuery(int handle,
244: ReportView reportView) throws InfoException {
245: return getReportManagerPersist().ExecReportQuery(handle,
246: reportView);
247: }
248:
249: public void registerDefinitions() throws InfoException {
250: getReportManager().registerDefinitions();
251: }
252:
253: public Vector registerReportSourceDefinitions(Vector vector)
254: throws InfoException {
255: return getReportManager().registerReportSourceDefinitions(
256: vector);
257: }
258:
259: public Vector registerReportDefinitions(Vector vector)
260: throws InfoException {
261: return getReportManager().registerReportDefinitions(vector);
262: }
263:
264: public Vector registerReportViews(Vector vector)
265: throws InfoException {
266: return getReportManager().registerReportViews(vector);
267: }
268:
269: public void deleteAllRepositories() throws InfoException {
270: getReportManager().deleteAllRepositories();
271: }
272:
273: public void deleteAllDefinitions() throws InfoException {
274: getReportManager().deleteAllDefinitions();
275: }
276:
277: public void deleteReportSourceRepository() throws InfoException {
278: getReportManager().deleteReportSourceRepository();
279: }
280:
281: public void deleteReportSourceDefinitionRepository()
282: throws InfoException {
283: getReportManager().deleteReportSourceDefinitionRepository();
284: }
285:
286: public void deleteReportDefinitionRepository() throws InfoException {
287: getReportManager().deleteReportDefinitionRepository();
288: }
289:
290: public void deleteReportViewRepository() throws InfoException {
291: getReportManager().deleteReportViewRepository();
292: }
293:
294: public void deleteReportView(String id, String reportDefinitionId,
295: String userId) throws InfoException {
296: getReportManager().deleteReportView(id, reportDefinitionId,
297: userId);
298: }
299:
300: public void deleteReportSource(String reportSourceDefinitionId)
301: throws InfoException {
302: getReportManager().deleteReportSource(reportSourceDefinitionId);
303: }
304:
305: public void deleteReportSourceDefinition(
306: String reportSourceDefinitionID) throws InfoException {
307: getReportManager().deleteReportSourceDefinition(
308: reportSourceDefinitionID);
309: }
310:
311: public void deleteReportDefinition(String reportDefinitionID)
312: throws InfoException {
313: getReportManager().deleteReportDefinition(reportDefinitionID);
314: }
315:
316: public void assingDefaultView(String id, String reportDefinitionId,
317: String userId) throws InfoException {
318: getReportManager().assingDefaultView(id, reportDefinitionId,
319: userId);
320: }
321:
322: public ReportResult ExecReportQuery(MicroReport microReport)
323: throws InfoException {
324: ReportManagerFactory reportManagerFactory = new ReportManagerFactory();
325: boolean isDistributed = reportGeneratorConfiguration
326: .getIsDistributed();
327: if (isDistributed) {
328: reportGeneratorConfiguration.getValues().put(
329: "IsDistributed", "false");
330: }
331: reportManager = reportManagerFactory.newReportManager(
332: reportGeneratorConfiguration, false, distributedHost);
333: if (isDistributed) {
334: reportGeneratorConfiguration.getValues().put(
335: "IsDistributed", "true");
336: }
337: return reportManager.ExecReportQuery(microReport);
338: }
339:
340: public int PrepareReport(MicroReport microReport)
341: throws InfoException {
342: return getReportManagerPersist().PrepareReport(microReport);
343: }
344:
345: /* public ZipOutputStream getMicroReport(int reportHandle, ReportView reportView, String userID, String fileName) throws InfoException {
346: return getReportManager().getMicroReport(reportHandle, reportView, userID, fileName);
347: }
348: */
349:
350: public String getXML(int handle) throws InfoException {
351: return getReportManagerPersist().getXML(handle);
352: }
353:
354: public String getXML(String reportDefinitionID, Map paramValues)
355: throws InfoException {
356: return getReportManager().getXML(reportDefinitionID,
357: paramValues);
358: }
359:
360: public Set getDimensionValues(int handle, String name)
361: throws InfoException {
362: return getReportManagerPersist().getDimensionValues(handle,
363: name);
364: }
365:
366: public Set getDimensionValues(String reportDefinitionID,
367: Map paramValues, String name) throws InfoException {
368: return getReportManager().getDimensionValues(
369: reportDefinitionID, paramValues, name);
370: }
371:
372: public Vector getUpdatedDataModel(int handle, int mode, int row,
373: int col, boolean isDistributed) throws InfoException {
374: return getReportManagerPersist().getUpdatedDataModel(handle,
375: mode, row, col, isDistributed);
376: }
377:
378: public boolean validateUser(String userName, String password,
379: String userRepositoryPath) throws InfoException {
380: return getReportManagerPersist().validateUser(userName,
381: password, userRepositoryPath);
382: }
383:
384: public boolean validateRol(String[] roles, String userName,
385: String rolRepositoryPath) throws InfoException {
386: return getReportManager().validateRol(roles, userName,
387: rolRepositoryPath);
388: }
389:
390: public void exportReport(String userName, String password,
391: String userRepositoryPath, String reportDefinitionId,
392: Map paramValues, boolean isLandscape, int type,
393: String destinationPath, String name) throws InfoException {
394: getReportManager().exportReport(userName, password,
395: userRepositoryPath, reportDefinitionId, paramValues,
396: isLandscape, type, destinationPath, name);
397: }
398:
399: public byte[] exportReport(Map params) throws InfoException {
400: return getReportManager().exportReport(params);
401: }
402:
403: public boolean addNewUser(String rootPasswd, String userName,
404: String userPassword, String userRepositoryPath)
405: throws InfoException {
406: return getReportManager().addNewUser(rootPasswd, userName,
407: userPassword, userRepositoryPath);
408: }
409:
410: public void addUserData(String userName, String name,
411: String company, String userDataRepositoryPath)
412: throws InfoException {
413: getReportManager().addUserData(userName, name, company,
414: userDataRepositoryPath);
415: }
416:
417: public void addUserRol(String userName, String rol,
418: String rolsRepositoryPath) throws InfoException {
419: getReportManager()
420: .addUserRol(userName, rol, rolsRepositoryPath);
421: }
422:
423: public boolean isAcceptedLicence() throws InfoException {
424: return getReportManager().isAcceptedLicence();
425: }
426:
427: public void acceptedLicence(boolean value) throws InfoException {
428: getReportManager().acceptedLicence(value);
429: }
430:
431: public MicroReport getMicroReport(String fileName)
432: throws InfoException {
433: return getReportManager().getMicroReport(fileName);
434: }
435:
436: public MicroReport getMicroReport(String reportDefinitionId,
437: Map param) throws InfoException {
438: return getReportManager().getMicroReport(reportDefinitionId,
439: param);
440: }
441:
442: public Collection getUserData(String userId,
443: String userDataRepositoryPath) throws InfoException {
444: return getReportManager().getUserData(userId,
445: userDataRepositoryPath);
446: }
447:
448: public void logClientData(String clientData) throws InfoException {
449: getReportManager().logClientData(clientData);
450: }
451:
452: public Matrix getMatrix(int handle) throws InfoException {
453: return getReportManagerPersist().getMatrix(handle);
454: }
455:
456: public ReportDefinition getReportDefinitionFromID(
457: String reportDefinitionId) throws InfoException {
458: return getReportManager().getReportDefinitionFromID(
459: reportDefinitionId);
460: }
461:
462: public ReportSourceDefinition getReportSourceDefinitionFromID(
463: String reportSourceDefinitionId) throws InfoException {
464: return getReportManager().getReportSourceDefinitionFromID(
465: reportSourceDefinitionId);
466: }
467:
468: public void init(
469: ReportGeneratorConfiguration reportGeneratorConfiguration)
470: throws InfoException {
471: }
472:
473: /**
474: * Instancia un report manager service
475: * @param propertiesPath
476: * @param log
477: * @return
478: * @throws com.calipso.reportgenerator.common.InfoException
479: */
480:
481: public static IReportManager getReportManagerService(
482: String propertiesPath, Log log, String distributedHost)
483: throws InfoException {
484: ReportManagerService reportManagerService = new ReportManagerService();
485: try {
486: reportManagerService.init(ReportGeneratorConfiguration
487: .getConfiguration(propertiesPath), distributedHost);
488: } catch (Exception e) {
489: throw new InfoException(
490: "Archivo no encontrado: ReportGeneratorConfiguration.properties, "
491: + ReportGeneratorConfiguration
492: .getConfigurationPath(propertiesPath),
493: e);
494: }
495: reportManagerService.setLogger(getLog(log));
496: return reportManagerService;
497: }
498:
499: /**
500: * Obtiene un log
501: * @param log
502: * @return
503: */
504: private static Log getLog(Log log) {
505: if (log == null) {
506: Properties props = new Properties();
507: props.setProperty("log4j.rootLogger", "DEBUG, A1");
508: props.setProperty("log4j.appender.A1",
509: "org.apache.log4j.ConsoleAppender");
510: props.setProperty("log4j.appender.A1.layout",
511: "org.apache.log4j.PatternLayout");
512: props.setProperty("log4j.appender.A1.layout",
513: "org.apache.log4j.PatternLayout");
514: props.setProperty("log4j.logger.test.reportmanager", "ALL");
515: Log localLog = LogFactory.getLog("ReportManager");
516: org.apache.log4j.PropertyConfigurator.configure(props);
517: return localLog;
518: } else {
519: return log;
520: }
521: }
522:
523: public static ReportGeneratorConfiguration getConfiguration() {
524: return reportGeneratorConfiguration;
525: }
526: }
|