Search in sources :

Example 1 with ReportsJasperMap

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

the class ReportsUserParamsAction method loadAddList.

/**
     * Loads the Parameter Add page
     */
@SuppressWarnings("unchecked")
public ActionForward loadAddList(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    logger.debug("In ReportsUserParamsAction:load Method: ");
    request.getSession().setAttribute("listOfAllParameters", new ReportsPersistence().getAllReportParams());
    ReportsParamQueryDAO paramDAO = new ReportsParamQueryDAO();
    ReportsUserParamsActionForm actionForm = (ReportsUserParamsActionForm) form;
    String strReportId = request.getParameter("reportId");
    if (strReportId == null) {
        strReportId = actionForm.getReportId() + "";
    }
    if (strReportId.equals("")) {
        strReportId = "0";
    }
    int reportId = Integer.parseInt(strReportId);
    String reportName = reportsPersistence.getReport((short) reportId).getReportName();
    List<ReportsJasperMap> reports = reportsPersistence.findJasperOfReportId(reportId);
    if (reports.size() > 0) {
        ReportsJasperMap reportFile = reports.get(0);
        String filename = reportFile.getReportJasper();
        File file = new File(BirtReportsUploadAction.getCustomReportStorageDirectory(), filename);
        if (file.exists()) {
            filename = file.getAbsolutePath();
        } else {
            filename = "report/" + filename;
        }
        if (filename.endsWith(".rptdesign")) {
            request.setAttribute("reportFile", filename);
            request.setAttribute("reportName", reportName);
            return mapping.findForward(ReportsConstants.BIRTREPORTPATH);
        }
    }
    actionForm.setReportId(reportId);
    request.getSession().setAttribute("listOfAllParametersForReportId", reportsPersistence.findParamsOfReportId(reportId));
    request.getSession().setAttribute("listOfReportJasper", reportsPersistence.findJasperOfReportId(reportId));
    List<ReportsParamsMap> reportParams = (List) request.getSession().getAttribute("listOfAllParametersForReportId");
    Object[] obj = reportParams.toArray();
    if (obj != null && obj.length > 0) {
        for (int i = 0; i < obj.length; i++) {
            ReportsParamsMap rp = (ReportsParamsMap) obj[i];
            if (rp.getReportsParams().getType().equalsIgnoreCase("Query")) {
                request.getSession().setAttribute("para" + (i + 1), paramDAO.listValuesOfParameters(rp.getReportsParams()));
            }
        }
    }
    return mapping.findForward(ReportsConstants.ADDLISTREPORTSUSERPARAMS);
}
Also used : ReportsParamsMap(org.mifos.reports.business.ReportsParamsMap) ReportsPersistence(org.mifos.reports.persistence.ReportsPersistence) ReportsParamQueryDAO(org.mifos.reports.business.dao.ReportsParamQueryDAO) ReportsUserParamsActionForm(org.mifos.reports.struts.actionforms.ReportsUserParamsActionForm) ReportsJasperMap(org.mifos.reports.business.ReportsJasperMap) List(java.util.List) File(java.io.File)

Example 2 with ReportsJasperMap

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

the class BirtReportsUploadAction method editThenUpload.

public ActionForward editThenUpload(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()));
    ReportsBO reportBO = rp.getReport(Short.valueOf(uploadForm.getReportId()));
    ReportsJasperMap reportJasperMap = reportBO.getReportsJasperMap();
    if (!isReportItsSelf(uploadForm, reportBO) && isReportAlreadyExist(request, uploadForm.getReportTitle(), category)) {
        return mapping.findForward(ActionForwards.editpreview_failure.toString());
    } else if (isReportActivityIdNull(request, reportBO)) {
        return mapping.findForward(ActionForwards.create_failure.toString());
    }
    reportBO.setReportName(uploadForm.getReportTitle());
    reportBO.setIsActive(Short.valueOf(uploadForm.getIsActive()));
    reportBO.setReportsCategoryBO(category);
    rp.createOrUpdate(reportBO);
    // kim
    String activityNameHead = "Can view ";
    rp.updateLookUpValue(reportBO.getActivityId(), activityNameHead + uploadForm.getReportTitle());
    legacyRolesPermissionsDao.reparentActivityUsingHibernate(reportBO.getActivityId(), category.getActivityId());
    legacyRolesPermissionsDao.changeActivityMessage(reportBO.getActivityId(), Localization.ENGLISH_LOCALE_ID, "Can view " + reportBO.getReportName());
    FormFile formFile = uploadForm.getFile();
    if (StringUtils.isEmpty(formFile.getFileName())) {
        formFile.destroy();
    } else {
        reportJasperMap.setReportJasper(formFile.getFileName());
        rp.createOrUpdate(reportJasperMap);
        uploadFile(formFile);
    }
    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) ReportsJasperMap(org.mifos.reports.business.ReportsJasperMap) ReportsBO(org.mifos.reports.business.ReportsBO) FormFile(org.apache.struts.upload.FormFile)

Example 3 with ReportsJasperMap

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

the class ReportsBusinessService method runReport.

public String runReport(int reportId, HttpServletRequest request, String applPath, String exportType) throws ServiceException, PersistenceException {
    String exportFileName = "";
    String error = "";
    Connection conn = null;
    List<ReportsJasperMap> reportJasperMap = reportsPersistence.findJasperOfReportId(reportId);
    ReportsJasperMap rjm = null;
    Object[] obj = reportJasperMap.toArray();
    if (obj != null && obj.length > 0) {
        rjm = (ReportsJasperMap) obj[0];
    }
    List<ReportsParamsMap> reportParams = (List) request.getSession().getAttribute("listOfAllParametersForReportId");
    obj = reportParams.toArray();
    Map parameters = new HashMap();
    if (obj != null && obj.length > 0) {
        for (Object element : obj) {
            ReportsParamsMap rp = (ReportsParamsMap) element;
            String paramname = rp.getReportsParams().getName();
            int para = 0;
            double dblpara = 0;
            String paramvalue = request.getParameter(paramname) == null ? "" : request.getParameter(paramname);
            String type = rp.getReportsParams().getClassname();
            if (type.equalsIgnoreCase("java.lang.Integer")) {
                paramvalue = paramvalue.equals("") ? "0" : paramvalue;
                try {
                    para = Integer.parseInt(paramvalue);
                    parameters.put(paramname, para);
                } catch (Exception e) {
                    error = "Not a valid Integer";
                }
            } else if (type.equalsIgnoreCase("java.lang.Double")) {
                paramvalue = paramvalue.equals("") ? "0" : paramvalue;
                try {
                    dblpara = Double.parseDouble(paramvalue);
                    parameters.put(paramname, dblpara);
                } catch (Exception e) {
                    error = "Not a Valid Double";
                }
            } else {
                parameters.put(paramname, paramvalue);
            }
        }
        request.getSession().setAttribute("paramerror", error);
        if (error.equals("")) {
            try {
                String jaspername = "";
                if (rjm != null) {
                    jaspername = rjm.getReportJasper() == null ? "" : rjm.getReportJasper();
                }
                jaspername = jaspername.replaceAll(".jasper", ".jrxml");
                conn = reportsPersistence.getJasperConnection();
                String fullpath = applPath + jaspername;
            } catch (Exception e) {
                throw new RuntimeException(e);
            } finally {
                try {
                // FIXME: why is this commented out? Looks like a
                // potential connection leak.
                /*
                         * if(conn!=null) conn.close();
                         */
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }
    } else {
        try {
            String jaspername = "";
            if (rjm != null) {
                jaspername = rjm.getReportJasper() == null ? "" : rjm.getReportJasper();
            }
            jaspername = jaspername.replaceAll(".jasper", ".jrxml");
            conn = reportsPersistence.getJasperConnection();
            String fullpath = applPath + jaspername;
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            try {
            /*
                     * if(conn!=null) conn.close();
                     */
            } catch (Exception se) {
                throw new RuntimeException(se);
            }
        }
    }
    return exportFileName;
}
Also used : ReportsParamsMap(org.mifos.reports.business.ReportsParamsMap) HashMap(java.util.HashMap) Connection(java.sql.Connection) SystemException(org.mifos.framework.exceptions.SystemException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ServiceException(org.mifos.framework.exceptions.ServiceException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) ReportsJasperMap(org.mifos.reports.business.ReportsJasperMap) AbstractBusinessObject(org.mifos.framework.business.AbstractBusinessObject) List(java.util.List) HashMap(java.util.HashMap) ReportsJasperMap(org.mifos.reports.business.ReportsJasperMap) Map(java.util.Map) ReportsParamsMap(org.mifos.reports.business.ReportsParamsMap)

Example 4 with ReportsJasperMap

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

the class BirtReportsUploadActionStrutsTest method testShouldSubmitSuccessAfterEdit.

@Test
public void testShouldSubmitSuccessAfterEdit() throws Exception {
    setRequestPathInfo("/birtReportsUploadAction.do");
    ReportsPersistence persistence = new ReportsPersistence();
    ReportsBO report = new ReportsBO();
    report.setReportName("testShouldSubmitSuccessAfterEdit");
    report.setReportsCategoryBO(persistence.getPersistentObject(ReportsCategoryBO.class, (short) 1));
    report.setIsActive((short) 1);
    short newActivityId = (short) legacyRolesPermissionsDao.calculateDynamicActivityId();
    legacyRolesPermissionsDao.createActivityForReports((short) 1, "test" + "testShouldSubmitSuccessAfterEdit");
    report.setActivityId(newActivityId);
    ReportsJasperMap reportJasperMap = report.getReportsJasperMap();
    reportJasperMap.setReportJasper("testFileName_EDIT.rptdesign");
    report.setReportsJasperMap(reportJasperMap);
    persistence.createOrUpdate(report);
    BirtReportsUploadActionForm editForm = new BirtReportsUploadActionForm();
    editForm.setReportId(report.getReportId().toString());
    editForm.setReportTitle("newTestShouldSubmitSuccessAfterEdit");
    editForm.setReportCategoryId("2");
    editForm.setIsActive("0");
    editForm.setFile(new MockFormFile("newTestShouldSubmitSuccessAfterEdit.rptdesign"));
    setActionForm(editForm);
    addRequestParameter("method", "editThenUpload");
    actionPerform();
    ReportsBO newReport = persistence.getReport(report.getReportId());
    Assert.assertEquals("newTestShouldSubmitSuccessAfterEdit", newReport.getReportName());
    Assert.assertEquals(2, newReport.getReportsCategoryBO().getReportCategoryId().shortValue());
    Assert.assertEquals(0, newReport.getIsActive().shortValue());
    Assert.assertEquals("newTestShouldSubmitSuccessAfterEdit.rptdesign", newReport.getReportsJasperMap().getReportJasper());
    ReportsJasperMap jasper = persistence.getPersistentObject(ReportsJasperMap.class, report.getReportsJasperMap().getReportId());
    Assert.assertEquals("newTestShouldSubmitSuccessAfterEdit.rptdesign", jasper.getReportJasper());
    removeReport(newReport.getReportId());
}
Also used : ReportsPersistence(org.mifos.reports.persistence.ReportsPersistence) MockFormFile(org.mifos.reports.business.MockFormFile) ReportsCategoryBO(org.mifos.reports.business.ReportsCategoryBO) BirtReportsUploadActionForm(org.mifos.reports.struts.actionforms.BirtReportsUploadActionForm) ReportsJasperMap(org.mifos.reports.business.ReportsJasperMap) ReportsBO(org.mifos.reports.business.ReportsBO) Test(org.junit.Test)

Example 5 with ReportsJasperMap

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

the class BirtReportsUploadActionStrutsTest method testShouldSubmitSucessWhenUploadNewReport.

@Test
public void testShouldSubmitSucessWhenUploadNewReport() throws Exception {
    setRequestPathInfo("/birtReportsUploadAction.do");
    BirtReportsUploadActionForm form = new BirtReportsUploadActionForm();
    form.setReportTitle("testShouldSubmitSucessWhenUploadNewReport");
    form.setReportCategoryId("1");
    form.setIsActive("1");
    form.setFile(new MockFormFile("testFileName1.rptdesign"));
    setActionForm(form);
    addRequestParameter("method", "upload");
    actionPerform();
    ReportsBO report = (ReportsBO) request.getAttribute("report");
    Assert.assertNotNull(report);
    ReportsPersistence rp = new ReportsPersistence();
    ReportsJasperMap jasper = rp.getPersistentObject(ReportsJasperMap.class, report.getReportsJasperMap().getReportId());
    Assert.assertNotNull(jasper);
    verifyNoActionErrors();
    verifyForward("create_success");
    removeReport(report.getReportId());
}
Also used : MockFormFile(org.mifos.reports.business.MockFormFile) ReportsPersistence(org.mifos.reports.persistence.ReportsPersistence) BirtReportsUploadActionForm(org.mifos.reports.struts.actionforms.BirtReportsUploadActionForm) ReportsJasperMap(org.mifos.reports.business.ReportsJasperMap) ReportsBO(org.mifos.reports.business.ReportsBO) Test(org.junit.Test)

Aggregations

ReportsJasperMap (org.mifos.reports.business.ReportsJasperMap)10 ReportsPersistence (org.mifos.reports.persistence.ReportsPersistence)7 Test (org.junit.Test)5 ReportsBO (org.mifos.reports.business.ReportsBO)5 MockFormFile (org.mifos.reports.business.MockFormFile)3 BirtReportsUploadActionForm (org.mifos.reports.struts.actionforms.BirtReportsUploadActionForm)3 File (java.io.File)2 List (java.util.List)2 ReportsCategoryBO (org.mifos.reports.business.ReportsCategoryBO)2 ReportsParamsMap (org.mifos.reports.business.ReportsParamsMap)2 Connection (java.sql.Connection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 FormFile (org.apache.struts.upload.FormFile)1 AbstractBusinessObject (org.mifos.framework.business.AbstractBusinessObject)1 ApplicationException (org.mifos.framework.exceptions.ApplicationException)1 PersistenceException (org.mifos.framework.exceptions.PersistenceException)1 ServiceException (org.mifos.framework.exceptions.ServiceException)1 SystemException (org.mifos.framework.exceptions.SystemException)1 AdminDocumentBO (org.mifos.reports.admindocuments.business.AdminDocumentBO)1