Search in sources :

Example 1 with BirtReportsUploadActionForm

use of org.mifos.reports.struts.actionforms.BirtReportsUploadActionForm in project head by mifos.

the class BirtReportsUploadAction method editpreview.

public ActionForward editpreview(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()));
    request.setAttribute("category", category);
    ReportsBO report = new ReportsPersistence().getReport(Short.valueOf(uploadForm.getReportId()));
    if (isReportInfoNotEdit(request, uploadForm, report)) {
        return mapping.findForward(ActionForwards.editpreview_failure.toString());
    } else if (!isReportItsSelf(uploadForm, report) && isReportAlreadyExist(request, uploadForm.getReportTitle(), category)) {
        return mapping.findForward(ActionForwards.editpreview_failure.toString());
    }
    return mapping.findForward(ActionForwards.editpreview_success.toString());
}
Also used : ReportsPersistence(org.mifos.reports.persistence.ReportsPersistence) ReportsCategoryBO(org.mifos.reports.business.ReportsCategoryBO) BirtReportsUploadActionForm(org.mifos.reports.struts.actionforms.BirtReportsUploadActionForm) ReportsBO(org.mifos.reports.business.ReportsBO)

Example 2 with BirtReportsUploadActionForm

use of org.mifos.reports.struts.actionforms.BirtReportsUploadActionForm in project head by mifos.

the class BirtReportsUploadAction method edit.

public ActionForward edit(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    BirtReportsUploadActionForm birtReportsUploadActionForm = (BirtReportsUploadActionForm) form;
    ReportsBO report = new ReportsPersistence().getReport(Short.valueOf(request.getParameter("reportId")));
    request.setAttribute(Constants.BUSINESS_KEY, report);
    birtReportsUploadActionForm.setReportTitle(report.getReportName());
    birtReportsUploadActionForm.setReportCategoryId(report.getReportsCategoryBO().getReportCategoryId().toString());
    birtReportsUploadActionForm.setIsActive(report.getIsActive().toString());
    request.getSession().setAttribute(ReportsConstants.LISTOFREPORTS, new ReportsPersistence().getAllReportCategories());
    return mapping.findForward(ActionForwards.edit_success.toString());
}
Also used : ReportsPersistence(org.mifos.reports.persistence.ReportsPersistence) BirtReportsUploadActionForm(org.mifos.reports.struts.actionforms.BirtReportsUploadActionForm) ReportsBO(org.mifos.reports.business.ReportsBO)

Example 3 with BirtReportsUploadActionForm

use of org.mifos.reports.struts.actionforms.BirtReportsUploadActionForm 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 4 with BirtReportsUploadActionForm

use of org.mifos.reports.struts.actionforms.BirtReportsUploadActionForm 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 BirtReportsUploadActionForm

use of org.mifos.reports.struts.actionforms.BirtReportsUploadActionForm 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

BirtReportsUploadActionForm (org.mifos.reports.struts.actionforms.BirtReportsUploadActionForm)13 ReportsPersistence (org.mifos.reports.persistence.ReportsPersistence)9 ReportsBO (org.mifos.reports.business.ReportsBO)7 Test (org.junit.Test)6 ReportsCategoryBO (org.mifos.reports.business.ReportsCategoryBO)6 MockFormFile (org.mifos.reports.business.MockFormFile)5 FormFile (org.apache.struts.upload.FormFile)4 ReportsJasperMap (org.mifos.reports.business.ReportsJasperMap)3 ActivityEntity (org.mifos.security.rolesandpermission.business.ActivityEntity)2 IOException (java.io.IOException)1 ActionErrors (org.apache.struts.action.ActionErrors)1 ActionMessage (org.apache.struts.action.ActionMessage)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 PersistenceException (org.mifos.framework.exceptions.PersistenceException)1 AddActivity (org.mifos.security.AddActivity)1 ActivityGeneratorException (org.mifos.security.activity.ActivityGeneratorException)1 RolesPermissionsBusinessService (org.mifos.security.rolesandpermission.business.service.RolesPermissionsBusinessService)1