Search in sources :

Example 1 with ParseResultDto

use of org.mifos.dto.domain.ParseResultDto 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 2 with ParseResultDto

use of org.mifos.dto.domain.ParseResultDto in project head by mifos.

the class ImportTransactionsServiceFacadeWebTier method confirmImport.

@Override
public ParseResultDto confirmImport(String importPluginClassname, String tempFileName) {
    MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(mifosUser);
    FileInputStream fileInput = null;
    try {
        final TransactionImport transactionImport = getInitializedImportPlugin(importPluginClassname, userContext.getId());
        fileInput = new FileInputStream(tempFileName);
        final ParseResultDto importResult = transactionImport.parse(fileInput);
        fileInput.close();
        fileInput = new FileInputStream(tempFileName);
        if (importPluginClassname.equalsIgnoreCase("org.almajmoua.AudiBankXlsImporter")) {
            importResult.setTrxIdsToUndo(transactionImport.storeForUndoImport(fileInput));
        } else {
            transactionImport.store(fileInput);
        }
        return importResult;
    } catch (Exception e) {
        throw new MifosRuntimeException(e);
    } finally {
        if (fileInput != null) {
            try {
                fileInput.close();
            } catch (Exception e2) {
                throw new MifosRuntimeException(e2);
            }
        }
    }
}
Also used : UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) ParseResultDto(org.mifos.dto.domain.ParseResultDto) FileInputStream(java.io.FileInputStream) TransactionImport(org.mifos.accounts.api.TransactionImport) BusinessRuleException(org.mifos.service.BusinessRuleException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 3 with ParseResultDto

use of org.mifos.dto.domain.ParseResultDto in project head by mifos.

the class ImportTransactionsServiceFacadeWebTier method parseImportTransactions.

@Override
public ParseResultDto parseImportTransactions(String importPluginClassname, InputStream inputStream) {
    MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(mifosUser);
    final TransactionImport ti = getInitializedImportPlugin(importPluginClassname, userContext.getId());
    final ParseResultDto importResult = ti.parse(inputStream);
    int numberRowSuccessfullyParsed = ti.getSuccessfullyParsedRows();
    importResult.setNumberRowSuccessfullyParsed(numberRowSuccessfullyParsed);
    String statusLogFile = generateStatusLogfile(importResult, ti);
    importResult.setStatusLogFile(statusLogFile);
    return importResult;
}
Also used : UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) ParseResultDto(org.mifos.dto.domain.ParseResultDto) TransactionImport(org.mifos.accounts.api.TransactionImport)

Example 4 with ParseResultDto

use of org.mifos.dto.domain.ParseResultDto 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

ParseResultDto (org.mifos.dto.domain.ParseResultDto)4 TransactionImport (org.mifos.accounts.api.TransactionImport)2 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)2 ImportTransactionsActionForm (org.mifos.application.importexport.struts.actionforms.ImportTransactionsActionForm)2 MifosUser (org.mifos.security.MifosUser)2 UserContext (org.mifos.security.util.UserContext)2 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 FormFile (org.apache.struts.upload.FormFile)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 Money (org.mifos.framework.util.helpers.Money)1 BusinessRuleException (org.mifos.service.BusinessRuleException)1