⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reportmanagerejb.java

📁 CRM源码This file describes some issues that should be implemented in future and how it should be imple
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    // end NRA code    /*     * No javadoc     * @see #sendReportByMail( long, String, String )     */    public void sendReportByMail(long reportSchedulerId)            throws EQLException, MessagingException {        sendReportByMail(reportSchedulerId, null);    }    /*     * No javadoc     * @see #sendReportByMail( long, String, String )     */    public void sendReportByMail(long reportSchedulerId, String transletName)            throws EQLException, MessagingException {        sendReportByMail(reportSchedulerId, transletName, null);    }    /**     * Makes the scheduled report (by report schedule ID), transforms it to     * HTML and sends by e-mail.     *     * @param reportSchedulerId report schedule ID to use     * @param transletName      XSL translet name     * @throws EQLException       on all EQL errors     * @throws MessagingException     */    public void sendReportByMail(long reportSchedulerId, String transletName, String reportFormat)            throws EQLException, MessagingException {        // Initialization.        LogonSession ls;        ls = AccessRightsManager.getSystemLogonSession();        ReportSchedulerObject scheduleObj = loadReportSchedulerObject(ls, reportSchedulerId);        // Get logon session to use.        Long createdBy = scheduleObj.getCreated_by();        if(createdBy != null) {            try {                ls = AccessRightsManager.getLogonSessionForUser(AccessRightsManager.getUser(createdBy.longValue()),                        AccessRightsManager.SYSTEM_SESSION_ID);            } catch (SecurityException ex) {                throw new GenericSystemException(ex);            }        }        // Get the report object.        Long reportID = scheduleObj.getReport_id();        ReportObject reportObj = loadReportObject(ls, reportID.longValue());        String name = reportObj.getName();        // Build Report object.        //Report report = ReportHelper.valueOf(reportObj);        ActionContext context = new EJBCacheActionContext(this);        Report report = ReportHelper.serializedValueOf(reportObj, ls, context);                //todo        //StringWriter writer = new StringWriter();        //printReport(ls, report, transletName, writer, new ReportCallbackAdapter());        //String reportString = writer.toString();        // Get the e-mail addresses, subject and body to use.        String to = scheduleObj.getTo_addr();        String cc = scheduleObj.getCc_addr();        String subject = scheduleObj.getSubject();        String body;        if(name != null) {            body = "\n\nSee report '" + name + "' in the attached file.";        } else {            body = "\n\nSee report in the attached file.";        }        if(getLogger().isDebugEnabled()) {            DEBUG("Send report: " + reportObj.getReport_id() + " with name '" +                    name + "' to '" + to + "'");        }        // Do the job.        doSendReportByMail(ls, report, transletName, to, cc, subject, body, reportFormat);    }    // ----------------------------------------------------- private methods    //    // Load ReportObject by its ID.    //    private ReportObject loadReportObject(LogonSession ls, long reportId)            throws EQLException {        JEOManagerLocal jeoManager = (JEOManagerLocal)                getLocalObject(JNDINames.JEOManager, JEOManagerLocalHome.class);        JEObjectHandler reportHnd = ReportObjectHandler.selectByID(jeoManager, ls, reportId);        if(reportHnd == null) {            throw new NullPointerException("Report: " + reportId + " not found.");        }        return (ReportObject) reportHnd.getJEObject();    }    //    // Load ReportSchedulerObject by its ID.    //    private ReportSchedulerObject loadReportSchedulerObject(LogonSession ls, long reportSchedulerId)            throws EQLException {        JEOManagerLocal jeoManager = (JEOManagerLocal)                getLocalObject(JNDINames.JEOManager, JEOManagerLocalHome.class);        JEObjectHandler scheduleHnd = ReportSchedulerObjectHandler.selectByID(jeoManager, ls, reportSchedulerId);        if(scheduleHnd == null) {            throw new NullPointerException("Report schedule: " + reportSchedulerId + " not found.");        }        return (ReportSchedulerObject) scheduleHnd.getJEObject();    }    //     // Makes an HTML report and sends it by e-mail.    //    // comment by NRA due to redundancy    /*private void doSendReportByMail( LogonSession ls,            Report report,            String transletName,            String to,            String cc,            String subject,            String body )    throws EQLException, MessagingException {    	doSendReportByMail( ls, report, transletName, to, cc, subject, body, null);    }*/    //    // Makes an formatted report and sends it by e-mail.    //    private void doSendReportByMail(LogonSession ls,                                    Report report,                                    String transletName,                                    String to,                                    String cc,                                    String subject,                                    String body,                                    String reportFormat)            throws EQLException, MessagingException {        // Get the creator 'from' address.        String from = ls.getUser().getEmail();        File tempFile = null;        File zipFile = null;        try {            // Prepare temporary file.            tempFile = doGenerateReport(ls, report, transletName, reportFormat, null);            // Zip report.            zipFile = getZipFile();            ZipHelper.zip(tempFile, zipFile);            // Send.            Attachment att = new Attachment(zipFile);            sendByMail(ls, from, to, cc, subject, body, new Attachment[]{att});        } catch (IOException ex) {            ERROR(ex);            throw new GenericSystemException("IO exception: " + ex.getMessage(), ex);        } finally {            // Remove files.            ReportHelper.clearDataFile(ls, report, reportFormat);            try {                if(zipFile != null && zipFile.exists()) {                    zipFile.delete();                }            } catch (Exception ex) {            }        }    }    //    // Makes an HTML report and save it as a temporary file.    //    private File doGenerateReport(LogonSession ls,                                  Report report,                                  String transletName,                                  String reportFormat,                                  ReportCallbackHnd hnd)            throws EQLException {        return doGenerateReport(ls, report, transletName, reportFormat, null, hnd);    }    private File doGenerateReport(LogonSession ls,                                  Report report,                                  String transletName,                                  Map transletParams,                                  ReportCallbackHnd hnd)            throws EQLException {        return doGenerateReport(ls, report, transletName, null, transletParams, hnd);    }    //  NRA code: core method with extra parameter to generated report file in specified format    private File doGenerateReport(LogonSession ls,                                  Report report,                                  String transletName,                                  String reportFormat,                                  Map transletParams,                                  ReportCallbackHnd hnd)            throws EQLException {        // Init.        File tempFile = null;        PrintWriter out = null;        Reqs[] reqss = report.getReqs();        GetRecordsLocal getRecords = (GetRecordsLocal)                getLocalObject(JNDINames.GetRecords, GetRecordsLocalHome.class);        // Get translet.        String transletClassName = null;        if(transletName != null) {            transletClassName = ReportTransletFactory.getTransletClassName(transletName);        }        if(transletClassName == null) {            transletClassName = ReportTransletFactory.getDefTransletClassName();        }        if(transletClassName == null) {            throw new NullPointerException("Cannot find translet by the name '" + transletName + "'.");        }        // Construct callback event.        ReportCallbackHndEvent ev = new ReportCallbackHndEvent(ls, report, transletName);        try {            // Prepare temporary file.            tempFile = ReportHelper.getDataFile(ls, report, reportFormat);            out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(tempFile), "UTF-8"));            // Iteration counter.            int iterId = 0;            int reqsSize = reqss.length;            // Create cached entity map.            Map entityMap = new Hashtable();            UserPropertyManagerLocal userPropManager = (UserPropertyManagerLocal)                    getLocalObject(JNDINames.UserPropertyManager, UserPropertyManagerLocalHome.class);            for(int i = 0; i < reqsSize; i++) {                // Get next Reqs object.                Reqs reqs = reqss[i];                ReqEntity entity = reqs.getReq().getReqEntity();                String entityName = null;                List<String> fieldsForGrid = null;                if (entity != null) {                    entityName = entity.getName();                                        if (report.getIgnoreIncludeToReport()) {                        String[] fieldsArray = userPropManager.getFieldsForGrid(ls.getUser(), entityName);                        if (fieldsArray != null)                            fieldsForGrid = Arrays.asList(fieldsArray);                    }                }                // Set counter.                reqs.setDocount(Boolean.TRUE);                // Set package size if it necessary.                boolean printPage = report.getPrintPage().booleanValue();                if(!printPage) {                    reqs.setPagesize(new Integer(MAX_RECORDS_PER_PAGE));                }                // Get Form object.                Form form = getForm(ls, reqs);                // Make the report page(s).                boolean hasNextPage = !printPage;                int page = (hasNextPage) ? 0:reqs.getPage().intValue();                do {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -