com.jasperreports.report.service.ReportServiceService.java Source code

Java tutorial

Introduction

Here is the source code for com.jasperreports.report.service.ReportServiceService.java

Source

/*\/**
 * Copyright (c) 2015-2016 wavemaker.com All Rights Reserved.
 * This software is the confidential and proprietary information of wavemaker-com * You shall not disclose such Confidential Information and shall use it only in accordance
 * with the terms of the source code license agreement you entered into with wavemaker.com *\/*/

package com.jasperreports.report.service;

import java.util.Map;
import java.util.HashMap;
import java.util.Properties;
import java.lang.Integer;
import java.lang.String;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.wavemaker.runtime.file.model.Downloadable;
import com.wavemaker.runtime.report.manager.ReportServiceManager;
import com.wavemaker.runtime.report.model.ReportContext;
import com.wavemaker.runtime.report.model.ExportType;

/**
* Report service class with methods to generate, download the report in expected format.
* This is a singleton class with all of its public methods exposed to the client via controller.
* Their return values and parameters will be passed to the client or taken
* from the client respectively.
*/

public class ReportServiceService {

    private static final Logger LOGGER = LoggerFactory.getLogger(ReportServiceService.class);

    @Autowired
    private ReportServiceManager reportServiceManager;

    public Downloadable deptBudgetGenerator(ExportType exportType, String reportTitle, Integer noOfEmployees,
            String orderClause) {
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("ReportTitle", reportTitle);
        parameters.put("NoOfEmployees", noOfEmployees);
        parameters.put("OrderClause", (orderClause == null ? "budget" : orderClause));

        Properties properties = new Properties();
        properties.put("queryType", "sql");
        properties.put("sessionFactoryRef", "hrdbSessionFactory");

        ReportContext reportContext = new ReportContext();
        reportContext.setReportName("DeptBudget");
        reportContext.setDataSourceType("dbReport");
        reportContext.setExportType(exportType);
        reportContext.setProperties(properties);
        reportContext.setParameters(parameters);

        return reportServiceManager.generateReport(reportContext);
    }

    public Downloadable empVacationGenerator(ExportType exportType, String reportTitle, Integer empID,
            String orderClause) {
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("ReportTitle", reportTitle);
        parameters.put("EmpID", empID);
        parameters.put("OrderClause", (orderClause == null ? "startdate" : orderClause));

        Properties properties = new Properties();
        properties.put("queryType", "hql");
        properties.put("sessionFactoryRef", "hrdbSessionFactory");

        ReportContext reportContext = new ReportContext();
        reportContext.setReportName("EmpVacation");
        reportContext.setDataSourceType("dbReport");
        reportContext.setExportType(exportType);
        reportContext.setProperties(properties);
        reportContext.setParameters(parameters);

        return reportServiceManager.generateReport(reportContext);
    }
}