Search in sources :

Example 11 with FormFile

use of org.apache.struts.upload.FormFile in project head by mifos.

the class ImportTransactionsAction method upload.

public ActionForward upload(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    final ImportTransactionsActionForm importTransactionsForm = (ImportTransactionsActionForm) form;
    final FormFile importTransactionsFile = importTransactionsForm.getImportTransactionsFile();
    final String importPluginClassname = importTransactionsForm.getImportPluginName();
    request.getSession().setAttribute(IMPORT_PLUGIN_CLASSNAME, importPluginClassname);
    final InputStream stream = importTransactionsFile.getInputStream();
    final String tempFilename = saveImportAsTemporaryFile(importTransactionsFile.getInputStream());
    request.getSession().setAttribute(IMPORT_TEMPORARY_FILENAME, tempFilename);
    final ParseResultDto importResult = this.importTransactionsServiceFacade.parseImportTransactions(importPluginClassname, importTransactionsFile.getInputStream());
    final List<String> errorsForDisplay = new ArrayList<String>();
    if (!importResult.getParseErrors().isEmpty()) {
        errorsForDisplay.addAll(importResult.getParseErrors());
    }
    int numberRowSuccessfullyParsed = importResult.getNumberRowSuccessfullyParsed();
    if (numberRowSuccessfullyParsed == -1) {
        numberRowSuccessfullyParsed = importResult.getSuccessfullyParsedPayments().size();
    }
    boolean submitButtonDisabled = false;
    if (numberRowSuccessfullyParsed == 0) {
        submitButtonDisabled = true;
    }
    if (importResult.isAmountInformationFilled() && importResult.isExtraRowInformationFilled()) {
        request.setAttribute("isExtraInformationFilled", true);
        request.setAttribute("numberOfErrorRows", importResult.getNumberOfErrorRows());
        request.setAttribute("numberOfIgnoredRows", importResult.getNumberOfIgnoredRows());
        request.setAttribute("numberOfReadRows", importResult.getNumberOfReadRows());
        request.setAttribute("totalAmountOfTransactionsImported", new Money(Money.getDefaultCurrency(), importResult.getTotalAmountOfTransactionsImported()).toString());
        request.setAttribute("totalAmountOfTransactionsWithError", new Money(Money.getDefaultCurrency(), importResult.getTotalAmountOfTransactionsWithError()).toString());
        request.setAttribute("totalAmountOfDisbursementsTransactionsImported", new Money(Money.getDefaultCurrency(), importResult.getTotalAmountOfDisbursementsImported().toString()));
        request.getSession().setAttribute(SESSION_ATTRIBUTE_LOG, importResult.getStatusLogFile().getBytes());
        request.getSession().setAttribute(SESSION_ATTRIBUTE_LOG_FILENAME, statusLogfileName(importTransactionsFile.getFileName()));
    } else {
        request.setAttribute("isExtraInformationFilled", false);
    }
    request.setAttribute("importTransactionsErrors", errorsForDisplay);
    request.setAttribute("numSuccessfulRows", numberRowSuccessfullyParsed);
    request.setAttribute("submitButtonDisabled", submitButtonDisabled);
    request.setAttribute("numberOfOverpayments", importResult.getNumberOfOverpayments());
    stream.close();
    importTransactionsFile.destroy();
    return mapping.findForward("import_results");
}
Also used : Money(org.mifos.framework.util.helpers.Money) ImportTransactionsActionForm(org.mifos.application.importexport.struts.actionforms.ImportTransactionsActionForm) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ParseResultDto(org.mifos.dto.domain.ParseResultDto) FormFile(org.apache.struts.upload.FormFile)

Example 12 with FormFile

use of org.apache.struts.upload.FormFile in project head by mifos.

the class BirtAdminDocumentUploadAction method editThenUpload.

@SuppressWarnings("unchecked")
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward editThenUpload(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    BirtAdminDocumentUploadActionForm uploadForm = (BirtAdminDocumentUploadActionForm) form;
    FormFile formFile = uploadForm.getFile();
    boolean newFile = false;
    if (StringUtils.isEmpty(formFile.getFileName())) {
        formFile.destroy();
    } else {
        uploadFile(formFile);
        newFile = true;
    }
    AdminDocumentBO admindoc = legacyAdminDocumentDao.getAdminDocumentById(Short.valueOf(SessionUtils.getAttribute("admindocId", request).toString()));
    admindoc.setAdminDocumentName(uploadForm.getAdminiDocumentTitle());
    admindoc.setIsActive(Short.valueOf(uploadForm.getIsActive()));
    if (newFile) {
        admindoc.setAdminDocumentIdentifier(formFile.getFileName());
    }
    legacyAdminDocumentDao.createOrUpdate(admindoc);
    if (Short.valueOf(uploadForm.getAccountTypeId()).shortValue() <= 2) {
        List<AccountStateEntity> masterList = (List<AccountStateEntity>) SessionUtils.getAttribute("SelectedStatus", request);
        List<AdminDocAccStateMixBO> admindoclist = legacyAdminDocAccStateMixDao.getMixByAdminDocuments(Short.valueOf(SessionUtils.getAttribute("admindocId", request).toString()));
        for (AdminDocAccStateMixBO temp : admindoclist) {
            legacyAdminDocAccStateMixDao.delete(temp);
        }
        AdminDocAccStateMixBO admindocaccstatemixBO = new AdminDocAccStateMixBO();
        for (AccountStateEntity acc : masterList) {
            admindocaccstatemixBO = new AdminDocAccStateMixBO();
            admindocaccstatemixBO.setAccountStateID(acc);
            admindocaccstatemixBO.setAdminDocumentID(admindoc);
            legacyAdminDocAccStateMixDao.createOrUpdate(admindocaccstatemixBO);
        }
    } else {
        List<AccountActionEntity> masterList = (List<AccountActionEntity>) SessionUtils.getAttribute("SelectedStatus", request);
        List<AdminDocAccActionMixBO> admindoclist = legacyAdminDocAccStateMixDao.getAccActionMixByAdminDocument(Short.valueOf(SessionUtils.getAttribute("admindocId", request).toString()));
        for (AdminDocAccActionMixBO temp : admindoclist) {
            legacyAdminDocAccStateMixDao.delete(temp);
        }
        AdminDocAccActionMixBO adminDocAccActionMixBO = new AdminDocAccActionMixBO();
        for (AccountActionEntity acc : masterList) {
            adminDocAccActionMixBO = new AdminDocAccActionMixBO();
            adminDocAccActionMixBO.setAccountAction(acc);
            adminDocAccActionMixBO.setAdminDocument(admindoc);
            legacyAdminDocAccStateMixDao.createOrUpdate(adminDocAccActionMixBO);
        }
    }
    return getViewBirtAdminDocumentPage(mapping, form, request, response);
}
Also used : BirtAdminDocumentUploadActionForm(org.mifos.reports.admindocuments.struts.actionforms.BirtAdminDocumentUploadActionForm) AdminDocAccStateMixBO(org.mifos.reports.admindocuments.business.AdminDocAccStateMixBO) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) AccountActionEntity(org.mifos.accounts.business.AccountActionEntity) FormFile(org.apache.struts.upload.FormFile) AdminDocumentBO(org.mifos.reports.admindocuments.business.AdminDocumentBO) ArrayList(java.util.ArrayList) List(java.util.List) AdminDocAccActionMixBO(org.mifos.reports.admindocuments.business.AdminDocAccActionMixBO) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 13 with FormFile

use of org.apache.struts.upload.FormFile 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 14 with FormFile

use of org.apache.struts.upload.FormFile in project head by mifos.

the class BirtReportsUploadActionStrutsTest method testShouldCreateFailureWhenActivityIdOutOfRange.

@Test
public void testShouldCreateFailureWhenActivityIdOutOfRange() throws Exception {
    ActivityEntity activityEntity = insertActivityForTest(Short.MIN_VALUE);
    FormFile file = new MockFormFile("testFilename");
    BirtReportsUploadActionForm actionForm = new BirtReportsUploadActionForm();
    setRequestPathInfo("/birtReportsUploadAction.do");
    addRequestParameter("method", "upload");
    actionForm.setFile(file);
    actionForm.setReportTitle("existingTitle");
    actionForm.setReportCategoryId("1");
    actionForm.setIsActive("1");
    setActionForm(actionForm);
    actionPerform();
    verifyForward("preview_failure");
    String[] errors = { ReportsConstants.ERROR_NOMOREDYNAMICACTIVITYID };
    verifyActionErrors(errors);
    deleteActivityForTest(activityEntity);
}
Also used : ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) MockFormFile(org.mifos.reports.business.MockFormFile) BirtReportsUploadActionForm(org.mifos.reports.struts.actionforms.BirtReportsUploadActionForm) FormFile(org.apache.struts.upload.FormFile) MockFormFile(org.mifos.reports.business.MockFormFile) Test(org.junit.Test)

Example 15 with FormFile

use of org.apache.struts.upload.FormFile in project head by mifos.

the class BirtReportsUploadActionStrutsTest method testUpgradePathNotRuined.

@Test
public void testUpgradePathNotRuined() throws Exception {
    // TODO Temporary solution to avoid unsuccessful test on some machines
    // Retrieve initial activities information
    List<ActivityEntity> activities = new RolesPermissionsBusinessService().getActivities();
    int newActivityId = activities.get(activities.size() - 1).getId() + 1;
    // Upload a report creating an activity for the report
    FormFile file = new MockFormFile("testFilename.rptdesign");
    BirtReportsUploadActionForm actionForm = new BirtReportsUploadActionForm();
    setRequestPathInfo("/birtReportsUploadAction.do");
    addRequestParameter("method", "upload");
    actionForm.setFile(file);
    actionForm.setReportTitle("exsitTitle");
    actionForm.setReportCategoryId("1");
    actionForm.setIsActive("1");
    setActionForm(actionForm);
    actionPerform();
    Assert.assertEquals(0, getErrorSize());
    Assert.assertNotNull(request.getAttribute("report"));
    // Simulate an future activities upgrade
    AddActivity activity = null;
    try {
        activity = new AddActivity((short) newActivityId, SecurityConstants.ORGANIZATION_MANAGEMENT, "no name");
        activity.upgrade(StaticHibernateUtil.getSessionTL().connection());
    } catch (Exception e) {
        legacyRolesPermissionsDao.delete(request.getAttribute("report"));
        StaticHibernateUtil.flushSession();
        throw e;
    }
    // Undo
    ReportsBO report = (ReportsBO) request.getAttribute("report");
    removeReport(report.getReportId());
}
Also used : RolesPermissionsBusinessService(org.mifos.security.rolesandpermission.business.service.RolesPermissionsBusinessService) ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) MockFormFile(org.mifos.reports.business.MockFormFile) AddActivity(org.mifos.security.AddActivity) BirtReportsUploadActionForm(org.mifos.reports.struts.actionforms.BirtReportsUploadActionForm) MifosRuntimeException(org.mifos.core.MifosRuntimeException) IOException(java.io.IOException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) FormFile(org.apache.struts.upload.FormFile) MockFormFile(org.mifos.reports.business.MockFormFile) ReportsBO(org.mifos.reports.business.ReportsBO) Test(org.junit.Test)

Aggregations

FormFile (org.apache.struts.upload.FormFile)16 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)6 InputStream (java.io.InputStream)5 ArrayList (java.util.ArrayList)4 ClientCustActionForm (org.mifos.customers.client.struts.actionforms.ClientCustActionForm)4 BirtReportsUploadActionForm (org.mifos.reports.struts.actionforms.BirtReportsUploadActionForm)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ClientNameDetailDto (org.mifos.dto.screen.ClientNameDetailDto)3 UploadedFileDto (org.mifos.dto.screen.UploadedFileDto)3 ReportsBO (org.mifos.reports.business.ReportsBO)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 List (java.util.List)2 ActionMessage (org.apache.struts.action.ActionMessage)2 Test (org.junit.Test)2 AccountActionEntity (org.mifos.accounts.business.AccountActionEntity)2 AccountStateEntity (org.mifos.accounts.business.AccountStateEntity)2 CustomFieldDto (org.mifos.dto.domain.CustomFieldDto)2