Search in sources :

Example 16 with ReportsBO

use of org.mifos.reports.business.ReportsBO in project head by mifos.

the class PentahoReportsServiceImpl method checkAccessToReport.

@Override
public boolean checkAccessToReport(Integer reportId) {
    ReportsBO report = this.reportsPersistence.getReport(reportId.shortValue());
    boolean result = false;
    if (report != null) {
        Short activityID = report.getActivityId();
        try {
            result = this.rolesPermissionService.hasUserAccessForActivity(activityID);
        } catch (Exception ex) {
            result = false;
        }
    }
    return result;
}
Also used : MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ReflectionException(org.mifos.reports.pentaho.util.ReflectionException) ReportProcessingException(org.pentaho.reporting.engine.classic.core.ReportProcessingException) IOException(java.io.IOException) AccessDeniedException(org.springframework.security.access.AccessDeniedException) ReportsBO(org.mifos.reports.business.ReportsBO)

Example 17 with ReportsBO

use of org.mifos.reports.business.ReportsBO in project head by mifos.

the class ReportTemplateDownloadServlet method doGet.

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String realPath = request.getParameter("realPath");
    boolean isReportAnAdminDocument = false;
    if (StringUtils.isBlank(realPath)) {
        realPath = "report";
    } else {
        isReportAnAdminDocument = true;
    }
    File dir = new File(ApplicationContextProvider.getBean(ViewOrganizationSettingsServiceFacade.class).getUploadStorageDirectory(), realPath);
    String reportFileName = "";
    if (isReportAnAdminDocument) {
        reportFileName = ((AdminDocumentBO) request.getSession().getAttribute("reportsBO")).getAdminDocumentIdentifier();
    } else {
        reportFileName = ((ReportsBO) request.getSession().getAttribute("reportsBO")).getReportsJasperMap().getReportJasper();
    }
    File file = new File(dir, reportFileName);
    if (!file.exists()) {
        file = new File(new File(getServletContext().getRealPath("/") + realPath), reportFileName);
    }
    try {
        BufferedInputStream is = new BufferedInputStream(new FileInputStream(file));
        response.setContentType("application/x-msdownload;charset=UTF-8");
        response.setHeader("Content-Disposition", "attachment; filename=" + reportFileName);
        OutputStream os = response.getOutputStream();
        byte[] buffer = new byte[4096];
        int bytesRead = 0;
        while ((bytesRead = is.read(buffer, 0, 4096)) != -1) {
            os.write(buffer, 0, bytesRead);
        }
        os.close();
        is.close();
    } catch (FileNotFoundException e) {
        response.sendRedirect("birtAdminDocumentUploadAction.do?method=getFileNotFoundPage");
    }
    request.getSession().setAttribute("reportsBO", null);
}
Also used : BufferedInputStream(java.io.BufferedInputStream) OutputStream(java.io.OutputStream) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) FileInputStream(java.io.FileInputStream) ReportsBO(org.mifos.reports.business.ReportsBO)

Example 18 with ReportsBO

use of org.mifos.reports.business.ReportsBO in project head by mifos.

the class BirtReportsUploadAction method createOrUpdateReport.

private ReportsBO createOrUpdateReport(ReportsCategoryBO category, int newActivityId, String reportTitle, Short isActive, String fileName, Boolean isDW) throws PersistenceException {
    ReportsBO reportBO = new ReportsBO();
    reportBO.setReportName(reportTitle);
    reportBO.setReportsCategoryBO(category);
    reportBO.setActivityId((short) newActivityId);
    reportBO.setIsActive(isActive);
    reportBO.setIsDW(isDW);
    ReportsJasperMap reportsJasperMap = reportBO.getReportsJasperMap();
    reportsJasperMap.setReportJasper(fileName);
    reportBO.setReportsJasperMap(reportsJasperMap);
    new ReportsPersistence().createOrUpdate(reportBO);
    return reportBO;
}
Also used : ReportsPersistence(org.mifos.reports.persistence.ReportsPersistence) ReportsJasperMap(org.mifos.reports.business.ReportsJasperMap) ReportsBO(org.mifos.reports.business.ReportsBO)

Example 19 with ReportsBO

use of org.mifos.reports.business.ReportsBO in project head by mifos.

the class BirtReportsUploadAction method upload.

public ActionForward upload(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    BirtReportsUploadActionForm uploadForm = (BirtReportsUploadActionForm) form;
    ReportsPersistence rp = new ReportsPersistence();
    ReportsCategoryBO category = rp.getPersistentObject(ReportsCategoryBO.class, Short.valueOf(uploadForm.getReportCategoryId()));
    if (isReportAlreadyExist(request, uploadForm.getReportTitle(), category)) {
        return mapping.findForward(ActionForwards.preview_failure.toString());
    }
    short parentActivity = category.getActivityId();
    int newActivityId;
    String activityNameHead = "Can view ";
    try {
        newActivityId = legacyRolesPermissionsDao.calculateDynamicActivityId();
        legacyRolesPermissionsDao.createActivityForReports(parentActivity, activityNameHead + uploadForm.getReportTitle());
    } catch (ActivityGeneratorException ex) {
        ActionErrors errors = new ActionErrors();
        errors.add(ex.getKey(), new ActionMessage(ex.getKey()));
        request.setAttribute(Globals.ERROR_KEY, errors);
        return mapping.findForward(ActionForwards.preview_failure.toString());
    }
    FormFile formFile = uploadForm.getFile();
    uploadFile(formFile);
    ReportsBO reportBO = createOrUpdateReport(category, newActivityId, uploadForm.getReportTitle(), Short.valueOf(uploadForm.getIsActive()), formFile.getFileName(), uploadForm.getIsDW());
    allowActivityPermission(reportBO, newActivityId);
    request.setAttribute("report", reportBO);
    return mapping.findForward(ActionForwards.create_success.toString());
}
Also used : ReportsPersistence(org.mifos.reports.persistence.ReportsPersistence) ReportsCategoryBO(org.mifos.reports.business.ReportsCategoryBO) BirtReportsUploadActionForm(org.mifos.reports.struts.actionforms.BirtReportsUploadActionForm) ActionMessage(org.apache.struts.action.ActionMessage) ActivityGeneratorException(org.mifos.security.activity.ActivityGeneratorException) ActionErrors(org.apache.struts.action.ActionErrors) FormFile(org.apache.struts.upload.FormFile) ReportsBO(org.mifos.reports.business.ReportsBO)

Example 20 with ReportsBO

use of org.mifos.reports.business.ReportsBO in project head by mifos.

the class BirtReportsUploadAction method isReportAlreadyExist.

private boolean isReportAlreadyExist(HttpServletRequest request, String reportName, ReportsCategoryBO categoryBO) throws Exception {
    for (ReportsBO report : new ReportsPersistence().getAllReports()) {
        if (reportName.equals(report.getReportName()) && categoryBO.getReportCategoryId().equals(report.getReportsCategoryBO().getReportCategoryId())) {
            ActionErrors errors = new ActionErrors();
            errors.add(ReportsConstants.ERROR_REPORTALREADYEXIST, new ActionMessage(ReportsConstants.ERROR_REPORTALREADYEXIST));
            request.setAttribute(Globals.ERROR_KEY, errors);
            return true;
        }
    }
    return false;
}
Also used : ReportsPersistence(org.mifos.reports.persistence.ReportsPersistence) ActionMessage(org.apache.struts.action.ActionMessage) ActionErrors(org.apache.struts.action.ActionErrors) ReportsBO(org.mifos.reports.business.ReportsBO)

Aggregations

ReportsBO (org.mifos.reports.business.ReportsBO)21 ReportsPersistence (org.mifos.reports.persistence.ReportsPersistence)10 Test (org.junit.Test)9 BirtReportsUploadActionForm (org.mifos.reports.struts.actionforms.BirtReportsUploadActionForm)7 ReportsCategoryBO (org.mifos.reports.business.ReportsCategoryBO)6 ReportsJasperMap (org.mifos.reports.business.ReportsJasperMap)5 FormFile (org.apache.struts.upload.FormFile)3 MockFormFile (org.mifos.reports.business.MockFormFile)3 ActivityEntity (org.mifos.security.rolesandpermission.business.ActivityEntity)3 IOException (java.io.IOException)2 ActionErrors (org.apache.struts.action.ActionErrors)2 ActionMessage (org.apache.struts.action.ActionMessage)2 LookUpValueEntity (org.mifos.application.master.business.LookUpValueEntity)2 MifosRuntimeException (org.mifos.core.MifosRuntimeException)2 PersistenceException (org.mifos.framework.exceptions.PersistenceException)2 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 OutputStream (java.io.OutputStream)1