@Override public Result downloadAndParse() { Result result = officeSheetPopulator.downloadAndParse(); if (result.isSuccess()) result = clientSheetPopulator.downloadAndParse(); if (result.isSuccess()) result = extrasSheetPopulator.downloadAndParse(); if (result.isSuccess()) { try { restClient.createAuthToken(); content = restClient.get("savingsaccounts?limit=-1"); Gson gson = new Gson(); JsonParser parser = new JsonParser(); JsonObject obj = parser.parse(content).getAsJsonObject(); JsonArray array = obj.getAsJsonArray("pageItems"); Iterator<JsonElement> iterator = array.iterator(); while (iterator.hasNext()) { JsonElement json = iterator.next(); CompactSavingsAccount savingsAccount = gson.fromJson(json, CompactSavingsAccount.class); if (savingsAccount.isActive()) savings.add(savingsAccount); } } catch (Exception e) { result.addError(e.getMessage()); logger.error(e.getMessage()); } } return result; }
@Override public Result upload() { Result result = new Result(); Sheet savingsTransactionSheet = workbook.getSheet("RecurringDepositTransaction"); for (Transaction transaction : savingsTransactions) { try { Gson gson = new Gson(); String payload = gson.toJson(transaction); restClient.post( "recurringdepositaccounts/" + transaction.getAccountId() + "/transactions?command=" + transaction.getTransactionType(), payload); Cell statusCell = savingsTransactionSheet.getRow(transaction.getRowIndex()).createCell(STATUS_COL); statusCell.setCellValue("Imported"); statusCell.setCellStyle(getCellStyle(workbook, IndexedColors.LIGHT_GREEN)); } catch (Exception e) { Cell savingsAccountIdCell = savingsTransactionSheet .getRow(transaction.getRowIndex()) .createCell(SAVINGS_ACCOUNT_NO_COL); savingsAccountIdCell.setCellValue(transaction.getAccountId()); String message = parseStatus(e.getMessage()); Cell statusCell = savingsTransactionSheet.getRow(transaction.getRowIndex()).createCell(STATUS_COL); statusCell.setCellValue(message); statusCell.setCellStyle(getCellStyle(workbook, IndexedColors.RED)); result.addError("Row = " + transaction.getRowIndex() + " ," + message); } } savingsTransactionSheet.setColumnWidth(STATUS_COL, 15000); writeString(STATUS_COL, savingsTransactionSheet.getRow(0), "Status"); return result; }