use of org.mifos.dto.domain.ParsedSavingsDto in project head by mifos.
the class ImportSavingsController method parseFile.
public ParsedSavingsDto parseFile(ImportSavingsFormBean importSavingsFormBean) {
ParsedSavingsDto result = null;
CommonsMultipartFile file = importSavingsFormBean.getFile();
InputStream is = null;
if (file == null) {
throw new MifosRuntimeException("File cannot be null");
}
try {
is = file.getInputStream();
result = importLoansSavingsFacade.parseImportSavings(is);
} catch (IOException ex) {
result = importLoansSavingsFacade.createSavingsDtoFromSingleError(ex.getMessage());
} finally {
closeStream(is);
importSavingsFormBean.setFile(null);
}
return result;
}
use of org.mifos.dto.domain.ParsedSavingsDto in project head by mifos.
the class ImportLoansSavingsFacadeWebTier method parseImportSavings.
@Override
public ParsedSavingsDto parseImportSavings(InputStream stream) {
xlsSavingsAccount.setLocale(personelServiceFacade.getUserPreferredLocale());
ParsedSavingsDto savingDto = xlsSavingsAccount.parse(stream);
return savingDto;
}
use of org.mifos.dto.domain.ParsedSavingsDto in project head by mifos.
the class XlsSavingsAccountImporter method parse.
public ParsedSavingsDto parse(InputStream is) {
ParsedSavingsDto result = null;
List<String> errors = new ArrayList<String>();
// temporary list for new accounts numbers, currently
List<String> newAccountsNumbers = new ArrayList<String>();
// not used
List<ImportedSavingDetail> parsedSavingDetails = new ArrayList<ImportedSavingDetail>();
try {
HSSFWorkbook workbook = new HSSFWorkbook(is);
HSSFSheet sheet = workbook.getSheetAt(0);
HSSFRow row = sheet.getRow(XlsSavingsImportTemplateConstants.FIRST_ROW_WITH_DATA.getValue());
if (row == null) {
throw new XlsParsingException(getMessage(XlsMessageConstants.NOT_ENOUGH_INPUT_ROW, null));
}
Iterator<Row> iterator = sheet.rowIterator();
while (iterator.hasNext() && (iterator.next().getRowNum() < XlsSavingsImportTemplateConstants.FIRST_ROW_WITH_DATA.getValue() - 1)) ;
while (iterator.hasNext()) {
row = (HSSFRow) iterator.next();
List<Object> params = new ArrayList<Object>();
XlsSavingsImportTemplateConstants currentCell = XlsSavingsImportTemplateConstants.ACCOUNT_NUMBER;
try {
String accountNumber = getCellStringValue(row, currentCell);
if (StringUtils.isBlank(accountNumber)) {
accountNumber = null;
} else if (!StringUtils.isBlank(accountNumber)) {
// ...but it's duplicate
if (!validateAccountNumber(accountNumber, newAccountsNumbers)) {
params.clear();
params.add(accountNumber);
throw new XlsParsingException(getCellError(XlsMessageConstants.DUPLICATE_GLOBAL_NUM_ERROR, row, currentCell.getValue(), params));
}
}
currentCell = XlsSavingsImportTemplateConstants.CUSTOMER_GLOBAL_ID;
String customerGlobalId = getCellStringValue(row, currentCell);
if (customerGlobalId.isEmpty()) {
params.clear();
params.add(customerGlobalId);
throw new XlsParsingException(getCellError(XlsMessageConstants.CUSTOMER_NOT_BLANK, row, currentCell.getValue(), params));
}
CustomerBO customerBO = null;
customerBO = validateCustomerGlobalId(customerGlobalId);
if (customerBO == null) {
params.clear();
params.add(customerGlobalId);
throw new XlsParsingException(getCellError(XlsMessageConstants.CUSTOMER_NOT_FOUND, row, currentCell.getValue(), params));
}
currentCell = XlsSavingsImportTemplateConstants.PRODUCT_NAME;
String productName = getCellStringValue(row, currentCell);
PrdOfferingDto prdOfferingDto = null;
prdOfferingDto = validateProductName(productName, customerBO, row, currentCell.getValue());
currentCell = XlsSavingsImportTemplateConstants.STATUS_NAME;
String statusName = getCellStringValue(row, currentCell);
XlsLoanSavingsAccountStatesConstants statusConstant = null;
statusConstant = validateStatusName(statusName, customerBO, row, currentCell.getValue());
currentCell = XlsSavingsImportTemplateConstants.CANCEL_FlAG_REASON;
String cancelReason = getCellStringValue(row, currentCell);
XlsLoanSavingsFlagsConstants flagConstant = null;
flagConstant = validateStatusFlagReason(cancelReason, statusName, AccountTypes.SAVINGS_ACCOUNT, row, currentCell.getValue());
currentCell = XlsSavingsImportTemplateConstants.SAVINGS_AMOUNT;
BigDecimal savingAmount = getCellDecimalValue(row, currentCell);
if (savingAmount == BigDecimal.valueOf(0) || null == savingAmount) {
savingAmount = savingsProductDao.findBySystemId(prdOfferingDto.getGlobalPrdOfferingNum()).getRecommendedAmount().getAmount();
}
currentCell = XlsSavingsImportTemplateConstants.SAVINGS_BALANCE;
BigDecimal savingBalance = getCellDecimalValue(row, currentCell);
if (savingBalance == null) {
savingBalance = BigDecimal.valueOf(0);
}
if (accountNumber != null) {
newAccountsNumbers.add(accountNumber);
}
LocalDate date = new LocalDate();
Short flagValue = flagConstant == null ? null : flagConstant.getFlag().getValue();
ImportedSavingDetail detail = new ImportedSavingDetail(accountNumber, customerGlobalId, prdOfferingDto.getGlobalPrdOfferingNum(), statusConstant.getState().getValue(), flagValue, savingAmount, savingBalance, date);
parsedSavingDetails.add(detail);
} catch (XlsParsingException xex) {
if (xex.isMultiple()) {
for (String msg : xex.getMessages()) {
errors.add(msg);
}
} else {
errors.add(xex.getMessage());
}
} catch (Exception cex) {
errors.add(cex.getMessage());
}
}
} catch (Exception ex) {
errors.add(ex.getMessage());
}
result = new ParsedSavingsDto(errors, parsedSavingDetails);
return result;
}
Aggregations