Search in sources :

Example 1 with ImportTransactionsActionForm

use of org.mifos.application.importexport.struts.actionforms.ImportTransactionsActionForm in project head by mifos.

the class ImportTransactionsAction method load.

public ActionForward load(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    final ImportTransactionsActionForm importTransactionsForm = (ImportTransactionsActionForm) form;
    importTransactionsForm.clear();
    clearOurSessionVariables(request.getSession());
    final List<ListItem<String>> importPlugins = this.importTransactionsServiceFacade.retrieveImportPlugins();
    request.setAttribute("importPlugins", importPlugins);
    return mapping.findForward("import_load");
}
Also used : ImportTransactionsActionForm(org.mifos.application.importexport.struts.actionforms.ImportTransactionsActionForm) ListItem(org.mifos.application.servicefacade.ListItem)

Example 2 with ImportTransactionsActionForm

use of org.mifos.application.importexport.struts.actionforms.ImportTransactionsActionForm in project head by mifos.

the class ImportTransactionsAction method confirm.

public ActionForward confirm(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    final String tempFilename = (String) request.getSession().getAttribute(IMPORT_TEMPORARY_FILENAME);
    final String importPluginClassname = (String) request.getSession().getAttribute(IMPORT_PLUGIN_CLASSNAME);
    final ImportTransactionsActionForm importTransactionsForm = (ImportTransactionsActionForm) form;
    final String importTransactionsFileName = importTransactionsForm.getImportTransactionsFile().getFileName();
    final ParseResultDto importResult = this.importTransactionsServiceFacade.confirmImport(importPluginClassname, tempFilename);
    if (null != importResult.getParseErrors() && !importResult.getParseErrors().isEmpty()) {
        for (String error : importResult.getParseErrors()) {
            logger.warn(importTransactionsFileName + ": " + error);
        }
    }
    this.importTransactionsServiceFacade.saveImportedFileName(importTransactionsFileName, importPluginClassname, importResult.getTrxIdsToUndo());
    logger.info(importResult.getNumberRowSuccessfullyParsed() + " transaction(s) imported from " + importTransactionsFileName + ".");
    return mapping.findForward("import_confirm");
}
Also used : ImportTransactionsActionForm(org.mifos.application.importexport.struts.actionforms.ImportTransactionsActionForm) ParseResultDto(org.mifos.dto.domain.ParseResultDto)

Example 3 with ImportTransactionsActionForm

use of org.mifos.application.importexport.struts.actionforms.ImportTransactionsActionForm 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)

Aggregations

ImportTransactionsActionForm (org.mifos.application.importexport.struts.actionforms.ImportTransactionsActionForm)3 ParseResultDto (org.mifos.dto.domain.ParseResultDto)2 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 FormFile (org.apache.struts.upload.FormFile)1 ListItem (org.mifos.application.servicefacade.ListItem)1 Money (org.mifos.framework.util.helpers.Money)1