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");
}
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);
}
}
}
}
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;
}
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");
}
Aggregations