com.webbfontaine.valuewebb.report.PDInformationForAnalysisReport.java Source code

Java tutorial

Introduction

Here is the source code for com.webbfontaine.valuewebb.report.PDInformationForAnalysisReport.java

Source

package com.webbfontaine.valuewebb.report;

import com.webbfontaine.valuewebb.model.util.Utils;
import com.webbfontaine.valuewebb.props.ApplicationProperties;
import com.webbfontaine.valuewebb.validation.InfoHandling;
import org.apache.commons.lang3.time.DateUtils;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.Locale;

import static com.webbfontaine.valuewebb.model.constants.Constants.FR;
import static com.webbfontaine.valuewebb.model.util.Utils.getLanguage;

/**
 * Copyrights 2002-2011 Webb Fontaine
 * Developer: Grisha Arzumanyan
 * Date: 11/04/2012
 * Time: 16:39
 * This software is the proprietary information of Webb Fontaine.
 * Its use is subject to License terms.
 */

@Name("pdInformationForAnalysisReport")
public class PDInformationForAnalysisReport extends Report {
    @In(create = true)
    InfoHandling infoHandling;

    private ReportParameter fromYearAndMonth;
    private ReportParameter toYearAndMonth;
    private ReportParameter statuses;
    private ReportParameter reportLocale;
    private ReportParameter appCountry;
    private MonthlyStatisticalReportBean bean = new MonthlyStatisticalReportBean();

    public PDInformationForAnalysisReport() {
        format = "xls";

        fromYearAndMonth = new ReportParameter("FROM_DATE", null, "FROM_DATE");
        toYearAndMonth = new ReportParameter("TO_DATE", null, "TO_DATE");
        statuses = new ReportParameter("STATUSES",
                Arrays.asList("Sent Ok", "GW Passed", "GW Locked", "Petition Query"), null);
        reportLocale = new ReportParameter("REPORT_LOCALE", Locale.ENGLISH, "Report locale");
        appCountry = new ReportParameter("APP_COUNTRY", "CI", "Application country");
    }

    @Override
    public String[] getReportsNames() {
        return new String[] { "pdInformationForAnalysis" };
    }

    @Override
    public String[] getSheetNames() {
        return new String[] { "PD Information for Analysis" };
    }

    @Override
    protected String jasperFilePath() {
        return "/reports/pdInformationForAnalysis.jasper";
    }

    @Override
    public boolean prepareParameters() {

        if (bean.getFromYear().compareTo(bean.getToYear()) > 0
                || bean.getFromYear().compareTo(bean.getToYear()) == 0
                        && bean.getFromMonth().compareTo(bean.getToMonth()) > 0) {
            infoHandling.setInfoList(Utils.translate("Incorrect interval! Please correct and try again"));
            return false;
        }

        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
        try {
            fromYearAndMonth.setValue(sdf.parse(bean.getFromYear() + bean.getFromMonth()));

            Date toDate = sdf.parse(bean.getToYear() + bean.getToMonth());

            toDate = DateUtils.addMonths(toDate, 1);
            toDate = DateUtils.addDays(toDate, -1);

            toYearAndMonth.setValue(toDate);
        } catch (ParseException e) {
            LOGGER.warn("", e);
            return false;
        }
        appCountry.setValue(ApplicationProperties.getAppCountry());
        reportLocale.setValue(FR.equals(getLanguage()) ? Locale.FRENCH : Locale.ENGLISH);
        return true;
    }

    @Override
    public String reportName() {
        return "PD_Information_For_Analysis_Report";
    }

    @Override
    protected String generatedReportFileName() {
        String reportName = reportName() + '-' + bean.getFromMonth() + '-' + bean.getFromYear();

        if (!(bean.getFromMonth() + bean.getFromYear()).equals(bean.getToMonth() + bean.getToYear())) {
            reportName += '-' + bean.getToMonth() + '.' + bean.getToYear();
        }

        return reportName + "." + getFormat();
    }

    @ReportParam
    public ReportParameter getFromYearAndMonth() {
        return fromYearAndMonth;
    }

    @ReportParam
    public ReportParameter getToYearAndMonth() {
        return toYearAndMonth;
    }

    @ReportParam
    public ReportParameter getStatuses() {
        return statuses;
    }

    public MonthlyStatisticalReportBean getBean() {
        return bean;
    }

    public void setBean(MonthlyStatisticalReportBean bean) {
        this.bean = bean;
    }

    @ReportParam
    public ReportParameter getAppCountry() {
        return appCountry;
    }

    public void setAppCountry(ReportParameter appCountry) {
        this.appCountry = appCountry;
    }

    @ReportParam
    public ReportParameter getReportLocale() {
        return reportLocale;
    }

    public void setReportLocale(ReportParameter reportLocale) {
        this.reportLocale = reportLocale;
    }
}