@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 populate(Workbook workbook) {
   Sheet savingsTransactionSheet = workbook.createSheet("SavingsTransaction");
   setLayout(savingsTransactionSheet);
   Result result = officeSheetPopulator.populate(workbook);
   if (result.isSuccess()) result = clientSheetPopulator.populate(workbook);
   if (result.isSuccess()) result = extrasSheetPopulator.populate(workbook);
   if (result.isSuccess()) result = populateLoansTable(savingsTransactionSheet);
   if (result.isSuccess()) result = setRules(savingsTransactionSheet);
   setDefaults(savingsTransactionSheet);
   return result;
 }
  private void setNames(Sheet worksheet) {
    Workbook savingsTransactionWorkbook = worksheet.getWorkbook();
    ArrayList<String> officeNames =
        new ArrayList<String>(Arrays.asList(officeSheetPopulator.getOfficeNames()));

    // Office Names
    Name officeGroup = savingsTransactionWorkbook.createName();
    officeGroup.setNameName("Office");
    officeGroup.setRefersToFormula("Offices!$B$2:$B$" + (officeNames.size() + 1));

    // Clients Named after Offices
    for (Integer i = 0; i < officeNames.size(); i++) {
      Integer[] officeNameToBeginEndIndexesOfClients =
          clientSheetPopulator.getOfficeNameToBeginEndIndexesOfClients().get(i);
      Name name = savingsTransactionWorkbook.createName();
      if (officeNameToBeginEndIndexesOfClients != null) {
        name.setNameName("Client_" + officeNames.get(i));
        name.setRefersToFormula(
            "Clients!$B$"
                + officeNameToBeginEndIndexesOfClients[0]
                + ":$B$"
                + officeNameToBeginEndIndexesOfClients[1]);
      }
    }

    // Counting clients with active savings and starting and end addresses of cells for naming
    HashMap<String, Integer[]> clientNameToBeginEndIndexes = new HashMap<String, Integer[]>();
    ArrayList<String> clientsWithActiveSavings = new ArrayList<String>();
    int startIndex = 1, endIndex = 1;
    String clientName = "";

    for (int i = 0; i < savings.size(); i++) {
      if (!clientName.equals(savings.get(i).getClientName())) {
        endIndex = i + 1;
        clientNameToBeginEndIndexes.put(clientName, new Integer[] {startIndex, endIndex});
        startIndex = i + 2;
        clientName = savings.get(i).getClientName();
        clientsWithActiveSavings.add(clientName);
      }
      if (i == savings.size() - 1) {
        endIndex = i + 2;
        clientNameToBeginEndIndexes.put(clientName, new Integer[] {startIndex, endIndex});
      }
    }

    // Account Number Named  after Clients
    for (int j = 0; j < clientsWithActiveSavings.size(); j++) {
      Name name = savingsTransactionWorkbook.createName();
      name.setNameName("Account_" + clientsWithActiveSavings.get(j).replaceAll(" ", "_"));
      name.setRefersToFormula(
          "SavingsTransaction!$Q$"
              + clientNameToBeginEndIndexes.get(clientsWithActiveSavings.get(j))[0]
              + ":$Q$"
              + clientNameToBeginEndIndexes.get(clientsWithActiveSavings.get(j))[1]);
    }

    // Payment Type Name
    Name paymentTypeGroup = savingsTransactionWorkbook.createName();
    paymentTypeGroup.setNameName("PaymentTypes");
    paymentTypeGroup.setRefersToFormula(
        "Extras!$D$2:$D$" + (extrasSheetPopulator.getPaymentTypesSize() + 1));
  }